当前位置: 首页>>代码示例>>Java>>正文


Java AnnotatedDeclaredType.addAnnotation方法代码示例

本文整理汇总了Java中org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType.addAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedDeclaredType.addAnnotation方法的具体用法?Java AnnotatedDeclaredType.addAnnotation怎么用?Java AnnotatedDeclaredType.addAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType的用法示例。


在下文中一共展示了AnnotatedDeclaredType.addAnnotation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSelfType

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
@Override
  public AnnotatedDeclaredType getSelfType(Tree tree) {
AnnotatedDeclaredType selfType = super.getSelfType(tree);

      TreePath path = getPath(tree);
      ClassTree enclosingClass = TreeUtils.enclosingClass(path);
      if (enclosingClass == null) {
          // I hope this only happens when tree is a fake tree that
          // we created, e.g. when desugaring enhanced-for-loops.
          enclosingClass = getCurrentClassTree(tree);
      }
      AnnotatedDeclaredType enclosingClassType = getAnnotatedType(enclosingClass);

      if (!selfType.isAnnotatedInHierarchy(READ_ONLY)) { // If there's already an annotation on selfType and it conflicts with MaybeMutable, that error will be found by the type validity check elsewhere.
      	if (enclosingClassType.isAnnotatedInHierarchy(READ_ONLY)) {
      		annotateInheritedFromClass(selfType, enclosingClassType.getAnnotations());
      	}
      	else {
      		selfType.addAnnotation(MAYBE_MUTABLE);
      	}
      }
      return selfType;
  }
 
开发者ID:mcoblenz,项目名称:Glacier,代码行数:24,代码来源:GlacierAnnotatedTypeFactory.java

示例2: visitDeclared

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
/**
 * If the declared type has no annotation, annotates it with
 * the same annotation as its underlying type's element.
 */
