Examples of JCExpression


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

    protected JCExpression processCond(JCNewClass init, final CompilationUnitTree cut, Node n, JCBlock encBlock) {
        Symbol initSym = rs.getSymbol(init, cut, n);
        if (!init.args.isEmpty()) {
            for (JCExpression arg : init.args) {
                final Type argType = rs.getType(arg, cut, n);
                JCExpression newArg = processCond(arg, cut, n, encBlock);
                if (!newArg.equals(arg)) {
                    init.args = rs.injectBefore(arg, init.args, true, cast((JCMethodInvocation) newArg, argType));
                }
            }
        }
        final boolean accessible = isAccessible(initSym, initSym.enclClass(), cut, n);
View Full Code Here

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

                Symbol s = rs.getSymbol(fa, cut, n);
                reflect(s, cut, n, null, encBlock);

                JCMethodInvocation reflectedFieldSetter = getReflectedFieldSetter(fa, assignExp.rhs, cut, s.type.isPrimitive(), n, s.isStatic());
                if (s.getModifiers().contains(Modifier.FINAL)) {
                    final JCExpression fieldMods = getId(getFieldVar(fa.name) + ".modifiers");

                    final int varMods = (int) (s.flags_field) & ~java.lang.reflect.Modifier.FINAL;
                    final JCLiteral mod = tm.Literal(varMods);
                    final JCAssign constChange = tm.Assign(fieldMods, mod);
                    JCExpressionStatement constChangeStmt = tm.Exec(constChange);
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, false);

        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);
        final List<String> exceptions = new LinkedList<String>();
        exceptions.add("java.lang.ClassNotFoundException"); //for forName

        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));
            }
            exceptions.add("java.lang.NoSuchMethodException"); //thrown for both methods and constructors when calling getDeclared..
        } 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()));
            exceptions.add("java.lang.NoSuchFieldException");
        }

        Symbol fieldMethSym = rs.getSymbol(cut, n, null, accesseeVarName, null);
        if (fieldMethSym == null) {
            final JCExpression getMethField = tm.Select(classGetter, getterName);

            final JCVariableDecl refDecl = tm.VarDef(tm.Modifiers(0l), accesseeVarName, javaReflectMethField, getNull());

            final JCMethodInvocation mi = tm.Apply(com.sun.tools.javac.util.List.<JCExpression>nil(), getMethField, args);
            final JCStatement refDeclInit = tm.Exec(tm.Assign(tm.Ident(refDecl.name), mi)); //separate initialization from declaration to make it easier to catch exceptions
View Full Code Here

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

            }
            getterName = elementUtils.getName("get" + typeName); //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);
        addAnyReflectionAccessExceptions(n);

        return mi;
    }
View Full Code Here

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

            typeName = StringUtils.capitalize(s.name.toString());
        } else {
            typeName = StringUtils.EMPTY;
        }

        final JCExpression accessor;
        if (staticField) {
            accessor = tm.Literal(StringUtils.EMPTY);
        } else {
            accessor = fa.selected;
        }
