本文整理汇总了Java中com.sun.source.tree.NewClassTree.getEnclosingExpression方法的典型用法代码示例。如果您正苦于以下问题:Java NewClassTree.getEnclosingExpression方法的具体用法?Java NewClassTree.getEnclosingExpression怎么用?Java NewClassTree.getEnclosingExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.NewClassTree
的用法示例。
在下文中一共展示了NewClassTree.getEnclosingExpression方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Tree visitNewClass(NewClassTree node, Trees p) {
Tree t = super.visitNewClass(node, p);
// new class tree > expression statement tree > block. Does not accept anonymous classes for ctor references.
if (node.getClassBody() == null && singleStatementLambdaMethodBody == getCurrentPath().getParentPath().getParentPath().getLeaf()) {
Tree parent = getCurrentPath().getParentPath().getLeaf();
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null || el.getKind() != ElementKind.CONSTRUCTOR || !el.getEnclosingElement().getKind().isClass()) {
return t;
}
el = el.getEnclosingElement();
if (parent.getKind() == Tree.Kind.EXPRESSION_STATEMENT || parent.getKind() == Tree.Kind.RETURN) {
ExpressionTree et = node.getEnclosingExpression();
if (et != null) {
if (el.getModifiers().contains(Modifier.STATIC) || !isMeaninglessQualifier(new TreePath(getCurrentPath().getParentPath(), et))) {
return t;
}
}
foundConstructorReferenceCandidate = true;
}
}
return t;
}
示例2: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public List<? extends TypeMirror> visitNewClass(NewClassTree node, Object p) {
TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
if (tm == null || tm.getKind() != TypeKind.DECLARED) {
return null;
}
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
if (theExpression.getLeaf() != node.getEnclosingExpression()) {
ExecutableType execType = (ExecutableType)info.getTypes().asMemberOf((DeclaredType)tm, el);
return visitMethodOrNew(node, p, node.getArguments(), execType);
} else {
DeclaredType dt = (DeclaredType)tm;
if (dt.getEnclosingType() == null) {
return null;
}
return Collections.singletonList(dt.getEnclosingType());
}
}
示例3: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, Void unused) {
sync(node);
builder.open(ZERO);
if (node.getEnclosingExpression() != null) {
scan(node.getEnclosingExpression(), null);
builder.breakOp();
token(".");
}
token("new");
builder.space();
addTypeArguments(node.getTypeArguments(), plusFour);
if (node.getClassBody() != null) {
List<Op> ops = visitModifiers(node.getClassBody().getModifiers(),
Direction.HORIZONTAL, Optional.<BreakTag>absent());
builder.addAll(ops);
}
scan(node.getIdentifier(), null);
addArguments(node.getArguments(), plusFour);
builder.close();
if (node.getClassBody() != null) {
addBodyDeclarations(
node.getClassBody().getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES);
}
return null;
}
示例4: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, Void p) {
//XXX:
if (node.getEnclosingExpression() != null) {
tree2Variable.put(node, make.Identifier("$" + currentVariableIndex++));
return null;
}
NewClassTree nue = make.NewClass(node.getEnclosingExpression(), Collections.<ExpressionTree>singletonList(make.Identifier("$" + currentVariableIndex++ + "$")), make.Identifier("$" + currentVariableIndex++), Collections.<ExpressionTree>singletonList(make.Identifier("$" + currentVariableIndex++ + "$")), null);
tree2Variable.put(node, nue);
return null;
}
示例5: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Choice<State<JCNewClass>> visitNewClass(final NewClassTree node, State<?> state) {
if (node.getEnclosingExpression() != null
|| (node.getTypeArguments() != null && !node.getTypeArguments().isEmpty())
|| node.getClassBody() != null) {
return Choice.none();
}
return chooseSubtrees(
state,
s -> unifyExpression(node.getIdentifier(), s),
s -> unifyExpressions(node.getArguments(), s),
(ident, args) -> maker().NewClass(null, null, ident, args, null));
}
示例6: 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;
}
示例7: 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;
}
示例8: visitNewClass
import com.sun.source.tree.NewClassTree; //导入方法依赖的package包/类
@Override
public Wrapper visitNewClass(NewClassTree arg0, Void arg1) {
if (arg0.getEnclosingExpression() != null) {
// expr.new C< ... > ( ... )
throw new AssertionError("TODO: Handle enclosing expression.");
}
return new NewInstanceWrapper(arg0, visit(arg0.getIdentifier(),
ExpressionWrapper.class), visitList(
arg0.getTypeArguments(), ExpressionWrapper.class),
visitList(arg0.getArguments(), ExpressionWrapper.class),
visit(arg0.getClassBody(), Wrapper.class));
}