當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeMaker.Exec方法代碼示例

本文整理匯總了Java中com.sun.tools.javac.tree.TreeMaker.Exec方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMaker.Exec方法的具體用法?Java TreeMaker.Exec怎麽用?Java TreeMaker.Exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.tools.javac.tree.TreeMaker的用法示例。


在下文中一共展示了TreeMaker.Exec方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

    if (isArray) {
        return super.createReadFromParcel(astHelper, rootElement, parcel, varName, true);
    }

    final TreeMaker treeMaker = astHelper.getTreeMaker();
    final JCTree.JCStatement booleanStatement = treeMaker.Exec(
            treeMaker.Assign(
                    treeMaker.Ident(astHelper.getName(varName)),
                    astHelper.getEquals(
                            treeMaker.Apply(
                                    List.<JCTree.JCExpression>nil(),
                                    treeMaker.Select(parcel, astHelper.getName("readByte")),
                                    List.<JCTree.JCExpression>nil()
                            ),
                            treeMaker.TypeCast(astHelper.getPrimitiveType(TypeKind.BYTE), treeMaker.Literal(1))
                    )
            )
    );
    return List.of(booleanStatement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:24,代碼來源:StatementCreatorBoolean.java

示例2: createWriteToParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createWriteToParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, JCTree.JCExpression flags, String varName, boolean isArray) {

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    if (!isArray) {
        final JCTree.JCStatement statement = treeMaker.Exec(
                treeMaker.Apply(
                        List.<JCTree.JCExpression>nil(),
                        treeMaker.Select(parcel, astHelper.getName("writeValue")),
                        List.of((JCTree.JCExpression) treeMaker.Ident(astHelper.getName(varName)))
                )
        );
        return List.of(statement);
    }

    return List.nil();
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:19,代碼來源:StatementCreatorObject.java

示例3: createWriteToParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createWriteToParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, JCTree.JCExpression flags, String varName, boolean isArray) {

    if (isArray) {
        return List.nil();
    }

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    final JCTree.JCExpression expression = treeMaker.Conditional(
            astHelper.getNotEquals(treeMaker.Ident(astHelper.getName(varName)), astHelper.getNull()),
            astHelper.getSimpleMethodCall(varName, "ordinal"),
            treeMaker.Literal(-1)
    );

    final JCTree.JCStatement statement = treeMaker.Exec(
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("writeInt")),
                    List.of(expression)
            )
    );

    return List.of(statement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:26,代碼來源:StatementCreatorEnum.java

示例4: createWriteToParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createWriteToParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, JCTree.JCExpression flags, String varName, boolean isArray) {

    if (isArray) {
        return super.createWriteToParcel(astHelper, rootElement, parcel, flags, varName, true);
    }

    final TreeMaker treeMaker = astHelper.getTreeMaker();
    final JCTree.JCExpression booleanConditional = treeMaker.Conditional(
            treeMaker.Ident(astHelper.getName(varName)),
            treeMaker.TypeCast(astHelper.getPrimitiveType(TypeKind.BYTE), treeMaker.Literal(1)),
            treeMaker.TypeCast(astHelper.getPrimitiveType(TypeKind.BYTE), treeMaker.Literal(0))
    );

    final JCTree.JCStatement statement =  treeMaker.Exec(
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("writeByte")),
                    List.of(booleanConditional)
            )
    );

    return List.of(statement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:25,代碼來源:StatementCreatorBoolean.java

示例5: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
    public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

        final TreeMaker treeMaker = astHelper.getTreeMaker();

        final Element element = astHelper.findFieldByName(rootElement, varName);
        if (element == null) {
            return List.nil();
        }

//        final JCTree.JCExpression type = astHelper.getTypeFromElement(element, isArray, false);
        final JCTree.JCExpression typeRaw = astHelper.getTypeFromElement(element, isArray, true);
        final JCTree.JCExpression classLoader = astHelper.getClassLoaderExpression(typeRaw);

        if (!isArray) {
            final JCTree.JCStatement statement = treeMaker.Exec(
                    treeMaker.Assign(
                            treeMaker.Ident(astHelper.getName(varName)),
                            treeMaker.TypeCast(
                                    typeRaw,
                                    treeMaker.Apply(
                                            List.<JCTree.JCExpression>nil(),
                                            treeMaker.Select(parcel, astHelper.getName("readValue")),
                                            List.of(classLoader)
                                    )
                            )
                    )
            );
            return List.of(statement);
        }



        return List.nil();
    }
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:36,代碼來源:StatementCreatorObject.java

