Java Code Examples for com.sun.tools.javac.tree.JCTree#JCFieldAccess
The following examples show how to use
com.sun.tools.javac.tree.JCTree#JCFieldAccess .
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 File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private boolean isStructuralMethod( JCTree.JCMethodInvocation tree ) { JCExpression methodSelect = tree.getMethodSelect(); if( methodSelect instanceof JCTree.JCFieldAccess ) { JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect; if( m.sym != null && !m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC ) ) { if( !isObjectMethod( m.sym ) ) { JCExpression thisArg = m.selected; return TypeUtil.isStructuralInterface( _tp, thisArg.type.tsym ); } } } return false; }
Example 2
Source File: ManLog_8.java From manifold with Apache License 2.0 | 6 votes |
public void error( JCDiagnostic.DiagnosticPosition pos, String key, Object... args ) { //noinspection StatementWithEmptyBody if( pos instanceof JCTree.JCFieldAccess && ("cant.assign.val.to.final.var".equals( key ) || "var.might.already.be.assigned".equals( key )) && isJailbreakSelect( (JCTree.JCFieldAccess)pos ) ) { // For @Jailbreak assignments, change error to warning re final var assignment //## todo: the error message can't be converted to a warning, make up a custom warning // report( diags.warning( source, pos, key, args ) ); } else if( !isSuppressedError( key ) ) { super.error( pos, key, args ); } }
Example 3
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private void assignTypes( JCExpression m, Symbol symbol ) { if( m instanceof JCTree.JCFieldAccess ) { JCTree.JCFieldAccess fieldAccess = (JCTree.JCFieldAccess)m; fieldAccess.sym = symbol; fieldAccess.type = symbol.type; assignTypes( fieldAccess.selected, symbol.owner ); } else if( m instanceof JCTree.JCIdent ) { JCTree.JCIdent ident = (JCTree.JCIdent)m; ident.sym = symbol; ident.type = symbol.type; } }
Example 4
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private JCExpression getRelationalOpEnumConst( TreeMaker make, JCTree tree ) { Symbol.ClassSymbol opClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ComparableUsing.Operator.class.getCanonicalName() ); Names names = Names.instance( _tp.getContext() ); Symbol.VarSymbol operatorSym = resolveField( tree.pos(), _tp.getContext(), names.fromString( tree.getTag().name() ), opClassSym.type ); JCTree.JCFieldAccess opEnumConst = (JCTree.JCFieldAccess)memberAccess( make, _tp.getElementUtil(), ComparableUsing.Operator.class.getName() + "." + tree.getTag().name() ); opEnumConst.type = operatorSym.type; opEnumConst.sym = operatorSym; opEnumConst.pos = tree.pos; assignTypes( opEnumConst.selected, opClassSym ); opEnumConst.selected.pos = tree.pos; return opEnumConst; }
Example 5
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
@SuppressWarnings("WeakerAccess") public static boolean isJailbreakReceiver( JCTree.JCFieldAccess fieldAccess ) { Symbol sym = null; JCExpression selected = fieldAccess.selected; if( selected instanceof JCTree.JCIdent ) { sym = ((JCTree.JCIdent)selected).sym; } else if( selected instanceof JCTree.JCMethodInvocation ) { if( ((JCTree.JCMethodInvocation)selected).meth instanceof JCTree.JCFieldAccess ) { sym = ((JCTree.JCFieldAccess)((JCTree.JCMethodInvocation)selected).meth).sym; } else if( ((JCTree.JCMethodInvocation)selected).meth instanceof JCTree.JCIdent ) { sym = ((JCTree.JCIdent)((JCTree.JCMethodInvocation)selected).meth).sym; } } return isJailbreakSymbol( sym ); }
Example 6
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private JCTree replaceWithReflection( JCTree.JCAssign assignTree ) { JCTree.JCFieldAccess tree = (JCTree.JCFieldAccess)assignTree.lhs; TreeMaker make = _tp.getTreeMaker(); JavacElements javacElems = _tp.getElementUtil(); boolean isStatic = tree.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC ); if( tree.sym instanceof Symbol.MethodSymbol ) { return assignTree; } Type type = tree.sym.type; Symbol.MethodSymbol reflectMethodSym = findFieldAccessReflectUtilMethod( tree, type, isStatic, true ); ArrayList<JCExpression> newArgs = new ArrayList<>(); newArgs.add( isStatic ? makeClassExpr( tree, tree.selected.type ) : tree.selected ); // receiver or class newArgs.add( make.Literal( tree.sym.flatName().toString() ) ); // field name newArgs.add( assignTree.rhs ); // field value Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() ); JCTree.JCMethodInvocation reflectCall = make.Apply( List.nil(), memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ), List.from( newArgs ) ); reflectCall.setPos( tree.pos ); reflectCall.type = type; JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect(); newMethodSelect.sym = reflectMethodSym; newMethodSelect.type = reflectMethodSym.type; assignTypes( newMethodSelect.selected, reflectMethodClassSym ); return reflectCall; }
Example 7
Source File: NameReplacer.java From manifold with Apache License 2.0 | 5 votes |
@Override public void visitSelect( JCTree.JCFieldAccess jcFieldAccess ) { super.visitSelect( jcFieldAccess ); Names names = Names.instance( _javacTask.getContext() ); jcFieldAccess.name = names.fromString( jcFieldAccess.name.toString() ); jcFieldAccess.pos = _offset; }
Example 8
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private boolean isReceiver( JCTree tree ) { Tree parent = _tp.getParent( tree ); if( parent instanceof JCTree.JCFieldAccess ) { return ((JCTree.JCFieldAccess)parent).getExpression() == tree; } return false; }
Example 9
Source File: ManLog_8.java From manifold with Apache License 2.0 | 5 votes |
boolean isJailbreakSelect( JCTree.JCFieldAccess pos ) { if( _extensionTransformerClass.get() == null ) { return false; } //noinspection ConstantConditions return (boolean)ReflectUtil.method( _extensionTransformerClass.get(), "isJailbreakReceiver", JCTree.JCFieldAccess.class ).invokeStatic( pos ); }
Example 10
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private boolean isConstructProxyCall( JCExpression expression ) { if( expression instanceof JCTree.JCMethodInvocation ) { // don't erase cast if we generated it here e.g.., for structural call cast on constructProxy JCExpression meth = ((JCTree.JCMethodInvocation)expression).meth; return meth instanceof JCTree.JCFieldAccess && ((JCTree.JCFieldAccess)meth).getIdentifier().toString().equals( "constructProxy" ); } return expression instanceof JCTypeCast && isConstructProxyCall( ((JCTypeCast)expression).getExpression() ); }
Example 11
Source File: ManAttr_8.java From manifold with Apache License 2.0 | 5 votes |
/** * Facilitates @Jailbreak. ManResolve#isAccessible() needs to know the JCFieldAccess in context. */ @Override public void visitSelect( JCTree.JCFieldAccess tree ) { // record JCFieldAccess trees as they are visited so we can access them elsewhere while in context _selects.push( tree ); try { super.visitSelect( tree ); } finally { _selects.pop(); } }
Example 12
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 4 votes |
/** * Erase all structural interface type literals to Object */ @Override public void visitSelect( JCTree.JCFieldAccess tree ) { super.visitSelect( tree ); if( _tp.isGenerate() && !shouldProcessForGeneration() ) { // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method return; } if( TypeUtil.isStructuralInterface( _tp, tree.sym ) && !isReceiver( tree ) ) { Symbol.ClassSymbol objectSym = getObjectClass(); JCTree.JCIdent objIdent = _tp.getTreeMaker().Ident( objectSym ); Tree parent = _tp.getParent( tree ); if( parent instanceof JCTree.JCVariableDecl ) { ((JCTree.JCVariableDecl)parent).type = objectSym.type; long parameterModifier = 8589934592L; // Flag.Flag.PARAMETER.value if( (((JCTree.JCVariableDecl)parent).mods.flags & parameterModifier) != 0 ) { objIdent.type = objectSym.type; ((JCTree.JCVariableDecl)parent).sym.type = objectSym.type; ((JCTree.JCVariableDecl)parent).vartype = objIdent; } } else if( parent instanceof JCTree.JCWildcard ) { JCTree.JCWildcard wildcard = (JCTree.JCWildcard)parent; wildcard.type = new Type.WildcardType( objectSym.type, wildcard.kind.kind, wildcard.type.tsym ); } result = objIdent; } else if( isJailbreakReceiver( tree ) ) { result = replaceWithReflection( tree ); } else { result = tree; } }
Example 13
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 4 votes |
private JCTree replaceWithReflection( JCTree.JCFieldAccess tree ) { TreeMaker make = _tp.getTreeMaker(); JavacElements javacElems = _tp.getElementUtil(); boolean isStatic = tree.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC ); if( tree.sym instanceof Symbol.MethodSymbol ) { return tree; } Tree parent = _tp.getParent( tree ); if( parent instanceof JCTree.JCAssign && ((JCTree.JCAssign)parent).lhs == tree || parent instanceof JCTree.JCAssignOp && ((JCTree.JCAssignOp)parent).lhs == tree ) { // handled in visitAssign() or visitAssignOp() return tree; } if( parent instanceof JCTree.JCUnary && ((JCTree.JCUnary)parent).arg == tree ) { Tree.Kind kind = parent.getKind(); if( kind != Tree.Kind.UNARY_MINUS && kind != Tree.Kind.UNARY_PLUS && kind != Tree.Kind.LOGICAL_COMPLEMENT && kind != Tree.Kind.BITWISE_COMPLEMENT ) { // supporting -, +, !, ~ not supporting --, ++ _tp.report( (JCTree)parent, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_INCREMENT_OP_NOT_ALLOWED_REFLECTION.get() ); return tree; } } Type type = tree.sym.type; if( type instanceof Type.ErrorType ) { // No such field/method return tree; } Symbol.MethodSymbol reflectMethodSym = findFieldAccessReflectUtilMethod( tree, type, isStatic, false ); ArrayList<JCExpression> newArgs = new ArrayList<>(); newArgs.add( isStatic ? makeClassExpr( tree, tree.selected.type ) : tree.selected ); // receiver or class newArgs.add( make.Literal( tree.sym.flatName().toString() ) ); // field name Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() ); JCTree.JCMethodInvocation reflectCall = make.Apply( List.nil(), memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ), List.from( newArgs ) ); reflectCall.setPos( tree.pos ); reflectCall.type = type; JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect(); newMethodSelect.sym = reflectMethodSym; newMethodSelect.type = reflectMethodSym.type; assignTypes( newMethodSelect.selected, reflectMethodClassSym ); return reflectCall; }
Example 14
Source File: JavadocMemberEnter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public void visitSelect(JCTree.JCFieldAccess tree) { scan(tree.selected); }
Example 15
Source File: ManAttr_8.java From manifold with Apache License 2.0 | 4 votes |
/** * Handles @Jailbreak */ @Override public void visitApply( JCTree.JCMethodInvocation tree ) { if( !(tree.meth instanceof JCTree.JCFieldAccess) ) { super.visitApply( tree ); patchMethodType( tree ); return; } if( JAILBREAK_PRIVATE_FROM_SUPERS ) { _manLog.pushSuspendIssues( tree ); // since method-calls can be nested, we need a tree of stacks TreeNode(JCTree.JCFieldAccess, Stack<JCDiagnostic>>) } JCTree.JCFieldAccess fieldAccess = (JCTree.JCFieldAccess)tree.meth; try { super.visitApply( tree ); patchMethodType( tree ); if( JAILBREAK_PRIVATE_FROM_SUPERS ) { if( fieldAccess.type instanceof Type.ErrorType ) { if( shouldCheckSuperType( fieldAccess.selected.type ) && _manLog.isJailbreakSelect( fieldAccess ) ) { // set qualifier type to supertype to handle private methods Type.ClassType oldType = (Type.ClassType)fieldAccess.selected.type; fieldAccess.selected.type = ((Symbol.ClassSymbol)oldType.tsym).getSuperclass(); ((JCTree.JCIdent)fieldAccess.selected).sym.type = fieldAccess.selected.type; fieldAccess.type = null; fieldAccess.sym = null; tree.type = null; // retry with supertype visitApply( tree ); // restore original type fieldAccess.selected.type = oldType; ((JCTree.JCIdent)fieldAccess.selected).sym.type = fieldAccess.selected.type; } } else { // apply any issues logged for the found method (only the top of the suspend stack) _manLog.recordRecentSuspendedIssuesAndRemoveOthers( tree ); } } } finally { if( JAILBREAK_PRIVATE_FROM_SUPERS ) { _manLog.popSuspendIssues( tree ); } } }
Example 16
Source File: JavadocMemberEnter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public void visitSelect(JCTree.JCFieldAccess tree) { scan(tree.selected); }
Example 17
Source File: JavadocMemberEnter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public void visitSelect(JCTree.JCFieldAccess tree) { scan(tree.selected); }
Example 18
Source File: JavadocMemberEnter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public void visitSelect(JCTree.JCFieldAccess tree) { scan(tree.selected); }
Example 19
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 4 votes |
private static void analyzeImports(CompilationUnitTree cut, Source src, EndPosTable endPosTable) { CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance(); long firstLine = 0; for (ImportTree imp : cut.getImports()) { JCTree.JCImport jcImport = (JCTree.JCImport) imp; int startPos = jcImport.getPreferredPosition(); int endPos = jcImport.getEndPosition(endPosTable); Range range = Range.create(src, startPos + 1, endPos); firstLine = range.begin.line; String importClass = imp.getQualifiedIdentifier().toString(); String simpleName = ClassNameUtils.getSimpleName(importClass); if (imp.isStatic()) { // TODO static asterisk Tree tree = imp.getQualifiedIdentifier(); if (tree instanceof JCTree.JCFieldAccess) { JCTree.JCFieldAccess fieldAccess = (JCTree.JCFieldAccess) tree; com.sun.tools.javac.util.Name name = fieldAccess.getIdentifier(); JCTree.JCExpression expression = fieldAccess.getExpression(); String methodName = name.toString(); String decClazz = expression.toString(); src.addStaticImport(methodName, decClazz); } else { log.warn("Not impl"); } } else { if (simpleName.equals("*")) { // wild for (String s : cachedASMReflector.getPackageClasses(importClass).values()) { src.addImport(s); } } else { src.addImport(importClass); } } } src.setClassStartLine(firstLine); }
Example 20
Source File: JavadocMemberEnter.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public void visitSelect(JCTree.JCFieldAccess tree) { scan(tree.selected); }