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


Java TreeMaker.MethodDef方法代碼示例

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


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

示例1: DefaultConstructor

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
/** Generate default constructor for given class. For classes different
 *  from java.lang.Object, this is:
 *
 *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
 *      super(x_0, ..., x_n)
 *    }
 *
 *  or, if based == true:
 *
 *    c(argtype_0 x_0, ..., argtype_n x_n) throws thrown {
 *      x_0.super(x_1, ..., x_n)
 *    }
 *
 *  @param make     The tree factory.
 *  @param c        The class owning the default constructor.
 *  @param argtypes The parameter types of the constructor.
 *  @param thrown   The thrown exceptions of the constructor.
 *  @param based    Is first parameter a this$n?
 */
JCTree DefaultConstructor(TreeMaker make,
                        ClassSymbol c,
                        List<Type> typarams,
                        List<Type> argtypes,
                        List<Type> thrown,
                        long flags,
                        boolean based) {
    List<JCVariableDecl> params = make.Params(argtypes, syms.noSymbol);
    List<JCStatement> stats = List.nil();
    if (c.type != syms.objectType)
        stats = stats.prepend(SuperCall(make, typarams, params, based));
    if ((c.flags() & ENUM) != 0 &&
        (types.supertype(c.type).tsym == syms.enumSym ||
         target.compilerBootstrap(c))) {
        // constructors of true enums are private
        flags = (flags & ~AccessFlags) | PRIVATE | GENERATEDCONSTR;
    } else
        flags |= (c.flags() & AccessFlags) | GENERATEDCONSTR;
    if (c.name.isEmpty()) flags |= ANONCONSTR;
    JCTree result = make.MethodDef(
        make.Modifiers(flags),
        names.init,
        null,
        make.TypeParams(typarams),
        params,
        make.Types(thrown),
        make.Block(0, stats),
        null);
    return result;
}
 
開發者ID:sebastianoe,項目名稱:s4j,代碼行數:50,代碼來源:MemberEnter.java

示例2: createGetReferencedKeyMethod

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCMethodDecl createGetReferencedKeyMethod(JavacNode fieldNode, TreeMaker maker, String relatedFieldName, boolean isOneToOne, JCIdent baseType, JCExpression referenceType) {
	return maker.MethodDef(
			maker.Modifiers(Flags.PUBLIC, List.of(maker.Annotation(chainDots(fieldNode, Override.class), List.<JCExpression>nil()))),
			fieldNode.toName("getReferencedKey"),
			chainDots(fieldNode, Long.class),
			List.<JCTypeParameter>nil(),
			List.<JCVariableDecl>of(
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("item"),
							(isOneToOne ? baseType : referenceType),
							null
					)
			),
			List.<JCExpression>nil(),
			maker.Block(
					0,
					List.<JCStatement>of(
							maker.Return(
									maker.Apply(
											List.<JCExpression>nil(),
											maker.Select(
												maker.Ident(fieldNode.toName("item")),
												fieldNode.toName("get" + toProperCase(relatedFieldName))
											),
											List.<JCExpression>nil()
									)
							)
					)
			),
			null
	);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:34,代碼來源:HandleRelations.java

示例3: overrideMethod

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public GMethod overrideMethod(Symbol.MethodSymbol methodSymbol, boolean addSupperCall) {
    String memberSignature = GClassMember.getMemberSignature(methodSymbol);
    GMethod method = (GMethod) getMember(memberSignature);
    if (method != null) {
        return method;
    }

    if (getElement() != null) {
        for (Element member : getElement().getEnclosedElements()) {
            String signature = GClassMember.getMemberSignature(member);
            if (member instanceof Symbol.MethodSymbol && signature.equals(memberSignature)) {
                return GMethod.getGMethod(getEnvironment(), member);
            }
        }
    }

    TreeMaker maker = getEnvironment().getMaker().forToplevel(getGUnit().getCompilationUnit());
    JavacElements utils = getEnvironment().getUtils();

    String typeName = methodSymbol.getReturnType().asElement().getQualifiedName().toString();
    JCExpression returnType = getEnvironment().createParser(typeName).parseType();
    List<JCVariableDecl> params = List.nil();
    int paramNum = 0;
    for (Type paramType : methodSymbol.asType().getParameterTypes()) {
        Name paramName = utils.getName("param" + paramNum++);
        JCExpression returnTypeName = getEnvironment().typeToTree(paramType);
        params = params.append(maker.at(getTree().getStartPosition()).VarDef(maker.Modifiers(Flags.PARAMETER), paramName, returnTypeName, null));
    }
    long modifiers = methodSymbol.flags() & (Flags.PUBLIC | Flags.PRIVATE | Flags.PROTECTED);
    JCTree.JCAnnotation overrideAnnotation = maker.Annotation(maker.Ident(utils.getName("Override")), List.<JCExpression>nil());

    JCMethodDecl methodDecl = maker.MethodDef(
            maker.Modifiers(modifiers, List.of(overrideAnnotation)),
            utils.getName(methodSymbol.getSimpleName()),
            returnType,
            List.<JCTypeParameter>nil(),
            params,
            List.<JCExpression>nil(),
            maker.Block(0, List.<JCStatement>nil()),
            null);

    method = new GMethod(this, methodDecl, null);
    method.setName(methodSymbol.getSimpleName().toString());
    method.setMemberSignature(memberSignature);

    if (addSupperCall) {
        method.appendSuperCall();
    }

    putMember(method);
    classDecl.defs = classDecl.defs.append(methodDecl);

    return method;
}
 
