Java 类org.eclipse.jface.text.BadPartitioningException 实例源码

项目:Tarski    文件:VisualizationSubscriber.java   
private ITypedRegion getPartition(final String partitionContentType) {
  final IDocumentExtension3 extension = (IDocumentExtension3) this.document;
  ITypedRegion[] computePartitioning = null;
  try {
    computePartitioning = extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING,
        0, this.document.getLength(), false);
  } catch (BadLocationException | BadPartitioningException e) {
    e.printStackTrace();
  }

  for (final ITypedRegion iTypedRegion : computePartitioning) {
    if (iTypedRegion.getType().equals(partitionContentType)) {
      return iTypedRegion;
    }
  }
  return null;
}
项目:Tarski    文件:SynchronizationManager.java   
private ITypedRegion getPartition(final String partitionContentType) {
  final IDocumentExtension3 extension = (IDocumentExtension3) this.document;
  ITypedRegion[] computePartitioning = null;
  try {
    computePartitioning = extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING,
        0, this.document.getLength(), false);
  } catch (BadLocationException | BadPartitioningException e) {
    e.printStackTrace();
  }

  for (final ITypedRegion iTypedRegion : computePartitioning) {
    if (iTypedRegion.getType().equals(partitionContentType)) {
      return iTypedRegion;
    }
  }
  return null;
}
项目:ftc    文件:TweakedLinkedModeUI.java   
/**
 * Registers our auto edit vetoer with the viewer.
 *
 * @param viewer
 *            the viewer we want to veto ui-triggered changes within linked
 *            positions
 */
