org.eclipse.mylyn.wikitext.ui_1.6.1.v20120425-0100

  //   Java source line #532	-> byte code offset #37
    //   Java source line #534	-> byte code offset #47
    //   Java source line #535	-> byte code offset #56
    //   Java source line #536	-> byte code offset #58
    //   Java source line #537	-> byte code offset #63
    //   Java source line #536	-> byte code offset #66
    //   Java source line #538	-> byte code offset #71
    //   Java source line #539	-> byte code offset #79
    //   Java source line #541	-> byte code offset #80
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	82	0	markupLanguage	MarkupLanguage
    //   0	82	1	markupContent	String
    //   1	80	2	markupSavePath	String
    //   36	36	3	file	java.io.File
    //   45	22	4	writer	java.io.Writer
    //   56	8	5	localObject	Object
    //   79	1	6	localIOException	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   47	56	56	finally
    //   2	76	79	java/io/IOException
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation;
import org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo;
import org.eclipse.ui.texteditor.IDocumentProvider;

public class MarkupDocumentProvider
  extends TextFileDocumentProvider
{
  private MarkupLanguage markupLanguage;
  
  public MarkupDocumentProvider()
  {
    super(new MarkupFileDocumentProvider(null));
  }
  
  public MarkupLanguage getMarkupLanguage()
  {
    return markupLanguage;
  }
  
  public void setMarkupLanguage(MarkupLanguage markupLanguage)
  {
    this.markupLanguage = markupLanguage;
  }
  
  public void connect(Object element)
    throws CoreException
  {
    super.connect(element);
    IDocument document = super.getDocument(element);
    connectPartitioner(document);
  }
  
  private void connectPartitioner(IDocument document)
  {
    FastMarkupPartitioner partitioner = new FastMarkupPartitioner();
    partitioner.setMarkupLanguage(markupLanguage == null ? null : markupLanguage.clone());
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
  }
  
  protected TextFileDocumentProvider.FileInfo createFileInfo(Object element)
    throws CoreException
  {
    if (dispatchToParent(element)) {
      return null;
    }
    return super.createFileInfo(element);
  }
  
  private boolean dispatchToParent(Object element)
  {
    return ((element instanceof IStorageEditorInput)) || ((element instanceof IFileEditorInput));
  }
  
  protected TextFileDocumentProvider.DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite)
    throws CoreException
  {
    if (dispatchToParent(element)) {
      new TextFileDocumentProvider.DocumentProviderOperation()
      {
        protected void execute(IProgressMonitor monitor)
          throws CoreException
        {
          getParentProvider().saveDocument(monitor, element, document, overwrite);
        }
      };
    }
    return super.createSaveOperation(element, document, overwrite);
  }
  
  private static class MarkupFileDocumentProvider
    extends FileDocumentProvider
  {
    protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
      throws CoreException
    {
      super.setDocumentContent(document, contentStream, encoding);
      MarkupDocumentProvider.cleanUpEolMarkers(document);
    }
    
    protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
      throws CoreException
    {
      String platformEolMarker = Text.DELIMITER;
      if (platformEolMarker.equals("\r"))
      {
        Document newDocument = new Document(document.get());
        MarkupDocumentProvider.replaceLineDelimiters(newDocument, "\n");
        document = newDocument;
      }
      super.doSaveDocument(monitor, element, document, overwrite);
    }
  }
  
  public static void cleanUpEolMarkers(IDocument document)
  {
    String platformEolMarker = Text.DELIMITER;
    replaceLineDelimiters(document, platformEolMarker);
  }
  
  private static void replaceLineDelimiters(IDocument document, String newLineDelimiter)
  {
    document.set(Pattern.compile("(\r\n|\n|\r)").matcher(document.get()).replaceAll(newLineDelimiter));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupDocumentProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.util.List;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
import org.eclipse.mylyn.wikitext.core.parser.LinkAttributes;
import org.eclipse.mylyn.wikitext.core.parser.Locator;
import org.eclipse.mylyn.wikitext.core.parser.builder.NoOpDocumentBuilder;

class MarkupHyperlinkDetector$1
  extends NoOpDocumentBuilder
{
  MarkupHyperlinkDetector$1(MarkupHyperlinkDetector paramMarkupHyperlinkDetector, List paramList) {}
  
  public void link(Attributes attributes, String hrefOrHashName, String text)
  {
    if ((hrefOrHashName != null) && (!hrefOrHashName.startsWith("#")))
    {
      IRegion region = createRegion();
      val$links.add(new MarkupHyperlinkDetector.HyperlinkDescriptor(hrefOrHashName, region));
    }
  }
  
  private IRegion createRegion()
  {
    int offset = getLocator().getLineCharacterOffset();
    int length = getLocator().getLineSegmentEndOffset() - offset;
    return new Region(offset, length);
  }
  
  public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
  {
    if ((type == DocumentBuilder.SpanType.LINK) && 
      ((attributes instanceof LinkAttributes)))
    {
      LinkAttributes linkAttributes = (LinkAttributes)attributes;
      if ((linkAttributes.getHref() != null) && (!linkAttributes.getHref().startsWith("#")))
      {
        IRegion region = createRegion();
        val$links.add(new MarkupHyperlinkDetector.HyperlinkDescriptor(linkAttributes.getHref(), region));
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupHyperlinkDetector.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;

public class Span
  extends Segment<Span>
{
  private final DocumentBuilder.SpanType type;
  
  public Span(DocumentBuilder.SpanType type, int offset, int length)
  {
    super(offset, length);
    this.type = type;
  }
  
  public Span(DocumentBuilder.SpanType type, Attributes attributes, int offset, int length)
  {
    super(attributes, offset, length);
    this.type = type;
  }
  
  public DocumentBuilder.SpanType getType()
  {
    return type;
  }
  
  public String toString()
  {
    return String.format("<%s offset=\"%s\" length=\"%s\"/>", new Object[] { type.name(), Integer.valueOf(getOffset()), Integer.valueOf(getLength()) });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.Span
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;

public class MarkupDamagerRepairer
  extends DefaultDamagerRepairer
{
  public MarkupDamagerRepairer(ITokenScanner scanner)
  {
    super(scanner);
  }
  
  public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged)
  {
    return partition;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupDamagerRepairer
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.osgi.util.NLS;

class FastMarkupPartitioner$PartitionTokenScanner
  implements IPartitionTokenScanner
{
  private final Map<Integer, PartitioningResult> cachedPartitioning = new HashMap();
  private MarkupLanguage markupLanguage;
  private int index = -1;
  private PartitioningResult lastComputed;
  
  private static class PartitioningResult
  {
    int offset;
    int length;
    ITypedRegion[] partitions;
    
    public PartitioningResult(int offset, int length, ITypedRegion[] partitions)
    {
      this.offset = offset;
      this.length = length;
      this.partitions = partitions;
    }
    
    public boolean overlapsWith(PartitioningResult other)
    {
      int end = offset + length;
      int thisEnd = offset + length;
      if (end > thisEnd) {
        return offset < thisEnd;
      }
      if (thisEnd > end) {
        return offset < end;
      }
      return true;
    }
  }
  
  public ITypedRegion[] computePartitions(IDocument document, int offset, int length)
  {
    if ((lastComputed != null) && (lastComputed.offset <= offset) && 
      (lastComputed.offset + lastComputed.length >= offset + length)) {
      return lastComputed.partitions;
    }
    PartitioningResult result = (PartitioningResult)cachedPartitioning.get(Integer.valueOf(offset));
    if ((result == null) || (length != length))
    {
      result = computeOlp(document, offset, length, -1);
      updateCache(result, document.getLength());
    }
    return partitions;
  }
  
  public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset)
  {
    lastComputed = computeOlp(document, offset, length, partitionOffset);
    index = -1;
    updateCache(lastComputed, document.getLength());
  }
  
  private void updateCache(PartitioningResult updated, int maxLength)
  {
    Iterator<PartitioningResult> it = cachedPartitioning.values().iterator();
    while (it.hasNext())
    {
      PartitioningResult result = (PartitioningResult)it.next();
      if ((offset >= maxLength) || ((updated != null) && (result.overlapsWith(updated)))) {
        it.remove();
      }
    }
    if (updated != null) {
      cachedPartitioning.put(Integer.valueOf(offset), updated);
    }
  }
  
  private PartitioningResult computeOlp(IDocument document, int offset, int length, int partitionOffset)
  {
    if (markupLanguage == null) {
      return new PartitioningResult(offset, length, null);
    }
    int startOffset = partitionOffset == -1 ? offset : Math.min(offset, partitionOffset);
    int endOffset = offset + length;
    
    MarkupParser markupParser = new MarkupParser(markupLanguage);
    markupLanguage.setBlocksOnly(partitionOffset != -1);
    markupLanguage.setFilterGenerativeContents(true);
    FastMarkupPartitioner.PartitionBuilder partitionBuilder = new FastMarkupPartitioner.PartitionBuilder(startOffset, markupLanguage.isBlocksOnly());
    markupParser.setBuilder(partitionBuilder);
    String markupContent;
    try
    {
      markupContent = document.get(startOffset, endOffset - startOffset);
    }
    catch (BadLocationException localBadLocationException)
    {
      String markupContent;
      markupContent = document.get();
    }
    markupParser.parse(markupContent);
    
    ITypedRegion[] latestPartitions = (ITypedRegion[])FastMarkupPartitioner.PartitionBuilder.access$0(partitionBuilder).toArray(new ITypedRegion[FastMarkupPartitioner.PartitionBuilder.access$0(partitionBuilder).size()]);
    List<ITypedRegion> partitioning = new ArrayList(latestPartitions.length);
    
    ITypedRegion previous = null;
    ITypedRegion[] arrayOfITypedRegion1;
    int j = (arrayOfITypedRegion1 = latestPartitions).length;
    for (int i = 0; i < j; i++)
    {
      ITypedRegion region = arrayOfITypedRegion1[i];
      if (region.getLength() != 0)
      {
        if ((previous != null) && (region.getOffset() < previous.getOffset() + previous.getLength()))
        {
          String message = NLS.bind(Messages.FastMarkupPartitioner_0, new Object[] { region, previous, 
            markupLanguage.getName() });
          if (FastMarkupPartitioner.debug)
          {
            String markupSavePath = FastMarkupPartitioner.access$0(markupLanguage, markupContent);
            message = NLS.bind(Messages.FastMarkupPartitioner_1, new Object[] { message, markupSavePath });
          }
          throw new IllegalStateException(message);
        }
        previous = region;
        if ((region.getOffset() >= startOffset) && (region.getOffset() < endOffset)) {
          partitioning.add(region);
        } else {
          if (region.getOffset() >= offset + length) {
            break;
          }
        }
      }
    }
    return new PartitioningResult(offset, length, (ITypedRegion[])partitioning.toArray(new ITypedRegion[partitioning.size()]));
  }
  
  public void setMarkupLanguage(MarkupLanguage markupLanguage)
  {
    this.markupLanguage = markupLanguage;
  }
  
  public int getTokenLength()
  {
    return lastComputed.partitions[index].getLength();
  }
  
  public int getTokenOffset()
  {
    return lastComputed.partitions[index].getOffset();
  }
  
  public IToken nextToken()
  {
    if ((lastComputed == null) || (lastComputed.partitions == null) || (++index >= lastComputed.partitions.length)) {
      return Token.EOF;
    }
    return new Token(lastComputed.partitions[index].getType());
  }
  
  public void setRange(IDocument document, int offset, int length)
  {
    setPartialRange(document, offset, length, null, -1);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner.PartitionTokenScanner
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.mylyn.internal.wikitext.ui.WikiTextUiPlugin;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

class MarkupHyperlinkDetector$EditFileHyperlink
  implements IHyperlink
{
  private final IFile file;
  private final IRegion region;
  
  protected MarkupHyperlinkDetector$EditFileHyperlink(IFile file, IRegion region)
  {
    this.file = file;
    this.region = region;
  }
  
  public IRegion getHyperlinkRegion()
  {
    return region;
  }
  
  public String getTypeLabel()
  {
    return null;
  }
  
  public String getHyperlinkText()
  {
    return NLS.bind(Messages.MarkupHyperlinkDetector_openFileInEditor, file.getName());
  }
  
  public void open()
  {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage activePage = window.getActivePage();
    try
    {
      IDE.openEditor(activePage, file);
    }
    catch (PartInitException e)
    {
      WikiTextUiPlugin.getDefault().log(e);
      MessageDialog.openError(window.getShell(), Messages.MarkupHyperlinkDetector_unexpectedError, 
        NLS.bind(Messages.MarkupHyperlinkDetector_openException, file.getName(), e.getMessage()));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupHyperlinkDetector.EditFileHyperlink
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.ITypedRegion;

public class FastMarkupPartitioner$MarkupPartition
  implements ITypedRegion
{
  private final Block block;
  private int offset;
  private int length;
  private List<Span> spans;
  
  private FastMarkupPartitioner$MarkupPartition(Block block, int offset, int length)
  {
    this.block = block;
    this.offset = offset;
    this.length = length;
  }
  
  public int getOffset()
  {
    return offset;
  }
  
  public int getLength()
  {
    return length;
  }
  
  public String getType()
  {
    return "__markup_block";
  }
  
  public Block getBlock()
  {
    return block;
  }
  
  public List<Span> getSpans()
  {
    if (this.spans == null)
    {
      List<Span> spans = new ArrayList();
      getSpans(block, spans);
      this.spans = spans;
    }
    return this.spans;
  }
  
  private void getSpans(Block block, List<Span> spans)
  {
    for (Segment<?> s : block.getChildren().asList()) {
      if ((s.getOffset() >= offset) && (s.getOffset() < offset + length)) {
        if ((s instanceof Span)) {
          spans.add((Span)s);
        } else {
          getSpans((Block)s, spans);
        }
      }
    }
  }
  
  public String toString()
  {
    return String.format("MarkupPartition(type=%s,offset=%s,length=%s,end=%s)", new Object[] { block.getType(), Integer.valueOf(offset), 
      Integer.valueOf(length), Integer.valueOf(offset + length) });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner.MarkupPartition
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.util.Iterator;
import java.util.List;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;

public class Segment<ChildType extends Segment<?>>
{
  private int offset;
  private int length;
  private Attributes attributes;
  private Segments<ChildType> children = new Segments();
  private Segment<?> parent;
  
  public Segment(int offset, int length)
  {
    if (offset < 0) {
      throw new IllegalArgumentException();
    }
    if (length < 0) {
      throw new IllegalArgumentException();
    }
    this.offset = offset;
    this.length = length;
  }
  
  public Segment(Attributes attributes, int offset, int length)
  {
    this(offset, length);
    this.attributes = attributes;
  }
  
  public int getEndOffset()
  {
    return offset + length;
  }
  
  public int getOffset()
  {
    return offset;
  }
  
  public int getLength()
  {
    return length;
  }
  
  public void setLength(int length)
  {
    if (length < 0) {
      throw new IllegalArgumentException();
    }
    this.length = length;
    if (!children.isEmpty())
    {
      int endOffset = getEndOffset();
      Iterator<ChildType> childIt = children.asList().iterator();
      while (childIt.hasNext())
      {
        ChildType child = (Segment)childIt.next();
        if (child.getOffset() >= endOffset)
        {
          childIt.remove();
        }
        else if (child.getEndOffset() > endOffset)
        {
          int newChildLength = endOffset - child.getOffset();
          child.setLength(newChildLength);
        }
      }
    }
  }
  
  public void add(ChildType child)
  {
    if (child.getOffset() < offset) {
      throw new IllegalArgumentException();
    }
    if (child.getEndOffset() > getEndOffset()) {
      throw new IllegalArgumentException();
    }
    children.add(child);
    parent = this;
  }
  
  public Segment<?> getParent()
  {
    return parent;
  }
  
  public Segments<ChildType> getChildren()
  {
    return children;
  }
  
  public Attributes getAttributes()
  {
    return attributes;
  }
  
  public void setAttributes(Attributes attributes)
  {
    this.attributes = attributes;
  }
  
  public void replaceChildren(Segment<?> s)
  {
    children = children;
    if (children != null) {
      for (ChildType child : children.asList()) {
        parent = this;
      }
    }
    children = null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.Segment
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import org.eclipse.jface.text.ITypedRegion;

class FastMarkupPartitioner$PartitionTokenScanner$PartitioningResult
{
  int offset;
  int length;
  ITypedRegion[] partitions;
  
  public FastMarkupPartitioner$PartitionTokenScanner$PartitioningResult(int offset, int length, ITypedRegion[] partitions)
  {
    this.offset = offset;
    this.length = length;
    this.partitions = partitions;
  }
  
  public boolean overlapsWith(PartitioningResult other)
  {
    int end = offset + length;
    int thisEnd = offset + length;
    if (end > thisEnd) {
      return offset < thisEnd;
    }
    if (thisEnd > end) {
      return offset < end;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner.PartitionTokenScanner.PartitioningResult
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import org.eclipse.osgi.util.NLS;

class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.messages";
  public static String FastMarkupPartitioner_0;
  public static String FastMarkupPartitioner_1;
  public static String MarkupHyperlinkDetector_openException;
  public static String MarkupHyperlinkDetector_openFileInEditor;
  public static String MarkupHyperlinkDetector_unexpectedError;
  public static String MarkupTokenScanner_2;
  public static String MarkupTokenScanner_3;
  public static String MarkupTokenScanner_badTokenLength;
  public static String MarkupTokenScanner_badTokenOffset;
  
  static
  {
    NLS.initializeMessages("org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.Messages
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.mylyn.internal.wikitext.ui.WikiTextUiPlugin;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
import org.eclipse.mylyn.wikitext.core.parser.LinkAttributes;
import org.eclipse.mylyn.wikitext.core.parser.Locator;
import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
import org.eclipse.mylyn.wikitext.core.parser.builder.NoOpDocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

public class MarkupHyperlinkDetector
  implements IHyperlinkDetector
{
  private MarkupLanguage markupLanguage;
  private IFile file;
  
  public void setMarkupLanguage(MarkupLanguage markupLanguage)
  {
    this.markupLanguage = markupLanguage;
  }
  
  public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks)
  {
    if ((markupLanguage == null) || (file == null)) {
      return null;
    }
    IDocument document = textViewer.getDocument();
    if ((document == null) || (document.getLength() == 0)) {
      return null;
    }
    int regionEnd;
    try
    {
      String content;
      if (region.getLength() == 0)
      {
        IRegion lineInfo = document.getLineInformationOfOffset(region.getOffset());
        int lineLength = lineInfo.getLength();
        int lineOffset = lineInfo.getOffset();
        int lineEnd = lineOffset + lineLength;
        regionEnd = region.getOffset() + region.getLength();
        String content;
        if (lineOffset < region.getOffset())
        {
          int regionLength = Math.max(regionEnd, lineEnd) - lineOffset;
          int contentOffset = lineOffset;
          content = document.get(lineOffset, regionLength);
        }
        else
        {
          int regionLength = Math.max(regionEnd, lineEnd) - region.getOffset();
          int contentOffset = region.getOffset();
          content = document.get(contentOffset, regionLength);
        }
      }
      else
      {
        String content = document.get(region.getOffset(), region.getLength());
        contentOffset = region.getOffset();
      }
    }
    catch (BadLocationException localBadLocationException)
    {
      int contentOffset;
      return null;
    }
    int contentOffset;
    String content;
    MarkupParser markupParser = new MarkupParser(markupLanguage);
    final List<HyperlinkDescriptor> links = new ArrayList();
    markupParser.setBuilder(new NoOpDocumentBuilder()
    {
      public void link(Attributes attributes, String hrefOrHashName, String text)
      {
        if ((hrefOrHashName != null) && (!hrefOrHashName.startsWith("#")))
        {
          IRegion region = createRegion();
          links.add(new MarkupHyperlinkDetector.HyperlinkDescriptor(hrefOrHashName, region));
        }
      }
      
      private IRegion createRegion()
      {
        int offset = getLocator().getLineCharacterOffset();
        int length = getLocator().getLineSegmentEndOffset() - offset;
        return new Region(offset, length);
      }
      
      public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
      {
        if ((type == DocumentBuilder.SpanType.LINK) && 
          ((attributes instanceof LinkAttributes)))
        {
          LinkAttributes linkAttributes = (LinkAttributes)attributes;
          if ((linkAttributes.getHref() != null) && (!linkAttributes.getHref().startsWith("#")))
          {
            IRegion region = createRegion();
            links.add(new MarkupHyperlinkDetector.HyperlinkDescriptor(linkAttributes.getHref(), region));
          }
        }
      }
    });
    markupParser.parse(content);
    if (!links.isEmpty())
    {
      List<IHyperlink> hyperlinks = new ArrayList(links.size());
      for (HyperlinkDescriptor descriptor : links) {
        if ((href.indexOf(':') == -1) && (href.length() > 1) && 
          (href.charAt(0) != '/'))
        {
          IRegion hyperlinkRegion = new Region(region.getOffset() + contentOffset, 
            region.getLength());
          if (region.getLength() > 0 ? 
            isInRegion(region, hyperlinkRegion) : 
            
            (hyperlinkRegion.getOffset() <= region.getOffset()) && (hyperlinkRegion.getOffset() + hyperlinkRegion.getLength() >= region.getOffset())) {
            try
            {
              IPath containerPath = file.getParent().getFullPath();
              IPath absolutePath = containerPath.append(href);
              IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(absolutePath);
              if (targetFile != null)
              {
                if (targetFile.exists()) {
                  hyperlinks.add(new EditFileHyperlink(targetFile, hyperlinkRegion));
                }
                IContainer parent = targetFile.getParent();
                if (parent.exists())
                {
                  String nameNoExtension = targetFile.getName();
                  if (nameNoExtension.indexOf('.') != -1) {
                    nameNoExtension = nameNoExtension.substring(0, nameNoExtension.lastIndexOf('.') + 1);
                  }
                  IResource[] members = parent.members();
                  IResource[] arrayOfIResource1;
                  int j = (arrayOfIResource1 = members).length;
                  for (int i = 0; i < j; i++)
                  {
                    IResource resource = arrayOfIResource1[i];
                    if ((resource.getType() == 1) && 
                      (resource.getName().startsWith(nameNoExtension)) && 
                      (!resource.equals(targetFile))) {
                      hyperlinks.add(new EditFileHyperlink((IFile)resource, hyperlinkRegion));
                    }
                  }
                }
              }
            }
            catch (Throwable localThrowable) {}
          }
        }
      }
      if (!hyperlinks.isEmpty()) {
        return (IHyperlink[])hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
      }
    }
    return null;
  }
  
  private boolean isInRegion(IRegion detectInRegion, IRegion hyperlinkRegion)
  {
    return (detectInRegion.getOffset() >= hyperlinkRegion.getOffset()) && (detectInRegion.getOffset() <= hyperlinkRegion.getOffset() + hyperlinkRegion.getLength());
  }
  
  public void setFile(IFile file)
  {
    this.file = file;
  }
  
  private static class HyperlinkDescriptor
  {
    String href;
    IRegion region;
    
    protected HyperlinkDescriptor(String href, IRegion region)
    {
      this.href = href;
      this.region = region;
    }
  }
  
  private static class EditFileHyperlink
    implements IHyperlink
  {
    private final IFile file;
    private final IRegion region;
    
    protected EditFileHyperlink(IFile file, IRegion region)
    {
      this.file = file;
      this.region = region;
    }
    
    public IRegion getHyperlinkRegion()
    {
      return region;
    }
    
    public String getTypeLabel()
    {
      return null;
    }
    
    public String getHyperlinkText()
    {
      return NLS.bind(Messages.MarkupHyperlinkDetector_openFileInEditor, file.getName());
    }
    
    public void open()
    {
      IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IWorkbenchPage activePage = window.getActivePage();
      try
      {
        IDE.openEditor(activePage, file);
      }
      catch (PartInitException e)
      {
        WikiTextUiPlugin.getDefault().log(e);
        MessageDialog.openError(window.getShell(), Messages.MarkupHyperlinkDetector_unexpectedError, 
          NLS.bind(Messages.MarkupHyperlinkDetector_openException, file.getName(), e.getMessage()));
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupHyperlinkDetector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor.syntax;

import java.io.InputStream;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.editors.text.FileDocumentProvider;

class MarkupDocumentProvider$MarkupFileDocumentProvider
  extends FileDocumentProvider
{
  protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
    throws CoreException
  {
    super.setDocumentContent(document, contentStream, encoding);
    MarkupDocumentProvider.cleanUpEolMarkers(document);
  }
  
  protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
    throws CoreException
  {
    String platformEolMarker = Text.DELIMITER;
    if (platformEolMarker.equals("\r"))
    {
      Document newDocument = new Document(document.get());
      MarkupDocumentProvider.access$0(newDocument, "\n");
      document = newDocument;
    }
    super.doSaveDocument(monitor, element, document, overwrite);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.MarkupDocumentProvider.MarkupFileDocumentProvider
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.progress.UIJob;

class MarkupEditor$13
  extends UIJob
{
  MarkupEditor$13(MarkupEditor paramMarkupEditor, String $anonymous0)
  {
    super($anonymous0);
  }
  
  public IStatus runInUIThread(IProgressMonitor monitor)
  {
    synchronized (this$0)
    {
      MarkupEditor.access$14(this$0, false);
    }
    if (!MarkupEditor.access$15(this$0)) {
      return Status.CANCEL_STATUS;
    }
    MarkupEditor.access$16(this$0);
    return Status.OK_STATUS;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.MarkupEditor.13
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor;

import java.util.Collection;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;

public abstract interface IFoldingStructure
{
  public abstract void collapseElements(Collection<OutlineItem> paramCollection, boolean paramBoolean);
  
  public abstract void expandElements(Collection<OutlineItem> paramCollection);
  
  public abstract void expandElementsExclusive(Collection<OutlineItem> paramCollection, boolean paramBoolean);
  
  public abstract void collapseAll(boolean paramBoolean);
  
  public abstract void expandAll();
  
  public abstract boolean isFoldingEnabled();
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.IFoldingStructure
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;

abstract class FoldingStructure$AbstractItemsAnnotationOperation
  implements FoldingStructure.AnnotationOperation
{
  final Set<String> ids;
  
  protected FoldingStructure$AbstractItemsAnnotationOperation(Collection<OutlineItem> items)
  {
    ids = idsOf(items);
  }
  
  Set<String> idsOf(Collection<OutlineItem> items)
  {
    if ((items == null) || (items.isEmpty())) {
      return Collections.emptySet();
    }
    Set<String> ids = new HashSet();
    for (OutlineItem item : items) {
      ids.add(item.getId());
    }
    return ids;
  }
  
  public final boolean operate(HeadingProjectionAnnotation annotation)
  {
    if (ids.contains(annotation.getHeadingId())) {
      return operateOnSelected(annotation);
    }
    return operateOnUnselected(annotation);
  }
  
  public abstract boolean operateOnSelected(HeadingProjectionAnnotation paramHeadingProjectionAnnotation);
  
  public boolean operateOnUnselected(HeadingProjectionAnnotation annotation)
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.FoldingStructure.AbstractItemsAnnotationOperation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

class MarkupEditor$3
  implements SelectionListener
{
  MarkupEditor$3(MarkupEditor paramMarkupEditor) {}
  
  public void widgetDefaultSelected(SelectionEvent selectionevent)
  {
    widgetSelected(selectionevent);
  }
  
  public void widgetSelected(SelectionEvent selectionevent)
  {
    if (MarkupEditor.access$1(this$0)) {
      MarkupEditor.access$2(this$0);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.ui.editor.MarkupEditor.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.ui.editor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;
import org.eclipse.swt.graphics.Point;

class FoldingStructure
  implements IFoldingStructure
{
  final ProjectionViewer viewer;
  final ITextOperationTarget textOperationTarget;
  
  private static abstract class AbstractItemsAnnotationOperation
    implements FoldingStructure.AnnotationOperation
  {
    final Set<String> ids;
    
    protected AbstractItemsAnnotationOperation(Collection<OutlineItem> items)
    {
      ids = idsOf(items);
    }
    
    Set<String> idsOf(Collection<OutlineItem> items)
    {
      if ((items == null) || (items.isEmpty())) {
        return Collections.emptySet();
      }
      Set<String> ids = new HashSet();
      for (OutlineItem item : items) {
        ids.add(item.getId());
      }
      return ids;
    }
    
    public final boolean operate(HeadingProjectionAnnotation annotation)
    {
      if (ids.contains(annotation.getHeadingId())) {
        return operateOnSelected(annotation);
      }
      return operateOnUnselected(annotation);
    }
    
    public abstract boolean operateOnSelected(HeadingProjectionAnnotation paramHeadingProjectionAnnotation);
    
    public boolean operateOnUnselected(HeadingProjectionAnnotation annotation)
    {
      return false;
    }
  }
  
  public FoldingStructure(MarkupEditor editor)
  {
    viewer = ((ProjectionViewer)editor.getViewer());
    textOperationTarget = ((ITextOperationTarget)editor.getAdapter(ITextOperationTarget.class));
  }
  
  public void collapseAll(boolean collapseRegionContainingCaret)
  {
    if (!isFoldingEnabled()) {
      return;
    }
    if (collapseRegionContainingCaret) {
      textOperationTarget.doOperation(21);
    } else {
      operateOnAnnotations(new AbstractItemsAnnotationOperation(new ArrayList())
      {
        public boolean operateOnSelected(HeadingProjectionAnnotation annotation)
        {
          return operateOnUnselected(annotation);
        }
        
        public boolean operateOnUnselected(HeadingProjectionAnnotation an
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd