本文整理汇总了Java中com.sun.source.util.TreePath.getLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.getLeaf方法的具体用法?Java TreePath.getLeaf怎么用?Java TreePath.getLeaf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.TreePath
的用法示例。
在下文中一共展示了TreePath.getLeaf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doesOverloadMakeLambdaAmbiguous
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private boolean doesOverloadMakeLambdaAmbiguous() {
TreePath parentPath = pathToNewClassTree.getParentPath();
Tree parentTree = parentPath.getLeaf();
if (!isInvocationTree(parentTree)) {
return false;
}
ExecutableElement invokingElement = getElementFromInvokingTree(parentPath);
int indexOfLambdaInArgs = getLambdaIndexFromInvokingTree(parentTree);
if (invokingElement == null || indexOfLambdaInArgs == -1) {
return false;
}
return isLambdaAnAmbiguousArgument(invokingElement, indexOfLambdaInArgs);
}
示例2: validateSelection
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static TreePath validateSelection(CompilationInfo ci, int start, int end) {
TreePath tp = ci.getTreeUtilities().pathFor((start + end) / 2 + 1);
for ( ; tp != null; tp = tp.getParentPath()) {
Tree leaf = tp.getLeaf();
long treeStart = ci.getTrees().getSourcePositions().getStartPosition(ci.getCompilationUnit(), leaf);
long treeEnd = ci.getTrees().getSourcePositions().getEndPosition(ci.getCompilationUnit(), leaf);
if (treeStart != start || treeEnd != end) {
continue;
}
return tp;
}
return null;
}
示例3: getElementFromInvokingTree
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private ExecutableElement getElementFromInvokingTree(TreePath treePath) {
Tree invokingTree = treePath.getLeaf();
Element result;
if (invokingTree.getKind() == Tree.Kind.METHOD_INVOCATION) {
MethodInvocationTree invokingMethTree = ((MethodInvocationTree) invokingTree);
TreePath methodTreePath = new TreePath(treePath, invokingMethTree);
result = getElementFromTreePath(methodTreePath);
} else {
result = getElementFromTreePath(treePath);
}
if (result != null && (result.getKind() == ElementKind.CONSTRUCTOR || result.getKind() == ElementKind.METHOD)) {
return (ExecutableElement) result;
}
return null;
}
示例4: isParentOf
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
public static boolean isParentOf(TreePath parent, TreePath path) {
Tree parentLeaf = parent.getLeaf();
while (path != null && path.getLeaf() != parentLeaf) {
path = path.getParentPath();
}
return path != null;
}
示例5: possiblyCast
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static Tree possiblyCast(WorkingCopy copy, ExpressionTree tree, TreePath path, boolean typeCast) {
if (!typeCast) {
return tree;
}
NewClassTree nct = (NewClassTree)path.getLeaf();
return copy.getTreeMaker().TypeCast(nct.getIdentifier(), tree);
}
示例6: visitAssert
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
public Boolean visitAssert(AssertTree node, TreePath p) {
if (p == null) {
super.visitAssert(node, p);
return false;
}
AssertTree at = (AssertTree) p.getLeaf();
if (!scan(node.getCondition(), at.getCondition(), p)) {
return false;
}
return scan(node.getDetail(), at.getDetail(), p);
}
示例7: run
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
@TriggerPattern("for ($type $varName : $expression) { $stmts$; }")
public static ErrorDescription run(HintContext ctx) {
TreePath tp = ctx.getPath();
EnhancedForLoopTree efl = (EnhancedForLoopTree) tp.getLeaf();
long statementStart = ctx.getInfo().getTrees().getSourcePositions().getStartPosition(ctx.getInfo().getCompilationUnit(), efl.getStatement());
int caret = ctx.getCaretLocation();
if (caret >= statementStart) {
return null;
}
TypeMirror expressionType = ctx.getInfo().getTrees().getTypeMirror(new TreePath(tp, efl.getExpression()));
if (expressionType == null || expressionType.getKind() != TypeKind.DECLARED) {
return null;
}
ExecutableElement iterator = findIterable(ctx.getInfo());
Types t = ctx.getInfo().getTypes();
if (iterator == null || !t.isSubtype(((DeclaredType) expressionType), t.erasure(iterator.getEnclosingElement().asType()))) {
return null;
}
FixImpl fix = new FixImpl(TreePathHandle.create(tp, ctx.getInfo()));
List<Fix> fixes = Collections.<Fix>singletonList(fix.toEditorFix());
return ErrorDescriptionFactory.createErrorDescription(ctx.getSeverity(),
NbBundle.getMessage(ExpandEnhancedForLoop.class, "ERR_ExpandEhancedForLoop"),
fixes,
ctx.getInfo().getFileObject(),
caret,
caret);
}
示例8: visitCompoundAssignment
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
public Boolean visitCompoundAssignment(CompoundAssignmentTree node, TreePath p) {
if (p == null) {
super.visitCompoundAssignment(node, p);
return false;
}
CompoundAssignmentTree bt = (CompoundAssignmentTree) p.getLeaf();
boolean result = scan(node.getExpression(), bt.getExpression(), p);
return result && scan(node.getVariable(), bt.getVariable(), p);
}
示例9: computeMethodInvocation
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf();
int realArgumentError = -1;
int i = 0;
for (Tree param : nat.getArguments()) {
if (param == error) {
realArgumentError = i;
break;
}
i++;
}
if (realArgumentError != (-1)) {
List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
int[] proposedIndex = new int[1];
List<ExecutableElement> ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
if (ee.isEmpty()) { //cannot be resolved
TypeMirror executable = info.getTrees().getTypeMirror(new TreePath(parent, nat.getMethodSelect()));
if (executable == null || executable.getKind() != TypeKind.EXECUTABLE) return null;
ExecutableType et = (ExecutableType) executable;
if (realArgumentError >= et.getParameterTypes().size()) {
return null;
}
proposedTypes.add(et.getParameterTypes().get(realArgumentError));
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return proposedTypes;
}
return null;
}
示例10: handlePossibleAnonymousInnerClass
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static Element handlePossibleAnonymousInnerClass(CompilationInfo info, final Element el) {
Element encl = el.getEnclosingElement();
Element doubleEncl = encl != null ? encl.getEnclosingElement() : null;
if ( doubleEncl != null
&& !doubleEncl.getKind().isClass()
&& !doubleEncl.getKind().isInterface()
&& doubleEncl.getKind() != ElementKind.PACKAGE
&& encl.getKind() == ElementKind.CLASS) {
TreePath enclTreePath = info.getTrees().getPath(encl);
Tree enclTree = enclTreePath != null ? enclTreePath.getLeaf() : null;
if (enclTree != null && TreeUtilities.CLASS_TREE_KINDS.contains(enclTree.getKind()) && enclTreePath.getParentPath().getLeaf().getKind() == Tree.Kind.NEW_CLASS) {
NewClassTree nct = (NewClassTree) enclTreePath.getParentPath().getLeaf();
if (nct.getClassBody() != null) {
Element parentElement = info.getTrees().getElement(new TreePath(enclTreePath, nct.getIdentifier()));
if (parentElement == null || parentElement.getKind().isInterface()) {
return parentElement;
} else {
//annonymous innerclass extending a class. Find out which constructor is used:
TreePath superConstructorCall = new FindSuperConstructorCall().scan(enclTreePath, null);
if (superConstructorCall != null) {
return info.getTrees().getElement(superConstructorCall);
}
}
}
}
return null;//prevent jumps to incorrect positions
} else {
if (encl != null) {
return encl;
} else {
return el;
}
}
}
示例11: isVarargsParameter
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static boolean isVarargsParameter(CompilationInfo ci, TreePath invPath) {
if (invPath.getLeaf().getKind() != Tree.Kind.METHOD_INVOCATION) {
return false;
}
MethodInvocationTree mit = (MethodInvocationTree)invPath.getLeaf();
Element e = ci.getTrees().getElement(invPath);
if (e == null || e.getKind() != ElementKind.METHOD) {
return false;
}
ExecutableElement ee = (ExecutableElement)e;
return ee.isVarArgs() && mit.getArguments().size() == ee.getParameters().size();
}
示例12: visitParenthesized
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
public Boolean visitParenthesized(ParenthesizedTree node, TreePath p) {
if (p == null)
return super.visitParenthesized(node, p);
ParenthesizedTree t = (ParenthesizedTree) p.getLeaf();
return scan(node.getExpression(), t.getExpression(), p);
}
示例13: getForwardReferences
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
/**
* Returns all elements of the given scope that are declared after given position in a source.
* @param path to the given search scope
* @param pos position in the source
* @param sourcePositions
* @param trees
* @return collection of forward references
*
* @since 0.136
*/
public static Collection<? extends Element> getForwardReferences(TreePath path, int pos, SourcePositions sourcePositions, Trees trees) {
HashSet<Element> refs = new HashSet<>();
Element el;
while(path != null) {
switch(path.getLeaf().getKind()) {
case VARIABLE:
el = trees.getElement(path);
if (el != null) {
refs.add(el);
}
TreePath parent = path.getParentPath();
if (TreeUtilities.CLASS_TREE_KINDS.contains(parent.getLeaf().getKind())) {
boolean isStatic = ((VariableTree)path.getLeaf()).getModifiers().getFlags().contains(Modifier.STATIC);
for(Tree member : ((ClassTree)parent.getLeaf()).getMembers()) {
if (member.getKind() == Tree.Kind.VARIABLE && sourcePositions.getStartPosition(path.getCompilationUnit(), member) >= pos &&
(isStatic || !((VariableTree)member).getModifiers().getFlags().contains(Modifier.STATIC))) {
el = trees.getElement(new TreePath(parent, member));
if (el != null) {
refs.add(el);
}
}
}
}
break;
case ENHANCED_FOR_LOOP:
EnhancedForLoopTree efl = (EnhancedForLoopTree)path.getLeaf();
if (sourcePositions.getEndPosition(path.getCompilationUnit(), efl.getExpression()) >= pos) {
el = trees.getElement(new TreePath(path, efl.getVariable()));
if (el != null) {
refs.add(el);
}
}
}
path = path.getParentPath();
}
return refs;
}
示例14: findEnclosingMethodPath
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static TreePath findEnclosingMethodPath(TreePath path) {
TreePath enclosingMethodPath = path;
TreePath nextPath = enclosingMethodPath.getParentPath();
Tree.Kind kind;
do {
Tree leaf = nextPath.getLeaf();
enclosingMethodPath = nextPath;
nextPath = nextPath.getParentPath();
kind = leaf.getKind();
} while (nextPath != null && !(kind == Tree.Kind.METHOD || kind == Tree.Kind.CLASS));
return enclosingMethodPath;
}
示例15: computeVariableDeclaration
import com.sun.source.util.TreePath; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeVariableDeclaration(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
VariableTree vt = (VariableTree) parent.getLeaf();
if (vt.getInitializer() == error) {
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(parent, vt.getType())));
}
TreePath context = parent.getParentPath();
if (vt.getType() != error || context == null) {
return null;
}
switch (context.getLeaf().getKind()) {
case ENHANCED_FOR_LOOP:
ExpressionTree iterableTree = ((EnhancedForLoopTree) context.getLeaf()).getExpression();
TreePath iterablePath = new TreePath(context, iterableTree);
TypeMirror type = getIterableGenericType(info, iterablePath);
types.add(ElementKind.LOCAL_VARIABLE);
return Collections.singletonList(type);
default:
types.add(ElementKind.CLASS);
return Collections.<TypeMirror>emptyList();
}
}