@Override
public Void visitDeclared(AnnotatedDeclaredType type, Void p) {
    if (!hasImmutabilityAnnotation(type)) {                  // case 2
        TypeElement tElt = (TypeElement) type.getUnderlyingType().asElement();
        AnnotatedTypeMirror tType = fromElement(tElt);
        if (hasImmutabilityAnnotation(tType)) {
            type.addAnnotation(getImmutabilityAnnotation(tType));
        } /*else
            type.addAnnotation(MUTABLE);*/
    }
    /*
    if (elem != null && elem.getKind().isField()) {
        // TODO: Javari wants different defaulting rules for type arguments
        // of field types: instead of THISMUTABLE use MUTABLE.
        // What is a nicer way to do this?
        if (visitedNodes.containsKey(type)) {
            return visitedNodes.get(type);
        }
        visitedNodes.put(type, null);
        Void r = scan(type.getTypeArguments(), null);
        return r;
    } else {*/
        return super.visitDeclared(type, p);
    //}
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:30,代码来源:JavariAnnotatedTypeFactory.java

示例3: getBoxedType

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
@Override
public AnnotatedDeclaredType getBoxedType(AnnotatedPrimitiveType type) {
    TypeElement typeElt = types.boxedClass(type.getUnderlyingType());
    AnnotationMirror am = DataflowUtils.createDataflowAnnotation(typeElt.asType().toString(), this.processingEnv);
    AnnotatedDeclaredType dt = fromElement(typeElt);
    //ConstantSlot cs = new ConstantSlot(am, InferenceMain.getInstance().getSlotManager().nextId());
    //InferenceMain.getInstance().getSlotManager().addVariable(cs);
    ConstantSlot cs = InferenceMain.getInstance().getSlotManager().createConstantSlot(am);
    dt.addAnnotation(InferenceMain.getInstance().getSlotManager().getAnnotation(cs));
    dt.addAnnotation(cs.getValue());
    return dt;
}
 
开发者ID:Jianchu,项目名称:generic-type-inference-solver,代码行数:13,代码来源:DataflowInferenceAnnotatedTypeFactory.java

示例4: getBoxedType

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
@Override
public AnnotatedDeclaredType getBoxedType(AnnotatedPrimitiveType type) {
    TypeElement typeElt = types.boxedClass(type.getUnderlyingType());
    AnnotationMirror am = DataflowUtils.createDataflowAnnotation(typeElt.asType().toString(),
            this.processingEnv);
    AnnotatedDeclaredType dt = fromElement(typeElt);
    dt.addAnnotation(am);
    return dt;
}
 
开发者ID:Jianchu,项目名称:generic-type-inference-solver,代码行数:10,代码来源:DataflowAnnotatedTypeFactory.java

示例5: visitDeclared

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
/**
 * For Declared types:
 *  Classes are mutable
 *  Interface declaration are placeholders
 *  Enum and annotations  are immutable
 */
@Override
public Void visitDeclared(AnnotatedDeclaredType type, Void p) {
    if (!hasImmutabilityAnnotation(type)) {
        // Actual element
        TypeElement element = (TypeElement)type.getUnderlyingType().asElement();
        AnnotatedDeclaredType elementType = fromElement(element);
        // ElementKind elemKind = elem != null ? elem.getKind() : ElementKind.OTHER;

        if (TypesUtils.isBoxedPrimitive(type.getUnderlyingType())
                || element.getQualifiedName().contentEquals("java.lang.String")
                || ElementUtils.isObject(element)) {
            // variation of case 1
            // TODO: These cases are more of hacks and they should
            // really be immutable or readonly
            type.addAnnotation(BOTTOM_QUAL);
        } else if (elementType.hasEffectiveAnnotation(IMMUTABLE)) {
            // case 2: known immutable types
            type.addAnnotation(IMMUTABLE);
        } /*else if (elemKind == ElementKind.LOCAL_VARIABLE) {
            type.addAnnotation(READONLY);
        } else if (elementType.hasEffectiveAnnotation(MUTABLE)) { // not immutable
            // case 7: mutable by default
            type.addAnnotation(MUTABLE);
        } else if (elemKind.isClass() || elemKind.isInterface()) {
            // case 9: class or interface declaration
            type.addAnnotation(BOTTOM_QUAL);
        } else if (elemKind.isField()) {
            // Element elem = type.getElement();
            // TODO: The element is null in the GenericsCasts test
            // case. Why?
            if (elem != null
                    && getAnnotatedType(
                            ElementUtils.enclosingClass(elem)).hasEffectiveAnnotation(
                            IMMUTABLE)) {
                type.addAnnotation(IMMUTABLE);
            } else {
                type.addAnnotation(MUTABLE);
            }
        } else if (element.getKind().isClass()
                || element.getKind().isInterface()) {
            // case 10
            type.addAnnotation(MUTABLE);
        } else {
            assert false : "shouldn't be here!";
        }*/
    }
    return super.visitDeclared(type, p);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:55,代码来源:ImmutabilityAnnotatedTypeFactory.java

示例6: visitDeclared

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
/**
 * For Declared types:
 *  Classes are mutable
 *  Interface declaration are placeholders
 *  Enum and annotations  are immutable
 */
@Override
public Void visitDeclared(AnnotatedDeclaredType type, Void p) {
    if (!hasImmutabilityAnnotation(type)) {
        // Actual element
        TypeElement element = (TypeElement)type.getUnderlyingType().asElement();
        AnnotatedDeclaredType elementType = fromElement(element);
        // ElementKind elemKind = elem != null ? elem.getKind() : ElementKind.OTHER;

        if (TypesUtils.isBoxedPrimitive(type.getUnderlyingType())
                || element.getQualifiedName().contentEquals("java.lang.String")
                || ElementUtils.isObject(element)) {
            // variation of case 1
            // TODO: These cases are more of hacks and they should
            // really be immutable or readonly
            type.addAnnotation(BOTTOM_QUAL);
        } else if (elementType.hasEffectiveAnnotation(IMMUTABLE)) {
            // case 2: known immutable types
            type.addAnnotation(IMMUTABLE);
        }
    }
    return null; //super.visitDeclared(type, p);
    /*
    if (!hasImmutabilityAnnotation(type)) {
        // Actual element
        TypeElement element = (TypeElement)type.getUnderlyingType().asElement();
        AnnotatedDeclaredType elementType = fromElement(element);
        // ElementKind elemKind = elem != null ? elem.getKind() : ElementKind.OTHER;

        if (TypesUtils.isBoxedPrimitive(type.getUnderlyingType())
                || element.getQualifiedName().contentEquals("java.lang.String")
                || ElementUtils.isObject(element)) {
            // variation of case 1
            // TODO: These cases are more of hacks and they should
            // really be immutable or readonly
            type.replaceAnnotation(BOTTOM_QUAL);
        } else if (elementType.hasEffectiveAnnotation(IMMUTABLE)) {
            // case 2: known immutable types
            type.replaceAnnotation(IMMUTABLE);
        //} else if (elemKind == ElementKind.LOCAL_VARIABLE) {
        //    type.replaceAnnotation(READONLY);
        } else if (elementType.hasEffectiveAnnotation(MUTABLE)) { // not immutable
            // case 7: mutable by default
            type.replaceAnnotation(MUTABLE);
        //} else if (elemKind.isClass() || elemKind.isInterface()) {
            // case 9: class or interface declaration
        //    type.replaceAnnotation(BOTTOM_QUAL);
        //} else if (elemKind.isField()) {
            /*
                && type.getElement() != null // We don't know the field context here
                && getAnnotatedType(ElementUtils.enclosingClass(type.getElement())).hasEffectiveAnnotation(IMMUTABLE)) {
            type.replaceAnnotation(IMMUTABLE);
            TODO: This case is not exercised by any of the test cases. Is it needed?

        } else if (element.getKind().isClass() || element.getKind().isInterface()) {
            // case 10
            type.replaceAnnotation(MUTABLE);
        } else {
            assert false : "shouldn't be here!";
        }

    }
    return super.visitDeclared(type, p);
    */
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:71,代码来源:IGJAnnotatedTypeFactory.java

示例7: visitNewClass

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入方法依赖的package包/类
@Override
public AnnotatedTypeMirror visitNewClass(NewClassTree node,
        AnnotatedTypeFactory f) {
    // constructorFromUse obviously has Void as return type.
    // Therefore, use the overall type to return.
    AnnotatedDeclaredType type = f.fromNewClass(node);
    // Enum constructors lead to trouble.
    // TODO: is there more to check? Can one annotate them?
    if (isNewEnum(type)) {
        return type;
    }
    // Add annotations that are on the constructor declaration.
    // constructorFromUse gives us resolution of polymorphic qualifiers.
    // However, it also applies defaulting, so we might apply too many qualifiers.
    // Therefore, ensure to only add the qualifiers that are explicitly on
    // the constructor, but then take the possibly substituted qualifier.
    AnnotatedExecutableType ex = f.constructorFromUse(node).first;

    ExecutableElement ctor = TreeUtils.elementFromUse(node);
    // TODO: There will be a nicer way to access this in 308 soon.
    List<TypeCompound> decall = ((com.sun.tools.javac.code.Symbol)ctor).getRawTypeAttributes();
    Set<AnnotationMirror> decret = AnnotationUtils.createAnnotationSet();
    for (TypeCompound da : decall) {
        if (da.position.type == com.sun.tools.javac.code.TargetType.METHOD_RETURN) {
            decret.add(da);
        }
    }

    // Collect all polymorphic qualifiers; we should substitute them.
    Set<AnnotationMirror> polys = AnnotationUtils.createAnnotationSet();
    for (AnnotationMirror anno : type.getAnnotations()) {
        if (QualifierPolymorphism.isPolymorphicQualified(anno)) {
            polys.add(anno);
        }
    }

    for (AnnotationMirror cta : ex.getReturnType().getAnnotations()) {
        AnnotationMirror ctatop = f.getQualifierHierarchy().getTopAnnotation(cta);
        if (f.isSupportedQualifier(cta) &&
                !type.isAnnotatedInHierarchy(cta)) {
            for (AnnotationMirror fromDecl : decret) {
                if (f.isSupportedQualifier(fromDecl) &&
                        AnnotationUtils.areSame(ctatop,
                                f.getQualifierHierarchy().getTopAnnotation(fromDecl))) {
                    type.addAnnotation(cta);
                    break;
                }
            }
        }

        // Go through the polymorphic qualifiers and see whether
        // there is anything left to replace.
        for (AnnotationMirror pa : polys) {
            if (AnnotationUtils.areSame(ctatop,
                    f.getQualifierHierarchy().getTopAnnotation(pa))) {
                type.replaceAnnotation(cta);
                break;
            }
        }
    }
    return type;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:63,代码来源:TypeFromTree.java


注:本文中的org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType.addAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。