com.sun.tools.javac.tree.JCTree.JCFieldAccess Java Examples

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: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visitSelect(JCFieldAccess tree) {
    if (!tree.type.hasTag(ERROR)) {
        result = tree.type;
    } else {
        Type selectedType;
        boolean prev = interfaceExpected;
        try {
            interfaceExpected = false;
            selectedType = visit(tree.selected);
        } finally {
            interfaceExpected = prev;
        }
        ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
        result = c.type;
    }
}
 
Example #2
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void visitApply(JCMethodInvocation tree) {
	try {
		if (!tree.typeargs.isEmpty()) {
			if (SELECT.equals(treeTag(tree.meth))) {
				JCFieldAccess left = (JCFieldAccess)tree.meth;
				printExpr(left.selected);
				print(".<");
				printExprs(tree.typeargs);
				print(">" + left.name);
			} else {
				print("<");
				printExprs(tree.typeargs);
				print(">");
				printExpr(tree.meth);
			}
		} else {
			printExpr(tree.meth);
		}
		print("(");
		printExprs(tree.args);
		print(")");
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #3
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitSelect(JCFieldAccess tree) {
    Type t = types.skipTypeVars(tree.selected.type, false);
    if (t.isCompound()) {
        tree.selected = coerce(
            translate(tree.selected, erasure(tree.selected.type)),
            erasure(tree.sym.owner.type));
    } else
        tree.selected = translate(tree.selected, erasure(t));

    // 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, tree.sym.erasure(types), pt);
    }
    else {
        tree.type = erasure(tree.type);
        result = tree;
    }
}
 
Example #4
Source File: Javac.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * 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 #5
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
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 #6
Source File: HandleLog.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) {
	JavacTreeMaker maker = typeNode.getTreeMaker();
	
	// private static final <loggerType> log = <factoryMethod>(<parameter>);
	JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName());
	JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName());

	JCExpression loggerName;
	if (loggerTopic == null || loggerTopic.trim().length() == 0) {
		loggerName = framework.createFactoryParameter(typeNode, loggingType);
	} else {
		loggerName = maker.Literal(loggerTopic);
	}

	JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName));

	JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
			maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)),
			typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext());
	
	injectFieldAndMarkGenerated(typeNode, fieldDecl);
	return true;
}
 
Example #7
Source File: TreePruner.java    From bazel with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkImportsResolvable(final JCCompilationUnit toplevel) {
    for (final JCImport imp : toplevel.getImports()) {
        if (!imp.staticImport || !imp.qualid.hasTag(SELECT))
            continue;
        final JCFieldAccess select = (JCFieldAccess) imp.qualid;
        final Symbol origin;
        if (select.name == names.asterisk || (origin = TreeInfo.symbol(select.selected)) == null || origin.kind != TYP)
            continue;

        TypeSymbol site = (TypeSymbol) TreeInfo.symbol(select.selected);
        if (!checkTypeContainsImportableElement(site, site, toplevel.packge, select.name, new HashSet<Symbol>())) {
            log.error(imp.pos(),
                      Errors.CantResolveLocation(KindName.STATIC,
                                                 select.name,
                                                 null,
                                                 null,
                                                 Fragments.Location(kindName(site),
                                                                    site,
                                                                    null)));
        }
    }
}
 
Example #9
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkImportedPackagesObservable(final JCCompilationUnit toplevel) {
    OUTER: for (JCImport imp : toplevel.getImports()) {
        if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) {
            TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym;
            if (toplevel.modle.visiblePackages != null) {
                //TODO - unclear: selects like javax.* will get resolved from the current module
                //(as javax is not an exported package from any module). And as javax in the current
                //module typically does not contain any classes or subpackages, we need to go through
                //the visible packages to find a sub-package:
                for (PackageSymbol known : toplevel.modle.visiblePackages.values()) {
                    if (Convert.packagePart(known.fullname) == tsym.flatName())
                        continue OUTER;
                }
            }
            if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) {
                log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, Errors.DoesntExist(tsym));
            }
        }
    }
}
 
Example #10
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** The class in which an access method for given symbol goes.
 *  @param sym        The access symbol
 *  @param protAccess Is access to a protected symbol in another
 *                    package?
 */
ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree) {
    if (protAccess) {
        Symbol qualifier = null;
        ClassSymbol c = currentClass;
        if (tree.hasTag(SELECT) && (sym.flags() & STATIC) == 0) {
            qualifier = ((JCFieldAccess) tree).selected.type.tsym;
            while (!qualifier.isSubClass(c, types)) {
                c = c.owner.enclClass();
            }
            return c;
        } else {
            while (!c.isSubClass(sym.owner, types)) {
                c = c.owner.enclClass();
            }
        }
        return c;
    } else {
        // the symbol is private
        return sym.owner.enclClass();
    }
}
 
