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


Java JCTree.getKind方法代码示例

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


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

示例1: isSynthetic

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private boolean isSynthetic(JCTree tree) {
       if (tree.getKind() == Kind.METHOD) {
           //filter synthetic constructors
           return (((JCMethodDecl)tree).mods.flags & Flags.GENERATEDCONSTR) != 0L;
       }
       //filter synthetic superconstructor calls
       if (tree.getKind() == Kind.EXPRESSION_STATEMENT && diffContext.origUnit != null) {
           JCExpressionStatement est = (JCExpressionStatement) tree;
           if (est.expr.getKind() == Kind.METHOD_INVOCATION) {
               JCMethodInvocation mit = (JCMethodInvocation) est.getExpression();
               if (mit.meth.getKind() == Kind.IDENTIFIER) {
                   JCIdent it = (JCIdent) mit.getMethodSelect();
                   return it.name == names._super && diffContext.syntheticTrees.contains(tree);
               }
           }
       }
return false;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:VeryPretty.java

示例2: diffTree

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * This form contains a special hack for if, so that `else' can be placed on the same
 * line as the statement block end.
 * If a block statement is generated instead of a single stat, a newline is appended unless `retainNewline'
 * is false. If statement print passes false when else part of the if is present.
 * 
 * @param oldT old tree
 * @param newT new tree
 * @param elementBounds the old element bounds
 * @param parentKind parent statement's kind
 * @param retainNewline retain newline if block is generated
 * @return localpointer value
 */
private int diffTree(JCTree oldT, JCTree newT, int[] elementBounds, Kind parentKind, boolean retainNewline) {
    if (oldT.getKind() != newT.getKind() && newT.getKind() == Kind.BLOCK) {
        tokenSequence.move(getOldPos(oldT));
        moveToSrcRelevant(tokenSequence, Direction.BACKWARD);
        tokenSequence.moveNext();
        if (elementBounds[0] < tokenSequence.offset())
            copyTo(elementBounds[0], tokenSequence.offset());
        printer.printBlock(oldT, newT, parentKind);
        // ensure there's a newline if the replaced command ended with one.
        int localpointer = getCommentCorrectedEndPos(oldT);
        if (retainNewline && localpointer > 0 && origText.charAt(localpointer - 1) == '\n') { // NOI18N
            printer.newline();
        }
        return localpointer;
    } else {
        // next statement can to seem redundant, but is not, see 117774
        copyTo(elementBounds[0], elementBounds[0] = getCommentCorrectedBounds(oldT)[0]);
        return diffTree(oldT, newT, elementBounds);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:CasualDiff.java

示例3: dimension

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private int dimension(JCTree t, int afterPos) {
    if (t.getKind() != Kind.ARRAY_TYPE) {
        return 0;
    }
    int add;
    if (afterPos >= 0) {
        final int[] bounds =  getBounds(t);
        add = afterPos < bounds[1] ? 1 : 0;
    } else {
        add = 1;
    }
    return add + dimension (((JCTree.JCArrayTypeTree)t).getType(), afterPos);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:CasualDiff.java

示例4: diffAssign

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
protected int diffAssign(JCAssign oldT, JCAssign newT, JCTree parent, int[] bounds) {
    int localPointer = bounds[0];
    // lhs
    int[] lhsBounds = getBounds(oldT.lhs);
    if (lhsBounds[0] < 0) {
        lhsBounds[0] = getOldPos(oldT.rhs);
        lhsBounds[1] = -1;
    }
    copyTo(localPointer, lhsBounds[0]);
    localPointer = diffTree(oldT.lhs, newT.lhs, lhsBounds);
    int[] rhsBounds = getCommentCorrectedBounds(oldT.rhs);

    //#174552: '=' may be missing if this is a synthetic annotation attribute assignment (of attribute name "value"):
    if (   oldT.lhs.getKind() == Kind.IDENTIFIER
        && newT.lhs.getKind() == Kind.IDENTIFIER
        && !((JCIdent) oldT.lhs).name.equals(((JCIdent) newT.lhs).name)) {
        tokenSequence.move(rhsBounds[0]);
        moveToSrcRelevant(tokenSequence, Direction.BACKWARD);
        if (tokenSequence.token().id() != JavaTokenId.EQ) {
            boolean spaceAroundAssignOps = (parent.getKind() == Kind.ANNOTATION || parent.getKind() == Kind.TYPE_ANNOTATION) ? diffContext.style.spaceAroundAnnotationValueAssignOps() : diffContext.style.spaceAroundAssignOps();
            if (spaceAroundAssignOps)
                printer.print(" = ");
            else
                printer.print("=");
            localPointer = lhsBounds[0];
        }
    }
    //#174552 end
    
    // rhs
    copyTo(localPointer, rhsBounds[0]);
    localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds);

    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:CasualDiff.java

示例5: diffErroneous

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
protected void diffErroneous(JCErroneous oldT, JCErroneous newT, int[] bounds) {
    JCTree oldTident = oldT.getErrorTrees().get(0);
    JCTree newTident = newT.getErrorTrees().get(0);
    if (oldTident.getKind() == Kind.IDENTIFIER && newTident.getKind() == Kind.IDENTIFIER) {
        diffIdent((JCIdent) oldTident, (JCIdent) newTident, bounds);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CasualDiff.java

示例6: arrayTypeTree

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private JCArrayTypeTree arrayTypeTree(JCTree typetree) {
    if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
        return (JCArrayTypeTree) typetree;
    } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
        return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
    } else {
        Assert.error("Could not determine array type from type tree: " + typetree);
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:TypeAnnotations.java

示例7: blankLines

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private void blankLines(JCTree tree, boolean before) {
    if (tree == null) {
        return;
    }
    int n = 0;
    // NOTE - out.blankLines() may truncate a previous line, iff it contains trailing whitespace.
    switch (tree.getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            n = before ? cs.getBlankLinesBeforeClass() : cs.getBlankLinesAfterClass();
    	if (((JCClassDecl) tree).defs.nonEmpty() && !before) {
                n = 0;
            } else {
                out.blanklines(n);
                toLeftMargin();
            }
            return;
        case METHOD: // do not handle for sythetic things
    	if ((((JCMethodDecl) tree).mods.flags & Flags.SYNTHETIC) == 0 &&
                ((JCMethodDecl) tree).name != names.init ||
                enclClass != null)
            {
                n = before
                        ? isFirst(tree, enclClass.defs)
                        ? enclClass.name == names.empty
                        ? cs.getBlankLinesAfterAnonymousClassHeader()
                        : cs.getBlankLinesAfterClassHeader()
                        : cs.getBlankLinesBeforeMethods()
                        : isLast(tree, enclClass.defs)
                        ? enclClass.name == names.empty
                        ? cs.getBlankLinesBeforeAnonymousClassClosingBrace()
                        : cs.getBlankLinesBeforeClassClosingBrace()
                        : cs.getBlankLinesAfterMethods();
                out.blanklines(n);
    	    toLeftMargin();
            }
            return;
        case VARIABLE: // just for the fields
            if (enclClass != null && enclClass.name != names.empty && (((JCVariableDecl) tree).mods.flags & ENUM) == 0) {
                n = before
                        ? isFirst(tree, enclClass.defs)
                        ? enclClass.name == names.empty
                        ? cs.getBlankLinesAfterAnonymousClassHeader()
                        : cs.getBlankLinesAfterClassHeader()
                        : cs.getBlankLinesBeforeFields()
                        : isLast(tree, enclClass.defs)
                        ? enclClass.name == names.empty
                        ? cs.getBlankLinesBeforeAnonymousClassClosingBrace()
                        : cs.getBlankLinesBeforeClassClosingBrace()
                        : cs.getBlankLinesAfterFields();
                out.blanklines(n);
                if (before) toLeftMargin();
            }
            return;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:VeryPretty.java

示例8: filterHidden

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public static List<JCTree> filterHidden(DiffContext diffContext, List<? extends JCTree> list) {
    LinkedList<JCTree> result = new LinkedList<JCTree>(); // todo (#pf): capacity?
    List<JCVariableDecl> fieldGroup = new ArrayList<JCVariableDecl>();
    List<JCVariableDecl> enumConstants = new ArrayList<JCVariableDecl>();
    for (JCTree tree : list) {
        if (tree.pos == (-1)) continue;
        if (diffContext.syntheticTrees.contains(tree)) continue;
        else if (Kind.VARIABLE == tree.getKind()) {
            JCVariableDecl var = (JCVariableDecl) tree;
            if ((var.mods.flags & Flags.ENUM) != 0) {
                // collect enum constants, make a field group from them
                // and set the flag.
                enumConstants.add(var);
            } else {
                if (!fieldGroup.isEmpty()) {
                    int oldPos = getOldPos(fieldGroup.get(0));

                    if (oldPos != (-1) && oldPos != NOPOS && oldPos == getOldPos(var) && fieldGroup.get(0).getModifiers() == var.getModifiers()) {
                        //seems like a field group:
                        fieldGroup.add(var);
                    } else {
                        if (fieldGroup.size() > 1) {
                            result.add(new FieldGroupTree(fieldGroup));
                        } else {
                            result.add(fieldGroup.get(0));
                        }
                        fieldGroup = new ArrayList<JCVariableDecl>();

                        fieldGroup.add(var);
                    }
                } else {
                    fieldGroup.add(var);
                }
            }
            continue;
        }

        if (!fieldGroup.isEmpty()) {
            if (fieldGroup.size() > 1) {
                result.add(new FieldGroupTree(fieldGroup));
            } else {
                result.add(fieldGroup.get(0));
            }
            fieldGroup = new ArrayList<JCVariableDecl>();
        }

        if (Kind.METHOD == tree.getKind()) {
            // filter syntetic constructors, i.e. constructors which are in
            // the tree, but not available in the source.
            if (tree.pos == (-1) || (((JCMethodDecl)tree).mods.flags & Flags.GENERATEDCONSTR) != 0)
                continue;
        } else if (Kind.BLOCK == tree.getKind()) {
            JCBlock block = (JCBlock) tree;
            if (block.stats.isEmpty() && block.pos == -1 && block.flags == 0)
                // I believe this is an sythetic block
                continue;
        }

        result.add(tree);
    }
    if (!fieldGroup.isEmpty()) {
        if (fieldGroup.size() > 1) {
            result.add(new FieldGroupTree(fieldGroup));
        } else {
            result.add(fieldGroup.get(0));
        }
    }
    if (!enumConstants.isEmpty()) {
        result.addFirst(new FieldGroupTree(enumConstants, !result.isEmpty()));
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:73,代码来源:CasualDiff.java


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