Java 类org.eclipse.jface.text.link.LinkedModeModel 实例源码

项目:n4js    文件:IdentifierExitPolicy.java   
/**
 * {@inheritDoc}
 *
 * If the entered character is not a valid identifier part, it is processed after linked editing has been quit.
 * Exceptions are the {@link #exitCharacters} that have been passed into the constructor.
 */
@Override
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {
    if (event.character == '\0')
        return null;
    for (char c : exitCharacters) {
        if (event.character == c) {
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        }
    }
    switch (event.character) {
    case SWT.CR:
        return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
    default: {
        if (!Character.isJavaIdentifierPart(event.character)) {
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
        }
        return null;
    }
    }
}
项目:ftc    文件:TweakedLinkedModeUI.java   
/**
 * This does the actual constructor work.
 *
 * @param model
 *            the linked mode model
 * @param targets
 *            the non-empty array of targets upon which the linked mode UI
 *            should act
 */
private void constructor(LinkedModeModel model, LinkedModeUITarget[] targets) {
    Assert.isNotNull(model);
    Assert.isNotNull(targets);
    Assert.isTrue(targets.length > 0);
    Assert.isTrue(model.getTabStopSequence().size() > 0);

    fModel = model;
    fTargets = targets;
    fCurrentTarget = targets[0];
    fIterator = new TabStopIterator(fModel.getTabStopSequence());
    fIterator.setCycling(!fModel.isNested());
    fModel.addLinkingListener(fLinkedListener);

    fAssistant = new ContentAssistant2();
    fAssistant.addProposalListener(fProposalListener);
    // TODO find a way to set up content assistant.
    // fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING);
    fCaretPosition.delete();
}
项目:texlipse    文件:BracketInserter.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

    if (fSize == fStack.size() && !isMasked(offset)) {
        if (event.character == fExitCharacter) {
            BracketLevel level= (BracketLevel) fStack.peek();
            if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                return null;
            if (level.fSecondPosition.offset == offset && length == 0)
                // don't enter the character if if its the closing peer
                return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        }
        // when entering an anonymous class between the parenthesis', we don't want
        // to jump after the closing parenthesis when return is pressed
        if (event.character == SWT.CR && offset > 0) {
            IDocument document= sourceViewer.getDocument();
            try {
                if (document.getChar(offset - 1) == '{')
                    return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
            } catch (BadLocationException e) {
            }
        }
    }
    return null;
}
项目:typescript.java    文件:LinkedNamesAssistProposal.java   
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
        LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
        if (position != null) {
            if (event.character == SWT.BS) {
                if (offset - 1 < position.getOffset()) {
                    //skip backspace at beginning of linked position
                    event.doit= false;
                }
            } else /* event.character == SWT.DEL */ {
                if (offset + 1 > position.getOffset() + position.getLength()) {
                    //skip delete at end of linked position
                    event.doit= false;
                }
            }
        }
    }

    return null; // don't change behavior
}
项目:typescript.java    文件:BracketInserter.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

            if (fSize == fStack.size() && !isMasked(offset)) {
                if (event.character == fExitCharacter) {
                    BracketLevel level = (BracketLevel) fStack.peek();
                    if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                        return null;
                    if (level.fSecondPosition.offset == offset && length == 0)
                        // don't enter the character if if its the closing peer
                        return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
                }
                // when entering an anonymous class between the parenthesis', we
                // don't want
                // to jump after the closing parenthesis when return is pressed
                if (event.character == SWT.CR && offset > 0) {
                    IDocument document = getSourceViewer().getDocument();
                    try {
                        if (document.getChar(offset - 1) == '{')
                            return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
                    } catch (BadLocationException e) {
                    }
                }
            }
            return null;
        }