Example #11
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitSelect(JCFieldAccess tree) {
    // need to special case-access of the form C.super.x
    // these will always need an access method, unless C
    // is a default interface subclassed by the current class.
    boolean qualifiedSuperAccess =
        tree.selected.hasTag(SELECT) &&
        TreeInfo.name(tree.selected) == names._super &&
        !types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type.tsym, currentClass);
    tree.selected = translate(tree.selected);
    if (tree.name == names._class) {
        result = classOf(tree.selected);
    }
    else if (tree.name == names._super &&
            types.isDirectSuperInterface(tree.selected.type.tsym, currentClass)) {
        //default super call!! Not a classic qualified super call
        TypeSymbol supSym = tree.selected.type.tsym;
        Assert.checkNonNull(types.asSuper(currentClass.type, supSym));
        result = tree;
    }
    else if (tree.name == names._this || tree.name == names._super) {
        result = makeThis(tree.pos(), tree.selected.type.tsym);
    }
    else
        result = access(tree.sym, tree, enclOp, qualifiedSuperAccess);
}
 
Example #12
Source File: TreePruner.java    From bazel with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitNewClass(NewClassTree node, Insertion ins) {
  JCNewClass na = (JCNewClass) node;
  JCExpression className = na.clazz;
  // System.out.printf("classname %s (%s)%n", className, className.getClass());
  while (! (className.getKind() == Tree.Kind.IDENTIFIER)) { // IdentifierTree
    if (className instanceof JCAnnotatedType) {
      className = ((JCAnnotatedType) className).underlyingType;
    } else if (className instanceof JCTypeApply) {
      className = ((JCTypeApply) className).clazz;
    } else if (className instanceof JCFieldAccess) {
      // This occurs for fully qualified names, e.g. "new java.lang.Object()".
      // I'm not quite sure why the field "selected" is taken, but "name" would
      // be a type mismatch. It seems to work, see NewPackage test case.
      className = ((JCFieldAccess) className).selected;
    } else {
      throw new Error(String.format("unrecognized JCNewClass.clazz (%s): %s%n" +
              "   surrounding new class tree: %s%n", className.getClass(), className, node));
    }
    // System.out.printf("classname %s (%s)%n", className, className.getClass());
  }

  return visitIdentifier((IdentifierTree) className, ins);
}
 
Example #14
Source File: CompleteExpression.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private boolean performComplete(JCExpression jcExpression, ArrayList<SuggestItem> result) {
    if (DLog.DEBUG) DLog.d(TAG, "analyse: class = " + jcExpression.getClass());
    //error expression
    if (jcExpression instanceof JCErroneous) {
        System.out.println("CompleteExpression.JCErroneous");
        List<? extends JCTree> errorTrees = ((JCErroneous) jcExpression).getErrorTrees();
        JCTree errExpr = errorTrees.get(0);
        if (errExpr instanceof JCExpression) {
            return performComplete((JCExpression) errExpr, result);
        }

    } else if (jcExpression instanceof JCFieldAccess) {
        //arrayList.to <-  JCFieldAccess
        //arrayList.add("Hello");
        //s.toLower, incomplete method but give JCFieldAccess
        return performCompleteFieldAccess((JCFieldAccess) jcExpression, result);

    } else if (jcExpression instanceof JCTree.JCIdent) {
        return performCompleteIdent((JCTree.JCIdent) jcExpression, result);

    }
    return false;
}
 
Example #15
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visitSelect(JCFieldAccess tree) {
    if (context() != null && tree.sym.kind == VAR &&
                (tree.sym.name == names._this ||
                 tree.sym.name == names._super)) {
        // A select of this or super means, if we are in a lambda,
        // we much have an instance context
        TranslationContext<?> localContext = context();
        while (localContext != null  && !localContext.owner.isStatic()) {
            if (localContext.tree.hasTag(LAMBDA)) {
                JCClassDecl clazz = (JCClassDecl)capturedDecl(localContext.depth, tree.sym);
                if (clazz == null) break;
                ((LambdaTranslationContext)localContext).addSymbol(clazz.sym, CAPTURED_THIS);
            }
            localContext = localContext.prev;
        }
    }
    super.visitSelect(tree);
}
 
Example #16
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * determine the receiver of the method call - the receiver can
 * be a type qualifier, the synthetic receiver parameter or 'super'.
 */
private JCExpression expressionInvoke(VarSymbol rcvr) {
    JCExpression qualifier =
            (rcvr != null) ?
                makeReceiver(rcvr) :
                tree.getQualifierExpression();

    //create the qualifier expression
    JCFieldAccess select = make.Select(qualifier, tree.sym.name);
    select.sym = tree.sym;
    select.type = tree.sym.erasure(types);

    //create the method call expression
    JCExpression apply = make.Apply(List.nil(), select,
            convertArgs(tree.sym, args.toList(), tree.varargsElement)).
            setType(tree.sym.erasure(types).getReturnType());

    apply = transTypes.coerce(attrEnv, apply,
            types.erasure(localContext.tree.referentType.getReturnType()));

    setVarargsIfNeeded(apply, tree.varargsElement);
    return apply;
}
 
