Java Code Examples for com.sun.tools.javac.tree.JCTree.JCIdent
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCIdent.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: TencentKona-8 Author: Tencent File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #2
Source Project: jdk8u60 Author: chenghanpeng File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #3
Source Project: openjdk-jdk8u Author: AdoptOpenJDK File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #4
Source Project: lua-for-android Author: qtiuto File: TransTypes.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public void visitIdent(JCIdent tree) { Type et = tree.sym.erasure(types); // Map type variables to their bounds. if (tree.sym.kind == TYP && tree.sym.type.hasTag(TYPEVAR)) { result = make.at(tree.pos).Type(et); } else // Map constants expressions to themselves. if (tree.type.constValue() != null) { result = tree; } // Insert casts of variable uses as needed. else if (tree.sym.kind == VAR) { result = retype(tree, et, pt); } else { tree.type = erasure(tree.type); result = tree; } }
Example #5
Source Project: lua-for-android Author: qtiuto File: Lower.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Construct definition of an access constructor. * @param pos The source code position of the definition. * @param constr The private constructor. * @param accessor The access method for the constructor. */ JCTree accessConstructorDef(int pos, Symbol constr, MethodSymbol accessor) { make.at(pos); JCMethodDecl md = make.MethodDef(accessor, accessor.externalType(types), null); JCIdent callee = make.Ident(names._this); callee.sym = constr; callee.type = constr.type; md.body = make.Block(0, List.of( make.Call( make.App( callee, make.Idents(md.params.reverse().tail.reverse()))))); return md; }
Example #6
Source Project: lua-for-android Author: qtiuto File: LambdaToMethod.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Translate identifiers within a lambda to the mapped identifier * @param tree */ @Override public void visitIdent(JCIdent tree) { if (context == null || !analyzer.lambdaIdentSymbolFilter(tree.sym)) { super.visitIdent(tree); } else { int prevPos = make.pos; try { make.at(tree); LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context; JCTree ltree = lambdaContext.translate(tree); if (ltree != null) { result = ltree; } else { //access to untranslated symbols (i.e. compile-time constants, //members defined inside the lambda body, etc.) ) super.visitIdent(tree); } } finally { make.at(prevPos); } } }
Example #7
Source Project: openjdk-jdk8u-backup Author: AdoptOpenJDK File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #8
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #9
Source Project: hottub Author: dsrg-uoft File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #10
Source Project: openjdk-8-source Author: keerath File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #11
Source Project: openjdk-8 Author: bpupadhyaya File: TestInvokeDynamic.java License: GNU General Public License v2.0 | 6 votes |
@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; }
Example #12
Source Project: EasyMPermission Author: mobmead File: Javac.java License: MIT License | 6 votes |
/** * 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; }
Example #13
Source Project: EasyMPermission Author: mobmead File: PrettyCommentsPrinter.java License: MIT License | 6 votes |
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); } }
Example #14
Source Project: EasyMPermission Author: mobmead File: JavacHandlerUtil.java License: MIT License | 6 votes |
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); }
Example #15
Source Project: bazel Author: bazelbuild File: TreePruner.java License: Apache License 2.0 | 6 votes |
private static boolean delegatingConstructor(List<JCStatement> stats) { if (stats.isEmpty()) { return false; } JCStatement stat = stats.get(0); if (stat.getKind() != Kind.EXPRESSION_STATEMENT) { return false; } JCExpression expr = ((JCExpressionStatement) stat).getExpression(); if (expr.getKind() != Kind.METHOD_INVOCATION) { return false; } JCExpression method = ((JCMethodInvocation) expr).getMethodSelect(); Name name; switch (method.getKind()) { case IDENTIFIER: name = ((JCIdent) method).getName(); break; case MEMBER_SELECT: name = ((JCFieldAccess) method).getIdentifier(); break; default: return false; } return name.contentEquals("this") || name.contentEquals("super"); }
Example #16
Source Project: bazel Author: bazelbuild File: TreePruner.java License: Apache License 2.0 | 6 votes |
private static boolean isUnused( JCCompilationUnit unit, Set<String> usedNames, JCImport importTree) { String simpleName = importTree.getQualifiedIdentifier() instanceof JCIdent ? ((JCIdent) importTree.getQualifiedIdentifier()).getName().toString() : ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().toString(); String qualifier = ((JCFieldAccess) importTree.getQualifiedIdentifier()).getExpression().toString(); if (qualifier.equals("java.lang")) { return true; } if (unit.getPackageName() != null && unit.getPackageName().toString().equals(qualifier)) { // remove imports of classes from the current package return true; } if (importTree.getQualifiedIdentifier() instanceof JCFieldAccess && ((JCFieldAccess) importTree.getQualifiedIdentifier()) .getIdentifier() .contentEquals("*")) { return false; } if (usedNames.contains(simpleName)) { return false; } return true; }
Example #17
Source Project: lua-for-android Author: qtiuto File: Check.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void checkModuleName (JCModuleDecl tree) { Name moduleName = tree.sym.name; Assert.checkNonNull(moduleName); if (lint.isEnabled(LintCategory.MODULE)) { JCExpression qualId = tree.qualId; while (qualId != null) { Name componentName; DiagnosticPosition pos; switch (qualId.getTag()) { case SELECT: JCFieldAccess selectNode = ((JCFieldAccess) qualId); componentName = selectNode.name; pos = selectNode.pos(); qualId = selectNode.selected; break; case IDENT: componentName = ((JCIdent) qualId).name; pos = qualId.pos(); qualId = null; break; default: throw new AssertionError("Unexpected qualified identifier: " + qualId.toString()); } if (componentName != null) { String moduleNameComponentString = componentName.toString(); int nameLength = moduleNameComponentString.length(); if (nameLength > 0 && Character.isDigit(moduleNameComponentString.charAt(nameLength - 1))) { log.warning(Lint.LintCategory.MODULE, pos, Warnings.PoorChoiceForModuleName(componentName)); } } } } }
Example #18
Source Project: lua-for-android Author: qtiuto File: Flow.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean isIdentOrThisDotIdent(JCTree lhs) { if (lhs.hasTag(IDENT)) return true; if (!lhs.hasTag(SELECT)) return false; JCFieldAccess fa = (JCFieldAccess)lhs; return fa.selected.hasTag(IDENT) && ((JCIdent)fa.selected).name == names._this; }
Example #19
Source Project: lua-for-android Author: qtiuto File: Flow.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitSelect(JCFieldAccess tree) { super.visitSelect(tree); JCTree sel = TreeInfo.skipParens(tree.selected); if (enforceThisDotInit && sel.hasTag(IDENT) && ((JCIdent)sel).name == names._this && tree.sym.kind == VAR) { checkInit(tree.pos(), (VarSymbol)tree.sym); } }
Example #20
Source Project: lua-for-android Author: qtiuto File: Flow.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitAssign(JCAssign tree) { JCTree lhs = TreeInfo.skipParens(tree.lhs); if (!(lhs instanceof JCIdent)) { scan(lhs); } scan(tree.rhs); letInit(lhs); }
Example #21
Source Project: lua-for-android Author: qtiuto File: Lower.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Construct an expression using the builder, with the given rval * expression as an argument to the builder. However, the rval * expression must be computed only once, even if used multiple * times in the result of the builder. We do that by * constructing a "let" expression that saves the rvalue into a * temporary variable and then uses the temporary variable in * place of the expression built by the builder. The complete * resulting expression is of the form * <pre> * (let <b>TYPE</b> <b>TEMP</b> = <b>RVAL</b>; * in (<b>BUILDER</b>(<b>TEMP</b>))) * </pre> * where <code><b>TEMP</b></code> is a newly declared variable * in the let expression. */ JCExpression abstractRval(JCExpression rval, Type type, TreeBuilder builder) { rval = TreeInfo.skipParens(rval); switch (rval.getTag()) { case LITERAL: return builder.build(rval); case IDENT: JCIdent id = (JCIdent) rval; if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH) return builder.build(rval); } Name name = TreeInfo.name(rval); if (name == names._super || name == names._this) return builder.build(rval); VarSymbol var = new VarSymbol(FINAL|SYNTHETIC, names.fromString( target.syntheticNameChar() + "" + rval.hashCode()), type, currentMethodSym); rval = convert(rval,type); JCVariableDecl def = make.VarDef(var, rval); // XXX cast JCExpression built = builder.build(make.Ident(var)); JCExpression res = make.LetExpr(def, built); res.type = built.type; return res; }
Example #22
Source Project: lua-for-android Author: qtiuto File: Annotate.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private Pair<MethodSymbol, Attribute> attributeAnnotationNameValuePair(JCExpression nameValuePair, Type thisAnnotationType, boolean badAnnotation, Env<AttrContext> env, boolean elidedValue) { if (!nameValuePair.hasTag(ASSIGN)) { log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue); attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env); return null; } JCAssign assign = (JCAssign)nameValuePair; if (!assign.lhs.hasTag(IDENT)) { log.error(nameValuePair.pos(), Errors.AnnotationValueMustBeNameValue); attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env); return null; } // Resolve element to MethodSym JCIdent left = (JCIdent)assign.lhs; Symbol method = resolve.resolveQualifiedMethod(elidedValue ? assign.rhs.pos() : left.pos(), env, thisAnnotationType, left.name, List.nil(), null); left.sym = method; left.type = method.type; if (method.owner != thisAnnotationType.tsym && !badAnnotation) log.error(left.pos(), Errors.NoAnnotationMember(left.name, thisAnnotationType)); Type resultType = method.type.getReturnType(); // Compute value part Attribute value = attributeAnnotationValue(resultType, assign.rhs, env); nameValuePair.type = resultType; return method.type.isErroneous() ? null : new Pair<>((MethodSymbol)method, value); }
Example #23
Source Project: lua-for-android Author: qtiuto File: LambdaToMethod.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private JCIdent makeThis(Type type, Symbol owner) { VarSymbol _this = new VarSymbol(PARAMETER | FINAL | SYNTHETIC, names._this, type, owner); return make.Ident(_this); }
Example #24
Source Project: lua-for-android Author: qtiuto File: TypeEnter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitIdent(JCIdent tree) { if (!tree.type.hasTag(ERROR)) { result = tree.type; } else { result = synthesizeClass(tree.name, msym.unnamedPackage).type; } }
Example #25
Source Project: netbeans Author: apache File: JackpotTrees.java License: Apache License 2.0 | 5 votes |
public static JCVariableDecl createVariableWildcard(Context ctx, Name name) { TreeMaker make = TreeMaker.instance(ctx); JCIdent jcIdent = make.Ident(name); JCErroneous err = new JCErroneous(List.<JCTree>nil()) {}; err.type = Symtab.instance(ctx).errType; JCVariableDecl var; try { var = createInstance(ctx, JCVariableDecl.class, name, jcIdent, new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, JCExpression.class, VarSymbol.class}, new Object[] {new FakeModifiers(), name, err, null, null}); } catch (IllegalStateException ex) { try { var = createInstance(ctx, JCVariableDecl.class, name, jcIdent, new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, JCExpression.class, VarSymbol.class, List.class}, new Object[] {new FakeModifiers(), name, err, null, null, List.nil()}); } catch (IllegalStateException ex2) { throw ex; } } var.sym = new VarSymbol(0, name, var.vartype.type, Symtab.instance(ctx).errSymbol); var.type = var.vartype.type; return var; }
Example #26
Source Project: j2cl Author: google File: CompilationUnitBuilder.java License: Apache License 2.0 | 5 votes |
private VariableDeclarationExpression toResource(JCTree resourceTree) { if (resourceTree.getTag() == Tag.VARDEF) { return createVariableDeclarationExpression((JCVariableDecl) resourceTree); } checkArgument(resourceTree.getTag() == Tag.IDENT); return toResource((JCIdent) resourceTree); }
Example #27
Source Project: j2cl Author: google File: CompilationUnitBuilder.java License: Apache License 2.0 | 5 votes |
private VariableDeclarationExpression toResource(JCIdent ident) { // Create temporary variables for resources declared outside of the try statement. Expression expression = convertIdent(ident); return VariableDeclarationExpression.newBuilder() .addVariableDeclaration( Variable.newBuilder() .setName("$resource") .setTypeDescriptor(expression.getTypeDescriptor()) .setFinal(true) .build(), expression) .build(); }
Example #28
Source Project: j2cl Author: google File: CompilationUnitBuilder.java License: Apache License 2.0 | 5 votes |
private Expression convertIdent(JCIdent identifier) { if (isThisExpression(identifier)) { return new ThisReference(getCurrentType().getTypeDescriptor()); } if (isSuperExpression(identifier)) { return new SuperReference(getCurrentType().getTypeDescriptor()); } Symbol symbol = identifier.sym; if (symbol instanceof ClassSymbol) { return new JavaScriptConstructorReference( environment.createDeclarationForType((ClassSymbol) identifier.sym)); } if (symbol instanceof MethodSymbol) { return NullLiteral.get().withComment(identifier.toString()); } VarSymbol varSymbol = (VarSymbol) symbol; if (symbol.getKind() == ElementKind.LOCAL_VARIABLE || symbol.getKind() == ElementKind.RESOURCE_VARIABLE || symbol.getKind() == ElementKind.PARAMETER || symbol.getKind() == ElementKind.EXCEPTION_PARAMETER) { Variable variable = variableByVariableElement.get(symbol); return resolveVariableReference(variable); } FieldDescriptor fieldDescriptor = environment.createFieldDescriptor(varSymbol, identifier.type); Expression qualifier = fieldDescriptor.isStatic() ? null : resolveOuterClassReference(fieldDescriptor.getEnclosingTypeDescriptor(), false); return FieldAccess.newBuilder() .setQualifier(qualifier) .setTargetFieldDescriptor(fieldDescriptor) .build(); }
Example #29
Source Project: j2cl Author: google File: CompilationUnitBuilder.java License: Apache License 2.0 | 5 votes |
private static boolean isSuperExpression(JCExpression expression) { if (expression instanceof JCIdent) { JCIdent ident = (JCIdent) expression; return ident.getName().contentEquals("super"); } return false; }
Example #30
Source Project: j2cl Author: google File: CompilationUnitBuilder.java License: Apache License 2.0 | 5 votes |
private static boolean isThisExpression(JCExpression expression) { if (expression instanceof JCIdent) { JCIdent ident = (JCIdent) expression; return ident.getName().contentEquals("this"); } return false; }