private void registerAutoEditVetoer(ITextViewer viewer) {
    try {
        String[] contentTypes = getContentTypes(viewer.getDocument());
        if (viewer instanceof ITextViewerExtension2) {
            ITextViewerExtension2 vExtension = ((ITextViewerExtension2) viewer);
            for (int i = 0; i < contentTypes.length; i++) {
                vExtension.prependAutoEditStrategy(fAutoEditVetoer, contentTypes[i]);
            }
        } else {
            Assert.isTrue(false);
        }

    } catch (BadPartitioningException e) {
        leave(ILinkedModeListener.EXIT_ALL);
    }
}
项目:brainfuck    文件:BfTemplateCompletionProcessor.java   
@Override
protected String extractPrefix(ITextViewer viewer, int offset) {
    try {
        if (offset == 0) {
            return "";
        }
        if (!(viewer.getDocument() instanceof IDocumentExtension3)) {
            return super.extractPrefix(viewer, offset);
        }
        IDocumentExtension3 document3 = (IDocumentExtension3) viewer.getDocument();
        ITypedRegion previousRegion = document3.getPartition(EditorConstants.BF_PARTITIONING, offset - 1, false);
        if (EditorConstants.PARTITION_TYPE_TEMPLATE_PARAMETERS.equals(previousRegion.getType())) {
            return viewer.getDocument().get(previousRegion.getOffset(), previousRegion.getLength());
        }
    } 
    catch (BadLocationException | BadPartitioningException ex) {
        BfActivator.getDefault().logError("Prefix for Template could not be computed", ex);
    }
    return super.extractPrefix(viewer, offset);
}
项目:brainfuck    文件:BfSourceViewerConfiguration.java   
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
    IRegion region = new Region(offset, 0);
    try {
        IDocument doc = textViewer.getDocument();

        if (doc instanceof IDocumentExtension3) {
            IDocumentExtension3 ext3 = (IDocumentExtension3) doc;
            region = ext3.getPartition(EditorConstants.BF_PARTITIONING, offset, true);
        }
        else {
            region = doc.getPartition(offset);
        }
    }
    catch (BadPartitioningException | BadLocationException ex) {
        BfActivator.getDefault().logError("Partitioning Problem", ex);
    }
    return region;
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertyValueScanner.java   
public boolean isWordStart(char c) {
    if ('=' != c && ':' != c || fDocument == null)
        return false;

    try {
        // check whether it is the first '=' in the logical line

        int i=fOffset-2;
        while (Character.isWhitespace(fDocument.getChar(i))) {
            i--;
        }

        ITypedRegion partition= null;
        if (fDocument instanceof IDocumentExtension3)
            partition= ((IDocumentExtension3)fDocument).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, i, false);
        return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
    } catch (BadLocationException ex) {
        return false;
    } catch (BadPartitioningException e) {
        return false;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesQuickAssistProcessor.java   
private static boolean getRenameKeysProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    ISourceViewer sourceViewer= invocationContext.getSourceViewer();
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    IField field= null;

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() != 1)
        return false;

    field= accessorClass.getField(keys.get(0));
    if (!field.exists())
        return false;
    if (resultingCollections == null)
        return true;

    String name= PropertiesFileEditorMessages.PropertiesCorrectionProcessor_rename_in_workspace;
    resultingCollections.add(new RenameKeyProposal(name, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE), field, sourceViewer.getTextWidget().getShell()));
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:AddBlockCommentAction.java   
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException {
    int selectionOffset= selection.getOffset();
    int selectionEndOffset= selectionOffset + selection.getLength();
    List<Edit> edits= new LinkedList<Edit>();
    ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false);

    handleFirstPartition(partition, edits, factory, selectionOffset);

    while (partition.getOffset() + partition.getLength() < selectionEndOffset) {
        partition= handleInteriorPartition(partition, edits, factory, docExtension);
    }

    handleLastPartition(partition, edits, factory, selectionEndOffset);

    executeEdits(edits);
}
项目:editorconfig-eclipse    文件:PropertyValueScanner.java   
@Override
public boolean isWordStart(char c) {
    if ('=' != c && ':' != c || fDocument == null)
        return false;

    try {
        // check whether it is the first '=' in the logical line

        int i = fOffset - 2;
        while (Character.isWhitespace(fDocument.getChar(i))) {
            i--;
        }

        ITypedRegion partition = null;
        if (fDocument instanceof IDocumentExtension3)
            partition = ((IDocumentExtension3) fDocument)
                    .getPartition(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, i, false);
        return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
    } catch (BadLocationException ex) {
        return false;
    } catch (BadPartitioningException e) {
        return false;
    }
}
项目:editorconfig-eclipse    文件:SectionScanner.java   
@Override
public boolean isWordStart(char c) {
    if ('=' != c && ':' != c || fDocument == null)
        return false;

    try {
        // check whether it is the first '=' in the logical line

        int i = fOffset - 2;
        while (Character.isWhitespace(fDocument.getChar(i))) {
            i--;
        }

        ITypedRegion partition = null;
        if (fDocument instanceof IDocumentExtension3)
            partition = ((IDocumentExtension3) fDocument)
                    .getPartition(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, i, false);
        return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
    } catch (BadLocationException ex) {
        return false;
    } catch (BadPartitioningException e) {
        return false;
    }
}
项目:WP3    文件:VisualizationSubscriber.java   
private ITypedRegion getPartition(final String partitionContentType) {
  final IDocumentExtension3 extension = (IDocumentExtension3) this.document;
  ITypedRegion[] computePartitioning = null;
  try {
    computePartitioning = extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING,
        0, this.document.getLength(), false);
  } catch (BadLocationException | BadPartitioningException e) {
    e.printStackTrace();
  }

  for (final ITypedRegion iTypedRegion : computePartitioning) {
    if (iTypedRegion.getType().equals(partitionContentType)) {
      return iTypedRegion;
    }
  }
  return null;
}
项目:WP3    文件:SynchronizationManager.java   
private ITypedRegion getPartition(final String partitionContentType) {
  final IDocumentExtension3 extension = (IDocumentExtension3) this.document;
  ITypedRegion[] computePartitioning = null;
  try {
    computePartitioning = extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING,
        0, this.document.getLength(), false);
  } catch (BadLocationException | BadPartitioningException e) {
    e.printStackTrace();
  }

  for (final ITypedRegion iTypedRegion : computePartitioning) {
    if (iTypedRegion.getType().equals(partitionContentType)) {
      return iTypedRegion;
    }
  }
  return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertyValueScanner.java   
