Package edu.umd.cs.findbugs.classfile.analysis

Examples of edu.umd.cs.findbugs.classfile.analysis.AnnotationValue


        }

        XMethod xMethod = XFactory.createXMethod(classContext.getJavaClass(), method);

        ClassDescriptor junitTestAnnotation = DescriptorFactory.createClassDescriptor("org/junit/Test");
        AnnotationValue av = xMethod.getAnnotation(junitTestAnnotation);
        if (av != null) {
            Object value = av.getValue("expected");

            if (value instanceof Type) {
                String className = ((Type) value).getClassName();
                if (className.equals("java.lang.NullPointerException")) {
                    return;
View Full Code Here


            }

            @Override
            public org.objectweb.asm.AnnotationVisitor visitAnnotation(String desc, boolean isVisible) {
                if (cBuilder instanceof ClassInfo.Builder) {
                    AnnotationValue value = new AnnotationValue(desc);
                    ((ClassInfo.Builder) cBuilder).addAnnotation(desc, value);
                    return value.getAnnotationVisitor();
                }
                return null;
            }

            @Override
            public void visitAttribute(Attribute arg0) {
                //
            }

            @Override
            public void visitEnd() {
                //
            }

            @Override
            public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
                //                if (name.equals("this$0"))
                //                    isInnerClass = true;

                if (desc == null) {
                    throw new NullPointerException("Description cannot be null");
                }
                if (cBuilder instanceof ClassInfo.Builder) {
                    final ClassInfo.Builder cBuilder2 = (ClassInfo.Builder) cBuilder;
                    if ((access & Opcodes.ACC_VOLATILE) != 0 || desc.contains("util/concurrent")) {
                        cBuilder2.setUsesConcurrency();
                    }
                    final FieldInfo.Builder fBuilder = new FieldInfo.Builder(slashedClassName, name, desc, access);
                    fBuilder.setSourceSignature(signature);
                    return new AbstractFieldAnnotationVisitor() {

                        @Override
                        public org.objectweb.asm.AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
                            AnnotationValue value = new AnnotationValue(desc);
                            fBuilder.addAnnotation(desc, value);
                            return value.getAnnotationVisitor();
                        }

                        @Override
                        public void visitEnd() {
                            cBuilder2.addFieldDescriptor(fBuilder.build());
View Full Code Here

            visitSomeInsn();
        }

        @Override
        public org.objectweb.asm.AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
            AnnotationValue value = new AnnotationValue(desc);
            mBuilder.addAnnotation(desc, value);
            return value.getAnnotationVisitor();
        }
View Full Code Here

        }

        @Override
        public org.objectweb.asm.AnnotationVisitor visitParameterAnnotation(int parameter, String desc,
                boolean visible) {
            AnnotationValue value = new AnnotationValue(desc);
            mBuilder.addParameterAnnotation(parameter, desc, value);
            return value.getAnnotationVisitor();
        }
View Full Code Here

            // AnalysisContext.logError("Error adding built-in nullness annotation",
            // e);
            return;
        }
        if (n == NullnessAnnotation.NONNULL && target == AnnotationDatabase.Target.PARAMETER) {
            xclass.addAnnotation(new AnnotationValue(PARAMETERS_ARE_NONNULL_BY_DEFAULT));
            return;
        } else if (n == NullnessAnnotation.NONNULL && target == AnnotationDatabase.Target.METHOD) {
            xclass.addAnnotation(new AnnotationValue(RETURN_VALUES_ARE_NONNULL_BY_DEFAULT));
            return;
        }
        // Get the default annotation type
        ClassDescriptor defaultAnnotationType;
        if (target == AnnotationDatabase.Target.ANY) {
            defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION;
        } else if (target == AnnotationDatabase.Target.FIELD) {
            defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_FIELDS;
        } else if (target == AnnotationDatabase.Target.METHOD) {
            defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_METHODS;
        } else if (target == AnnotationDatabase.Target.PARAMETER) {
            defaultAnnotationType = FindBugsDefaultAnnotations.DEFAULT_ANNOTATION_FOR_PARAMETERS;
        } else {
            throw new IllegalArgumentException("Unknown target for default annotation: " + target);
        }

        // Get the JSR-305 nullness annotation type
        ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(n);

        // Construct an AnnotationValue containing the default annotation
        AnnotationValue annotationValue = new AnnotationValue(defaultAnnotationType);
        AnnotationVisitor v = annotationValue.getAnnotationVisitor();
        v.visit("value", Type.getObjectType(nullnessAnnotationType.getClassName()));
        v.visitEnd();

        if (DEBUG) {
            System.out.println("Adding AnnotationValue " + annotationValue + " to class " + xclass);
View Full Code Here

        // Get JSR-305 nullness annotation type
        ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(annotation);

        // Create an AnnotationValue
        AnnotationValue annotationValue = new AnnotationValue(nullnessAnnotationType);

        // Destructively add the annotation to the FieldInfo object
        ((FieldInfo) xfield).addAnnotation(annotationValue);
    }