開發者ID:ixkor,項目名稱:genaroid,代碼行數:55,代碼來源:GClass.java

示例4: createSetRelatedIdMethod

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCMethodDecl createSetRelatedIdMethod(JavacNode fieldNode, TreeMaker maker, String relatedFieldName, boolean isOneToOne, JCIdent baseType, JCExpression referenceType) {
	return maker.MethodDef(
			maker.Modifiers(Flags.PUBLIC, List.of(maker.Annotation(chainDots(fieldNode, Override.class), List.<JCExpression>nil()))),
			fieldNode.toName("setRelatedId"),
			maker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID"))),
			List.<JCTypeParameter>nil(),
			List.<JCVariableDecl>of(
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("item"),
							(isOneToOne ? baseType : referenceType),
							null
					),
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("id"),
							chainDots(fieldNode, Long.class),
							null
					)
			),
			List.<JCExpression>nil(),
			maker.Block(
					0,
					List.<JCStatement>of(
							maker.Exec(
									maker.Apply(
											List.<JCExpression>nil(),
											maker.Select(
												maker.Ident(fieldNode.toName("item")),
												fieldNode.toName("set" + toProperCase(relatedFieldName))
											),
											List.<JCExpression>of(
													maker.Ident(fieldNode.toName("id"))
											)
									)
							)
					)
			),
			null
	);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:42,代碼來源:HandleRelations.java

示例5: 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

示例6: visit

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public void visit(MethodWrapper w) {
    MethodWrapper oldCurrentMethod = currentMethod;
    currentMethod = w;
    try {
        TreeMaker maker = builder.getTreeMaker();
    
        JCBlock body = generate(w.getBody(), JCBlock.class);
        JCMethodDecl meth = (JCMethodDecl) w.getTarget();
        if (meth != null) {
            // Shortcut, just replace the body
            meth.body = body;
            result = meth;
            return;
        }
    
        ListBuffer<JCVariableDecl> paramList = new ListBuffer<JCVariableDecl>();
        for (DeclareVariableWrapper p : w.getParameters()) {
            paramList.append(generate(p, JCVariableDecl.class));
        }
    
        ListBuffer<JCAnnotation> anns = new ListBuffer<JCAnnotation>();
        if (w.isOverride()) {
            anns.append(maker.Annotation(
                    builder.nameToExpression(OVERRIDE_CLASS_NAME),
                    List.<JCExpression> nil()));
        }
        long numericFlags = toNumericFlags(w.getFlags());
        JCModifiers mods = maker.Modifiers(numericFlags, anns.toList());
    
        List<JCExpression> throwDecls = generate(w.getThrows(),
                JCExpression.class);
    
        Name methodName = builder.getName(w.getName());
        result = maker.MethodDef( //
                mods, //
                methodName, //
                generate(w.getReturnType()), //
                List.<JCTypeParameter> nil(), // no type parameters
                paramList.toList(), // parameters
                throwDecls, //
                body, // method body
                null // no default value
                );
    } finally {
        currentMethod = oldCurrentMethod;
    }
}
 
開發者ID:provegard,項目名稱:yield4j,代碼行數:49,代碼來源:JavacCodeGenerator.java


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