public boolean isWordStart(char c) {
    if ('=' != c && ':' != c || fDocument == null)
        return false;

    try {
        // check whether it is the first '=' in the logical line

        int i=fOffset-2;
        while (Character.isWhitespace(fDocument.getChar(i))) {
            i--;
        }

        ITypedRegion partition= null;
        if (fDocument instanceof IDocumentExtension3)
            partition= ((IDocumentExtension3)fDocument).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, i, false);
        return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
    } catch (BadLocationException ex) {
        return false;
    } catch (BadPartitioningException e) {
        return false;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesQuickAssistProcessor.java   
private static boolean getRenameKeysProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    ISourceViewer sourceViewer= invocationContext.getSourceViewer();
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    IField field= null;

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() != 1)
        return false;

    field= accessorClass.getField(keys.get(0));
    if (!field.exists())
        return false;
    if (resultingCollections == null)
        return true;

    String name= PropertiesFileEditorMessages.PropertiesCorrectionProcessor_rename_in_workspace;
    resultingCollections.add(new RenameKeyProposal(name, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE), field, sourceViewer.getTextWidget().getShell()));
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AddBlockCommentAction.java   
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException {
    int selectionOffset= selection.getOffset();
    int selectionEndOffset= selectionOffset + selection.getLength();
    List<Edit> edits= new LinkedList<Edit>();
    ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false);

    handleFirstPartition(partition, edits, factory, selectionOffset);

    while (partition.getOffset() + partition.getLength() < selectionEndOffset) {
        partition= handleInteriorPartition(partition, edits, factory, docExtension);
    }

    handleLastPartition(partition, edits, factory, selectionEndOffset);

    executeEdits(edits);
}
项目:Pydev    文件:DocUtils.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
public static String[] getAllDocumentContentTypes(IDocument document) throws BadPartitioningException {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 ext = (IDocumentExtension3) document;
        String[] partitionings = ext.getPartitionings();

        Set contentTypes = new HashSet();
        contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE);

        int len = partitionings.length;
        for (int i = 0; i < len; i++) {
            String[] legalContentTypes = ext.getLegalContentTypes(partitionings[i]);
            int len2 = legalContentTypes.length;
            for (int j = 0; j < len2; j++) {
                contentTypes.add(legalContentTypes[j]);
            }
            contentTypes.addAll(Arrays.asList(legalContentTypes));
        }
        return (String[]) contentTypes.toArray(new String[contentTypes.size()]);
    }
    return document.getLegalContentTypes();
}
项目:vertigo-chroma-kspplugin    文件:DocumentUtils.java   
/**
 * Indique si l'offset d'un document donné se trouve dans une région donnée.
 * 
 * @param document Document.
 * @param offset Offset.
 * @param contentType Content type de la région.
 * @return
 */
public static boolean isContentType(IDocument document, int offset, KspRegionType regionType) {
    try {
        /* Extrait le type de la partition. */
        IDocumentExtension3 de3 = (IDocumentExtension3) document;
        String regionContentType = de3.getContentType(KspRegionType.PARTITIONING, offset, true);

        /* Vérifie que la région correspond. */
        return regionType.getContentType().equals(regionContentType);
    } catch (BadLocationException | BadPartitioningException e) {
        ErrorUtils.handle(e);
    }

    return false;
}
项目:vertigo-chroma-kspplugin    文件:DocumentUtils.java   
/**
 * Indique si une sélection d'un document représente exactement une région de string (aux double quote près).
 * 
 * @param document Document.
 * @param selection Sélection de texte.
 * @return <code>true</code> si c'est exactement une région de string.
 */
public static boolean isExactKspString(IDocument document, ITextSelection selection) {
    IDocumentExtension3 extension = (IDocumentExtension3) document;
    try {
        /* Charge les régions du document couverte par la sélecion. */
        ITypedRegion[] regions = extension.computePartitioning(KspRegionType.PARTITIONING, selection.getOffset(), selection.getLength(), false);

        /* Vérifie qu'on a une seule région. */
        if (regions.length != 1) {
            return false;
        }

        /* Charge la région entière */
        ITypedRegion region = extension.getPartition(KspRegionType.PARTITIONING, selection.getOffset(), false);

        /* Vérifie que c'est une région de string KSP. */
        if (!region.getType().equals(KspRegionType.STRING.getContentType())) {
            return false;
        }

        /* Vérifie que la région couvre exactement la sélection */
        int selectionWithQuoteOffset = selection.getOffset() - 1; // Prend en compte la double quote ouvrante.
        int selectionWithQuoteLength = selection.getLength() + 2; // Prend en compte les deux double quote.
        if (region.getOffset() == selectionWithQuoteOffset && region.getLength() == selectionWithQuoteLength) {
            return true;
        }
    } catch (BadLocationException | BadPartitioningException e) {
        ErrorUtils.handle(e);
    }

    return false;
}
项目:ftc    文件:TweakedLinkedModeUI.java   
private void unregisterAutoEditVetoer(ITextViewer viewer) {
    try {
        String[] contentTypes = getContentTypes(viewer.getDocument());
        if (viewer instanceof ITextViewerExtension2) {
            ITextViewerExtension2 vExtension = ((ITextViewerExtension2) viewer);
            for (int i = 0; i < contentTypes.length; i++) {
                vExtension.removeAutoEditStrategy(fAutoEditVetoer, contentTypes[i]);
            }
        } else {
            Assert.isTrue(false);
        }
    } catch (BadPartitioningException e) {
        leave(ILinkedModeListener.EXIT_ALL);
    }
}
项目:ftc    文件:TweakedLinkedModeUI.java   
/**
 * Returns all possible content types of <code>document</code>.
 *
 * @param document
 *            the document
 * @return all possible content types of <code>document</code>
 * @throws BadPartitioningException
 *             if partitioning is invalid for this document
 * @since 3.1
 */
