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


Java FieldAccess類代碼示例

本文整理匯總了Java中lombok.javac.handlers.JavacHandlerUtil.FieldAccess的典型用法代碼示例。如果您正苦於以下問題:Java FieldAccess類的具體用法?Java FieldAccess怎麽用?Java FieldAccess使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: handle

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
    deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
    EqualsAndHashCode ann = annotation.getInstance();
    List<String> excludes = List.from(ann.exclude());
    List<String> includes = List.from(ann.of());
    JavacNode typeNode = annotationNode.up();
    
    checkForBogusFieldNames(typeNode, annotation);
    
    Boolean callSuper = ann.callSuper();
    if (!annotation.isExplicit("callSuper")) callSuper = null;
    if (!annotation.isExplicit("exclude")) excludes = null;
    if (!annotation.isExplicit("of")) includes = null;
    
    if (excludes != null && includes != null) {
        excludes = null;
        annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
    }
    
    FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
    
    generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:24,代碼來源:HandleEqualsAndHashCode.java

示例2: handle

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
    handleFlagUsage(annotationNode, ConfigurationKeys.EQUALS_AND_HASH_CODE_FLAG_USAGE, "@EqualsAndHashCode");
    
    deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
    EqualsAndHashCode ann = annotation.getInstance();
    List<String> excludes = List.from(ann.exclude());
    List<String> includes = List.from(ann.of());
    JavacNode typeNode = annotationNode.up();
    List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@EqualsAndHashCode(onParam=", annotationNode);
    checkForBogusFieldNames(typeNode, annotation);
    
    Boolean callSuper = ann.callSuper();
    if (!annotation.isExplicit("callSuper")) callSuper = null;
    if (!annotation.isExplicit("exclude")) excludes = null;
    if (!annotation.isExplicit("of")) includes = null;
    
    if (excludes != null && includes != null) {
        excludes = null;
        annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
    }
    
    Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS);
    boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
    FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
    
    generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess, onParam);
}
 
開發者ID:git03394538,項目名稱:lombok-ianchiu,代碼行數:28,代碼來源:HandleEqualsAndHashCode.java

示例3: generateEqualsAndHashCodeForType

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public void generateEqualsAndHashCodeForType(JavacNode typeNode, JavacNode source) {
    if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
        //The annotation will make it happen, so we can skip it.
        return;
    }
    
    generateMethods(typeNode, source, null, null, null, false, FieldAccess.GETTER, List.<JCAnnotation>nil());
}
 
開發者ID:git03394538,項目名稱:lombok-ianchiu,代碼行數:9,代碼來源:HandleEqualsAndHashCode.java

示例4: createSimpleGetterBody

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
private List<JCStatement> createSimpleGetterBody(TreeMaker treeMaker, JavacNode field) {
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);

    JCStatement returnExpression = null;
    
    String varTypeString = fieldDecl.vartype.toString();
    boolean isMutable = false;
    boolean isTypeCastNeeded = false;
    if (Timestamp.class.getSimpleName().equals(varTypeString) || Timestamp.class.getName().equals(varTypeString)) {
        isMutable = true;
        isTypeCastNeeded = true;
    } else if (varTypeString.endsWith("[]")) {
        isMutable = true;
    }
    
    if (isMutable) {
        JCExpression nullCheck = treeMaker.Binary(CTC_EQUAL, fieldRef, treeMaker.Literal(CTC_BOT, null));
        JCExpression callClone = treeMaker.Apply(List.<JCExpression>nil(), treeMaker.Select(fieldRef, field.toName("clone")), List.<JCExpression>nil());					
        if (isTypeCastNeeded) {
            callClone = treeMaker.TypeCast(
                    fieldDecl.vartype,
                    callClone
            );
        }
        
        JCConditional conditional = treeMaker.Conditional(
                nullCheck, 
                treeMaker.Literal(CTC_BOT, null), 
                callClone
        );
        
        returnExpression = treeMaker.Return(conditional);
    } else {
        returnExpression = treeMaker.Return(fieldRef);
    }
    
    return List.<JCStatement>of(returnExpression);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:40,代碼來源:HandleGetter.java

示例5: generateEqualsAndHashCodeForType

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public void generateEqualsAndHashCodeForType(JavacNode typeNode, JavacNode source) {
    if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
        //The annotation will make it happen, so we can skip it.
        return;
    }
    
    generateMethods(typeNode, source, null, null, null, false, FieldAccess.GETTER);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:9,代碼來源:HandleEqualsAndHashCode.java

示例6: createSimpleGetterBody

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public List<JCStatement> createSimpleGetterBody(JavacTreeMaker treeMaker, JavacNode field) {
    return List.<JCStatement>of(treeMaker.Return(createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD)));
}
 
開發者ID:git03394538,項目名稱:lombok-ianchiu,代碼行數:4,代碼來源:HandleGetter.java

示例7: createSetter

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public static JCMethodDecl createSetter(long access, JavacNode field, JavacTreeMaker treeMaker, String setterName, boolean shouldReturnThis, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
    if (setterName == null) return null;
    
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    
    JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);
    JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(fieldDecl.name));
    
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
    
    Name methodName = field.toName(setterName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
    
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
    
    if (nonNulls.isEmpty()) {
        statements.append(treeMaker.Exec(assign));
    } else {
        JCStatement nullCheck = generateNullCheck(treeMaker, field, source);
        if (nullCheck != null) statements.append(nullCheck);
        statements.append(treeMaker.Exec(assign));
    }
    
    JCExpression methodType = null;
    if (shouldReturnThis) {
        methodType = cloneSelfType(field);
    }
    
    if (methodType == null) {
        //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
        methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID));
        shouldReturnThis = false;
    }
    
    if (shouldReturnThis) {
        JCReturn returnStatement = treeMaker.Return(treeMaker.Ident(field.toName("this")));
        statements.append(returnStatement);
    }
    
    JCBlock methodBody = treeMaker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    
    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    
    JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
    copyJavadoc(field, decl, CopyJavadoc.SETTER);
    return decl;
}
 