Example #17
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Translate qualified `this' references within a lambda to the mapped identifier
 * @param tree
 */
@Override
public void visitSelect(JCFieldAccess tree) {
    if (context == null || !analyzer.lambdaFieldAccessFilter(tree)) {
        super.visitSelect(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 {
                super.visitSelect(tree);
            }
        } finally {
            make.at(prevPos);
        }
    }
}
 
Example #18
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
    Type result = attr.attribTree(tree, env, annotationValueInfo(expectedElementType));
    if (result.isErroneous()) {
        // Does it look like an unresolved class literal?
        if (TreeInfo.name(tree) == names._class &&
                ((JCFieldAccess) tree).selected.type.isErroneous()) {
            Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName();
            return new Attribute.UnresolvedClass(expectedElementType,
                    types.createErrorType(n,
                            syms.unknownSymbol, syms.classType));
        } else {
            return new Attribute.Error(result.getOriginalType());
        }
    }

    // Class literals look like field accesses of a field named class
    // at the tree level
    if (TreeInfo.name(tree) != names._class) {
        log.error(tree.pos(), Errors.AnnotationValueMustBeClassLiteral);
        return new Attribute.Error(syms.errType);
    }

    return new Attribute.Class(types,
            (((JCFieldAccess) tree).selected).type);
}
 
Example #19
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
JCExpression abstractLval(JCExpression lval, final TreeBuilder builder) {
    lval = TreeInfo.skipParens(lval);
    switch (lval.getTag()) {
    case IDENT:
        return builder.build(lval);
    case SELECT: {
        final JCFieldAccess s = (JCFieldAccess)lval;
        Symbol lid = TreeInfo.symbol(s.selected);
        if (lid != null && lid.kind == TYP) return builder.build(lval);
        return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));
    }
    case INDEXED: {
        final JCArrayAccess i = (JCArrayAccess)lval;
        return abstractRval(i.indexed, indexed -> abstractRval(i.index, syms.intType, index -> {
            JCExpression newLval = make.Indexed(indexed, index);
            newLval.setType(i.type);
            return builder.build(newLval);
        }));
    }
    case TYPECAST: {
        return abstractLval(((JCTypeCast)lval).expr, builder);
    }
    }
    throw new AssertionError(lval);
}
 
Example #20
Source File: CompleteExpression.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private boolean performCompleteFieldAccess(@NonNull JCFieldAccess jcFieldAccess,
                                           @NonNull ArrayList<SuggestItem> result) {
    int startPosition = jcFieldAccess.getStartPosition();
    int cursorOffset = mCursor - startPosition;
    int incompleteLength = jcFieldAccess.getIdentifier().length();
    String incomplete = jcFieldAccess.getIdentifier().toString();
    //simple hack, improve later
    if (incomplete.equals("<error>")) {
        incomplete = "";
    }
    if (DLog.DEBUG) DLog.d(TAG, "incomplete = " + incomplete);

    JCExpression expression = jcFieldAccess.getExpression();
    IClass type = new TypeResolver(mClassLoader, mAst, mCurrentType)
            .resolveType(expression, mCursor);
    if (type != null) {
        List<IMethod> methods = type.getMethods();
        for (IMethod method : methods) {
            if (method.getMethodName().startsWith(incomplete)) {
                setInfo(method, mEditor, incomplete);
                result.add(method);
            }
        }
        ArrayList<IField> fields = type.getFields();
        for (IField field : fields) {
            if (field.getFieldName().startsWith(incomplete)) {
                setInfo(field, mEditor, incomplete);
                result.add(field);
            }
        }

        return true;
    }
    return false;
}
 
Example #21
Source File: TreeFinder.java    From annotation-tools with MIT License 5 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitMemberSelect(MemberSelectTree node, Insertion ins) {
  dbug.debug("TypePositionFinder.visitMemberSelect(%s)%n", node);
  JCFieldAccess raw = (JCFieldAccess) node;
  return Pair.of(astRecord(node),
      raw.getEndPosition(tree.endPositions) - raw.name.length());
}
 
Example #22
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  This is used to filter out those select nodes that need to be adjusted
 *  when translating away lambda expressions - at the moment, this is the
 *  set of nodes that select `this' (qualified this)
 */
