Examples of JCExpression


Examples of com.sun.tools.javac.tree.JCTree.JCExpression

    implements EnhancedForLoopTreeMatcher, WhileLoopTreeMatcher {

  @Override
  public Description matchWhileLoop(WhileLoopTree tree, VisitorState state) {
    JCWhileLoop whileLoop = (JCWhileLoop) tree;
    JCExpression whileExpression = ((JCParens) whileLoop.getCondition()).getExpression();
    if (whileExpression instanceof MethodInvocationTree) {
      MethodInvocationTree methodInvocation = (MethodInvocationTree) whileExpression;
      if (methodSelect(isDescendantOfMethod("java.util.Iterator", "hasNext()")).matches(
          methodInvocation, state)) {
        IdentifierTree identifier = getIncrementedIdentifer(extractSingleStatement(whileLoop.body));
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

        prefix = "!";
        break;
      default:
        return Description.NO_MATCH;
    }
    JCExpression left = (JCExpression) tree.getLeftOperand();
    JCExpression right = (JCExpression) tree.getRightOperand();
   
    String leftMatch = matchNaN(left);
    if (leftMatch != null) {
      return describeMatch(tree, SuggestedFix.replace(tree,
          String.format("%s%s.isNaN(%s)", prefix, leftMatch, toString(right, state))));
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

        if (args.size() <= argNum) {
          return false;
        }
        ExpressionTree arg = args.get(argNum);

        JCExpression methodSelect = (JCExpression) t.getMethodSelect();
        if (methodSelect instanceof JCFieldAccess) {
          JCFieldAccess fieldAccess = (JCFieldAccess) methodSelect;
          return ASTHelpers.sameVariable(fieldAccess.getExpression(), arg);
        } else if (methodSelect instanceof JCIdent) {
          // A bare method call: "equals(foo)".  Receiver is implicitly "this".
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

      public boolean matches(ExpressionTree expr, VisitorState state) {
        if (!(expr instanceof JCFieldAccess)) {
          // TODO(user): throw IllegalArgumentException?
          return false;
        }
        JCExpression selected = ((JCFieldAccess) expr).getExpression();
        if (selected instanceof JCNewClass) {
          return true;
        }
        Symbol sym = ASTHelpers.getSymbol(selected);
        return sym instanceof VarSymbol;
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

   */
  public static Supplier<Type> genericTypeOf(final Supplier<ExpressionTree> expressionSupplier, final int n) {
    return new Supplier<Type>() {
      @Override
      public Type get(VisitorState state) {
        JCExpression jcExpression = (JCExpression) expressionSupplier.get(state);
        if (jcExpression.type.getTypeArguments().size() <= n) {
          return state.getSymtab().objectType;
        }
        return jcExpression.type.getTypeArguments().get(n);
      }
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

  public String getAnnotationValue(String an, JCModifiers modifiers) {
    for(JCAnnotation a : modifiers.getAnnotations()) {
      if(a.annotationType.toString().equals(an)) {
        if(a.args.size() != 1) throw new RuntimeException("Annotation value args!=1");
        JCExpression value = a.args.get(0);
        String val = "";
        try {
            val = value.getClass().getField("value").get(value).toString();
        }catch(Throwable e) {new RuntimeException(e);}
       
//        System.out.println("getAnnotationValue: " + val);
       
//        if(val.indexOf("(") <0) return "";
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

        return tree;
    }

    private Scope getScope(Tree stmt, final CompilationUnitTree cut, Scope validScope) {
        if (stmt instanceof JCVariableDecl) {
            JCExpression exp = ((JCVariableDecl) stmt).init;
            ((JCVariableDecl) stmt).init = null;
            TreePath path = TreePath.getPath(cut, stmt);
            validScope = trees.getScope(path);
            ((JCVariableDecl) stmt).init = exp;
        } else if (stmt instanceof JCEnhancedForLoop) {
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

            final JCFieldAccess fa = (JCFieldAccess) ifExp;
            final boolean accessible = isAccessible(fa, cut, n);
            if (!accessible) {
                Symbol s = rs.getSymbol(ifExp, cut, n);
                reflect(s, cut, n, null, encBlock);
                final JCExpression accessor;
                if (s.isStatic()) {
                    accessor = tm.Literal(StringUtils.EMPTY);
                } else {
                    accessor = fa.selected;
                }
                ifExp = getReflectedAccess(fa, cut, n, null, accessor);
                reflectionInjected = true;
            }
        } else if (ifExp instanceof JCMethodInvocation) {
            JCMethodInvocation mi = (JCMethodInvocation) ifExp;
            final MethodSymbol mSym = rs.getSymbol(mi, cut, n);
            if (!mi.args.isEmpty()) {
                for (JCExpression arg : mi.args) {
                    JCExpression newArg = processCond(arg, cut, n, encBlock);
                    if (!newArg.equals(arg)) {
                        mi.args = Resolver.injectBefore(arg, mi.args, true, newArg);
                    }
                }
            }
            Symbol accSym = rs.getInvokationTarget(mi, cut, n);
            final boolean accessible = isAccessible(mSym, accSym, cut, n);
            if (!accessible) {
                ifExp.type = mSym.getReturnType();
                reflect(mSym, cut, n, mi.args, encBlock);
                JCExpression accessor = rs.getInvokationExp(mi, cut, n);
                ifExp = getReflectedAccess(mSym, cut, accessor, mi.args, n);
                methodInjected = true;
            } else {
                ifExp.type = mSym.getReturnType();
            }
        } else if (ifExp instanceof JCNewClass) {
            JCNewClass init = (JCNewClass) ifExp;
            Symbol initSym = rs.getSymbol(ifExp, cut, n);
            if (!init.args.isEmpty()) {
                for (JCExpression arg : init.args) {
                    JCExpression newArg = processCond(arg, cut, n, encBlock);
                    if (!newArg.equals(arg)) {
                        init.args = rs.injectBefore(arg, init.args, true, newArg);
                    }
                }
            }
            final boolean accessible = isAccessible(initSym, initSym.enclClass(), cut, n);
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

        //getClass var
        MethodSymbol javaLangClassSym = (MethodSymbol) rs.getSymbol(elementUtils.getName(clazz), cs, cut, n);

        JCIdent javaLangClassId = tm.Ident(javaLangClassSym.getReturnType().tsym);
        //        Name classVarName = getClassVarName(className);
        JCExpression forNameAccessor = tm.Select(javaLangClassId, javaLangClassSym.name);
        JCExpression className = tm.Literal(typeId.toString());
        JCMethodInvocation classGetter = tm.Apply(com.sun.tools.javac.util.List.<JCExpression>nil(), forNameAccessor, com.sun.tools.javac.util.List.<JCExpression>of(className));
//        JCVariableDecl classDecl = tm.VarDef(tm.Modifiers(Flags.FINAL), classVarName, javaLangClassId, classGetter);

        JCExpression[] types = getTypes(params);
        final com.sun.tools.javac.util.List<JCExpression> args;

        final JCExpression javaReflectMethField;
        final Name getterName;
        if (symbol instanceof MethodSymbol) {
            if (symbol.isConstructor()) {
                getterName = elementUtils.getName("getDeclaredConstructor");
                javaReflectMethField = getIdAfterImporting("java.lang.reflect.Constructor");
                args = toList(types);
            } else {
                getterName = elementUtils.getName("getDeclaredMethod");
                javaReflectMethField = getIdAfterImporting("java.lang.reflect.Method");
                JCExpression mName = tm.Literal(symbol.name.toString());
                args = merge(Collections.singleton(mName), toList(types));
            }
        } else {
            getterName = elementUtils.getName("getDeclaredField");
            javaReflectMethField = getIdAfterImporting("java.lang.reflect.Field");
            args = com.sun.tools.javac.util.List.<JCExpression>of(tm.Literal(symbol.name.toString()));
        }

        Symbol fieldMethSym = rs.getSymbol(cut, n, null, accesseeVarName, null);
        if (fieldMethSym == null) {
            final JCExpression getMethField = tm.Select(classGetter, getterName);
            JCMethodInvocation mi = tm.Apply(com.sun.tools.javac.util.List.<JCExpression>nil(), getMethField, args);
            final JCVariableDecl refDecl = tm.VarDef(tm.Modifiers(Flags.FINAL), accesseeVarName, javaReflectMethField, mi);
            final JCMethodInvocation setAccInvoc = getMethodInvoc(accesseeVarName + ".setAccessible", true);
            JCStatement setAccessibleExec = tm.Exec(setAccInvoc); //should there be a dereflect / or just setinaccessible just after access? Would be better to set true only at access/set time and set-false after it. So reflect injects only one stmt while access/set 3
            JCStatement[] refStmts = new JCStatement[2];
View Full Code Here

Examples of com.sun.tools.javac.tree.JCTree.JCExpression

            fieldMethInitId = tm.Ident(getFieldVar(s.name));
            getterName = elementUtils.getName("get"); //TODO: for type safety replace with primitive concatenation
            args = com.sun.tools.javac.util.List.<JCExpression>of(accessor);
        }

        final JCExpression getMethField = tm.Select(fieldMethInitId, getterName);
        JCMethodInvocation mi = tm.Apply(com.sun.tools.javac.util.List.<JCExpression>nil(), getMethField, args);
        reflectionInjected = true; //call this method to actually use it!

        return mi;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.