示例6: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

    // parcel.createTypedArrayList(Type.CREATOR)

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    // here we have List<OUR_TYPE>
    final Element fieldElement = astHelper.findFieldByName(rootElement, varName);
    if (fieldElement == null) {
        return List.nil();
    }

    final JCTree.JCExpression typeOfElement = astHelper.getListTypeParameter((DeclaredType) fieldElement.asType());

    final JCTree.JCExpression creator = treeMaker.Select(typeOfElement, astHelper.getName("CREATOR"));

    final JCTree.JCStatement statement = treeMaker.Exec(
            treeMaker.Assign(
                    treeMaker.Ident(astHelper.getName(varName)),
                    treeMaker.Apply(
                            List.<JCTree.JCExpression>nil(),
                            treeMaker.Select(parcel, astHelper.getName("createTypedArrayList")),
                            List.of(creator)
                    )
            )
    );

    return List.of(statement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:31,代碼來源:StatementCreatorTypedList.java

示例7: createResultCalculation

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) {
	/* result = result * PRIME + (expr); */
	TreeMaker maker = typeNode.getTreeMaker();
	Name resultName = typeNode.toName(RESULT_NAME);
	JCExpression mult = maker.Binary(CTC_MUL, maker.Ident(resultName), maker.Ident(typeNode.toName(PRIME_NAME)));
	JCExpression add = maker.Binary(CTC_PLUS, mult, expr);
	return maker.Exec(maker.Assign(maker.Ident(resultName), add));
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:9,代碼來源:HandleEqualsAndHashCode.java

示例8: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

    // var = new ArrayList
    // parcel.readList(var, ClassLoader)

    final TreeMaker treeMaker = astHelper.getTreeMaker();
    final Element fieldElement = astHelper.findFieldByName(rootElement, varName);

    if (fieldElement == null) {
        return List.nil();
    }

    final JCTree.JCExpression type = astHelper.getListTypeParameter((DeclaredType) fieldElement.asType());

    final JCTree.JCExpression create = treeMaker.Assign(
            treeMaker.Ident(astHelper.getName(varName)),
            treeMaker.NewClass(
                    null,
                    null,
                    treeMaker.TypeApply(astHelper.getType("java.util", "ArrayList"), List.of(type)), // our ArrayList<TYPE>
                    List.<JCTree.JCExpression>nil(), // params
                    null
            )
    );

    final JCTree.JCExpression classLoader = astHelper.getClassLoaderExpression(type);

    final JCTree.JCStatement call = treeMaker.Exec(
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("readList")),
                    List.of(
                            treeMaker.Ident(astHelper.getName(varName)),
                            classLoader
                    )
            )
    );

    return List.of(
            treeMaker.Exec(create),
            call
    );
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:45,代碼來源:StatementCreatorList.java

示例9: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

    if (isArray) {
        return List.nil();
    }

    // int = read
    // value = int > -1 ? Value.values()[int] : null

    final JCTree.JCExpression enumTypeExpression = astHelper.getTypeFromElement(
            astHelper.findFieldByName(rootElement, varName),
            false,
            false
    );

    if (enumTypeExpression == null) {
        return List.nil();
    }

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    final String tmpEnumName = "_" + varName;
    final JCTree.JCExpression tmpEnumIdent = treeMaker.Ident(astHelper.getName(tmpEnumName));

    final JCTree.JCStatement enumVar = treeMaker.VarDef(
            astHelper.getModifiers(Modifier.FINAL),
            astHelper.getName(tmpEnumName),
            astHelper.getPrimitiveType(TypeKind.INT),
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("readInt")),
                    List.<JCTree.JCExpression>nil()
            )
    );

    final JCTree.JCExpression enumCond = treeMaker.Conditional(
            astHelper.getGreater(tmpEnumIdent, treeMaker.Literal(-1)),
            treeMaker.Indexed(
                    treeMaker.Apply(
                            List.<JCTree.JCExpression>nil(),
                            treeMaker.Select(enumTypeExpression, astHelper.getName("values")),
                            List.<JCTree.JCExpression>nil()
                    ),
                    tmpEnumIdent
            ),
            astHelper.getNull()
    );

    final JCTree.JCStatement enumStatement = treeMaker.Exec(
            treeMaker.Assign(
                    treeMaker.Ident(astHelper.getName(varName)), enumCond
            )
    );

    return List.of(enumVar, enumStatement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:58,代碼來源:StatementCreatorEnum.java

示例10: createWriteToParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createWriteToParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, JCTree.JCExpression flags, String varName, boolean isArray) {

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    final Name itemName = astHelper.getName(varName);
    final JCTree.JCExpression item = treeMaker.Ident(itemName);

    final JCTree.JCExpression textUtils = astHelper.getType("android.text", "TextUtils");

    if (!isArray) {
        final JCTree.JCStatement writeToParcel = treeMaker.Exec(
                treeMaker.Apply(
                        List.<JCTree.JCExpression>nil(),
                        treeMaker.Select(textUtils, astHelper.getName("writeToParcel")),
                        List.of(
                                item, parcel, flags
                        )
                )
        );
        return List.of(writeToParcel);
    }

    // if csa == null -> write -1
    // else iterate and write

    final JCTree.JCStatement ifNull = treeMaker.Exec(
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("writeInt")),
                    List.of((JCTree.JCExpression) treeMaker.Literal(-1))
            )
    );

    final Name loopVariableName = astHelper.getName("_cs");

    final JCTree.JCVariableDecl loopVar = treeMaker.VarDef(
            astHelper.getModifiers(),
            loopVariableName,
            astHelper.getType("java.lang", "CharSequence"),
            null
    );

    final JCTree.JCStatement writeLength = treeMaker.Exec(
            treeMaker.Apply(
                    List.<JCTree.JCExpression>nil(),
                    treeMaker.Select(parcel, astHelper.getName("writeInt")),
                    List.of(
                            (JCTree.JCExpression) treeMaker.Select(item, astHelper.getName("length"))
                    )
            )
    );

    final JCTree.JCStatement forLoop = treeMaker.ForeachLoop(
            loopVar,
            item,
            treeMaker.Exec(
                    treeMaker.Apply(
                            List.<JCTree.JCExpression>nil(),
                            treeMaker.Select(textUtils, astHelper.getName("writeToParcel")),
                            List.of(
                                    treeMaker.Ident(loopVariableName), parcel, flags
                            )
                    )
            )
    );

    final JCTree.JCStatement ifNotNull = treeMaker.Block(
            0,
            List.of(writeLength, forLoop)
    );

    final JCTree.JCStatement ifBlock = treeMaker.If(
            astHelper.getEquals(item, astHelper.getNull()),
            ifNull,
            ifNotNull
    );

    return List.of(ifBlock);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:81,代碼來源:StatementCreatorCharSequence.java