private boolean lambdaFieldAccessFilter(JCFieldAccess fAccess) {
    LambdaTranslationContext lambdaContext =
            context instanceof LambdaTranslationContext ?
                    (LambdaTranslationContext) context : null;
    return lambdaContext != null
            && !fAccess.sym.isStatic()
            && fAccess.name == names._this
            && (fAccess.sym.owner.kind == TYP)
            && !lambdaContext.translatedSymbols.get(CAPTURED_OUTER_THIS).isEmpty();
}
 
Example #23
Source File: HandleLog.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static void processAnnotation(LoggingFramework framework, AnnotationValues<?> annotation, JavacNode annotationNode, String loggerTopic) {
	deleteAnnotationIfNeccessary(annotationNode, framework.getAnnotationClass());

	JavacNode typeNode = annotationNode.up();
	switch (typeNode.getKind()) {
	case TYPE:
		String logFieldName = annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_ANY_FIELD_NAME);
		if (logFieldName == null) logFieldName = "log";
		
		boolean useStatic = !Boolean.FALSE.equals(annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_ANY_FIELD_IS_STATIC));
		
		if ((((JCClassDecl)typeNode.get()).mods.flags & Flags.INTERFACE) != 0) {
			annotationNode.addError("@Log is legal only on classes and enums.");
			return;
		}
		if (fieldExists(logFieldName, typeNode) != MemberExistsResult.NOT_EXISTS) {
			annotationNode.addWarning("Field '" + logFieldName + "' already exists.");
			return;
		}

		JCFieldAccess loggingType = selfType(typeNode);
		createField(framework, typeNode, loggingType, annotationNode.get(), logFieldName, useStatic, loggerTopic);
		break;
	default:
		annotationNode.addError("@Log is legal only on types.");
		break;
	}
}
 
Example #24
Source File: JavacImportList.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public String getFullyQualifiedNameForSimpleName(String unqualified) {
	for (JCTree def : defs) {
		if (!(def instanceof JCImport)) continue;
		JCTree qual = ((JCImport) def).qualid;
		if (!(qual instanceof JCFieldAccess)) continue;
		String simpleName = ((JCFieldAccess) qual).name.toString();
		if (simpleName.equals(unqualified)) {
			return LombokInternalAliasing.processAliases(qual.toString());
		}
	}
	
	return null;
}
 
Example #25
Source File: HandleExtensionMethod.java    From EasyMPermission with MIT License 5 votes vote down vote up
private String methodNameOf(final JCMethodInvocation methodCall) {
	if (methodCall.meth instanceof JCIdent) {
		return ((JCIdent) methodCall.meth).name.toString();
	} else {
		return ((JCFieldAccess) methodCall.meth).name.toString();
	}
}
 
Example #26
Source File: HandleExtensionMethod.java    From EasyMPermission with MIT License 5 votes vote down vote up
private JCExpression receiverOf(final JCMethodInvocation methodCall) {
	if (methodCall.meth instanceof JCIdent) {
		return annotationNode.getTreeMaker().Ident(annotationNode.toName("this"));
	} else {
		return ((JCFieldAccess) methodCall.meth).selected;
	}
}
 
Example #27
Source File: PathAndPackageVerifier.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String next() {
    Name name;
    if (next instanceof JCIdent) {
        name = ((JCIdent) next).name;
        next = null;
    } else {
        JCFieldAccess fa = (JCFieldAccess) next;
        name = fa.name;
        next = fa.selected;
    }
    return name.toString();
}
 
Example #28
Source File: HandleExtensionMethod.java    From EasyMPermission with MIT License 5 votes vote down vote up
public List<Extension> getExtensions(final JavacNode typeNode, final List<Object> extensionProviders) {
	List<Extension> extensions = new ArrayList<Extension>();
	for (Object extensionProvider : extensionProviders) {
		if (!(extensionProvider instanceof JCFieldAccess)) continue;
		JCFieldAccess provider = (JCFieldAccess) extensionProvider;
		if (!("class".equals(provider.name.toString()))) continue;
		Type providerType = CLASS.resolveMember(typeNode, provider.selected);
		if (providerType == null) continue;
		if ((providerType.tsym.flags() & (INTERFACE | ANNOTATION)) != 0) continue;
		
		extensions.add(getExtension(typeNode, (ClassType) providerType));
	}
	return extensions;
}
 
Example #29
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private static MethodSymbol getMemberSymbol(JCTree.JCExpression node) {
  switch (node.getKind()) {
    case IDENTIFIER:
      return (MethodSymbol) ((JCTree.JCIdent) node).sym.baseSymbol();
    case MEMBER_SELECT:
      return (MethodSymbol) ((JCTree.JCFieldAccess) node).sym;
    default:
      throw new AssertionError("Unexpected tree kind: " + node.getKind());
  }
}
 
Example #30
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitSelect(JCFieldAccess tree) {
	try {
		printExpr(tree.selected, TreeInfo.postfixPrec);
		print("." + tree.name);
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}