Example usage for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameinterface

List of usage examples for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameinterface

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameinterface.

Prototype

int TokenNameinterface

To view the source code for org.eclipse.jdt.core.compiler ITerminalSymbols TokenNameinterface.

Click Source Link

Usage

From source file:com.cb.eclipse.folding.java.calculation.RootStrategy.java

License:Open Source License

/**
 * Process until we hit the 'class' identifier. That is the sign that we've
 * actually found the beginning of the 'type'. We throw away any remaining
 * regions that weren't captured by previous identifier collisions, because
 * they will be assigned to the type by Eclipse.
 * //w w w.  ja va 2 s . com
 * @see com.cb.eclipse.folding.java.calculation.RegionCalculationStrategy#keepProcessing(int)
 */
public boolean keepProcessing(int nextToken) {

    if (nextToken == ITerminalSymbols.TokenNameclass || nextToken == ITerminalSymbols.TokenNameinterface) {
        helper.reset();
        return false;
    }
    return true;
}

From source file:com.github.elucash.lambda4jdt.FoldingStructureProvider.java

License:Open Source License

private IRegion computeHeaderComment(FoldingStructureComputationContext ctx) throws JavaModelException {
    // search at most up to the first type
    ISourceRange range = ctx.getFirstType().getSourceRange();
    if (range == null)
        return null;
    int start = 0;
    int end = range.getOffset();

    /* code adapted from CommentFormattingStrategy:
     * scan the header content up to the first type. Once a comment is
     * found, accumulate any additional comments up to the stop condition.
     * The stop condition is reaching a package declaration, import container,
     * or the end of the input./*from w w w  .j av a 2  s . com*/
     */
    IScanner scanner = ctx.getScanner();
    scanner.resetTo(start, end);

    int headerStart = -1;
    int headerEnd = -1;
    try {
        boolean foundComment = false;
        int terminal = scanner.getNextToken();
        while (terminal != ITerminalSymbols.TokenNameEOF && !(terminal == ITerminalSymbols.TokenNameclass
                || terminal == ITerminalSymbols.TokenNameinterface || terminal == ITerminalSymbols.TokenNameenum
                || (foundComment && (terminal == ITerminalSymbols.TokenNameimport
                        || terminal == ITerminalSymbols.TokenNamepackage)))) {

            if (terminal == ITerminalSymbols.TokenNameCOMMENT_JAVADOC
                    || terminal == ITerminalSymbols.TokenNameCOMMENT_BLOCK
                    || terminal == ITerminalSymbols.TokenNameCOMMENT_LINE) {
                if (!foundComment)
                    headerStart = scanner.getCurrentTokenStartPosition();
                headerEnd = scanner.getCurrentTokenEndPosition();
                foundComment = true;
            }
            terminal = scanner.getNextToken();
        }

    } catch (InvalidInputException ex) {
        return null;
    }

    if (headerEnd != -1) {
        return new Region(headerStart, headerEnd - headerStart);
    }
    return null;
}

From source file:org.eclipse.mylyn.java.ui.editor.AutoFoldingStructureProvider.java

License:Open Source License

private IRegion computeHeaderComment(IType type) throws JavaModelException {
    if (fCachedDocument == null)
        return null;

    // search at most up to the first type
    ISourceRange range = type.getSourceRange();
    if (range == null)
        return null;
    int start = 0;
    int end = range.getOffset();

    if (fInput instanceof ISourceReference) {
        String content;/* www.ja  va 2 s.  com*/
        try {
            content = fCachedDocument.get(start, end - start);
        } catch (BadLocationException e) {
            return null; // ignore header comment in that case
        }

        /* code adapted from CommentFormattingStrategy:
         * scan the header content up to the first type. Once a comment is
         * found, accumulate any additional comments up to the stop condition.
         * The stop condition is reaching a package declaration, import container,
         * or the end of the input.
         */
        IScanner scanner = ToolFactory.createScanner(true, false, false, false);
        scanner.setSource(content.toCharArray());

        int headerStart = -1;
        int headerEnd = -1;
        try {
            boolean foundComment = false;
            int terminal = scanner.getNextToken();
            while (terminal != ITerminalSymbols.TokenNameEOF && !(terminal == ITerminalSymbols.TokenNameclass
                    || terminal == ITerminalSymbols.TokenNameinterface
                    || terminal == ITerminalSymbols.TokenNameenum
                    || (foundComment && (terminal == ITerminalSymbols.TokenNameimport
                            || terminal == ITerminalSymbols.TokenNamepackage)))) {

                if (terminal == ITerminalSymbols.TokenNameCOMMENT_JAVADOC
                        || terminal == ITerminalSymbols.TokenNameCOMMENT_BLOCK
                        || terminal == ITerminalSymbols.TokenNameCOMMENT_LINE) {
                    if (!foundComment)
                        headerStart = scanner.getCurrentTokenStartPosition();
                    headerEnd = scanner.getCurrentTokenEndPosition();
                    foundComment = true;
                }
                terminal = scanner.getNextToken();
            }

        } catch (InvalidInputException ex) {
            return null;
        }

        if (headerEnd != -1) {
            return new Region(headerStart, headerEnd - headerStart);
        }
    }
    return null;
}