本文整理汇总了Java中com.sun.source.tree.Tree类的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tree类属于com.sun.source.tree包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import com.sun.source.tree.Tree; //导入依赖的package包/类
protected <R, P> R scan(CancellableTreePathScanner<R, P> scanner, Tree toScan, P p) {
if (isCancelled())
return null;
try {
synchronized (this) {
this.pathScanner = scanner;
}
if (isCancelled())
return null;
return scanner.scan(toScan, p);
} finally {
synchronized (this) {
this.pathScanner = null;
}
}
}
示例2: scan
import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
public Tree scan(Tree tree, Element p) {
final TreePath currentPath = getCurrentPath();
if(docScanner != null && tree != null && currentPath != null) {
switch(tree.getKind()) {
case METHOD:
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
case VARIABLE:
TreePath path = new TreePath(currentPath, tree);
scanJavadoc(path, p);
default:
break;
}
}
return super.scan(tree, p);
}
示例3: visitThrow
import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
public Boolean visitThrow(ThrowTree node, Void p) {
TypeMirror type = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
boolean isCaught = false;
OUTER: for (Pair<Set<TypeMirror>, Tree> pair : caughtExceptions) {
Set<TypeMirror> caught = pair.first();
for (TypeMirror c : caught) {
if (info.getTypes().isSubtype(type, c)) {
isCaught = true;
targetTrees.add(pair.second());
break OUTER;
}
}
}
return super.visitThrow(node, p) == Boolean.TRUE || !isCaught;
}
示例4: getJavaSource
import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected JavaSource getJavaSource(Phase p) {
if (treePathHandle == null && docTreePathHandle == null) {
return null;
}
switch (p) {
case PRECHECK:
case FASTCHECKPARAMETERS:
return JavaSource.forFileObject(docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
: treePathHandle.getFileObject());
case PREPARE:
case CHECKPARAMETERS:
if(treePathHandle != null && treePathHandle.getKind() == Tree.Kind.LABELED_STATEMENT) {
return JavaSource.forFileObject(treePathHandle.getFileObject());
}
ClasspathInfo cpInfo = getClasspathInfo(refactoring);
JavaSource source = JavaSource.create(cpInfo, docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
: treePathHandle.getFileObject());
return source;
}
throw new IllegalStateException();
}
示例5: DiffContext
import com.sun.source.tree.Tree; //导入依赖的package包/类
/**
* Note: the constructor is only used when creating new compilation units; a special flag will be set up, so an initial comment is not skipped.
*/
public DiffContext(CompilationInfo copy, CompilationUnitTree cut, String code, PositionConverter positionConverter, FileObject file, Set<Tree> syntheticTrees, CompilationUnitTree mainUnit, String mainCode) {
this.tokenSequence = TokenHierarchy.create(code, JavaTokenId.language()).tokenSequence(JavaTokenId.language());
this.origText = code;
this.style = getCodeStyle(copy);
this.context = JavaSourceAccessor.getINSTANCE().getJavacTask(copy).getContext();
this.origUnit = (JCCompilationUnit) cut;
this.trees = copy.getTrees();
this.doc = null;
this.positionConverter = positionConverter;
this.file = file;
this.syntheticTrees = syntheticTrees;
this.mainUnit = (JCCompilationUnit) mainUnit;
this.mainCode = mainCode;
this.textLength = copy.getSnapshot() == null ? Integer.MAX_VALUE : copy.getSnapshot().getOriginalOffset(copy.getSnapshot().getText().length());
this.blockSequences = new BlockSequences(this.tokenSequence, doc, textLength);
this.forceInitialComment = true;
}
示例6: resolve
import com.sun.source.tree.Tree; //导入依赖的package包/类
public TreePath resolve(CompilationInfo compilationInfo) throws IllegalArgumentException {
TreePath p = parent.resolve(compilationInfo);
if (p == null) return null;
List<Tree> children = listChildren(p.getLeaf());
if (index < children.size()) {
Tree t = children.get(index);
if (t.getKind() == kind) {
return new TreePath(p, t);
}
}
return null;
}
示例7: isFakeClass
import com.sun.source.tree.Tree; //导入依赖的package包/类
public static boolean isFakeClass(Tree t) {
if (!(t instanceof ClassTree)) {
return false;
}
ClassTree ct = (ClassTree) t;
if (ct.getMembers().isEmpty()) {
return false;
}
CharSequence wildcardTreeName = Utilities.getWildcardTreeName(ct.getMembers().get(0));
if (wildcardTreeName == null) {
return false;
}
return wildcardTreeName.toString().startsWith("$$");
}
示例8: isCaretInsideDeclarationName
import com.sun.source.tree.Tree; //导入依赖的package包/类
private static boolean isCaretInsideDeclarationName(CompilationInfo info, Tree t, TreePath path, int caret) {
try {
switch (t.getKind()) {
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
case METHOD:
case VARIABLE:
int[] span = org.netbeans.modules.java.editor.base.semantic.Utilities.findIdentifierSpan(path, info, info.getDocument());
if (span == null || span[0] == (-1) || span[1] == (-1)) {
return false;
}
return span[0] <= caret && caret <= span[1];
default:
return false;
}
} catch (IOException iOException) {
Exceptions.printStackTrace(iOException);
return false;
}
}
示例9: checkAmbiguous
import com.sun.source.tree.Tree; //导入依赖的package包/类
/**
* Checks whether a method or constructor call would become ambiguous if the parameter type changes.
*
* @param info compilation context
* @param parentExec path to the constructor or method invocation
* @param argIndex
* @param casteeType
* @return
*/
private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) {
CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN);
String prefix = null;
if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) {
prefix = "(" + altType + ")"; // NOI18N
}
Tree leaf = parentExec.getLeaf();
List<? extends Tree> arguments;
if (leaf instanceof MethodInvocationTree) {
MethodInvocationTree mi = (MethodInvocationTree)leaf;
arguments = mi.getArguments();
} else {
arguments = ((NewClassTree)leaf).getArguments();
}
Tree argTree = arguments.get(argIndex);
TreePath argPath = new TreePath(parentExec, argTree);
return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix);
}
示例10: performRewrite
import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
TreePath p = ctx.getPath();
if (p.getLeaf().getKind() != Tree.Kind.NEW_CLASS) {
return;
}
NewClassTree origNct = (NewClassTree)p.getLeaf();
if (origNct.getArguments().size() != 1) {
return;
}
NewClassTree nct = GeneratorUtilities.get(ctx.getWorkingCopy()).importComments(origNct, ctx.getWorkingCopy().getCompilationUnit());
ExpressionTree charArg = nct.getArguments().get(0);
TreeMaker mk = ctx.getWorkingCopy().getTreeMaker();
ExpressionTree newExpr = mk.NewClass(nct.getEnclosingExpression(), (List<ExpressionTree>)nct.getTypeArguments(), nct.getIdentifier(),
Collections.<ExpressionTree>emptyList(), nct.getClassBody());
Tree replace = mk.MethodInvocation(
Collections.<ExpressionTree>emptyList(),
mk.MemberSelect(newExpr, "append"), // NOI18N
Collections.singletonList(charArg));
ctx.getWorkingCopy().rewrite(nct, replace);
}
示例11: generateMethodContents
import com.sun.source.tree.Tree; //导入依赖的package包/类
private void generateMethodContents(List<StatementTree> methodStatements) {
Iterator<TypeMirrorHandle> additionalType = additionalLocalTypes.iterator();
Iterator<String> additionalName = additionalLocalNames.iterator();
while (additionalType.hasNext() && additionalName.hasNext()) {
TypeMirror tm = additionalType.next().resolve(copy);
if (tm == null) {
//XXX:
return;
}
Tree type = make.Type(tm);
methodStatements.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), additionalName.next(), type, null));
}
if (from == to && statements.get(from).getKind() == Tree.Kind.BLOCK) {
methodStatements.addAll(((BlockTree) statements.get(from)).getStatements());
} else {
methodStatements.addAll(statements.subList(from, to + 1));
}
}
示例12: moveToEnd
import com.sun.source.tree.Tree; //导入依赖的package包/类
public void moveToEnd(Tree t) {
if (t == null) {
return ;
}
long end = sourcePositions.getEndPosition(info.getCompilationUnit(), t);
if (end == (-1))
return ;
if (t.getKind() == Kind.ARRAY_TYPE) {
moveToEnd(((ArrayTypeTree) t).getType());
return ;
}
moveToOffset(end);
}
示例13: performRewrite
import com.sun.source.tree.Tree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
// path should be the typecast expression
TreePath path = ctx.getPath();
TreePath exprPath = exprHandle.resolve(ctx.getWorkingCopy());
if (path.getLeaf().getKind() != Tree.Kind.TYPE_CAST || exprPath == null || !EXPRESSION_KINDS.contains(exprPath.getLeaf().getKind())) {
// PENDING - some message ?
return;
}
WorkingCopy copy = ctx.getWorkingCopy();
TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
TypeCastTree cast = (TypeCastTree)path.getLeaf();
// rewrite the type cast to the casted Math.random()
copy.rewrite(path.getLeaf(), cast.getExpression());
// rewrite the outermost expression to a typecast of it
ExpressionTree expr = (ExpressionTree)exprPath.getLeaf();
if (expr.getKind() != Tree.Kind.PARENTHESIZED) {
expr = make.Parenthesized(expr);
}
copy.rewrite(exprPath.getLeaf(), make.TypeCast(cast.getType(), (ExpressionTree)expr));
}
示例14: computeMethodInvocation
import com.sun.source.tree.Tree; //导入依赖的package包/类
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
boolean errorInRealArguments = false;
for (Tree param : nat.getArguments()) {
errorInRealArguments |= param == error;
}
if (errorInRealArguments) {
List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
int[] proposedIndex = new int[1];
List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
if (ee.isEmpty()) { //cannot be resolved
return null;
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return proposedTypes;
}
return null;
}
示例15: getStart
import com.sun.source.tree.Tree; //导入依赖的package包/类
public int getStart() {
final int[] result = new int[] {-1};
try {
JavaSource.create(info.getClasspathInfo()).runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController parameter) throws Exception {
Tree tree = info.getTrees().getTree(element);
if (tree != null) {
result[0] = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tree);
}
}
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return result[0];
}