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


Java TreeMaker.Ident方法代碼示例

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


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

示例1: readField

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public static JCTree.JCExpression readField(JavacNode fieldNode, JCTree.JCExpression receiver) {
    TreeMaker maker = fieldNode.getTreeMaker();

    JCTree.JCVariableDecl fieldDecl = (JCTree.JCVariableDecl) fieldNode.get();

    if (receiver == null) {
        if ((fieldDecl.mods.flags & Flags.STATIC) == 0) {
            receiver = maker.Ident(fieldNode.toName("this"));
        } else {
            JavacNode containerNode = fieldNode.up();
            if (containerNode != null && containerNode.get() instanceof JCTree.JCClassDecl) {
                JCTree.JCClassDecl container = (JCTree.JCClassDecl) fieldNode.up().get();
                receiver = maker.Ident(container.name);
            }
        }
    }

    return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name);
}
 
開發者ID:aalmiray,項目名稱:griffon2,代碼行數:20,代碼來源:HandlerUtils.java

示例2: cloneSelfType

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public static JCExpression cloneSelfType(JavacNode field) {
	JavacNode typeNode = field;
	TreeMaker maker = field.getTreeMaker();
	while (typeNode != null && typeNode.getKind() != Kind.TYPE) typeNode = typeNode.up();
	if (typeNode != null && typeNode.get() instanceof JCClassDecl) {
		JCClassDecl type = (JCClassDecl) typeNode.get();
		ListBuffer<JCExpression> typeArgs = ListBuffer.lb();
		if (!type.typarams.isEmpty()) {
			for (JCTypeParameter tp : type.typarams) {
				typeArgs.append(maker.Ident(tp.name));
			}
			return maker.TypeApply(maker.Ident(type.name), typeArgs.toList());
		} else {
			return maker.Ident(type.name);
		}
	} else {
		return null;
	}
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:20,代碼來源:JavacHandlerUtil.java

示例3: createTypeReference

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCExpression createTypeReference(JavacNode type) {
	java.util.List<String> list = new ArrayList<String>();
	list.add(type.getName());
	JavacNode tNode = type.up();
	while (tNode != null && tNode.getKind() == Kind.TYPE) {
		list.add(tNode.getName());
		tNode = tNode.up();
	}
	Collections.reverse(list);
	
	TreeMaker maker = type.getTreeMaker();
	JCExpression chain = maker.Ident(type.toName(list.get(0)));
	
	for (int i = 1; i < list.size(); i++) {
		chain = maker.Select(chain, type.toName(list.get(i)));
	}
	
	return chain;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:20,代碼來源:HandleEqualsAndHashCode.java

示例4: buildExceptionClassExpression

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@NotNull
public static JCTree.JCExpression buildExceptionClassExpression(@NotNull String exceptionClass,
                                                                @NotNull TreeMaker factory,
                                                                @NotNull Names symbolsTable)
{
    String[] parts = exceptionClass.split("\\.");
    JCTree.JCIdent identifier = factory.Ident(symbolsTable.fromString(parts[0]));
    JCTree.JCFieldAccess selector = null;
    for (int i = 1; i < parts.length; i++) {
        selector = factory.Select(selector == null ? identifier : selector, symbolsTable.fromString(parts[i]));
    }
    return selector == null ? identifier : selector;
}
 
開發者ID:denis-zhdanov,項目名稱:traute,代碼行數:14,代碼來源:InstrumentationUtil.java

示例5: memberAccess

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  JCExpression expr = make.Ident( node.getName( components[0] ) );
  for( int i = 1; i < components.length; i++ )
  {
    expr = make.Select( expr, node.getName( components[i] ) );
  }
  return expr;
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:10,代碼來源:ExtensionTransformer.java

示例6: memberAccess

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCTree.JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  JCTree.JCExpression expr = make.Ident( node.getName( components[0] ) );
  for( int i = 1; i < components.length; i++ )
  {
    expr = make.Select( expr, node.getName( components[i] ) );
  }
  return expr;
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:10,代碼來源:BootstrapInserter.java

示例7: buildStatements

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
static Statements buildStatements(ASTHelper astHelper, ParcelableData data) {

        final StatementCreatorFactory factory = new StatementCreatorFactory();
        final TreeMaker treeMaker = astHelper.getTreeMaker();

        final JCTree.JCExpression source    = treeMaker.Ident(astHelper.getName(READ_PARCEL_VAR_NAME));

        final JCTree.JCExpression dest      = treeMaker.Ident(astHelper.getName(WRITE_PARCEL_VAR_NAME));
        final JCTree.JCExpression flags     = treeMaker.Ident(astHelper.getName(WRITE_FLAGS_VAR_NAME));

        List<JCTree.JCStatement> read = List.nil();
        List<JCTree.JCStatement> write = List.nil();

        boolean isArray;
        ParcelableType type;

        for (ParcelableItem item: data.items) {

            isArray = false;
            type = item.type;

            if (type == ParcelableType.ARRAY) {
                isArray = true;
                type = ((ParcelableItemArray)item).arrayType;
            }

            final StatementCreator creator = factory.get(type);
            read = read.appendList(creator.createReadFromParcel(astHelper, data.element, source, item.name, isArray));
            write = write.appendList(creator.createWriteToParcel(astHelper, data.element, dest, flags, item.name, isArray));
        }

        return new Statements(read, write);
    }
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:34,代碼來源:ParcelableTreeModifier.java

示例8: createJavaLangObject

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public static JCExpression createJavaLangObject(JavacAST ast) {
	TreeMaker maker = ast.getTreeMaker();
	JCExpression out = maker.Ident(ast.toName("java"));
	out = maker.Select(out, ast.toName("lang"));
	out = maker.Select(out, ast.toName("Object"));
	return out;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:8,代碼來源:JavacResolution.java

示例9: createFieldAccessor

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
static JCExpression createFieldAccessor(TreeMaker maker, JavacNode field, FieldAccess fieldAccess, JCExpression receiver) {
	boolean lookForGetter = lookForGetter(field, fieldAccess);
	
	GetterMethod getter = lookForGetter ? findGetter(field) : null;
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	
	if (getter == null) {
		if (receiver == null) {
			if ((fieldDecl.mods.flags & Flags.STATIC) == 0) {
				receiver = maker.Ident(field.toName("this"));
			} else {
				JavacNode containerNode = field.up();
				if (containerNode != null && containerNode.get() instanceof JCClassDecl) {
					JCClassDecl container = (JCClassDecl) field.up().get();
					receiver = maker.Ident(container.name);
				}
			}
		}
		
		return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name);
	}
	
	if (receiver == null) receiver = maker.Ident(field.toName("this"));
	JCMethodInvocation call = maker.Apply(List.<JCExpression>nil(),
			maker.Select(receiver, getter.name), List.<JCExpression>nil());
	return call;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:28,代碼來源:JavacHandlerUtil.java

示例10: createNewInstance

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public JCNewClass createNewInstance(String className, List<JCExpression> params) {
    TreeMaker maker = getEnvironment().getMaker();
    JavacElements utils = getEnvironment().getUtils();
    JCIdent ident = maker.Ident(utils.getName(className));
    return maker.NewClass(null, null, ident, params, getTree());
}
 
開發者ID:ixkor,項目名稱:genaroid,代碼行數:7,代碼來源:GClass.java

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

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

示例13: cloneType0

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCExpression cloneType0(TreeMaker maker, JCTree in) {
	if (in == null) return null;
	
	if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
	
	if (in instanceof JCIdent) {
		return maker.Ident(((JCIdent) in).name);
	}
	
	if (in instanceof JCFieldAccess) {
		JCFieldAccess fa = (JCFieldAccess) in;
		return maker.Select(cloneType0(maker, fa.selected), fa.name);
	}
	
	if (in instanceof JCArrayTypeTree) {
		JCArrayTypeTree att = (JCArrayTypeTree) in;
		return maker.TypeArray(cloneType0(maker, att.elemtype));
	}
	
	if (in instanceof JCTypeApply) {
		JCTypeApply ta = (JCTypeApply) in;
		ListBuffer<JCExpression> lb = ListBuffer.lb();
		for (JCExpression typeArg : ta.arguments) {
			lb.append(cloneType0(maker, typeArg));
		}
		return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
	}
	
	if (in instanceof JCWildcard) {
		JCWildcard w = (JCWildcard) in;
		JCExpression newInner = cloneType0(maker, w.inner);
		TypeBoundKind newKind;
		switch (w.getKind()) {
		case SUPER_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.SUPER);
			break;
		case EXTENDS_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
			break;
		default:
		case UNBOUNDED_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
			break;
		}
		return maker.Wildcard(newKind, newInner);
	}
	
	// This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
	return (JCExpression) in;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:51,代碼來源:JavacHandlerUtil.java

示例14: createField

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCVariableDecl createField(Object anno, JavacNode fieldNode) {
	TreeMaker maker = fieldNode.getTreeMaker();
	JCVariableDecl field = (JCVariableDecl) fieldNode.get();
	
	String relatedFieldName = null;
	boolean isOneToOne = false;
	boolean isUnique = false;

	Name baseTypeName = ((JCClassDecl) fieldNode.up().get()).name;
	JCIdent baseType = maker.Ident(baseTypeName);		
	JCExpression referenceType = getFieldType(fieldNode, FieldAccess.ALWAYS_FIELD);
	
	if (anno instanceof OneToOne) {
		isOneToOne = true;
		relatedFieldName = ((OneToOne) anno).field();
	} else {
		relatedFieldName = ((OneToMany) anno).field();
		isUnique = ((OneToMany) anno).unique();

		if (referenceType instanceof JCTypeApply) {
			referenceType = ((JCTypeApply) referenceType).arguments.get(0);
		}
	}
	
	JCClassDecl anonClass = maker.AnonymousClassDef(
			maker.Modifiers(0),
			List.<JCTree>of(
					createGetReferencedKeyMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType),
					createSetReferencedObjectMethod(fieldNode, maker, field, baseType, isUnique),
					createSetRelatedIdMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType)
			)
	);
	
	JCVariableDecl var = maker.VarDef(
			maker.Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL),
			fieldNode.toName(toUpperCase(field.name.toString())),
			maker.TypeApply(
					(isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
					List.<JCExpression>of(baseType, referenceType)
			),
			maker.NewClass(
					null,
					List.<JCExpression>nil(),
					maker.TypeApply(
							(isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
							List.<JCExpression>of(baseType, referenceType)
					),
					List.<JCExpression>nil(),
					anonClass
			)
	);
	
	return var;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:55,代碼來源:HandleRelations.java

示例15: 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.Ident方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。