项目:bts    文件:ConfigurableCompletionProposal.java   
/**
     * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will
     * exit the mode when <code>closingCharacter</code> is typed and an exit position at
     * <code>getCursorPosition() + 1</code>.
     *
     * @param document the document
     */
    protected void setUpLinkedMode(IDocument document) {
        try {
            LinkedPositionGroup group= new LinkedPositionGroup();
            group.addPosition(new LinkedPosition(document, getSelectionStart(), getSelectionLength(), LinkedPositionGroup.NO_STOP));

            LinkedModeModel model= new LinkedModeModel();
            model.addGroup(group);
            model.forceInstall();

            LinkedModeUI ui= new LinkedModeUI(model, viewer);
//          ui.setSimpleMode(true);
            ui.setExitPolicy(new ExitPolicy(exitChars));
            ui.setExitPosition(viewer, getCursorPosition() + getReplacementOffset(), 0, Integer.MAX_VALUE);
            ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
            ui.enter();
        } catch (BadLocationException e) {
            log.info(e.getMessage(), e);
        }
    }
项目:bts    文件:ConfigurableCompletionProposal.java   
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {
    if (event.character == '\0')
        return null;
    for (char c: exitCharacters) {
        if (event.character == c) {
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        }
    }

    switch (event.character) {
        case SWT.CR:
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        default:
            return null;
    }
}
项目:bts    文件:RenameLinkedMode.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    showPreview = (event.stateMask & SWT.CTRL) != 0 && (event.character == SWT.CR || event.character == SWT.LF);
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
        LinkedPosition position = model.findPosition(new LinkedPosition(document, offset, 0,
                LinkedPositionGroup.NO_STOP));
        if (position != null) {
            if (event.character == SWT.BS) {
                if (offset - 1 < position.getOffset()) {
                    // skip backspace at beginning of linked position
                    event.doit = false;
                }
            } else /* event.character == SWT.DEL */{
                if (offset + 1 > position.getOffset() + position.getLength()) {
                    // skip delete at end of linked position
                    event.doit = false;
                }
            }
        }
    }
    return null; // don't change behavior
}
项目:che    文件:TextChange.java   
/**
 * Executes the text edits on the given document. Subclasses that override this method should call
 * <code>super.performEdits(document)</code>.
 *
 * @param document the document
 * @return an object representing the undo of the executed edits
 * @exception MalformedTreeException is thrown if the edit tree isn't in a valid state. This
 *     exception is thrown before any edit is executed. So the document is still in its original
 *     state.
 * @exception BadLocationException is thrown if one of the edits in the tree can't be executed.
 *     The state of the document is undefined if this exception is thrown.
 * @since 3.5
 */
protected UndoEdit performEdits(IDocument document)
    throws BadLocationException, MalformedTreeException {
  DocumentRewriteSession session = null;
  try {
    if (document instanceof IDocumentExtension4) {
      session =
          ((IDocumentExtension4) document)
              .startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
    }

    LinkedModeModel.closeAllModels(document);
    TextEditProcessor processor = createTextEditProcessor(document, TextEdit.CREATE_UNDO, false);
    return processor.performEdits();

  } finally {
    if (session != null) {
      ((IDocumentExtension4) document).stopRewriteSession(session);
    }
  }
}
项目:eclipse-wtp-json    文件:JSONCharacterPairInserter.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event,
        int offset, int length) {
    if (!isMasked(offset)) {
        if (event.character == fExit)
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET,
                    false);
        if (event.character == '\r' || event.character == '\n'
                && offset > 0) {
            try {
                if (fDocument.getChar(offset - 1) == '{') {
                    return new ExitFlags(ILinkedModeListener.EXIT_ALL,
                            true);
                }
            } catch (BadLocationException e) {
            }
        }
    }
    return null;
}
项目:APICloud-Studio    文件:ExitPolicy.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length)
{
    if (shouldInsertNewline())
    {
        if (event.character == '\n' || event.character == '\r')
        {
            return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
        }
    }

    if (event.character != fExitCharacter)
        return null;

    if (fSize == fStack.size() && !isEscaped(offset))
    {
        BracketLevel level = fStack.peek();
        if (offset < level.fFirstPosition.offset || level.fSecondPosition.offset < offset)
            return null;
        if (level.fSecondPosition.offset == offset && length == 0)
            // don't enter the character if it is the closing peer
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
    }

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:CompilationUnitEditor.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

            if (fSize == fStack.size() && !isMasked(offset)) {
                if (event.character == fExitCharacter) {
                    BracketLevel level= fStack.peek();
                    if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                        return null;
                    if (level.fSecondPosition.offset == offset && length == 0)
                        // don't enter the character if if its the closing peer
                        return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
                }
                // when entering an anonymous class between the parenthesis', we don't want
                // to jump after the closing parenthesis when return is pressed
                if (event.character == SWT.CR && offset > 0) {
                    IDocument document= getSourceViewer().getDocument();
                    try {
                        if (document.getChar(offset - 1) == '{')
                            return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
                    } catch (BadLocationException e) {
                    }
                }
            }
            return null;
        }