開發者ID:git03394538,項目名稱:lombok-ianchiu,代碼行數:59,代碼來源:HandleSetter.java

示例8: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam, boolean makeAbstract) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;
    
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    
    List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
    
    Name methodName = field.toName(witherName);
    
    JCExpression returnType = cloneSelfType(field);
    
    JCBlock methodBody = null;
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
    
    JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
    
    if (!makeAbstract) {
        ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
        
        JCExpression selfType = cloneSelfType(field);
        if (selfType == null) return null;
        
        ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
        for (JavacNode child : field.up().down()) {
            if (child.getKind() != Kind.FIELD) continue;
            JCVariableDecl childDecl = (JCVariableDecl) child.get();
            // Skip fields that start with $
            if (childDecl.name.toString().startsWith("$")) continue;
            long fieldFlags = childDecl.mods.flags;
            // Skip static fields.
            if ((fieldFlags & Flags.STATIC) != 0) continue;
            // Skip initialized final fields.
            if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
            if (child.get() == field.get()) {
                args.append(maker.Ident(fieldDecl.name));
            } else {
                args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
            }
        }
        
        JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
        JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
        JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
        JCReturn returnStatement = maker.Return(conditional);
        
        if (nonNulls.isEmpty()) {
            statements.append(returnStatement);
        } else {
            JCStatement nullCheck = generateNullCheck(maker, field, source);
            if (nullCheck != null) statements.append(nullCheck);
            statements.append(returnStatement);
        }
        
        methodBody = maker.Block(0, statements.toList());
    }
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    
    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
    
    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    if (makeAbstract) access = access | Flags.ABSTRACT;
    JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
    copyJavadoc(field, decl, CopyJavadoc.WITHER);
    return decl;
}
 
開發者ID:git03394538,項目名稱:lombok-ianchiu,代碼行數:75,代碼來源:HandleWither.java

示例9: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;
    
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
    
    Name methodName = field.toName(witherName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
    
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
    
    JCExpression selfType = cloneSelfType(field);
    if (selfType == null) return null;
    
    ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
    for (JavacNode child : field.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        JCVariableDecl childDecl = (JCVariableDecl) child.get();
        // Skip fields that start with $
        if (childDecl.name.toString().startsWith("$")) continue;
        long fieldFlags = childDecl.mods.flags;
        // Skip static fields.
        if ((fieldFlags & Flags.STATIC) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
        if (child.get() == field.get()) {
            args.append(maker.Ident(fieldDecl.name));
        } else {
            args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
        }
    }
    
    JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
    JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
    JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
    JCReturn returnStatement = maker.Return(conditional);
    
    if (nonNulls.isEmpty()) {
        statements.append(returnStatement);
    } else {
        JCStatement nullCheck = generateNullCheck(maker, field, source);
        if (nullCheck != null) statements.append(nullCheck);
        statements.append(returnStatement);
    }
    
    JCExpression returnType = cloneSelfType(field);
    
    JCBlock methodBody = maker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    
    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
    
    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
    copyJavadoc(field, decl, CopyJavadoc.WITHER);
    return decl;
}
 
開發者ID:mobmead,項目名稱:EasyMPermission,代碼行數:69,代碼來源:HandleWither.java

示例10: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的package包/類
private JCMethodDecl createWither(long access, JavacNode field, TreeMaker treeMaker, JCTree source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
    String witherName = toWitherName(field);
    if (witherName == null) return null;
    
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    
    ListBuffer<JCStatement> statements = ListBuffer.lb();
    List<JCAnnotation> nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN);
    List<JCAnnotation> nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN);
    
    Name methodName = field.toName(witherName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
    
    JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
    
    JCExpression selfType = cloneSelfType(field);
    if (selfType == null) return null;
    
    TreeMaker maker = field.getTreeMaker();
    
    ListBuffer<JCExpression> args = ListBuffer.lb();
    for (JavacNode child : field.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        JCVariableDecl childDecl = (JCVariableDecl) child.get();
        // Skip fields that start with $
        if (childDecl.name.toString().startsWith("$")) continue;
        long fieldFlags = childDecl.mods.flags;
        // Skip static fields.
        if ((fieldFlags & Flags.STATIC) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
        if (child.get() == field.get()) {
            args.append(maker.Ident(fieldDecl.name));
        } else {
            args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
        }
    }
    
    JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
    JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
    JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
    JCReturn returnStatement = maker.Return(conditional);
    
    if (nonNulls.isEmpty()) {
        statements.append(returnStatement);
    } else {
        JCStatement nullCheck = generateNullCheck(treeMaker, field);
        if (nullCheck != null) statements.append(nullCheck);
        statements.append(returnStatement);
    }
    
    JCExpression returnType = cloneSelfType(field);
    
    JCBlock methodBody = treeMaker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    
    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
    
    if (isFieldDeprecated(field)) {
        annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil()));
    }
    return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, returnType,
            methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:68,代碼來源:HandleWither.java

示例11: createField

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的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

示例12: createSetReferencedObjectMethod

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //導入依賴的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


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