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 Project: lua-for-android   Author: qtiuto   File: TransTypes.java    License: 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 #2
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: 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 #3
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: 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 #4
Source Project: lua-for-android   Author: qtiuto   File: Lower.java    License: 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 #5
Source Project: lua-for-android   Author: qtiuto   File: Lower.java    License: 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 #6
Source Project: lua-for-android   Author: qtiuto   File: Lower.java    License: 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 #7
Source Project: lua-for-android   Author: qtiuto   File: Annotate.java    License: 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 #8
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: 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 #9
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: 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 #10
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: 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 #11
Source Project: lua-for-android   Author: qtiuto   File: TypeEnter.java    License: 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 #12
Source Project: javaide   Author: tranleduy2000   File: CompleteExpression.java    License: 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 #13
Source Project: EasyMPermission   Author: mobmead   File: Javac.java    License: 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 #14
Source Project: EasyMPermission   Author: mobmead   File: PrettyCommentsPrinter.java    License: 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 #15
Source Project: EasyMPermission   Author: mobmead   File: HandleLog.java    License: 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 #16
Source Project: EasyMPermission   Author: mobmead   File: JavacHandlerUtil.java    License: 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 #17
Source Project: annotation-tools   Author: typetools   File: TreeFinder.java    License: 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 #18
Source Project: bazel   Author: bazelbuild   File: TreePruner.java    License: 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 #19
Source Project: bazel   Author: bazelbuild   File: TreePruner.java    License: 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 #20
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitTypeApply(JCTypeApply tree) {
    if (tree.type.hasTag(CLASS)) {
        List<JCExpression> args = tree.arguments;
        List<Type> forms = tree.type.tsym.type.getTypeArguments();

        Type incompatibleArg = firstIncompatibleTypeArg(tree.type);
        if (incompatibleArg != null) {
            for (JCTree arg : tree.arguments) {
                if (arg.type == incompatibleArg) {
                    log.error(arg, Errors.NotWithinBounds(incompatibleArg, forms.head));
                }
                forms = forms.tail;
             }
         }

        forms = tree.type.tsym.type.getTypeArguments();

        boolean is_java_lang_Class = tree.type.tsym.flatName() == names.java_lang_Class;

        // For matching pairs of actual argument types `a' and
        // formal type parameters with declared bound `b' ...
        while (args.nonEmpty() && forms.nonEmpty()) {
            validateTree(args.head,
                    !(isOuter && is_java_lang_Class),
                    false);
            args = args.tail;
            forms = forms.tail;
        }

        // Check that this type is either fully parameterized, or
        // not parameterized at all.
        if (tree.type.getEnclosingType().isRaw())
            log.error(tree.pos(), Errors.ImproperlyFormedTypeInnerRawParam);
        if (tree.clazz.hasTag(SELECT))
            visitSelectInternal((JCFieldAccess)tree.clazz);
    }
}
 
Example #21
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitSelect(JCFieldAccess tree) {
    if (tree.type.hasTag(CLASS)) {
        visitSelectInternal(tree);

        // Check that this type is either fully parameterized, or
        // not parameterized at all.
        if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty())
            log.error(tree.pos(), Errors.ImproperlyFormedTypeParamMissing);
    }
}
 
Example #22
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitSelectInternal(JCFieldAccess tree) {
    if (tree.type.tsym.isStatic() &&
        tree.selected.type.isParameterized()) {
        // The enclosing type is not a class, so we are
        // looking at a static member type.  However, the
        // qualifying expression is parameterized.
        log.error(tree.pos(), Errors.CantSelectStaticClassFromParamType);
    } else {
        // otherwise validate the rest of the expression
        tree.selected.accept(this);
    }
}
 
Example #23
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #24
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isCanonical(JCTree tree) {
    while (tree.hasTag(SELECT)) {
        JCFieldAccess s = (JCFieldAccess) tree;
        if (s.sym.owner.getQualifiedName() != TreeInfo.symbol(s.selected).getQualifiedName())
            return false;
        tree = s.selected;
    }
    return true;
}
 
Example #25
Source Project: lua-for-android   Author: qtiuto   File: Flow.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #26
Source Project: lua-for-android   Author: qtiuto   File: Flow.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #27
Source Project: lua-for-android   Author: qtiuto   File: Lower.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** If tree refers to a qualified this or super expression
 *  for anything but the current class, add the outer this
 *  stack as a free variable.
 */
public void visitSelect(JCFieldAccess tree) {
    if ((tree.name == names._this || tree.name == names._super) &&
        tree.selected.type.tsym != clazz &&
        outerThisStack.head != null)
        visitSymbol(outerThisStack.head);
    super.visitSelect(tree);
}
 
Example #28
Source Project: lua-for-android   Author: qtiuto   File: Lower.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Do we need an access method to reference symbol in other package?
 */
boolean needsProtectedAccess(Symbol sym, JCTree tree) {
    if ((sym.flags() & PROTECTED) == 0 ||
        sym.owner.owner == currentClass.owner || // fast special case
        sym.packge() == currentClass.packge())
        return false;
    if (!currentClass.isSubClass(sym.owner, types))
        return true;
    if ((sym.flags() & STATIC) != 0 ||
        !tree.hasTag(SELECT) ||
        TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
        return false;
    return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
}
 
Example #29
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generate an indy method call with given name, type and static bootstrap
 * arguments types
 */
private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
        List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
        Name methName) {
    int prevPos = make.pos;
    try {
        make.at(pos);
        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                syms.stringType,
                syms.methodTypeType).appendList(bsmStaticArgToTypes(staticArgs));

        Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
                bsmName, bsm_staticArgs, List.nil());

        DynamicMethodSymbol dynSym =
                new DynamicMethodSymbol(methName,
                                        syms.noSymbol,
                                        bsm.isStatic() ?
                                            ClassFile.REF_invokeStatic :
                                            ClassFile.REF_invokeVirtual,
                                        (MethodSymbol)bsm,
                                        indyType,
                                        staticArgs.toArray());

        JCFieldAccess qualifier = make.Select(make.QualIdent(site.tsym), bsmName);
        qualifier.sym = dynSym;
        qualifier.type = indyType.getReturnType();

        JCMethodInvocation proxyCall = make.Apply(List.nil(), qualifier, indyArgs);
        proxyCall.type = indyType.getReturnType();
        return proxyCall;
    } finally {
        make.at(prevPos);
    }
}
 
Example #30
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: 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();
}