當前位置: 首頁>>代碼示例>>Java>>正文


Java Kind類代碼示例

本文整理匯總了Java中com.sun.source.tree.Tree.Kind的典型用法代碼示例。如果您正苦於以下問題:Java Kind類的具體用法?Java Kind怎麽用?Java Kind使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Kind類屬於com.sun.source.tree.Tree包,在下文中一共展示了Kind類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compute

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
private static ErrorDescription compute(HintContext ctx, String methodName) {
    TreePath message = ctx.getVariables().get("$message");
    List<List<TreePath>> sorted = Utilities.splitStringConcatenationToElements(ctx.getInfo(), message);

    if (sorted.size() <= 1) {
        return null;
    }

    //check for erroneous trees:
    for (List<TreePath> tps : sorted)
        for (TreePath tp : tps)
            if (tp.getLeaf().getKind() == Kind.ERRONEOUS) return null;

    FixImpl fix = new FixImpl(NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat_fix"), methodName, TreePathHandle.create(ctx.getPath(), ctx.getInfo()), TreePathHandle.create(message, ctx.getInfo()));

    return ErrorDescriptionFactory.forTree(ctx, message, NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat"), fix.toEditorFix());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:LoggerStringConcat.java

示例2: typeUsed

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
private void typeUsed(Element decl, TreePath expr, boolean methodInvocation) {
    if (decl != null && (expr == null || expr.getLeaf().getKind() == Kind.IDENTIFIER || expr.getLeaf().getKind() == Kind.PARAMETERIZED_TYPE)) {
        if (!isErroneous(decl)) {
            ImportTree imp = element2Import.get(decl);

            if (imp != null) {
                addUsage(imp);
                if (isStar(imp)) {
                    //TODO: explain
                    handleUnresolvableImports(decl, methodInvocation, false);
                }
            }
        } else {
            handleUnresolvableImports(decl, methodInvocation, true);
            
            for (Entry<Element, ImportTree> e : element2Import.entrySet()) {
                if (importedBySingleImport.contains(e.getKey())) continue;
                
                if (e.getKey().getSimpleName().equals(decl.getSimpleName())) {
                    import2Highlight.remove(e.getValue());
                }
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:UnusedImports.java

示例3: forBLOCK

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
@Hint(displayName = "#LBL_Empty_BLOCK", description = "#DSC_Empty_BLOCK", category = "empty", hintKind = Hint.Kind.INSPECTION, severity = Severity.VERIFIER, suppressWarnings = SUPPRESS_WARNINGS_KEY, id = "EmptyStatements_BLOCK")
@TriggerTreeKind(Tree.Kind.EMPTY_STATEMENT)
@NbBundle.Messages({"ERR_EmptyBLOCK=Remove semicolon"})
public static ErrorDescription forBLOCK(HintContext ctx) {

    Tree parent = ctx.getPath().getParentPath().getLeaf();
    if (!EnumSet.of(Kind.BLOCK).contains(parent.getKind())) {
        return null;
}

    final List<Fix> fixes = new ArrayList<>();
    fixes.add(FixFactory.createSuppressWarningsFix(ctx.getInfo(), ctx.getPath(), SUPPRESS_WARNINGS_KEY));
    fixes.add(JavaFixUtilities.removeFromParent(ctx, Bundle.ERR_EmptyBLOCK(), ctx.getPath()));

    return createErrorDescription(ctx, ctx.getPath().getLeaf(), fixes, Kind.BLOCK);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:EmptyStatements.java

示例4: fqnFor

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
private String fqnFor(Tree t) {
    Element el = ASTService.getElementImpl(t);

    if (el != null) {
        if (el.getKind().isClass() || el.getKind().isInterface() || el.getKind() == ElementKind.PACKAGE) {
            return ((QualifiedNameable) el).getQualifiedName().toString();
        } else {
            Logger.getLogger(ElementOverlay.class.getName()).log(Level.SEVERE, "Not a QualifiedNameable: {0}", el);
            return null;
        }
    } else if (t instanceof QualIdentTree) {
        return ((QualIdentTree) t).getFQN();
    } else if (t.getKind() == Kind.PARAMETERIZED_TYPE) {
        return fqnFor(((ParameterizedTypeTree) t).getType());
    } else {
        Logger.getLogger(ElementOverlay.class.getName()).log(Level.FINE, "No element and no QualIdent");
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ElementOverlay.java

示例5: diffDoLoop

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
protected int diffDoLoop(JCDoWhileLoop oldT, JCDoWhileLoop newT, int[] bounds) {
    int localPointer = bounds[0];

    int[] bodyBounds = new int[] { localPointer, endPos(oldT.body) };
    int oldIndent = newT.body.hasTag(Tag.BLOCK) ? -1 : printer.indent();
    localPointer = diffTree(oldT.body, newT.body, bodyBounds, oldT.getKind());
    if (!newT.body.hasTag(Tag.BLOCK))
        printer.undent(oldIndent);
    int[] condBounds = getBounds(oldT.cond);
    if (oldT.body.getKind() != Kind.BLOCK && newT.body.getKind() == Kind.BLOCK) {
        moveBackToToken(tokenSequence, condBounds[0], JavaTokenId.WHILE);
        localPointer = tokenSequence.offset();
    } else {
        copyTo(localPointer, condBounds[0]);
        localPointer = diffTree(oldT.cond, newT.cond, condBounds);
    }
    copyTo(localPointer, bounds[1]);

    return bounds[1];
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CasualDiff.java

示例6: getKindLiteral

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
public Kind getKindLiteral() {
    switch (this) {
    case INT:
        return Kind.INT_LITERAL;
    case LONG:
        return Kind.LONG_LITERAL;
    case FLOAT:
        return Kind.FLOAT_LITERAL;
    case DOUBLE:
        return Kind.DOUBLE_LITERAL;
    case BOOLEAN:
        return Kind.BOOLEAN_LITERAL;
    case CHAR:
        return Kind.CHAR_LITERAL;
    case CLASS:
        return Kind.STRING_LITERAL;
    case BOT:
        return Kind.NULL_LITERAL;
    default:
        throw new AssertionError("unknown literal kind " + this);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:TypeTag.java

示例7: performRewrite

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath path = ctx.getPath();
    TypeCastTree tct = (TypeCastTree) path.getLeaf();
    ExpressionTree expression = tct.getExpression();

    while (expression.getKind() == Kind.PARENTHESIZED
           && !JavaFixUtilities.requiresParenthesis(((ParenthesizedTree) expression).getExpression(), tct, path.getParentPath().getLeaf())) {
        expression = ((ParenthesizedTree) expression).getExpression();
    }

    while (path.getParentPath().getLeaf().getKind() == Kind.PARENTHESIZED
           && !JavaFixUtilities.requiresParenthesis(expression, path.getLeaf(), path.getParentPath().getParentPath().getLeaf())) {
        path = path.getParentPath();
    }

    wc.rewrite(path.getLeaf(), expression);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:RemoveUselessCast.java

示例8: generateClassBody

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
protected boolean generateClassBody(TreePath p) throws Exception {
    Element e = copy.getTrees().getElement(p);
    boolean isUsableElement = e != null && (e.getKind().isClass() || e.getKind().isInterface());
    if (isUsableElement) {
        return true;
    }
    if (e.getKind() == ElementKind.ENUM_CONSTANT) {
        VariableTree var = (VariableTree) p.getLeaf();
        if (var.getInitializer() != null && var.getInitializer().getKind() == Kind.NEW_CLASS) {
            NewClassTree nct = (NewClassTree) var.getInitializer();
            if (nct.getClassBody() != null) {
                return true;
            }
        }
    }
    return !generateClassBody2(copy, p);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ImplementAllAbstractMethods.java

示例9: performRewrite

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    Tree.Kind k = ctx.getPath().getLeaf().getKind();
    if (!TreeUtilities.CLASS_TREE_KINDS.contains(k)) {
        // TODO: report
        return;
    }
    ClassTree ct = (ClassTree)ctx.getPath().getLeaf();
    ModifiersTree mt = ct.getModifiers();
    Set<Modifier> mods = new HashSet<>(mt.getFlags());
    mods.remove(Modifier.FINAL);
    mods.add(Modifier.ABSTRACT);
    ModifiersTree newMt = wc.getTreeMaker().Modifiers(mods, mt.getAnnotations());
    wc.rewrite(mt, newMt);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:ImplementAllAbstractMethods.java

示例10: assignmentToCatchBlockParameter

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToCatchBlockParameter", description = "#DESC_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToCatchBlockParameter", category = "assignment_issues", enabled = false, suppressWarnings = "AssignmentToCatchBlockParameter", options=Options.QUERY) //NOI18N
@TriggerTreeKind(Kind.CATCH)
public static List<ErrorDescription> assignmentToCatchBlockParameter(HintContext context) {
    final Trees trees = context.getInfo().getTrees();
    final TreePath catchPath = context.getPath();
    final Element param = trees.getElement(TreePath.getPath(catchPath, ((CatchTree) catchPath.getLeaf()).getParameter()));
    if (param == null || param.getKind() != ElementKind.EXCEPTION_PARAMETER) {
        return null;
    }
    final TreePath block = TreePath.getPath(catchPath, ((CatchTree) catchPath.getLeaf()).getBlock());
    final List<TreePath> paths = new LinkedList<TreePath>();
    new AssignmentFinder(trees, param).scan(block, paths);
    final List<ErrorDescription> ret = new ArrayList<ErrorDescription>(paths.size());
    for (TreePath path : paths) {
        ret.add(ErrorDescriptionFactory.forTree(context, path, NbBundle.getMessage(AssignmentIssues.class, "MSG_AssignmentToCatchBlockParameter", param.getSimpleName()))); //NOI18N
    }
    return ret;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:AssignmentIssues.java

示例11: run

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:RenameConstructor.java

示例12: findOuterIf

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
private static TreePath findOuterIf(HintContext ctx, TreePath treePath) {
    while (!ctx.isCanceled()) {
        treePath = treePath.getParentPath();
        if (treePath == null) {
            break;
        }
        Tree leaf = treePath.getLeaf();
        
        if (leaf.getKind() == Kind.IF) {
            return treePath;
        }
        
        if (leaf.getKind() == Kind.BLOCK) {
            BlockTree b = (BlockTree)leaf;
            if (b.getStatements().size() == 1) {
                // ok, empty blocks can be around synchronized(this) 
                // statements
                continue;
            }
        }
        
        return null;
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:DoubleCheck.java

示例13: CompoundAssignment

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
public CompoundAssignmentTree CompoundAssignment(Kind operator, 
                                                 ExpressionTree variable, 
                                                 ExpressionTree expression) {
    final Tag op;
    switch (operator) {
        case MULTIPLY_ASSIGNMENT: op = JCTree.Tag.MUL_ASG; break;
        case DIVIDE_ASSIGNMENT: op = JCTree.Tag.DIV_ASG; break;
        case REMAINDER_ASSIGNMENT: op = JCTree.Tag.MOD_ASG; break;
        case PLUS_ASSIGNMENT: op = JCTree.Tag.PLUS_ASG; break;
        case MINUS_ASSIGNMENT: op = JCTree.Tag.MINUS_ASG; break;
        case LEFT_SHIFT_ASSIGNMENT: op = JCTree.Tag.SL_ASG; break;
        case RIGHT_SHIFT_ASSIGNMENT: op = JCTree.Tag.SR_ASG; break;
        case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT: op = JCTree.Tag.USR_ASG; break;
        case AND_ASSIGNMENT: op = JCTree.Tag.BITAND_ASG; break;
        case XOR_ASSIGNMENT: op = JCTree.Tag.BITXOR_ASG; break;
        case OR_ASSIGNMENT: op = JCTree.Tag.BITOR_ASG; break;
        default:
            throw new IllegalArgumentException("Illegal binary operator: " + operator);
    }
    return make.at(NOPOS).Assignop(op, (JCExpression)variable, (JCExpression)expression);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:TreeFactory.java

示例14: Unary

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
public UnaryTree Unary(Kind operator, ExpressionTree arg) {
    final Tag op;
    switch (operator) {
        case POSTFIX_INCREMENT: op = JCTree.Tag.POSTINC; break;
        case POSTFIX_DECREMENT: op = JCTree.Tag.POSTDEC; break;
        case PREFIX_INCREMENT: op = JCTree.Tag.PREINC; break;
        case PREFIX_DECREMENT: op = JCTree.Tag.PREDEC; break;
        case UNARY_PLUS: op = JCTree.Tag.POS; break;
        case UNARY_MINUS: op = JCTree.Tag.NEG; break;
        case BITWISE_COMPLEMENT: op = JCTree.Tag.COMPL; break;
        case LOGICAL_COMPLEMENT: op = JCTree.Tag.NOT; break;
        default:
            throw new IllegalArgumentException("Illegal unary operator: " + operator);
    }
    return make.at(NOPOS).Unary(op, (JCExpression)arg);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:TreeFactory.java

示例15: Wildcard

import com.sun.source.tree.Tree.Kind; //導入依賴的package包/類
public WildcardTree Wildcard(Kind kind, Tree type) {
    final BoundKind boundKind;
    switch (kind) {
        case UNBOUNDED_WILDCARD:
            boundKind = BoundKind.UNBOUND;
            break;
        case EXTENDS_WILDCARD:
            boundKind = BoundKind.EXTENDS;
            break;
        case SUPER_WILDCARD:
            boundKind = BoundKind.SUPER;
            break;
        default:
            throw new IllegalArgumentException("Unknown wildcard bound " + kind);
    }
    TypeBoundKind tbk = make.at(NOPOS).TypeBoundKind(boundKind);
    return make.at(NOPOS).Wildcard(tbk, (JCExpression)type);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:TreeFactory.java


注:本文中的com.sun.source.tree.Tree.Kind類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。