本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCIdent类的典型用法代码示例。如果您正苦于以下问题:Java JCIdent类的具体用法?Java JCIdent怎么用?Java JCIdent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCIdent类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCIdent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitMethodInvocation
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
super.visitMethodInvocation(node, p);
JCMethodInvocation apply = (JCMethodInvocation)node;
JCIdent ident = (JCIdent)apply.meth;
Symbol oldSym = ident.sym;
if (!oldSym.isConstructor()) {
Object[] staticArgs = new Object[arity.arity];
for (int i = 0; i < arity.arity ; i++) {
staticArgs[i] = saks[i].getValue(syms, names, types);
}
ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
}
return null;
}
示例2: visitIdent
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public void visitIdent(final JCIdent node) {
if (node.sym instanceof ClassSymbol) {
// If this is a ClassSymbol, then we have the type. Apply
// substitution if necessary.
print(substitutionInventory.applyTypeSubstitution(node.type));
} else {
// Not a type.
// Attempt template field substitution.
final String identifier = node.name.toString();
print(currentSubstitution()
.filter(field -> substitutionInventory.isSubstitutableFieldName(identifier))
.orElse(identifier));// Neither a substitutable type nor a substitutable field.
}
}
示例3: calculateGuess
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
* Turns an expression into a guessed intended literal. Only works for
* literals, as you can imagine.
*
* Will for example turn a TrueLiteral into 'Boolean.valueOf(true)'.
*/
public static Object calculateGuess(JCExpression expr) {
if (expr instanceof JCLiteral) {
JCLiteral lit = (JCLiteral) expr;
if (lit.getKind() == com.sun.source.tree.Tree.Kind.BOOLEAN_LITERAL) {
return ((Number) lit.value).intValue() == 0 ? false : true;
}
return lit.value;
} else if (expr instanceof JCIdent || expr instanceof JCFieldAccess) {
String x = expr.toString();
if (x.endsWith(".class")) x = x.substring(0, x.length() - 6);
else {
int idx = x.lastIndexOf('.');
if (idx > -1) x = x.substring(idx + 1);
}
return x;
} else
return null;
}
示例4: suppress
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
private boolean suppress(JCTree tree) {
if (tree instanceof JCBlock) {
JCBlock block = (JCBlock) tree;
return (Position.NOPOS == block.pos) && block.stats.isEmpty();
}
if (tree instanceof JCExpressionStatement) {
JCExpression expr = ((JCExpressionStatement)tree).expr;
if (expr instanceof JCMethodInvocation) {
JCMethodInvocation inv = (JCMethodInvocation) expr;
if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
if (!(inv.meth instanceof JCIdent)) return false;
return ((JCIdent) inv.meth).name.toString().equals("super");
}
}
return false;
}
示例5: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override public void visitAnnotation(JCAnnotation tree) {
print("@");
print(tree.annotationType);
if (tree.args.isEmpty()) return;
print("(");
boolean done = false;
if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
JCAssign arg1 = (JCAssign) tree.args.get(0);
JCIdent arg1Name = arg1.lhs instanceof JCIdent ? ((JCIdent) arg1.lhs) : null;
if (arg1Name != null && arg1Name.name == name_value(arg1Name.name)) {
print(arg1.rhs);
done = true;
}
}
if (!done) print(tree.args, ", ");
print(")");
}
示例6: isConstructorCall
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
public static boolean isConstructorCall(final JCStatement statement) {
if (!(statement instanceof JCExpressionStatement)) return false;
JCExpression expr = ((JCExpressionStatement) statement).expr;
if (!(expr instanceof JCMethodInvocation)) return false;
JCExpression invocation = ((JCMethodInvocation) expr).meth;
String name;
if (invocation instanceof JCFieldAccess) {
name = ((JCFieldAccess) invocation).name.toString();
} else if (invocation instanceof JCIdent) {
name = ((JCIdent) invocation).name.toString();
} else {
name = "";
}
return "super".equals(name) || "this".equals(name);
}
示例7: unpack
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
private static void unpack(StringBuilder sb, JCExpression expr) {
if (expr instanceof JCIdent) {
sb.append(((JCIdent) expr).name.toString());
return;
}
if (expr instanceof JCFieldAccess) {
JCFieldAccess jcfa = (JCFieldAccess) expr;
unpack(sb, jcfa.selected);
sb.append(".").append(jcfa.name.toString());
return;
}
if (expr instanceof JCTypeApply) {
sb.setLength(0);
sb.append("ERR:");
sb.append("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate.");
sb.append("__ERR__");
return;
}
sb.setLength(0);
sb.append("ERR:");
sb.append("Expected a type of some sort, not a " + expr.getClass().getName());
sb.append("__ERR__");
}
示例8: visit
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public JCTree visit(final PackageDeclaration n, final Object arg) {
//ARG0: JCExpression
// It returns a full qualified name
JCExpression arg0 = (JCExpression) n.getName().accept(this, arg);
/* TODO - Not supporting annotations
if (n.getAnnotations() != null) {
for (final AnnotationExpr a : n.getAnnotations()) {
JCTree result = a.accept(this, arg);
}
}
*/
if (arg0 instanceof JCIdent) {
return new AJCIdent((JCIdent) arg0, ((n.getComment() != null) ? n.getComment().getContent() : null));
}
return new AJCFieldAccess((JCFieldAccess) arg0, ((n.getComment() != null) ? n.getComment().getContent() : null));
}
示例9: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
public void visitAnnotation(JCAnnotation tree) {
try {
print("@");
printExpr(tree.annotationType);
if (tree.args.nonEmpty()) {
print("(");
if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
JCExpression lhs = ((JCAssign)tree.args.get(0)).lhs;
if (lhs instanceof JCIdent && ((JCIdent)lhs).name.toString().equals("value")) tree.args = List.of(((JCAssign)tree.args.get(0)).rhs);
}
printExprs(tree.args);
print(")");
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例10: visitClass
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public Object visitClass (ClassTree classTree, Trees trees) {
Tree extendTree = classTree.getExtendsClause();
if (extendTree instanceof JCTypeApply) { //generic classes case
JCTypeApply generic = (JCTypeApply) extendTree;
extendTree = generic.clazz;
}
if (extendTree instanceof JCIdent) {
JCIdent tree = (JCIdent) extendTree;
Scope members = tree.sym.members();
if (checkScope(members))
return super.visitClass(classTree, trees);
if (checkSuperTypes((ClassType) tree.type))
return super.visitClass(classTree, trees);
}
callSuperUsed = false;
return super.visitClass(classTree, trees);
}
示例11: visitTypeReferencePart
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
@Override
public boolean visitTypeReferencePart(TypeReferencePart node) {
JCIdent ident = (JCIdent) toTree(node.astIdentifier());
List<JCExpression> typeArguments = toList(JCExpression.class, node.astTypeArguments());
if (typeArguments.isEmpty()) {
return set(node, ident);
} else {
JCTypeApply typeApply = treeMaker.TypeApply(ident, typeArguments);
Position jcOpenBracketPos = getConversionPositionInfo(node, "<");
if (jcOpenBracketPos == null) {
setPos(posOfStructure(node, "<", true), node.getPosition().getEnd(), typeApply);
} else {
setPos(jcOpenBracketPos.getStart(), node.getPosition().getEnd(), typeApply);
}
return set(node, typeApply);
}
}
示例12: isThereInMiniTree
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
* This function walks into a tree with nodes of type JCBinary to search for
* a string as one of the elements of the tree.
* @param toTest The String searched as Element in the tree.
* @param expression The bifurcation tree searched.
* @return True if the string was found, or False.
*/
private boolean isThereInMiniTree(String toTest, JCTree expression) {
if(expression instanceof JCParens){
if(isThereInMiniTree(toTest, ((JCParens) expression).expr))
return true;
} else if(expression instanceof JCIdent){
if(((JCIdent) expression).name.toString().equals(toTest))
return true;
} else if(expression instanceof JCBinary){
if(isThereInMiniTree(toTest, ((JCBinary) expression).rhs))
return true;
if(isThereInMiniTree(toTest, ((JCBinary) expression).lhs))
return true;
}
return false;
}
示例13: receiverSameAsArgument
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
* Matches when the receiver of an instance method is the same reference as a particular argument
* to the method. For example, receiverSameAsArgument(1) would match {@code obj.method("", obj)}
*
* @param argNum The number of the argument to compare against (zero-based.
*/
public static Matcher<? super MethodInvocationTree> receiverSameAsArgument(final int argNum) {
return new Matcher<MethodInvocationTree>() {
@Override
public boolean matches(MethodInvocationTree t, VisitorState state) {
List<? extends ExpressionTree> args = t.getArguments();
if (args.size() <= argNum) {
return false;
}
ExpressionTree arg = args.get(argNum);
JCExpression methodSelect = (JCExpression) t.getMethodSelect();
if (methodSelect instanceof JCFieldAccess) {
JCFieldAccess fieldAccess = (JCFieldAccess) methodSelect;
return ASTHelpers.sameVariable(fieldAccess.getExpression(), arg);
} else if (methodSelect instanceof JCIdent) {
// A bare method call: "equals(foo)". Receiver is implicitly "this".
return "this".equals(arg.toString());
}
return false;
}
};
}
示例14: getSymbol
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
* Gets the symbol for a tree. Returns null if this tree does not have a symbol because it is of
* the wrong type, if {@code tree} is null, or if the symbol cannot be found due to a compilation
* error.
*/
// TODO(eaftan): refactor other code that accesses symbols to use this method
public static Symbol getSymbol(Tree tree) {
if (tree instanceof JCFieldAccess) {
return ((JCFieldAccess) tree).sym;
}
if (tree instanceof JCIdent) {
return ((JCIdent) tree).sym;
}
if (tree instanceof JCMethodInvocation) {
return ASTHelpers.getSymbol((MethodInvocationTree) tree);
}
if (tree instanceof JCNewClass) {
return ASTHelpers.getSymbol((NewClassTree) tree);
}
if (tree instanceof MemberReferenceTree) {
return ((JCMemberReference) tree).sym;
}
if (tree instanceof JCAnnotatedType) {
return getSymbol(((JCAnnotatedType) tree).underlyingType);
}
return getDeclaredSymbol(tree);
}
示例15: getReceiverType
import com.sun.tools.javac.tree.JCTree.JCIdent; //导入依赖的package包/类
/**
* Returns the type of a receiver of a method call expression. Precondition: the expressionTree
* corresponds to a method call.
*
* <p>Examples:
*
* <pre>{@code
* a.b.foo() ==> type of a.b
* a.bar().foo() ==> type of a.bar()
* this.foo() ==> type of this
* foo() ==> type of this
* TheClass.aStaticMethod() ==> TheClass
* aStaticMethod() ==> type of class in which method is defined
* }</pre>
*/
public static Type getReceiverType(ExpressionTree expressionTree) {
if (expressionTree instanceof JCFieldAccess) {
JCFieldAccess methodSelectFieldAccess = (JCFieldAccess) expressionTree;
return methodSelectFieldAccess.selected.type;
} else if (expressionTree instanceof JCIdent) {
JCIdent methodCall = (JCIdent) expressionTree;
return methodCall.sym.owner.type;
} else if (expressionTree instanceof JCMethodInvocation) {
return getReceiverType(((JCMethodInvocation) expressionTree).getMethodSelect());
} else if (expressionTree instanceof JCMemberReference) {
return ((JCMemberReference) expressionTree).getQualifierExpression().type;
}
throw new IllegalArgumentException(
"Expected a JCFieldAccess or JCIdent from expression " + expressionTree);
}