示例11: callSet

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCStatement callSet(JavacNode source, JCExpression receiver, JCExpression value) {
	TreeMaker maker = source.getTreeMaker();
	return maker.Exec(maker.Apply(NIL_EXPRESSION, maker.Select(receiver, source.toName("set")), List.<JCExpression>of(value)));
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:5,代碼來源:HandleGetter.java

示例12: createSetReferencedObjectMethod

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCMethodDecl createSetReferencedObjectMethod(JavacNode fieldNode, TreeMaker maker, JCVariableDecl field, JCIdent baseType, boolean isUnique) {
	JCExpression refVariableType = getFieldType(fieldNode, FieldAccess.ALWAYS_FIELD);
	if (isUnique) {
		refVariableType = maker.TypeApply(
				chainDots(fieldNode, java.util.List.class),
				List.<JCExpression>of(refVariableType)
		);
	}
	
	JCStatement statement = null;
	if (isUnique) {
		statement = maker.Exec(
				maker.Assign(
						maker.Select(
								maker.Ident(fieldNode.toName("item")),
								field.name
						),
						maker.Apply(
								List.<JCExpression>nil(),
								maker.Select(
										maker.Ident(fieldNode.toName("this")),
										fieldNode.toName("firstOrDefault")
								),
								List.<JCExpression>of(
										maker.Ident(fieldNode.toName("ref"))
								)
						)
				)
		);
	} else {
		statement = maker.Exec(
				maker.Assign(
						maker.Select(
							maker.Ident(fieldNode.toName("item")),
							field.name
						),
						maker.Ident(fieldNode.toName("ref"))
				)
		);
	}
	return maker.MethodDef(
			maker.Modifiers(Flags.PUBLIC, List.of(maker.Annotation(chainDots(fieldNode, Override.class), List.<JCExpression>nil()))),
			fieldNode.toName("setReferencedObject"),
			maker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID"))),
			List.<JCTypeParameter>nil(),
			List.<JCVariableDecl>of(
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("item"),
							baseType,
							null
					),
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("ref"),
							refVariableType,
							null
					)
			),
			List.<JCExpression>nil(),
			maker.Block(
					0,
					List.<JCStatement>of(
							statement
					)
			),
			null
	);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:70,代碼來源:HandleRelations.java

示例13: SuperCall

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
/** Generate call to superclass constructor. This is:
 *
 *    super(id_0, ..., id_n)
 *
 * or, if based == true
 *
 *    id_0.super(id_1,...,id_n)
 *
 *  where id_0, ..., id_n are the names of the given parameters.
 *
 *  @param make    The tree factory
 *  @param params  The parameters that need to be passed to super
 *  @param typarams  The type parameters that need to be passed to super
 *  @param based   Is first parameter a this$n?
 */
JCExpressionStatement SuperCall(TreeMaker make,
               List<Type> typarams,
               List<JCVariableDecl> params,
               boolean based) {
    JCExpression meth;
    if (based) {
        meth = make.Select(make.Ident(params.head), names._super);
        params = params.tail;
    } else {
        meth = make.Ident(names._super);
    }
    List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
    return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
}
 
開發者ID:sebastianoe,項目名稱:s4j,代碼行數:30,代碼來源:MemberEnter.java


注:本文中的com.sun.tools.javac.tree.TreeMaker.Exec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。