项目:Eclipse-Postfix-Code-Completion    文件:AbstractJavaCompletionProposal.java   
/**
 * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will
 * exit the mode when <code>closingCharacter</code> is typed and an exit position at
 * <code>getCursorPosition() + 1</code>.
 *
 * @param document the document
 * @param closingCharacter the exit character
 */
protected void setUpLinkedMode(IDocument document, char closingCharacter) {
    if (getTextViewer() != null && autocloseBrackets()) {
        int offset= getReplacementOffset() + getCursorPosition();
        int exit= getReplacementOffset() + getReplacementString().length();
        try {
            LinkedPositionGroup group= new LinkedPositionGroup();
            group.addPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP));

            LinkedModeModel model= new LinkedModeModel();
            model.addGroup(group);
            model.forceInstall();

            LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer());
            ui.setSimpleMode(true);
            ui.setExitPolicy(new ExitPolicy(closingCharacter, document));
            ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE);
            ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
            ui.enter();
        } catch (BadLocationException x) {
            JavaPlugin.log(x);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:LinkedNamesAssistProposal.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
        LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
        if (position != null) {
            if (event.character == SWT.BS) {
                if (offset - 1 < position.getOffset()) {
                    //skip backspace at beginning of linked position
                    event.doit= false;
                }
            } else /* event.character == SWT.DEL */ {
                if (offset + 1 > position.getOffset() + position.getLength()) {
                    //skip delete at end of linked position
                    event.doit= false;
                }
            }
        }
    }

    return null; // don't change behavior
}
项目:idecore    文件:BracketInserter.java   
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

    if (fSize == fStack.size() && !isMasked(offset)) {
        if (event.character == fExitCharacter) {
            BracketLevel level = fStack.peek();
            if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                return null;
            if (level.fSecondPosition.offset == offset && length == 0)
                // don't enter the character if if its the closing peer
                return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        }
        // when entering an anonymous class between the parenthesis', we don't want
        // to jump after the closing parenthesis when return is pressed
        if (event.character == SWT.CR && offset > 0) {
            IDocument document = getSourceViewer().getDocument();
            try {
                if (document.getChar(offset - 1) == '{')
                    return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
            } catch (BadLocationException e) {}
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CompilationUnitEditor.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {

            if (fSize == fStack.size() && !isMasked(offset)) {
                if (event.character == fExitCharacter) {
                    BracketLevel level= fStack.peek();
                    if (level.fFirstPosition.offset > offset || level.fSecondPosition.offset < offset)
                        return null;
                    if (level.fSecondPosition.offset == offset && length == 0)
                        // don't enter the character if if its the closing peer
                        return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
                }
                // when entering an anonymous class between the parenthesis', we don't want
                // to jump after the closing parenthesis when return is pressed
                if (event.character == SWT.CR && offset > 0) {
                    IDocument document= getSourceViewer().getDocument();
                    try {
                        if (document.getChar(offset - 1) == '{')
                            return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
                    } catch (BadLocationException e) {
                    }
                }
            }
            return null;
        }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AbstractJavaCompletionProposal.java   
/**
 * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will
 * exit the mode when <code>closingCharacter</code> is typed and an exit position at
 * <code>getCursorPosition() + 1</code>.
 *
 * @param document the document
 * @param closingCharacter the exit character
 */
protected void setUpLinkedMode(IDocument document, char closingCharacter) {
    if (getTextViewer() != null && autocloseBrackets()) {
        int offset= getReplacementOffset() + getCursorPosition();
        int exit= getReplacementOffset() + getReplacementString().length();
        try {
            LinkedPositionGroup group= new LinkedPositionGroup();
            group.addPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP));

            LinkedModeModel model= new LinkedModeModel();
            model.addGroup(group);
            model.forceInstall();

            LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer());
            ui.setSimpleMode(true);
            ui.setExitPolicy(new ExitPolicy(closingCharacter, document));
            ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE);
            ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
            ui.enter();
        } catch (BadLocationException x) {
            JavaPlugin.log(x);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:LinkedNamesAssistProposal.java   
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
        LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
        if (position != null) {
            if (event.character == SWT.BS) {
                if (offset - 1 < position.getOffset()) {
                    //skip backspace at beginning of linked position
                    event.doit= false;
                }
            } else /* event.character == SWT.DEL */ {
                if (offset + 1 > position.getOffset() + position.getLength()) {
                    //skip delete at end of linked position
                    event.doit= false;
                }
            }
        }
    }

    return null; // don't change behavior
}
项目:eclipse-multicursor    文件:DeleteBlockingExitPolicy.java   
@Override
public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
    if (length == 0 && (event.character == SWT.BS || event.character == SWT.DEL)) {
        LinkedPosition position= model.findPosition(new LinkedPosition(fDocument, offset, 0, LinkedPositionGroup.NO_STOP));
        if (position != null) {
            if (event.character == SWT.BS) {
                if (offset - 1 < position.getOffset()) {
                    //skip backspace at beginning of linked position
                    event.doit= false;
                }
            } else /* event.character == SWT.DEL */ {
                if (offset + 1 > position.getOffset() + position.getLength()) {
                    //skip delete at end of linked position
                    event.doit= false;
                }
            }
        }
    }

    return null; // don't change behavior
}
项目:eclipse-multicursor    文件:SelectNextOccurrenceHandler.java   
private void startLinkedEdit(List<IRegion> selections, ITextViewer viewer, Point originalSelection)
        throws BadLocationException {
    final LinkedPositionGroup linkedPositionGroup = new LinkedPositionGroup();
    for (IRegion selection : selections) {
        linkedPositionGroup.addPosition(new LinkedPosition(viewer.getDocument(), selection.getOffset(), selection
                .getLength()));
    }

    LinkedModeModel model = new LinkedModeModel();
    model.addGroup(linkedPositionGroup);
    model.forceInstall();
    //FIXME can add a listener here to listen for the end of linked mode
    //model.addLinkingListener(null);

    LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
    ui.setExitPolicy(new DeleteBlockingExitPolicy(viewer.getDocument()));
    ui.enter();

    // by default the text being edited is selected so restore original selection
    viewer.setSelectedRange(originalSelection.x, originalSelection.y);
}
项目:goclipse    文件:LangCompletionProposal.java   
protected void applyLinkedMode(ITextViewer viewer) throws BadLocationException {
    LinkedModeModel model = getLinkedModeModel(viewer);
    if(model == null) {
        return;
    }
    model.forceInstall();

    LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
    ui.setExitPolicy(new CompletionProposalExitPolicy());
    ui.setExitPosition(viewer, endPositionAfterApply, 0, Integer.MAX_VALUE);
    if(firstLinkedModeGroupPosition != -1) {
        positionAfterApply = null;
    }
    ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
    ui.setDoContextInfo(true);
    ui.enableColoredLabels(true);

    ui.enter();
}
项目:goclipse    文件:LangCompletionProposal.java   
protected LinkedModeModel getLinkedModeModel(ITextViewer viewer) throws BadLocationException {
    Indexable<SourceRange> sourceSubElements = proposal.getSourceSubElements();
    if(sourceSubElements == null || sourceSubElements.isEmpty()) {
        return null;
    }

    LinkedModeModel model = new LinkedModeModel();

    IDocument document = viewer.getDocument();
    int replaceOffset = getReplaceOffset();

    firstLinkedModeGroupPosition = -1;

    for (SourceRange sr : sourceSubElements) {
        LinkedPositionGroup group = new LinkedPositionGroup();
        int posOffset = replaceOffset + sr.getOffset();
        group.addPosition(new LinkedPosition(document, posOffset, sr.getLength()));
        if(firstLinkedModeGroupPosition == -1) {
            firstLinkedModeGroupPosition = posOffset;
        }
        model.addGroup(group);
    }

    return model;
}
项目:ec4e    文件:EditorConfigCompletionProposal.java   
@Override
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {

    if (event.character == fExitCharacter) {
        if (environment.anyPositionContains(offset))
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        else
            return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
    }

    switch (event.character) {
    case ';':
        return new ExitFlags(ILinkedModeListener.NONE, true);
    case SWT.CR:
        // when entering an anonymous class as a parameter, we don't
        // want
        // to jump after the parenthesis when return is pressed
        if (offset > 0) {
            try {
                if (fDocument.getChar(offset - 1) == '{')
                    return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
            } catch (BadLocationException e) {
            }
        }
        return null;
    default:
        return null;
    }
}
项目:ftc    文件:TweakedLinkedModeUI.java   
public void resume(LinkedModeModel model, int flags) {
    if ((flags & ILinkedModeListener.EXIT_ALL) != 0) {
        leave(flags);
    } else {
        connect();
        if ((flags & ILinkedModeListener.SELECT) != 0)
            select();
        ensureAnnotationModelInstalled();
        redraw();
    }
}
项目:texlipse    文件:TexCompletionProposal.java   
public void apply(IDocument document) {
    try {
        if (fentry.arguments > 0) {
            StringBuffer displayKey = new StringBuffer(fentry.key);
            for (int j=0; j < fentry.arguments; j++)
                displayKey.append("{}");
            document.replace(fReplacementOffset, fReplacementLength, displayKey.toString());
            if (TexlipsePlugin.getDefault().getPreferenceStore()
                    .getBoolean(TexlipseProperties.SMART_PARENS)){
                LinkedModeModel model= new LinkedModeModel();
                for (int j=0; j < fentry.arguments; j++){
                    int newOffset = fReplacementOffset + fentry.key.length() + j*2 + 1;
                    LinkedPositionGroup group = new LinkedPositionGroup();
                    group.addPosition(new LinkedPosition(document, newOffset, 0, LinkedPositionGroup.NO_STOP));
                    model.addGroup(group);
                }
                model.forceInstall();
                LinkedModeUI ui = new EditorLinkedModeUI(model, fviewer);
                ui.setSimpleMode(false);
                ui.setExitPolicy(new ExitPolicy('}', fviewer));
                ui.setExitPosition(fviewer, fReplacementOffset + displayKey.length(),
                        0, Integer.MAX_VALUE);
                ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
                ui.enter();
            }
        } else {
            document.replace(fReplacementOffset, fReplacementLength, fentry.key);
        }
    } catch (BadLocationException x) {
    }
}
项目:eclipse.jdt.ls    文件:LinkedProposalPositionGroup.java   
@Override
public TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model) throws CoreException {
    ImportRewrite impRewrite= StubUtility.createImportRewrite(fCompilationUnit, true);
    String replaceString= impRewrite.addImport(fTypeProposal);

    MultiTextEdit composedEdit= new MultiTextEdit();
    composedEdit.addChild(new ReplaceEdit(position.getOffset(), position.getLength(), replaceString));
    composedEdit.addChild(impRewrite.rewriteImports(null));
    return composedEdit;
}
项目:typescript.java    文件:TypeScriptCompletionProposal.java   
public ExitFlags doExit(LinkedModeModel environment, VerifyEvent event, int offset, int length) {

            if (event.character == fExitCharacter) {
                if (environment.anyPositionContains(offset))
                    return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
                else
                    return new ExitFlags(ILinkedModeListener.UPDATE_CARET, true);
            }

            switch (event.character) {
            case ';':
                return new ExitFlags(ILinkedModeListener.NONE, true);
            case SWT.CR:
                // when entering an anonymous class as a parameter, we don't
                // want
                // to jump after the parenthesis when return is pressed
                if (offset > 0) {
                    try {
                        if (fDocument.getChar(offset - 1) == '{')
                            return new ExitFlags(ILinkedModeListener.EXIT_ALL, true);
                    } catch (BadLocationException e) {
                    }
                }
                return null;
            default:
                return null;
            }
        }