private String[] getContentTypes(IDocument document) throws BadPartitioningException {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 ext = (IDocumentExtension3) document;
        String[] partitionings = ext.getPartitionings();
        Set contentTypes = new HashSet(20);
        for (int i = 0; i < partitionings.length; i++) {
            contentTypes.addAll(Arrays.asList(ext.getLegalContentTypes(partitionings[i])));
        }
        contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE);
        return (String[]) contentTypes.toArray(new String[contentTypes.size()]);
    }
    return document.getLegalContentTypes();
}
项目:fluentmark    文件:MkSpellingEngine.java   
/**
 * Check the given document regions only for those regions that are in the default document
 * partition.
 */
@Override
protected void check(IDocument doc, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector,
        IProgressMonitor monitor) {

    Filter filter = new Filter();
    try {
        regions = filter.exec(doc, regions);
    } catch (BadLocationException | BadPartitioningException e) {
        Log.error("Failed to filter doc partitions: " + e.getMessage());
    }

    super.check(doc, regions, checker, collector, monitor);
}
项目:che    文件:SynchronizableDocument.java   
public ITypedRegion[] computePartitioning(
    String partitioning, int offset, int length, boolean includeZeroLengthPartitions)
    throws BadLocationException, BadPartitioningException {
  Object lockObject = getLockObject();
  if (lockObject == null) {
    return super.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions);
  }
  synchronized (lockObject) {
    return super.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions);
  }
}
项目:APICloud-Studio    文件:CharacterPairMatcher.java   
private boolean isUnclosedPair(char c, IDocument document, int offset) throws BadLocationException
{
    // TODO Refactor and combine this copy-pasted code from PeerCharacterCloser
    int beginning = 0;
    // Don't check from very beginning of the document! Be smarter/quicker and check from beginning of
    // partition if we can
    if (document instanceof IDocumentExtension3)
    {
        try
        {
            IDocumentExtension3 ext = (IDocumentExtension3) document;
            ITypedRegion region = ext.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
            beginning = region.getOffset();
        }
        catch (BadPartitioningException e)
        {
            // ignore
        }
    }
    // Now check leading source and see if we're an unclosed pair.
    String previous = document.get(beginning, offset - beginning);
    boolean open = false;
    int index = -1;
    while ((index = previous.indexOf(c, index + 1)) != -1)
    {
        open = !open;
    }
    return open;
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesQuickAssistProcessor.java   
public static ICompletionProposal[] collectAssists(PropertiesAssistContext invocationContext) throws BadLocationException, BadPartitioningException {
    ArrayList<ICompletionProposal> resultingCollections= new ArrayList<ICompletionProposal>();

    getEscapeUnescapeBackslashProposals(invocationContext, resultingCollections);
    getCreateFieldsInAccessorClassProposals(invocationContext, resultingCollections);
    getRemovePropertiesProposals(invocationContext, resultingCollections);
    getRenameKeysProposals(invocationContext, resultingCollections);

    if (resultingCollections.size() == 0)
        return null;
    return resultingCollections.toArray(new ICompletionProposal[resultingCollections.size()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:RemoveBlockCommentAction.java   
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
    List<Edit> edits= new LinkedList<Edit>();
    int tokenLength= getCommentStart().length();

    int offset= selection.getOffset();
    int endOffset= offset + selection.getLength();

    ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false);
    int partOffset= partition.getOffset();
    int partEndOffset= partOffset + partition.getLength();

    while (partEndOffset < endOffset) {

        if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
            edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
            edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
        }

        partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
        partOffset= partition.getOffset();
        partEndOffset= partOffset + partition.getLength();
    }

    if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
        edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
        edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
    }

    executeEdits(edits);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesQuickAssistProcessor.java   
public static ICompletionProposal[] collectAssists(PropertiesAssistContext invocationContext) throws BadLocationException, BadPartitioningException {
    ArrayList<ICompletionProposal> resultingCollections= new ArrayList<ICompletionProposal>();

    getEscapeUnescapeBackslashProposals(invocationContext, resultingCollections);
    getCreateFieldsInAccessorClassProposals(invocationContext, resultingCollections);
    getRemovePropertiesProposals(invocationContext, resultingCollections);
    getRenameKeysProposals(invocationContext, resultingCollections);

    if (resultingCollections.size() == 0)
        return null;
    return resultingCollections.toArray(new ICompletionProposal[resultingCollections.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RemoveBlockCommentAction.java   
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
    List<Edit> edits= new LinkedList<Edit>();
    int tokenLength= getCommentStart().length();

    int offset= selection.getOffset();
    int endOffset= offset + selection.getLength();

    ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false);
    int partOffset= partition.getOffset();
    int partEndOffset= partOffset + partition.getLength();

    while (partEndOffset < endOffset) {

        if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
            edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
            edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
        }

        partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
        partOffset= partition.getOffset();
        partEndOffset= partOffset + partition.getLength();
    }

    if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
        edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
        edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
    }

    executeEdits(edits);
}
项目:goclipse    文件:AbstractDocumentScanner.java   
public ITypedRegion getPartition(int position) throws BadLocationException {
    if(!partitionContainsPosition(lastPartition, position)) {
        if(documentExt3 != null) {
            try {
                lastPartition = documentExt3.getPartition(partitioning, position, false);
            } catch (BadPartitioningException e) {
                throw assertFail(); // Cannot happen, we have ensured that partitioning exists
            }
        } else {
            lastPartition = document.getPartition(position);
        }
    }
    return lastPartition;
}
项目:brainfuck    文件:BfSourceViewerConfiguration.java   
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
    IAnnotationModel model = sourceViewer.getAnnotationModel();
    @SuppressWarnings("unchecked")
    Iterator<Annotation> i = model.getAnnotationIterator();
    Annotation provideText = null;
    AnnotationPreferenceLookup preferenceLookup = EditorsUI.getAnnotationPreferenceLookup();
    int annotationLayer = -1;
    while (i.hasNext()) {
        Annotation ann = i.next();

        Position p = model.getPosition(ann);
        if (p == null || !p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
            continue;
        }
        if (UNCHANGED_QUICKDIFF_ANNOTATION.equals(ann.getType())) {
            continue; //Ignore unchanged line notification
        }
        if (provideText == null) {
            provideText = ann;
        }
        AnnotationPreference preference = preferenceLookup.getAnnotationPreference(ann);
        if (preference != null && preference.getPresentationLayer() > annotationLayer) {
            provideText = ann;
            annotationLayer = preference.getPresentationLayer();
        }
    }
    String text = null;
    if (provideText != null) {
        if (this.hoverContributions.containsKey(provideText.getType())) {
            text = this.hoverContributions.get(provideText.getType()).getHoverText(provideText, textViewer, hoverRegion);
        }
        else {
            text = "<b>" +  provideText.getText() + "</b>";
        }
    }
    try {
        if (text == null) {
            IDocument document = textViewer.getDocument();
            if (document instanceof IDocumentExtension3) {
                IDocumentExtension3 ext3 = (IDocumentExtension3) document;
                ITypedRegion partition = ext3.getPartition(EditorConstants.BF_PARTITIONING, hoverRegion.getOffset(), false);
                if (EditorConstants.PARTITION_TYPE_BRAINFUCK_CODE.equals(partition.getType())) {
                    text = "Offset: [<b>" + hoverRegion.getOffset() + "</b>]";
                }
            }
        }
    }
    catch (BadLocationException | BadPartitioningException ex) {
        BfActivator.getDefault().logError("hoverRegion partitioning could not be evaluated", ex);
    }
    return text;
}
项目:APICloud-Studio    文件:PeerCharacterCloser.java   
private boolean isUnclosedPair(VerifyEvent event, IDocument document, int offset) throws BadLocationException
{
    final char closingCharacter = getPeerCharacter(event.character);
    // This doesn't matter if the user is not typing an "end" character.
    if (closingCharacter != event.character)
        return false;
    char c = event.character;
    int beginning = 0;
    // Don't check from very beginning of the document! Be smarter/quicker and check from beginning of
    // partition if we can.
    // FIXME What type of partitions does this make sense for? We should check across "code" partitions. Limit to
    // single string/comment partition?
    if (document instanceof IDocumentExtension3)
    {
        try
        {
            IDocumentExtension3 ext = (IDocumentExtension3) document;
            ITypedRegion region = getPartition(ext, IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
            beginning = region.getOffset();
        }
        catch (BadPartitioningException e)
        {
            // ignore
        }
    }
    // Now check leading source and see if we're an unclosed pair.
    String previous = document.get(beginning, offset - beginning);
    boolean open = false;
    int index = -1;
    while ((index = previous.indexOf(c, index + 1)) != -1)
    {
        // if (ignoreScope(document, beginning + index))
        // continue;
        open = !open;
        if (open)
        {
            c = closingCharacter;
        }
        else
        {
            c = event.character;
        }
    }
    return open;
}
项目:APICloud-Studio    文件:PeerCharacterCloser.java   
protected ITypedRegion getPartition(IDocumentExtension3 ext, String defaultPartitioning, int offset, boolean b)
        throws BadLocationException, BadPartitioningException
{
    return ext.getPartition(defaultPartitioning, offset, b);
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesQuickAssistProcessor.java   
private static boolean getEscapeUnescapeBackslashProposals(IQuickAssistInvocationContext invocationContext, ArrayList<ICompletionProposal> resultingCollections) throws BadLocationException,
        BadPartitioningException {
    ISourceViewer sourceViewer= invocationContext.getSourceViewer();
    IDocument document= sourceViewer.getDocument();
    Point selectedRange= sourceViewer.getSelectedRange();
    int selectionOffset= selectedRange.x;
    int selectionLength= selectedRange.y;
    int proposalOffset;
    int proposalLength;
    String text;
    if (selectionLength == 0) {
        if (selectionOffset != document.getLength()) {
            char ch= document.getChar(selectionOffset);
            if (ch == '=' || ch == ':') { //see PropertiesFilePartitionScanner()
                return false;
            }
        }

        ITypedRegion partition= null;
        if (document instanceof IDocumentExtension3)
            partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, invocationContext.getOffset(), false);
        if (partition == null)
            return false;

        String type= partition.getType();
        if (!(type.equals(IPropertiesFilePartitions.PROPERTY_VALUE) || type.equals(IDocument.DEFAULT_CONTENT_TYPE))) {
            return false;
        }
        proposalOffset= partition.getOffset();
        proposalLength= partition.getLength();
        text= document.get(proposalOffset, proposalLength);

        if (type.equals(IPropertiesFilePartitions.PROPERTY_VALUE)) {
            text= text.substring(1); //see PropertiesFilePartitionScanner()
            proposalOffset++;
            proposalLength--;
        }
    } else {
        proposalOffset= selectionOffset;
        proposalLength= selectionLength;
        text= document.get(proposalOffset, proposalLength);
    }

    if (PropertiesFileEscapes.containsUnescapedBackslash(text)) {
        if (resultingCollections == null)
            return true;
        resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength,
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes));
        return true;
    }
    if (PropertiesFileEscapes.containsEscapedBackslashes(text)) {
        if (resultingCollections == null)
            return true;
        resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.unescapeBackslashes(text), proposalOffset, proposalLength,
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_unescapeBackslashes));
        return true;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesQuickAssistProcessor.java   
private static boolean getCreateFieldsInAccessorClassProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    List<String> fields= new ArrayList<String>();

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() == 0)
        return false;

    for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
        String key= iterator.next();
        if (!isValidJavaIdentifier(key))
            continue;
        IField field= accessorClass.getField(key);
        if (field.exists())
            continue;
        if (resultingCollections == null)
            return true;
        fields.add(key);
    }

    if (fields.size() == 0)
        return false;

    ICompilationUnit cu= accessorClass.getCompilationUnit();
    try {
        Change change= AccessorClassModifier.addFields(cu, fields);
        String name= Messages.format(fields.size() == 1 ? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_field_in_accessor_label : PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_fields_in_accessor_label, BasicElementLabels.getFileName(cu));
        resultingCollections.add(new CUCorrectionProposal(name, cu, (TextChange) change, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)));
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesQuickAssistProcessor.java   
private static boolean getRemovePropertiesProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    List<String> fields= new ArrayList<String>();

    IFile file= invocationContext.getFile();
    if (file == null)
        return false;

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() == 0)
        return false;
    if (resultingCollections == null)
        return true;

    for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
        String key= iterator.next();
        IField field= accessorClass.getField(key);
        if (field.exists())
            fields.add(key);
    }

    ICompilationUnit cu= accessorClass.getCompilationUnit();
    try {
        Change propertiesFileChange= NLSPropertyFileModifier.removeKeys(file.getFullPath(), keys);
        Change[] changes;
        if (fields.size() > 0) {
            Change accessorChange= AccessorClassModifier.removeFields(cu, fields);
            changes= new Change[] { propertiesFileChange, accessorChange };
        } else {
            changes= new Change[] { propertiesFileChange };
        }

        String name= (keys.size() == 1)
                ? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_property_label
                : PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_properties_label;
        resultingCollections.add(new RemovePropertiesProposal(name, 4, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE), changes));
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:AddBlockCommentAction.java   
/**
 * Handles partition boundaries within the selection. The end of the current
 * partition and the start of the next partition are examined for whether
 * they contain comment tokens that interfere with the created comment.
 * <p>
 * Comment tokens are removed from interior multi-line comments. Javadoc
 * comments are left as is; instead, multi-line comment tokens are inserted
 * before and after Javadoc partitions to ensure that the entire selected
 * area is commented.
 * </p>
 * <p>
 * The next partition is returned.
 * </p>
 *
 * @param partition the current partition
 * @param edits the list of edits to add to
 * @param factory the edit factory
 * @param docExtension the document to get the partitions from
 * @return the next partition after the current
 * @throws BadLocationException if accessing the document fails - this can
 *         only happen if the document gets modified concurrently
 * @throws BadPartitioningException if the document does not have a Java
 *         partitioning
 */