View Full Code Here

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

     * @param reflectedAccess
     * @param t
     * @return parenthesis with the method casted to t
     */
    JCParens cast(JCMethodInvocation reflectedAccess, Type t) {
        final JCExpression castedAccess;
        final String methName = reflectedAccess.meth.toString();
        if (!t.isPrimitive() || methName.endsWith("invoke") || methName.endsWith("newInstance")) {
            castedAccess = tm.TypeCast(rs.getBoxedType(t), reflectedAccess);
        } else {
            castedAccess = reflectedAccess;
View Full Code Here

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

            }
            ProducedType sequenceType = specifierExpression.getTypeModel().getSupertype(typeFact().getIterableDeclaration());
            ProducedType expectedIterableType = typeFact().isNonemptyIterableType(sequenceType)
                    ? typeFact().getNonemptyIterableType(sequenceElementType)
                    : typeFact().getIterableType(sequenceElementType);
            JCExpression castElem = at(stmt).TypeCast(makeJavaType(sequenceElementType, CeylonTransformer.JT_NO_PRIMITIVES), elem_name.makeIdent());
            List<JCAnnotation> annots = makeJavaTypeAnnotations(variable.getDeclarationModel());

            // ceylon.language.Iterator<T> $V$iter$X = ITERABLE.getIterator();
            JCExpression containment = expressionGen().transformExpression(specifierExpression, BoxingStrategy.BOXED, expectedIterableType);
           
            // final U n = $elem$X;
            // or
            // final U n = $elem$X.getKey();
            JCExpression loopVarInit;
            ProducedType loopVarType;
            if (valueVariable == null) {
                loopVarType = sequenceElementType;
                loopVarInit = castElem;
            } else {
                loopVarType = variable.getDeclarationModel().getType();
                loopVarInit = at(stmt).Apply(null, makeSelect(castElem, Naming.getGetterName("key")), List.<JCExpression> nil());
            }
            JCVariableDecl itemOrKeyDecl = at(stmt).VarDef(make().Modifiers(FINAL, annots), loopVarName.asName(), makeJavaType(loopVarType),
                    boxUnboxIfNecessary(loopVarInit, true, loopVarType, CodegenUtil.getBoxingStrategy(variable.getDeclarationModel())));
            final SyntheticName iteratorVarName = loopVarName.suffixedBy(Suffix.$iterator$).alias();
            List<JCStatement> itemDecls = List.<JCStatement> of(itemOrKeyDecl);

            if (valueVariable != null) {
                // final V n = $elem$X.getElement();
                ProducedType valueVarType = valueVariable.getDeclarationModel().getType();
                JCExpression valueVarTypeExpr = makeJavaType(valueVarType);
                JCExpression valueVarInitExpr = at(stmt).Apply(null, makeSelect(castElem, Naming.getGetterName("item")), List.<JCExpression> nil());
                String valueVarName = valueVariable.getIdentifier().getText();
                JCVariableDecl valueDecl = at(stmt).VarDef(make().Modifiers(FINAL, annots), names().fromString(valueVarName), valueVarTypeExpr,
                        boxUnboxIfNecessary(valueVarInitExpr, true, valueVarType, CodegenUtil.getBoxingStrategy(valueVariable.getDeclarationModel())));
                itemDecls = itemDecls.append(valueDecl);
            }
View Full Code Here

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

        public JCStatement closeOuterSubstitution() {
            if (outerSubst == null) {
                throw new BugException("No outer substitution to close");
            }
            try (SavedPosition pos = noPosition()) {
                JCExpression alias = naming.makeName(value, Naming.NA_IDENT);
                outerSubst.close();
                outerSubst = null;
                JCExpression var = naming.makeName(value, Naming.NA_IDENT);
                return make().Exec(make().Assign(var, alias));
            }
        }
View Full Code Here

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

     */
    class Switch extends SwitchTransformation {
        public Switch() {
        }
        public JCStatement transformSwitch(Tree.SwitchStatement stmt) {
            JCExpression switchExpr = expressionGen().transformExpression(
                    stmt.getSwitchClause().getExpression(),
                    BoxingStrategy.UNBOXED,
                    getSwitchExpressionType(stmt));
            return transformSwitch(stmt, switchExpr);
        }
View Full Code Here

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

     */
    class IfNullElseSwitch extends SwitchTransformation {
       
        @Override
        public JCStatement transformSwitch(SwitchStatement stmt) {
            JCExpression selectorExpr = expressionGen().transformExpression(stmt.getSwitchClause().getExpression(), BoxingStrategy.BOXED, getSwitchExpressionType(stmt));
            Naming.SyntheticName selectorAlias = naming.alias("sel");
            JCVariableDecl selector = makeVar(selectorAlias, makeJavaType(getSwitchExpressionType(stmt)), selectorExpr);
            // Make a switch out of the non-null cases
            JCStatement switch_ = new Switch().transformSwitch(stmt,
                    expressionGen().applyErasureAndBoxing(selectorAlias.makeIdent(),
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.