当前位置: 首页>>代码示例>>Java>>正文


Java CompilationInfo.getTokenHierarchy方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo.getTokenHierarchy方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo.getTokenHierarchy方法的具体用法?Java CompilationInfo.getTokenHierarchy怎么用?Java CompilationInfo.getTokenHierarchy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.CompilationInfo的用法示例。


在下文中一共展示了CompilationInfo.getTokenHierarchy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findTokenWithText

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static Token<JavaTokenId> findTokenWithText(CompilationInfo info, String text, int start, int end) {
    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language()).subSequence(start, end);
    
    while (ts.moveNext()) {
        Token<JavaTokenId> t = ts.token();
        
        if (t.id() == JavaTokenId.IDENTIFIER) {
            boolean nameMatches;
            
            if (!(nameMatches = text.equals(info.getTreeUtilities().decodeIdentifier(t.text()).toString()))) {
                ExpressionTree expr = info.getTreeUtilities().parseExpression(t.text().toString(), new SourcePositions[1]);
                
                nameMatches = expr.getKind() == Kind.IDENTIFIER && text.contentEquals(((IdentifierTree) expr).getName());
            }
            
            if (nameMatches) {
                return t;
            }
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Utilities.java

示例2: findIdentifierSpanImpl

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, IdentifierTree tree, CompilationUnitTree cu, SourcePositions positions) {
    int start = (int)positions.getStartPosition(cu, tree);
    int endPosition = (int)positions.getEndPosition(cu, tree);
    
    if (start == (-1) || endPosition == (-1))
        return null;

    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());

    if (ts.move(start) == Integer.MAX_VALUE) {
        return null;
    }

    if (ts.moveNext()) {
        if (ts.offset() >= start) {
            Token<JavaTokenId> t = ts.token();
            return t;
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Utilities.java

示例3: createHighlightImpl

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static Token<JavaTokenId> createHighlightImpl(CompilationInfo info, Document doc, TreePath tree) {
    Tree leaf = tree.getLeaf();
    SourcePositions positions = info.getTrees().getSourcePositions();
    CompilationUnitTree cu = info.getCompilationUnit();
    
    //XXX: do not use instanceof:
    if (leaf instanceof MethodTree || leaf instanceof VariableTree || leaf instanceof ClassTree
            || leaf instanceof MemberSelectTree || leaf instanceof AnnotatedTypeTree || leaf instanceof MemberReferenceTree) {
        return findIdentifierSpan(info, doc, tree);
    }
    
    int start = (int) positions.getStartPosition(cu, leaf);
    int end = (int) positions.getEndPosition(cu, leaf);
    
    if (start == Diagnostic.NOPOS || end == Diagnostic.NOPOS) {
        return null;
    }
    
    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
    
    if (ts.move(start) == Integer.MAX_VALUE) {
        return null;
    }
    
    if (ts.moveNext()) {
        Token<JavaTokenId> token = ts.token();
        if (ts.offset() == start && token != null) {
            final JavaTokenId id = token.id();
            if (id == JavaTokenId.IDENTIFIER) {
                return token;
            }
            if (id == JavaTokenId.THIS || id == JavaTokenId.SUPER) {
                return ts.offsetToken();
            }
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:Utilities.java

示例4: findUnresolvedElementToken

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static Token findUnresolvedElementToken(CompilationInfo info, int offset) throws IOException {
    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());

    if (ts == null) {
        return null;
    }

    ts.move(offset);
    if (ts.moveNext()) {
        Token t = ts.token();

        if (t.id() == JavaTokenId.DOT) {
            ts.moveNext();
            t = ts.token();
        } else {
            if (t.id() == JavaTokenId.LT) {
                ts.moveNext();
                t = ts.token();
            } else {
                if (t.id() == JavaTokenId.NEW) {
                    boolean cont = ts.moveNext();

                    while (cont && ts.token().id() == JavaTokenId.WHITESPACE) {
                        cont = ts.moveNext();
                    }

                    if (!cont) {
                        return null;
                    }
                    t = ts.token();
                }
            }
        }

        if (t.id() == JavaTokenId.IDENTIFIER) {
            return ts.offsetToken();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:SearchModuleDependency.java

示例5: findBodyStartImpl

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private static int findBodyStartImpl(CompilationInfo info, Tree cltree, CompilationUnitTree cu, SourcePositions positions, Document doc) {
    int start = (int)positions.getStartPosition(cu, cltree);
    int end   = (int)positions.getEndPosition(cu, cltree);
    
    if (start == (-1) || end == (-1)) {
        return -1;
    }
    int startPos = -1;
    switch (cltree.getKind()) {
        case CLASS: case INTERFACE: case ENUM: {
            ClassTree ct = (ClassTree)cltree;
            startPos = findSubtreeEnd(cu, positions,
                    ct.getImplementsClause(),
                    ct.getExtendsClause(),
                    ct.getTypeParameters(),
                    ct.getModifiers()
            );
            break;
        }
            
        case METHOD:  {
            // if the method contains some parameters, skip to the end of the parameter list
            MethodTree mt = (MethodTree)cltree;
            startPos = findSubtreeEnd(cu, positions, mt.getDefaultValue(), mt.getThrows(), mt.getParameters(), mt.getModifiers());
            break;
        }
    }
    if (startPos > start) {
        start = startPos;
    }
    
    if (start > doc.getLength() || end > doc.getLength()) {
        if (DEBUG) {
            System.err.println("Log: position outside document: ");
            System.err.println("decl = " + cltree);
            System.err.println("startOffset = " + start);
            System.err.println("endOffset = " + end);
            Thread.dumpStack();
        }
        
        return (-1);
    }
    TokenHierarchy<JavaTokenId> th = (TokenHierarchy<JavaTokenId>)info.getTokenHierarchy();
    TokenSequence<JavaTokenId> seq = (TokenSequence<JavaTokenId>)th.tokenSequence();
    seq.move(start);
    while (seq.moveNext()) {
        if (seq.token().id() == JavaTokenId.LBRACE) {
            return seq.offset();
        }
    }
    return (-1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:Utilities.java

示例6: findUnresolvedElementToken

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
public static Token findUnresolvedElementToken(CompilationInfo info, int offset) throws IOException {
    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
    
    if (ts == null) {
        return null;
    }
    
    ts.move(offset);
    if (ts.moveNext()) {
        Token<JavaTokenId> t = ts.token();

        if (t.id() == JavaTokenId.DOT) {
            ts.moveNext();
            t = ts.token();
        } else {
            if (t.id() == JavaTokenId.LT) {
                ts.moveNext();
                t = ts.token();
            } else {
                if (t.id() == JavaTokenId.NEW || t.id() == JavaTokenId.WHITESPACE) {
                    t = skipWhitespaces(ts);

                    if (t == null) return null;
                } else if (t.id() == JavaTokenId.IMPORT) {
                    t = skipWhitespaces(ts);

                    if (t == null) return null;
                }
            }
        }

        while (t.id() == JavaTokenId.WHITESPACE) {
            ts.moveNext();
            t = ts.token();
        }
        
        switch (t.id()) {
            case IDENTIFIER:
            case INT_LITERAL:
            case LONG_LITERAL:
            case FLOAT_LITERAL:
            case DOUBLE_LITERAL:
            case CHAR_LITERAL:
            case STRING_LITERAL:
            case TRUE:
            case FALSE:
            case NULL:
                return ts.offsetToken();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:ErrorHintsProvider.java


注:本文中的org.netbeans.api.java.source.CompilationInfo.getTokenHierarchy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。