private ITypedRegion handleInteriorPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, IDocumentExtension3 docExtension) throws BadPartitioningException, BadLocationException {

    // end of previous partition
    String partType= partition.getType();
    int partEndOffset= partition.getOffset() + partition.getLength();
    int tokenLength= getCommentStart().length();

    boolean wasJavadoc= false; // true if the previous partition is javadoc

    if (partType == IJavaPartitions.JAVA_DOC) {

        wasJavadoc= true;

    } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {

        // already in a comment - remove ending mark
        edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$

    }

    // advance to next partition
    partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
    partType= partition.getType();

    // start of next partition
    if (wasJavadoc) {

        // if previous was javadoc, and the current one is not a comment,
        // then add a block comment start
        if (partType == IDocument.DEFAULT_CONTENT_TYPE
                || isSpecialPartition(partType)) {
            edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart()));
        }

    } else { // !wasJavadoc

        if (partType == IJavaPartitions.JAVA_DOC) {
            // if next is javadoc, end block comment before
            edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd()));
        } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
            // already in a comment - remove startToken
            edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
        }
    }

    return partition;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesQuickAssistProcessor.java   
private static boolean getEscapeUnescapeBackslashProposals(IQuickAssistInvocationContext invocationContext, ArrayList<ICompletionProposal> resultingCollections) throws BadLocationException,
        BadPartitioningException {
    ISourceViewer sourceViewer= invocationContext.getSourceViewer();
    IDocument document= sourceViewer.getDocument();
    Point selectedRange= sourceViewer.getSelectedRange();
    int selectionOffset= selectedRange.x;
    int selectionLength= selectedRange.y;
    int proposalOffset;
    int proposalLength;
    String text;
    if (selectionLength == 0) {
        if (selectionOffset != document.getLength()) {
            char ch= document.getChar(selectionOffset);
            if (ch == '=' || ch == ':') { //see PropertiesFilePartitionScanner()
                return false;
            }
        }

        ITypedRegion partition= null;
        if (document instanceof IDocumentExtension3)
            partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, invocationContext.getOffset(), false);
        if (partition == null)
            return false;

        String type= partition.getType();
        if (!(type.equals(IPropertiesFilePartitions.PROPERTY_VALUE) || type.equals(IDocument.DEFAULT_CONTENT_TYPE))) {
            return false;
        }
        proposalOffset= partition.getOffset();
        proposalLength= partition.getLength();
        text= document.get(proposalOffset, proposalLength);

        if (type.equals(IPropertiesFilePartitions.PROPERTY_VALUE)) {
            text= text.substring(1); //see PropertiesFilePartitionScanner()
            proposalOffset++;
            proposalLength--;
        }
    } else {
        proposalOffset= selectionOffset;
        proposalLength= selectionLength;
        text= document.get(proposalOffset, proposalLength);
    }

    if (PropertiesFileEscapes.containsUnescapedBackslash(text)) {
        if (resultingCollections == null)
            return true;
        resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.escape(text, false, true, false), proposalOffset, proposalLength,
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashes));
        return true;
    }
    if (PropertiesFileEscapes.containsEscapedBackslashes(text)) {
        if (resultingCollections == null)
            return true;
        resultingCollections.add(new EscapeBackslashCompletionProposal(PropertiesFileEscapes.unescapeBackslashes(text), proposalOffset, proposalLength,
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_unescapeBackslashes));
        return true;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesQuickAssistProcessor.java   
private static boolean getCreateFieldsInAccessorClassProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    List<String> fields= new ArrayList<String>();

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() == 0)
        return false;

    for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
        String key= iterator.next();
        if (!isValidJavaIdentifier(key))
            continue;
        IField field= accessorClass.getField(key);
        if (field.exists())
            continue;
        if (resultingCollections == null)
            return true;
        fields.add(key);
    }

    if (fields.size() == 0)
        return false;

    ICompilationUnit cu= accessorClass.getCompilationUnit();
    try {
        Change change= AccessorClassModifier.addFields(cu, fields);
        String name= Messages.format(fields.size() == 1 ? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_field_in_accessor_label : PropertiesFileEditorMessages.PropertiesCorrectionProcessor_create_fields_in_accessor_label, BasicElementLabels.getFileName(cu));
        resultingCollections.add(new CUCorrectionProposal(name, cu, (TextChange) change, 5, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)));
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesQuickAssistProcessor.java   
private static boolean getRemovePropertiesProposals(PropertiesAssistContext invocationContext, ArrayList<ICompletionProposal> resultingCollections)
        throws BadLocationException, BadPartitioningException {
    IDocument document= invocationContext.getDocument();
    int selectionOffset= invocationContext.getOffset();
    int selectionLength= invocationContext.getLength();
    List<String> fields= new ArrayList<String>();

    IFile file= invocationContext.getFile();
    if (file == null)
        return false;

    IType accessorClass= invocationContext.getAccessorType();
    if (accessorClass == null || !isEclipseNLSUsed(accessorClass))
        return false;

    List<String> keys= getKeysFromSelection(document, selectionOffset, selectionLength);
    if (keys == null || keys.size() == 0)
        return false;
    if (resultingCollections == null)
        return true;

    for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
        String key= iterator.next();
        IField field= accessorClass.getField(key);
        if (field.exists())
            fields.add(key);
    }

    ICompilationUnit cu= accessorClass.getCompilationUnit();
    try {
        Change propertiesFileChange= NLSPropertyFileModifier.removeKeys(file.getFullPath(), keys);
        Change[] changes;
        if (fields.size() > 0) {
            Change accessorChange= AccessorClassModifier.removeFields(cu, fields);
            changes= new Change[] { propertiesFileChange, accessorChange };
        } else {
            changes= new Change[] { propertiesFileChange };
        }

        String name= (keys.size() == 1)
                ? PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_property_label
                : PropertiesFileEditorMessages.PropertiesCorrectionProcessor_remove_properties_label;
        resultingCollections.add(new RemovePropertiesProposal(name, 4, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE), changes));
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return false;
    }
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AddBlockCommentAction.java   
/**
 * Handles partition boundaries within the selection. The end of the current
 * partition and the start of the next partition are examined for whether
 * they contain comment tokens that interfere with the created comment.
 * <p>
 * Comment tokens are removed from interior multi-line comments. Javadoc
 * comments are left as is; instead, multi-line comment tokens are inserted
 * before and after Javadoc partitions to ensure that the entire selected
 * area is commented.
 * </p>
 * <p>
 * The next partition is returned.
 * </p>
 *
 * @param partition the current partition
 * @param edits the list of edits to add to
 * @param factory the edit factory
 * @param docExtension the document to get the partitions from
 * @return the next partition after the current
 * @throws BadLocationException if accessing the document fails - this can
 *         only happen if the document gets modified concurrently
 * @throws BadPartitioningException if the document does not have a Java
 *         partitioning
 */