View Full Code Here

        }
        // Get JSR-305 nullness annotation type
        ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(annotation);

        // Create an AnnotationValue
        AnnotationValue annotationValue = new AnnotationValue(nullnessAnnotationType);

        // Destructively add the annotation to the MethodInfo object
        xmethod.addAnnotation(annotationValue);
    }
View Full Code Here

        }
        // Get JSR-305 nullness annotation type
        ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(annotation);

        // Create an AnnotationValue
        AnnotationValue annotationValue = new AnnotationValue(nullnessAnnotationType);

        if (!xmethod.getClassName().equals(cName)) {
            if (SystemProperties.ASSERTIONS_ENABLED) {
                AnalysisContext.logError("Could not fully resolve method " + cName + "." + mName + sig + " to apply annotation "
                        + annotation);
View Full Code Here

            break;
        }

        // Try out default JDT (Eclipse) annotations
        if(result == null){
            AnnotationValue annotationValue = o.getAnnotation(TypeQualifierResolver.eclipseNonNullByDefault);
            if(annotationValue != null){
                Collection<AnnotationValue> resolvedTypeQualifiers = TypeQualifierResolver.resolveTypeQualifiers(annotationValue);
                tqa = extractAnnotation(resolvedTypeQualifiers, typeQualifierValue);
                if(tqa != null){
                    return tqa;
View Full Code Here

        if (DEBUG_DEFAULT_ANNOTATION) {
            System.out.println("Checking for " + defaultAnnotation + " containing " + typeQualifierValue + " on " + o);
        }
        // - check to see if default annotation is present; if not, return null
        AnnotationValue annotationValue = o.getAnnotation(defaultAnnotation);
        if (annotationValue == null) {
            if (DEBUG_DEFAULT_ANNOTATION) {
                System.out.println("   ===> no " + defaultAnnotation);
            }
            return null;
        }

        // - get value - should be Type or array of Type
        Object value = annotationValue.getValue("value");
        if (value == null) {
            if (DEBUG_DEFAULT_ANNOTATION) {
                System.out.println("   ===> value is null");
            }
            return null;
        }
        Object[] types;
        if (value instanceof Object[]) {
            types = (Object[]) value;
        } else {
            types = new Object[] { value };
        }

        // - scan through array elements; see if any match the
        // TypeQualifierValue (including type qualifier nicknames)
        for (Object obj : types) {
            if (!(obj instanceof Type)) {
                if (DEBUG_DEFAULT_ANNOTATION) {
                    System.out
                    .println("Found a non-Type value in value array of " + defaultAnnotation.toString() + " annotation");
                }
                continue;
            }

            Type type = (Type) obj;
            if (DEBUG_DEFAULT_ANNOTATION) {
                System.out.println("  ===> checking " + type.getDescriptor());
            }
            if (type.getDescriptor().startsWith("[")) {
                continue;
            }
            ClassDescriptor typeDesc = DescriptorFactory.instance().getClassDescriptor(type.getInternalName());

            // There is no general way to figure out whether a particular
            // type is a type qualifier we're interested in without
            // resolving it.
            AnnotationValue annotation = new AnnotationValue(typeDesc);
            Collection<AnnotationValue> resolvedTypeQualifiers = TypeQualifierResolver.resolveTypeQualifiers(annotation);
            TypeQualifierAnnotation tqa = extractAnnotation(resolvedTypeQualifiers, typeQualifierValue);
            if (tqa != null) {
                return tqa;
            }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.classfile.analysis.AnnotationValue

Copyright © 2018 www.massapicom. 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.