项目:typescript.java    文件:RenameLinkedMode.java   
@Override
public void left(LinkedModeModel model, int flags) {
    linkedModeLeft();
    if ((flags & ILinkedModeListener.UPDATE_CARET) != 0) {
        doRename(fShowPreview);
    }
}
项目:bts    文件:XtextEditor.java   
/**
 * Finds the next position after the given position.
 * 
 * @param position
 *            the current position
 * @return the next position
 */
protected int findNextPosition(int position) {
    ISourceViewer viewer = getSourceViewer();
    int widget = -1;
    int next = position;
    while (next != BreakIterator.DONE && widget == -1) {
        next = fIterator.following(next);
        if (next != BreakIterator.DONE)
            widget = modelOffset2WidgetOffset(viewer, next);
    }

    IDocument document = viewer.getDocument();
    LinkedModeModel model = LinkedModeModel.getModel(document, position);
    if (model != null) {
        LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionEnd = linkedPosition.getOffset() + linkedPosition.getLength();
            if (position != linkedPositionEnd && linkedPositionEnd < next)
                next = linkedPositionEnd;
        } else {
            LinkedPosition nextLinkedPosition = model.findPosition(new LinkedPosition(document, next, 0));
            if (nextLinkedPosition != null) {
                int nextLinkedPositionOffset = nextLinkedPosition.getOffset();
                if (position != nextLinkedPositionOffset && nextLinkedPositionOffset < next)
                    next = nextLinkedPositionOffset;
            }
        }
    }

    return next;
}
项目:bts    文件:XtextEditor.java   
/**
 * Finds the previous position before the given position.
 * 
 * @param position
 *            the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
    ISourceViewer viewer = getSourceViewer();
    int widget = -1;
    int previous = position;
    while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
        previous = fIterator.preceding(previous);
        if (previous != BreakIterator.DONE)
            widget = modelOffset2WidgetOffset(viewer, previous);
    }

    IDocument document = viewer.getDocument();
    LinkedModeModel model = LinkedModeModel.getModel(document, position);
    if (model != null) {
        LinkedPosition linkedPosition = model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionOffset = linkedPosition.getOffset();
            if (position != linkedPositionOffset && previous < linkedPositionOffset)
                previous = linkedPositionOffset;
        } else {
            LinkedPosition previousLinkedPosition = model
                    .findPosition(new LinkedPosition(document, previous, 0));
            if (previousLinkedPosition != null) {
                int previousLinkedPositionEnd = previousLinkedPosition.getOffset()
                        + previousLinkedPosition.getLength();
                if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd)
                    previous = previousLinkedPositionEnd;
            }
        }
    }

    return previous;
}
项目:bts    文件:RenameLinkedMode.java   
public boolean start(IRenameElementContext renameElementContext, IProgressMonitor monitor) {
    if (renameElementContext == null)
        throw new IllegalArgumentException("RenameElementContext is null");
    this.linkedPositionGroup = linkedPositionGroupCalculator.getLinkedPositionGroup(renameElementContext, monitor);
    if (linkedPositionGroup == null || linkedPositionGroup.isEmpty())
        return false;
    this.editor = (XtextEditor) renameElementContext.getTriggeringEditor();
    this.focusEditingSupport = new FocusEditingSupport();
    ISourceViewer viewer = editor.getInternalSourceViewer();
    IDocument document = viewer.getDocument();
    originalSelection = viewer.getSelectedRange();
    currentPosition = linkedPositionGroup.getPositions()[0];
    originalName = getCurrentName();
    try {
        linkedModeModel = new LinkedModeModel();
        linkedModeModel.addGroup(linkedPositionGroup);
        linkedModeModel.forceInstall();
        linkedModeModel.addLinkingListener(new EditorSynchronizer());
        LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer);
        ui.setExitPolicy(new ExitPolicy(document));
        if (currentPosition.includes(originalSelection.x))
            ui.setExitPosition(viewer, originalSelection.x, 0, Integer.MAX_VALUE);
        ui.enter();
        if (currentPosition.includes(originalSelection.x)
                && currentPosition.includes(originalSelection.x + originalSelection.y))
            viewer.setSelectedRange(originalSelection.x, originalSelection.y);
        if (viewer instanceof IEditingSupportRegistry) {
            IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
            registry.register(focusEditingSupport);
        }
        openPopup();
        return true;
    } catch (BadLocationException e) {
        throw new WrappedException(e);
    }
}
项目:bts    文件:RenameLinkedMode.java   
public void left(LinkedModeModel model, int flags) {
    //boolean isValidNewName = updateNewName();
    if ((flags & ILinkedModeListener.UPDATE_CARET) != 0) {// && isValidNewName) {
        if (showPreview)
            controller.startRefactoring(RefactoringType.REFACTORING_PREVIEW);
        else
            controller.startRefactoring(RefactoringType.REFACTORING_DIRECT);
    } else {
        controller.cancelLinkedMode();
    }
}
项目:che    文件:LinkedProposalPositionGroup.java   
@Override
public TextEdit computeEdits(
    int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model)
    throws CoreException {
  ImportRewrite impRewrite = StubUtility.createImportRewrite(fCompilationUnit, true);
  String replaceString = impRewrite.addImport(fTypeProposal);

  MultiTextEdit composedEdit = new MultiTextEdit();
  composedEdit.addChild(
      new ReplaceEdit(position.getOffset(), position.getLength(), replaceString));
  composedEdit.addChild(impRewrite.rewriteImports(null));
  return composedEdit;
}
项目:che    文件:UndoTextFileChange.java   
private UndoEdit doPerformEdits(IDocument document, boolean[] setContentStampSuccess)
    throws MalformedTreeException, BadLocationException, CoreException {
  // perform the changes
  LinkedModeModel.closeAllModels(document);
  UndoEdit redo = fUndo.apply(document, TextEdit.CREATE_UNDO);

  // try to restore the document content stamp
  setContentStampSuccess[0] = ContentStamps.set(document, fContentStampToRestore);
  return redo;
}
项目:velocity-edit    文件:VelocityTemplateProposal.java   
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    apply(viewer.getDocument());

    try {
        LinkedModeModel model = new LinkedModeModel();

        StringBuffer insert = new StringBuffer();
        insert.append(macro.name);
        insert.append("(");

        int parameterOffset = position.offset + insert.length();
        for (int k = 0; k < macro.parameters.length; k++) {
            LinkedPositionGroup group = new LinkedPositionGroup();

            if (k > 0)
                // space between parameters
                parameterOffset++;

            group.addPosition(new LinkedPosition(viewer.getDocument(), parameterOffset, macro.parameters[k].length(),
                    LinkedPositionGroup.NO_STOP));
            model.addGroup(group);

            parameterOffset += macro.parameters[k].length();
        }

        model.forceInstall();

        LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
        ui.setExitPosition(viewer, parameterOffset + 1, 0, Integer.MAX_VALUE);
        ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
        ui.enter();

        fSelectedRegion = ui.getSelectedRegion();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:APICloud-Studio    文件:XMLAttributeProposal.java   
/**
 * Special code added to allow tabstop positions so we can easily tab past the quotes for Events/Attributes.
 */
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset)
{
    super.apply(viewer, trigger, stateMask, offset);

    // See if there are any positions that should be linked. Last is always exit, first is cursor position
    if (_positions != null && _positions.length > 0)
    {
        IDocument document = viewer.getDocument();
        boolean validPrefix = isValidPrefix(getPrefix(document, offset), getDisplayString());
        int shift = (validPrefix) ? offset - this._replacementOffset : 0;

        try
        {
            LinkedModeModel.closeAllModels(document); // Exit out of any existing linked mode

            LinkedModeModel model = new LinkedModeModel();
            int i = 0;
            for (int pos : _positions)
            {
                LinkedPositionGroup group = new LinkedPositionGroup();
                group.addPosition(new LinkedPosition(document, (offset - shift) + pos, 0, i++));
                model.addGroup(group);
            }

            model.forceInstall();
            LinkedModeUI ui = new LinkedModeUI(model, viewer);
            ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
            ui.setExitPosition(viewer, (offset - shift) + _positions[_positions.length - 1], 0, Integer.MAX_VALUE);
            ui.enter();
        }
        catch (BadLocationException e)
        {
            IdeLog.logError(XMLPlugin.getDefault(), e);
        }
    }
}
项目:APICloud-Studio    文件:AttributeOrEventProposal.java   
/**
 * Special code added to allow tabstop positions so we can easily tab past the quotes for Events/Attributes.
 */
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset)
{
    super.apply(viewer, trigger, stateMask, offset);

    // See if there are any positions that should be linked. Last is always exit, first is cursor position
    if (_positions != null && _positions.length > 0)
    {
        IDocument document = viewer.getDocument();
        boolean validPrefix = isValidPrefix(getPrefix(document, offset), getDisplayString());
        int shift = (validPrefix) ? offset - this._replacementOffset : 0;

        try
        {
            LinkedModeModel.closeAllModels(document); // Exit out of any existing linked mode

            LinkedModeModel model = new LinkedModeModel();
            int i = 0;
            for (int pos : _positions)
            {
                LinkedPositionGroup group = new LinkedPositionGroup();
                group.addPosition(new LinkedPosition(document, (offset - shift) + pos, 0, i++));
                model.addGroup(group);
            }

            model.forceInstall();
            LinkedModeUI ui = new LinkedModeUI(model, viewer);
            ui.setCyclingMode(LinkedModeUI.CYCLE_ALWAYS);
            ui.setExitPosition(viewer, (offset - shift) + _positions[_positions.length - 1], 0, Integer.MAX_VALUE);
            ui.enter();
        }
        catch (BadLocationException e)
        {
            IdeLog.logError(HTMLPlugin.getDefault(), e);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:LinkedProposalPositionGroup.java   
@Override
public TextEdit computeEdits(int offset, LinkedPosition position, char trigger, int stateMask, LinkedModeModel model) throws CoreException {
    ImportRewrite impRewrite= StubUtility.createImportRewrite(fCompilationUnit, true);
    String replaceString= impRewrite.addImport(fTypeProposal);

    MultiTextEdit composedEdit= new MultiTextEdit();
    composedEdit.addChild(new ReplaceEdit(position.getOffset(), position.getLength(), replaceString));
    composedEdit.addChild(impRewrite.rewriteImports(null));
    return composedEdit;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
/**
 * Finds the next position after the given position.
 *
 * @param position the current position
 * @return the next position
 */
protected int findNextPosition(int position) {
    ISourceViewer viewer= getSourceViewer();
    int widget= -1;
    int next= position;
    while (next != BreakIterator.DONE && widget == -1) { // XXX: optimize
        next= fIterator.following(next);
        if (next != BreakIterator.DONE)
            widget= modelOffset2WidgetOffset(viewer, next);
    }

    IDocument document= viewer.getDocument();
    LinkedModeModel model= LinkedModeModel.getModel(document, position);
    if (model != null && next != BreakIterator.DONE) {
        LinkedPosition linkedPosition= model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionEnd= linkedPosition.getOffset() + linkedPosition.getLength();
            if (position != linkedPositionEnd && linkedPositionEnd < next)
                next= linkedPositionEnd;
        } else {
            LinkedPosition nextLinkedPosition= model.findPosition(new LinkedPosition(document, next, 0));
            if (nextLinkedPosition != null) {
                int nextLinkedPositionOffset= nextLinkedPosition.getOffset();
                if (position != nextLinkedPositionOffset && nextLinkedPositionOffset < next)
                    next= nextLinkedPositionOffset;
            }
        }
    }

    return next;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
/**
 * Finds the previous position before the given position.
 *
 * @param position the current position
 * @return the previous position
 */
protected int findPreviousPosition(int position) {
    ISourceViewer viewer= getSourceViewer();
    int widget= -1;
    int previous= position;
    while (previous != BreakIterator.DONE && widget == -1) { // XXX: optimize
        previous= fIterator.preceding(previous);
        if (previous != BreakIterator.DONE)
            widget= modelOffset2WidgetOffset(viewer, previous);
    }

    IDocument document= viewer.getDocument();
    LinkedModeModel model= LinkedModeModel.getModel(document, position);
    if (model != null && previous != BreakIterator.DONE) {
        LinkedPosition linkedPosition= model.findPosition(new LinkedPosition(document, position, 0));
        if (linkedPosition != null) {
            int linkedPositionOffset= linkedPosition.getOffset();
            if (position != linkedPositionOffset && previous < linkedPositionOffset)
                previous= linkedPositionOffset;
        } else {
            LinkedPosition previousLinkedPosition= model.findPosition(new LinkedPosition(document, previous, 0));
            if (previousLinkedPosition != null) {
                int previousLinkedPositionEnd= previousLinkedPosition.getOffset() + previousLinkedPosition.getLength();
                if (position != previousLinkedPositionEnd && previous < previousLinkedPositionEnd)
                    previous= previousLinkedPositionEnd;
            }
        }
    }

    return previous;
}