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

项目:LibertyEiffel-Eclipse-Plugin    文件:EiffelAutoEditStrategy.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    if (command.text.equals("{")) {
        int line;
        try {
            line = document.getLineOffset(command.offset);
            String indent = getIndentOfLine(document, line);

            command.text = "{" + "\r\n" + indent + "}";
            configureCommand(command);

        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
项目:LibertyEiffel-Eclipse-Plugin    文件:EiffelAutoEditStrategy.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    if (command.text.equals("{")) {
        int line;
        try {
            line = document.getLineOffset(command.offset);
            String indent = getIndentOfLine(document, line);

            command.text = "{" + "\r\n" + indent + "}";
            configureCommand(command);

        } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
项目:DarwinSPL    文件:DwprofileAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HyexpressionAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HyvalidityformulaAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HydatavalueAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HymappingAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HyconstraintsAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:DarwinSPL    文件:HymanifestAutoEditStrategy.java   
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
    boolean isLineBreak = isLineBreak(text);
    if (!isLineBreak) {
        return;
    }

    String documentText = document.get();
    String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
    if (openingBracketBefore == null) {
        return;
    }
    // add additional indentation (because a line break was entered after an opening
    // bracket)
    command.text = command.text + "\t";
    String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
    boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
    // add closing bracket (if required)
    if (closingBracketIsMissing) {
        command.text = command.text + textAfter;
        command.text = command.text + closingBracket;
    }
    command.shiftsCaret = false;
    command.caretOffset = command.offset + textAfter.length() + 1;
}
项目:texlipse    文件:TexEditorTools.java   
/**
 * Returns a text String of the (line + <code>lineDif</code>). 
 * @param document  IDocument that contains the line.
 * @param command   DocumentCommand that determines the line.
 * @param delim     are delimiters included
 * @param lineDif   0 = current line, 1 = next line, -1 previous line etc...
 * @return          the text of the line. 
 */
public String getStringAt(IDocument document, 
        DocumentCommand command, boolean delim, int lineDif) {
    String line = "";
       int lineBegin, lineLength;
       try {
           if (delim) {
               lineLength = getLineLength(document, command, true, lineDif);
           } else {
               lineLength = getLineLength(document, command, false, lineDif);
           }
           if (lineLength > 0) {
               lineBegin = document.getLineOffset(document
                       .getLineOfOffset(command.offset) + lineDif);
               line = document.get(lineBegin, lineLength);
           }
       } catch (BadLocationException e) {
           TexlipsePlugin.log("TexEditorTools.getStringAt", e);
       }
       return line;
}
项目:texlipse    文件:TexAutoIndentStrategy.java   
/**
 * Erases the \item -string from a line
 * 
 * @param d
 * @param c
 */
private void dropItem(IDocument d, DocumentCommand c) {
    try {
        if (itemSetted && itemAtLine == (d.getLineOfOffset(c.offset) - 1)) {
            IRegion r = d.getLineInformationOfOffset(c.offset);
            String line = d.get(r.getOffset(), r.getLength());
            if ("\\item".equals(line.trim()) || "\\item[]".equals(line.trim())) {
                c.shiftsCaret = false;
                c.length = line.length();
                c.offset = r.getOffset();
                c.text = getIndentation(line);
                c.caretOffset = c.offset + c.text.length();
            }
        }
    } catch (BadLocationException e) {
        TexlipsePlugin.log("TexAutoIndentStrategy:dropItem", e);
    }
    itemSetted = false;
}
项目:hybris-commerce-eclipse-plugin    文件:ImpexBracesAutoEditStrategy.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {

    if (command.text.equalsIgnoreCase("\"")) {
        command.text = "\"\"";
        configureCommand(command);
    }
    else if (command.text.equalsIgnoreCase("'")) {
        command.text = "''";
        configureCommand(command);
    }
    else if (command.text.equalsIgnoreCase("[")) {
        command.text = "[]";
        configureCommand(command);
    }
    else if (command.text.equalsIgnoreCase("(")) {
        command.text = "()";
        configureCommand(command);
    }

}
项目:angular-eclipse    文件:StructuredAutoEditStrategyAngular.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    if (!supportsSmartInsert(document)) {
        return;
    }
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model != null) {
            if (command.text != null) {
                smartInsertCloseEndEL(command, document, model);
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
项目:angular-eclipse    文件:StructuredAutoEditStrategyAngular.java   
private void smartInsertCloseEndEL(DocumentCommand command, IDocument document, IStructuredModel model) {
    try {
        if (isPreferenceEnabled(AngularUIPreferenceNames.TYPING_COMPLETE_END_EL) && command.text.equals("{") //$NON-NLS-1$
                && document.getLength() > 0 && document.getChar(command.offset - 1) == '{') {
            IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset - 1);

            command.text += "}}";
            command.shiftsCaret = false;
            command.caretOffset = command.offset + 1;
            command.doit = false;
        }
    } catch (BadLocationException e) {

    }

}
项目:fluentmark    文件:LineWrapEditStrategy.java   
@Override
public void customizeDocumentCommand(final IDocument doc, final DocumentCommand cmd) {
    if (cmd.length != 0 || cmd.text == null) return;

    try {
        if (TextUtilities.endsWith(doc.getLegalLineDelimiters(), cmd.text) != -1) {
            if (AutoEdit.isBlankLine(doc, cmd.offset)) {
                int beg = AutoEdit.getLineOffset(doc, cmd.offset);
                int len = cmd.offset - beg;

                DeleteEdit blanks = new DeleteEdit(beg, len);
                blanks.apply(doc);
                cmd.offset = beg;

            } else {
                autoIndent(doc, cmd, false);    // return entered
            }

        } else if (evaluateInsertPoint(doc, cmd)) {
            autoIndent(doc, cmd, true);     // insert point exceeds limit
        } else if (evaluateLineWidth(doc, cmd)) {
            wrapLines(doc, cmd);            // line end exceeds limit
        }
    } catch (BadLocationException e) {}
}
项目:typescript.java    文件:JSDocAutoIndentStrategy.java   
private String createMethodTags(IDocument document, DocumentCommand command, String indentation,
        String lineDelimiter, IFunction method) throws CoreException, BadLocationException {
    IRegion partition = TextUtilities.getPartition(document, fPartitioning, command.offset, false);
    IFunction inheritedMethod = getInheritedMethod(method);
    String comment = CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
    if (comment != null) {
        comment = comment.trim();
        boolean javadocComment = comment.startsWith("/**"); //$NON-NLS-1$
        if (!isFirstComment(document, command, method, javadocComment))
            return null;
        boolean isJavaDoc = partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
        if (javadocComment == isJavaDoc) {
            return prepareTemplateComment(comment, indentation, method.getJavaScriptProject(), lineDelimiter);
        }
    }
    return null;
}
项目:typescript.java    文件:JSDocAutoIndentStrategy.java   
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {

        if (!isSmartMode())
            return;

        if (command.text != null) {
            if (command.length == 0) {
                String[] lineDelimiters = document.getLegalLineDelimiters();
                int index = TextUtilities.endsWith(lineDelimiters, command.text);
                if (index > -1) {
                    // ends with line delimiter
                    if (lineDelimiters[index].equals(command.text))
                        // just the line delimiter
                        indentAfterNewLine(document, command);
                    return;
                }
            }

            if (command.text.equals("/")) { //$NON-NLS-1$
                indentAfterCommentEnd(document, command);
                return;
            }
        }
    }
项目:bts    文件:MultiLineTerminalsEditStrategy.java   
/**
 * Expects the cursor to be in the same line as the start terminal
 * puts any text between start terminal and cursor into a separate newline before the cursor.
 * puts any text between cursor and end terminal into a separate newline after the cursor.
 * puts the closing terminal into a separate line at the end.
 * adds a closing terminal if not existent.
 */
protected CommandInfo handleCursorInFirstLine(IDocument document, DocumentCommand command, IRegion startTerminal,
        IRegion stopTerminal) throws BadLocationException {
    CommandInfo newC = new CommandInfo();
    newC.isChange = true;
    newC.offset = command.offset;
    newC.text += command.text + indentationString;
    newC.cursorOffset = command.offset + newC.text.length();
    if (stopTerminal == null && atEndOfLineInput(document, command.offset)) {
        newC.text += command.text + getRightTerminal();
    }
    if (stopTerminal != null && stopTerminal.getOffset() >= command.offset && util.isSameLine(document, stopTerminal.getOffset(), command.offset)) {
        String string = document.get(command.offset, stopTerminal.getOffset() - command.offset);
        if (string.trim().length() > 0)
            newC.text += string.trim();
        newC.text += command.text;
        newC.length += string.length();
    }
    return newC;
}
项目:bts    文件:PartitionDeletionEditStrategy.java   
@Override
protected void internalCustomizeDocumentCommand(IDocument document, DocumentCommand command)
        throws BadLocationException {
    if (command.text.equals("") && command.length == 1) {
        if (command.offset + right.length() + left.length() > document.getLength())
            return;
        if (command.offset + command.length - left.length() < 0)
            return;
        if (command.length != left.length())
            return;
        String string = document.get(command.offset, left.length() + right.length());
        if (string.equals(left + right)) {
            command.length = left.length() + right.length();
        }
    }
}
项目:bts    文件:CompoundMultiLineTerminalsEditStrategy.java   
@Override
protected void internalCustomizeDocumentCommand(IDocument document, DocumentCommand command)
        throws BadLocationException {
    if (command.length != 0)
        return;
    String[] lineDelimiters = document.getLegalLineDelimiters();
    int delimiterIndex = TextUtilities.startsWith(lineDelimiters, command.text);
    if (delimiterIndex != -1) {
        MultiLineTerminalsEditStrategy bestStrategy = null;
        IRegion bestStart = null;
        for(MultiLineTerminalsEditStrategy strategy: strategies) {
            IRegion candidate = strategy.findStartTerminal(document, command.offset);
            if (candidate != null) {
                if (bestStart == null || bestStart.getOffset() < candidate.getOffset()) {
                    bestStrategy = strategy;
                    bestStart = candidate;
                }
            }
        }
        if (bestStrategy != null) {
            bestStrategy.internalCustomizeDocumentCommand(document, command);
        }
    }
}
项目:gwt-eclipse-plugin    文件:StructuredAutoEditStrategyInlinedCss.java   
private boolean checkAndPrepareForNewline(IDocument document,
    DocumentCommand command) {
  try {
    String documentAndCommandText = document.get(0, command.offset)
        + command.text;
    /*
     * The only case where we want to add an indentation after newline is if
     * there is a opening curly brace.
     */
    Matcher matcher = NEWLINE_AFTER_OPEN_BRACE.matcher(documentAndCommandText);
    if (!matcher.matches()) {
      return false;
    }
  } catch (BadLocationException e) {
    return false;
  }

  /*
   * The StructuredAutoEditStrategyCSS will only add proper indentation if the
   * last character is a newline. We remove the whitespace following the
   * newline which was added by the XML autoedit strategy that comes before
   * us.
   */
  command.text = command.text.replaceAll("\\n\\s+$", "\n");
  return command.text.endsWith("\n");
}
项目:velocity-edit    文件:VelocityAutoIndentStrategy.java   
public void smartIndentOnBackspace(IDocument doc, DocumentCommand cmd)
{
    if (isUsingTab) { return; }
    if ((cmd.offset == -1) || (doc.getLength() == 0)) { return; }
    try
    {
        int len = doc.getLength();
        int p = (cmd.offset != len) ? cmd.offset : (cmd.offset - 1);
        int line = doc.getLineOfOffset(p);
        int start = doc.getLineOffset(line);
        int whiteend = findEndOfWhiteSpace(doc, start, start + doc.getLineLength(line));
        if ((cmd.offset + 1) != whiteend) { return; }
        int indent = indentWidthOf(doc.get(start, whiteend - start), fTabWidth);
        indent = unIndent(indent, 1);
        cmd.offset = start;
        cmd.length = whiteend - start;
        cmd.text = getIndentString(indent).toString();
    }
    catch (BadLocationException e)
    {
    }
}
项目:velocity-edit    文件:VelocityAutoIndentStrategy.java   
public void sameIndentAs(int matchoffset, int line, IDocument document, DocumentCommand cmd)
{
    try
    {
        int indent = getIndentOfLine(document, document.getLineOfOffset(matchoffset));
        StringBuffer buf = getIndentString(indent);
        int start = (line < 0) ? 0 : document.getLineOffset(line);
        int whiteend = findEndOfWhiteSpace(document, start, cmd.offset);
        buf.append(document.get(whiteend, cmd.offset - whiteend));
        buf.append(cmd.text);
        cmd.length += (cmd.offset - start);
        cmd.offset = start;
        cmd.text = buf.toString();
    }
    catch (BadLocationException e)
    {
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertiesFileAutoEditStrategy.java   
private ICompletionProposal escape(DocumentCommand command) {
    try {
        String charsetName= fFile.getCharset();
        if (!charsetName.equals(fCharsetName)) {
            fCharsetName= charsetName;
            fCharsetEncoder= Charset.forName(fCharsetName).newEncoder();
        }
    } catch (CoreException e) {
        return null;
    }

    String text= command.text;
    boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text);
    boolean escapeBackslash= (text.length() > 1) && ((escapeUnicodeChars && PropertiesFileEscapes.containsUnescapedBackslash(text)) || PropertiesFileEscapes.containsInvalidEscapeSequence(text));

    if (!escapeUnicodeChars && !escapeBackslash)
        return null;

    command.text= PropertiesFileEscapes.escape(text, false, false, escapeUnicodeChars);
    if (escapeBackslash) {
        String proposalText= PropertiesFileEscapes.escape(text, false, true, escapeUnicodeChars);
        return new EscapeBackslashCompletionProposal(proposalText, command.offset, command.text.length(),
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashesInOriginalString);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:AbstractJavaCompletionProposal.java   
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset) throws BadLocationException {
    DocumentCommand cmd= new DocumentCommand() {
    };

    cmd.offset= referenceOffset;
    cmd.length= 0;
    cmd.text= Character.toString(trigger);
    cmd.doit= true;
    cmd.shiftsCaret= true;
    cmd.caretOffset= getReplacementOffset() + getCursorPosition();

    SmartSemicolonAutoEditStrategy strategy= new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING);
    strategy.customizeDocumentCommand(document, cmd);

    replace(document, cmd.offset, cmd.length, cmd.text);
    setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length());
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaDocAutoIndentStrategy.java   
/**
 * Creates the Javadoc tags for newly inserted comments.
 *
 * @param document the document
 * @param command the command
 * @param indentation the base indentation to use
 * @param lineDelimiter the line delimiter to use
 * @param unit the compilation unit shown in the editor
 * @return the tags to add to the document
 * @throws CoreException if accessing the Java model fails
 * @throws BadLocationException if accessing the document fails
 */
private String createJavaDocTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, ICompilationUnit unit)
    throws CoreException, BadLocationException
{
    IJavaElement element= unit.getElementAt(command.offset);
    if (element == null)
        return null;

    switch (element.getElementType()) {
    case IJavaElement.TYPE:
        return createTypeTags(document, command, indentation, lineDelimiter, (IType) element);

    case IJavaElement.METHOD:
        return createMethodTags(document, command, indentation, lineDelimiter, (IMethod) element);

    default:
        return null;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaDocAutoIndentStrategy.java   
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method)
    throws CoreException, BadLocationException
{
    IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false);
    IMethod inheritedMethod= getInheritedMethod(method);
    String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
    if (comment != null) {
        comment= comment.trim();
        boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$
        if (!isFirstComment(document, command, method, javadocComment))
            return null;
        boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
        if (javadocComment == isJavaDoc) {
            return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaDocAutoIndentStrategy.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {

    if (!isSmartMode())
        return;

    if (command.text != null) {
        if (command.length == 0) {
            String[] lineDelimiters= document.getLegalLineDelimiters();
            int index= TextUtilities.endsWith(lineDelimiters, command.text);
            if (index > -1) {
                // ends with line delimiter
                if (lineDelimiters[index].equals(command.text))
                    // just the line delimiter
                    indentAfterNewLine(document, command);
                return;
            }
        }

        if (command.text.equals("/")) { //$NON-NLS-1$
            indentAfterCommentEnd(document, command);
            return;
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:PropertiesFileAutoEditStrategy.java   
private ICompletionProposal escape(DocumentCommand command) {
    try {
        String charsetName= fFile.getCharset();
        if (!charsetName.equals(fCharsetName)) {
            fCharsetName= charsetName;
            fCharsetEncoder= Charset.forName(fCharsetName).newEncoder();
        }
    } catch (CoreException e) {
        return null;
    }

    String text= command.text;
    boolean escapeUnicodeChars= !fCharsetEncoder.canEncode(text);
    boolean escapeBackslash= (text.length() > 1) && ((escapeUnicodeChars && PropertiesFileEscapes.containsUnescapedBackslash(text)) || PropertiesFileEscapes.containsInvalidEscapeSequence(text));

    if (!escapeUnicodeChars && !escapeBackslash)
        return null;

    command.text= PropertiesFileEscapes.escape(text, false, false, escapeUnicodeChars);
    if (escapeBackslash) {
        String proposalText= PropertiesFileEscapes.escape(text, false, true, escapeUnicodeChars);
        return new EscapeBackslashCompletionProposal(proposalText, command.offset, command.text.length(),
                PropertiesFileEditorMessages.EscapeBackslashCompletionProposal_escapeBackslashesInOriginalString);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AbstractJavaCompletionProposal.java   
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset) throws BadLocationException {
    DocumentCommand cmd= new DocumentCommand() {
    };

    cmd.offset= referenceOffset;
    cmd.length= 0;
    cmd.text= Character.toString(trigger);
    cmd.doit= true;
    cmd.shiftsCaret= true;
    cmd.caretOffset= getReplacementOffset() + getCursorPosition();

    SmartSemicolonAutoEditStrategy strategy= new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING);
    strategy.customizeDocumentCommand(document, cmd);

    replace(document, cmd.offset, cmd.length, cmd.text);
    setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length());
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaDocAutoIndentStrategy.java   
/**
 * Creates the Javadoc tags for newly inserted comments.
 *
 * @param document the document
 * @param command the command
 * @param indentation the base indentation to use
 * @param lineDelimiter the line delimiter to use
 * @param unit the compilation unit shown in the editor
 * @return the tags to add to the document
 * @throws CoreException if accessing the Java model fails
 * @throws BadLocationException if accessing the document fails
 */
private String createJavaDocTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, ICompilationUnit unit)
    throws CoreException, BadLocationException
{
    IJavaElement element= unit.getElementAt(command.offset);
    if (element == null)
        return null;

    switch (element.getElementType()) {
    case IJavaElement.TYPE:
        return createTypeTags(document, command, indentation, lineDelimiter, (IType) element);

    case IJavaElement.METHOD:
        return createMethodTags(document, command, indentation, lineDelimiter, (IMethod) element);

    default:
        return null;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaDocAutoIndentStrategy.java   
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method)
    throws CoreException, BadLocationException
{
    IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false);
    IMethod inheritedMethod= getInheritedMethod(method);
    String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
    if (comment != null) {
        comment= comment.trim();
        boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$
        if (!isFirstComment(document, command, method, javadocComment))
            return null;
        boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
        if (javadocComment == isJavaDoc) {
            return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaDocAutoIndentStrategy.java   
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {

    if (!isSmartMode())
        return;

    if (command.text != null) {
        if (command.length == 0) {
            String[] lineDelimiters= document.getLegalLineDelimiters();
            int index= TextUtilities.endsWith(lineDelimiters, command.text);
            if (index > -1) {
                // ends with line delimiter
                if (lineDelimiters[index].equals(command.text))
                    // just the line delimiter
                    indentAfterNewLine(document, command);
                return;
            }
        }

        if (command.text.equals("/")) { //$NON-NLS-1$
            indentAfterCommentEnd(document, command);
            return;
        }
    }
}
项目:Pydev    文件:AutoEditStrategyNewLineHelper.java   
public String getPreviousLineIndent(DocumentCommand command, IDocument document) {
    String prevLineIndent = "";
    try {
        // find start of line
        int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
        IRegion info = document.getLineInformationOfOffset(p);
        int start = info.getOffset();

        // find white spaces
        int end = findEndOfWhiteSpace(document, start, command.offset);

        if (end > start) {
            prevLineIndent = document.get(start, end - start);
        }
    } catch (BadLocationException e) {
        //ignore
    }
    return prevLineIndent;
}
项目:Pydev    文件:AutoEditStrategyScopeCreationHelper.java   
private String getReplacement(DocumentCommand command, Tuple<String, String> found, String selectedText) {
    String replacement;
    if (found != null && found.o1.equals(command.text)) {
        replacement = found.o1 + selectedText + found.o2;

    } else {
        if (command.text.length() == 1) {
            char peer;
            char char0 = command.text.charAt(0);
            try {
                peer = StringUtils.getPeer(char0);
            } catch (Exception e) {
                peer = char0;
            }
            replacement = char0 + selectedText + peer;
        } else {
            replacement = command.text + selectedText + command.text;
        }

    }
    return replacement;
}
项目:Pydev    文件:AutoEditStrategyHelper.java   
/**
 * Called right after a ' or "
 */
public void handleAutoClose(IDocument document, DocumentCommand command, char start, char end) {
    TextSelectionUtils ps = new TextSelectionUtils(document, new TextSelection(document, command.offset,
            command.length));

    try {
        char nextChar = ps.getCharAfterCurrentOffset();
        if (Character.isJavaIdentifierPart(nextChar)) {
            //we're just before a word (don't try to do anything in this case)
            //e.g. |var (| is cursor position)
            return;
        }
    } catch (BadLocationException e) {
    }

    command.text = Character.toString(start) + Character.toString(end);
    command.shiftsCaret = false;
    command.caretOffset = command.offset + 1;
}
项目:Pydev    文件:AutoEditStrategyHelper.java   
public void handleAutoSkip(IDocument document, DocumentCommand command, char c) {
    TextSelectionUtils ps = new TextSelectionUtils(document, new TextSelection(document, command.offset,
            command.length));

    Tuple<String, String> beforeAndAfterMatchingChars = ps.getBeforeAndAfterMatchingChars(c);

    //Reminder: int matchesBefore = beforeAndAfterMatchingChars.o1.length();
    int matchesAfter = beforeAndAfterMatchingChars.o2.length();

    if (matchesAfter == 1) {
        //just walk the caret
        command.text = "";
        command.shiftsCaret = false;
        command.caretOffset = command.offset + 1;
    }
}
项目:Pydev    文件:AutoEditStrategyHelper.java   
public void handleCloseParens(IDocument document, DocumentCommand command, char c) {
    // you can only do the replacement if the next character already there is what the user is trying to input

    try {
        if (command.offset < document.getLength()
                && document.get(command.offset, 1).equals(command.text)) {
            // the following searches through each of the end braces and
            // sees if the command has one of them

            boolean found = false;
            for (int i = 1; i <= BRACKETS.length && !found; i += 2) {
                char b = BRACKETS[i];
                if (b == c) {
                    found = true;
                    performPairReplacement(document, command);
                }
            }
        }
    } catch (BadLocationException e) {
        Log.log(e);
    }
}
项目:Pydev    文件:AutoEditStrategyHelper.java   
/**
 * @return true if we should skip a ), ] or }
 */
public boolean canSkipCloseParenthesis(IDocument document, DocumentCommand command) throws BadLocationException {
    TextSelectionUtils ps = new TextSelectionUtils(document, command.offset);

    char c = ps.getCharAtCurrentOffset();

    try {
        char peer = StringUtils.getPeer(c);

        String contentType = getContentType(document, command);
        String doc = getPartsWithPartition(document, contentType);
        int chars = StringUtils.countChars(c, doc);
        int peers = StringUtils.countChars(peer, doc);

        boolean skipChar = chars == peers;
        return skipChar;
    } catch (NoPeerAvailableException e) {
        return false;
    }
}
项目:Pydev    文件:PySourceViewer.java   
/**
 * Overridden because we want to do things differently in block selection mode.
 */
@Override
protected void customizeDocumentCommand(DocumentCommand command) {
    if (pyAutoIndentStrategy == null) {
        pyAutoIndentStrategy = this.getEdit().getAutoEditStrategy();
    }

    boolean blockSelection = false;
    try {
        blockSelection = this.getTextWidget().getBlockSelection();
    } catch (Throwable e) {
        //that's OK (only available in eclipse 3.5)
    }

    pyAutoIndentStrategy.setBlockSelection(blockSelection);
    super.customizeDocumentCommand(command);
}