本文整理汇总了Java中com.sun.source.tree.NewClassTree.getArguments方法的典型用法代码示例。如果您正苦于以下问题:Java NewClassTree.getArguments方法的具体用法?Java NewClassTree.getArguments怎么用?Java NewClassTree.getArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.NewClassTree
的用法示例。
在下文中一共展示了NewClassTree.getArguments方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
if (!matchWithinClass) {
return Description.NO_MATCH;
}
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
if (methodSymbol == null) {
throw new RuntimeException("not expecting unresolved method here");
}
List<? extends ExpressionTree> actualParams = tree.getArguments();
if (tree.getClassBody() != null && actualParams.size() > 0) {
// passing parameters to constructor of anonymous class
// this constructor just invokes the constructor of the superclass, and
// in the AST does not have the parameter nullability annotations from the superclass.
// so, treat as if the superclass constructor is being invoked directly
// see https://github.com/uber/NullAway/issues/102
Type supertype = state.getTypes().supertype(methodSymbol.owner.type);
Symbol.MethodSymbol superConstructor =
findSuperConstructorInType(methodSymbol, supertype, state.getTypes());
if (superConstructor == null) {
throw new RuntimeException("must find constructor in supertype");
}
methodSymbol = superConstructor;
}
return handleInvocation(state, methodSymbol, actualParams);
}
示例2: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, AnnotatedTypeMirror p) {
super.visitNewClass(node, p);
if (useFbc) {
boolean allCommitted = true;
Type type = ((JCTree) node).type;
for (ExpressionTree a : node.getArguments()) {
final AnnotatedTypeMirror t = getAnnotatedType(a);
allCommitted &= (isCommitted(t) || isFbcBottom(t));
}
if (!allCommitted) {
p.replaceAnnotation(createFreeAnnotation(type));
}
}
return null;
}
示例3: computeNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
NewClassTree nct = (NewClassTree) parent.getLeaf();
boolean errorInRealArguments = false;
for (Tree param : nct.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;
}
Tree id = nct.getIdentifier();
if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
id = ((ParameterizedTypeTree) id).getType();
}
if (id == error) {
return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
}
return null;
}
示例4: getLambdaIndexFromInvokingTree
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private int getLambdaIndexFromInvokingTree(Tree invokingTree) {
List<? extends ExpressionTree> invokingArgs;
if (invokingTree.getKind() == Tree.Kind.METHOD_INVOCATION) {
MethodInvocationTree invokingMethTree = ((MethodInvocationTree) invokingTree);
invokingArgs = invokingMethTree.getArguments();
} else if (invokingTree.getKind() == Tree.Kind.NEW_CLASS) {
NewClassTree invokingConstrTree = (NewClassTree) invokingTree;
invokingArgs = invokingConstrTree.getArguments();
} else {
return -1;
}
return getIndexOfLambdaInArgs(newClassTree, invokingArgs);
}
示例5: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Boolean visitNewClass(NewClassTree node, Void p) {
scan(node.getEnclosingExpression(), p);
for (ExpressionTree et : node.getArguments()) {
Boolean used = scan(et, p);
if (used == Boolean.TRUE) {
passedToMethod = true;
}
}
return false;
}
示例6: computeNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
NewClassTree nct = (NewClassTree) parent.getLeaf();
boolean errorInRealArguments = false;
for (Tree param : nct.getArguments()) {
errorInRealArguments |= param == error;
}
if (errorInRealArguments) {
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
return null;
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return proposedTypes;
}
Tree id = nct.getIdentifier();
if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
id = ((ParameterizedTypeTree) id).getType();
}
if (id == error) {
return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
}
return null;
}
示例7: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public MethodArgument[] visitNewClass(NewClassTree node, Object p) {
if (!methodInvocation || offset != positions.getEndPosition(tree, node.getIdentifier())) {
return super.visitNewClass(node, p);
}
List<? extends ExpressionTree> args = node.getArguments();
List<? extends Tree> argTypes = node.getTypeArguments();
arguments = composeArguments(args, argTypes);
return arguments;
}
示例8: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Node visitNewClass(NewClassTree tree, Void p) {
// see JLS 15.9
Tree enclosingExpr = tree.getEnclosingExpression();
if (enclosingExpr != null) {
scan(enclosingExpr, p);
}
// We ignore any class body because its methods should
// be visited separately.
// Convert constructor arguments
ExecutableElement constructor = TreeUtils.elementFromUse(tree);
List<? extends ExpressionTree> actualExprs = tree.getArguments();
List<Node> arguments = convertCallArguments(constructor,
actualExprs);
Node constructorNode = scan(tree.getIdentifier(), p);
Node node = new ObjectCreationNode(tree, constructorNode, arguments);
Set<TypeMirror> thrownSet = new HashSet<>();
// Add exceptions explicitly mentioned in the throws clause.
List<? extends TypeMirror> thrownTypes = constructor.getThrownTypes();
thrownSet.addAll(thrownTypes);
// Add Throwable to account for unchecked exceptions
TypeElement throwableElement = elements
.getTypeElement("java.lang.Throwable");
thrownSet.add(throwableElement.asType());
extendWithNodeWithExceptions(node, thrownSet);
return node;
}
示例9: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Node visitNewClass(NewClassTree tree, Void p) {
// see JLS 15.9
Tree enclosingExpr = tree.getEnclosingExpression();
if (enclosingExpr != null) {
scan(enclosingExpr, p);
}
// We ignore any class body because its methods should
// be visited separately.
// TODO: For anonymous classes we want to propagate the current store
// to the anonymous class.
// See Issues 266, 811.
// Convert constructor arguments
ExecutableElement constructor = TreeUtils.elementFromUse(tree);
List<? extends ExpressionTree> actualExprs = tree.getArguments();
List<Node> arguments = convertCallArguments(constructor, actualExprs);
// TODO: for anonymous classes, don't use the identifier alone.
// See Issue 890.
Node constructorNode = scan(tree.getIdentifier(), p);
Node node = new ObjectCreationNode(tree, constructorNode, arguments);
Set<TypeMirror> thrownSet = new HashSet<>();
// Add exceptions explicitly mentioned in the throws clause.
List<? extends TypeMirror> thrownTypes = constructor.getThrownTypes();
thrownSet.addAll(thrownTypes);
// Add Throwable to account for unchecked exceptions
TypeElement throwableElement = elements.getTypeElement("java.lang.Throwable");
thrownSet.add(throwableElement.asType());
extendWithNodeWithExceptions(node, thrownSet);
return node;
}
示例10: checkMethodInvocation
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private static boolean checkMethodInvocation(HintContext ctx, TreePath invPath, TreePath valPath) {
Trees trees = ctx.getInfo().getTrees();
Tree invLeaf = invPath.getLeaf();
List<? extends ExpressionTree> arguments;
TypeMirror m;
switch (invLeaf.getKind()) {
case METHOD_INVOCATION: {
MethodInvocationTree mit = (MethodInvocationTree)invLeaf;
arguments = mit.getArguments();
m = trees.getTypeMirror(new TreePath(invPath, mit.getMethodSelect()));
break;
}
case NEW_CLASS: {
NewClassTree nct = (NewClassTree)invLeaf;
arguments = nct.getArguments();
Element e = trees.getElement(invPath);
TypeMirror cl = trees.getTypeMirror(invPath);
if (!Utilities.isValidType(cl) || cl.getKind().isPrimitive()) {
return false;
}
m = ctx.getInfo().getTypes().asMemberOf((DeclaredType)cl, e);
break;
}
default:
return false;
}
if (!Utilities.isValidType(m) || m.getKind() != TypeKind.EXECUTABLE) {
return false;
}
ExecutableType execType = (ExecutableType)m;
int idx = arguments.indexOf(ctx.getPath().getLeaf());
if (idx < 0 || idx >= execType.getParameterTypes().size()) {
return false;
}
TypeMirror paramType = execType.getParameterTypes().get(idx);
TypeMirror curType = trees.getTypeMirror(ctx.getPath());
TypeMirror valType = trees.getTypeMirror(valPath);
if (!paramType.getKind().isPrimitive() && valType.getKind().isPrimitive()) {
valType = ctx.getInfo().getTypes().boxedClass((PrimitiveType)valType).asType();
// ensure that the passed INSTANCE type will not change when the boxing is removed
if (!ctx.getInfo().getTypes().isSameType(curType, valType)) {
return false;
}
}
return Utilities.checkAlternativeInvocation(ctx.getInfo(), invPath, ctx.getPath(), valPath, null);
}
示例11: validateSelection
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
public static TreePath validateSelection(CompilationInfo ci, int start, int end, Set<TypeKind> ignoredTypes) {
int[] span = TreeUtils.ignoreWhitespaces(ci, Math.min(start, end), Math.max(start, end));
start = span[0];
end = span[1];
TreePath tp = ci.getTreeUtilities().pathFor((start + end) / 2 + 1);
for ( ; tp != null; tp = tp.getParentPath()) {
Tree leaf = tp.getLeaf();
if ( !ExpressionTree.class.isAssignableFrom(leaf.getKind().asInterface())
&& (leaf.getKind() != Kind.VARIABLE || ((VariableTree) leaf).getInitializer() == null))
continue;
long treeStart = ci.getTrees().getSourcePositions().getStartPosition(ci.getCompilationUnit(), leaf);
long treeEnd = ci.getTrees().getSourcePositions().getEndPosition(ci.getCompilationUnit(), leaf);
if (treeStart != start || treeEnd != end) {
continue;
}
TypeMirror type = ci.getTrees().getTypeMirror(tp);
if (type != null && type.getKind() == TypeKind.ERROR) {
type = ci.getTrees().getOriginalType((ErrorType) type);
}
if (type == null || ignoredTypes.contains(type.getKind()))
continue;
if(tp.getLeaf().getKind() == Kind.ASSIGNMENT)
continue;
if (tp.getLeaf().getKind() == Kind.ANNOTATION)
continue;
if (!TreeUtils.isInsideClass(tp))
return null;
TreePath candidate = tp;
tp = tp.getParentPath();
while (tp != null) {
switch (tp.getLeaf().getKind()) {
case VARIABLE:
VariableTree vt = (VariableTree) tp.getLeaf();
if (vt.getInitializer() == leaf) {
return candidate;
} else {
return null;
}
case NEW_CLASS:
NewClassTree nct = (NewClassTree) tp.getLeaf();
if (nct.getIdentifier().equals(candidate.getLeaf())) { //avoid disabling hint ie inside of anonymous class higher in treepath
for (Tree p : nct.getArguments()) {
if (p == leaf) {
return candidate;
}
}
return null;
}
}
leaf = tp.getLeaf();
tp = tp.getParentPath();
}
return candidate;
}
return null;
}
示例12: documentationImpl
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
private String documentationImpl(String code, int cursor) {
code = code.substring(0, cursor);
if (code.trim().isEmpty()) { //TODO: comment handling
code += ";";
}
if (guessKind(code) == Kind.IMPORT)
return null;
OuterWrap codeWrap = proc.outerMap.wrapInTrialClass(Wrap.methodWrap(code));
AnalyzeTask at = proc.taskFactory.new AnalyzeTask(codeWrap, keepParameterNames);
SourcePositions sp = at.trees().getSourcePositions();
CompilationUnitTree topLevel = at.firstCuTree();
TreePath tp = pathFor(topLevel, sp, codeWrap.snippetIndexToWrapIndex(cursor));
if (tp == null)
return null;
TreePath prevPath = null;
while (tp != null && tp.getLeaf().getKind() != Kind.METHOD_INVOCATION && tp.getLeaf().getKind() != Kind.NEW_CLASS) {
prevPath = tp;
tp = tp.getParentPath();
}
if (tp == null)
return null;
Iterable<Pair<ExecutableElement, ExecutableType>> candidates;
List<? extends ExpressionTree> arguments;
if (tp.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
MethodInvocationTree mit = (MethodInvocationTree) tp.getLeaf();
candidates = methodCandidates(at, tp);
arguments = mit.getArguments();
} else {
NewClassTree nct = (NewClassTree) tp.getLeaf();
candidates = newClassCandidates(at, tp);
arguments = nct.getArguments();
}
if (!isEmptyArgumentsContext(arguments)) {
List<TypeMirror> actuals = computeActualInvocationTypes(at, arguments, prevPath);
List<TypeMirror> fullActuals = actuals != null ? actuals : Collections.emptyList();
candidates =
this.filterExecutableTypesByArguments(at, candidates, fullActuals)
.stream()
.filter(method -> parameterType(method.fst, method.snd, fullActuals.size(), true).findAny().isPresent())
.collect(Collectors.toList());
}
try (SourceCache sourceCache = new SourceCache(at)) {
return Util.stream(candidates)
.map(method -> Util.expunge(element2String(sourceCache, method.fst)))
.collect(joining("\n"));
}
}