private ITypedRegion handleInteriorPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, IDocumentExtension3 docExtension) throws BadPartitioningException, BadLocationException {

    // end of previous partition
    String partType= partition.getType();
    int partEndOffset= partition.getOffset() + partition.getLength();
    int tokenLength= getCommentStart().length();

    boolean wasJavadoc= false; // true if the previous partition is javadoc

    if (partType == IJavaPartitions.JAVA_DOC) {

        wasJavadoc= true;

    } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {

        // already in a comment - remove ending mark
        edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$

    }

    // advance to next partition
    partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
    partType= partition.getType();

    // start of next partition
    if (wasJavadoc) {

        // if previous was javadoc, and the current one is not a comment,
        // then add a block comment start
        if (partType == IDocument.DEFAULT_CONTENT_TYPE
                || isSpecialPartition(partType)) {
            edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart()));
        }

    } else { // !wasJavadoc

        if (partType == IJavaPartitions.JAVA_DOC) {
            // if next is javadoc, end block comment before
            edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd()));
        } else if (partType == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
            // already in a comment - remove startToken
            edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
        }
    }

    return partition;
}
项目:Eclipse-Postfix-Code-Completion    文件:BlockCommentAction.java   
/**
 * Runs the real command once all the editor, document, and selection checks have succeeded.
 *
 * @param selection the current selection we are being called for
 * @param docExtension the document extension where we get the partitioning from
 * @param factory the edit factory we can use to create <code>Edit</code>s
 * @throws BadLocationException if an edition fails
 * @throws BadPartitioningException if a partitioning call fails
 */
protected abstract void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException;