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


Java AnnotatedDeclaredType类代码示例

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


AnnotatedDeclaredType类属于org.checkerframework.framework.type.AnnotatedTypeMirror包,在下文中一共展示了AnnotatedDeclaredType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: isValidUse

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
/**
 * Tests that the qualifiers present on the useType are valid qualifiers,
 * given the qualifiers on the declaration of the type, declarationType.
 * 
 * For Glacier, we don't allow qualifiers on the useType that are not redundant -- except that for Object, anything goes.
 */
@Override
public boolean isValidUse(AnnotatedDeclaredType declarationType,
        AnnotatedDeclaredType useType, Tree tree) {
	// Users can't specify bottom annotations.
	if (useType.hasAnnotation(GlacierBottom.class)) {
		return false;
	}
	
    if(TypesUtils.isObject(declarationType.getUnderlyingType())) {
        // If the declared type is Object, the use can have any Glacier annotation.
        return true;
    }

    // We need to make sure that users never apply annotations that conflict with the ones in the declarations. 
    // Check that directly rather than calling super.isValidUse().
    AnnotationMirror immutableAnnotation = AnnotationBuilder.fromClass(elements, Immutable.class);
    AnnotationMirror useAnnotation = useType.getAnnotationInHierarchy(immutableAnnotation);

    if (useAnnotation != null) {
    	return declarationType.hasAnnotation(useAnnotation);
    }
    else {
    	return !declarationType.hasAnnotation(useAnnotation);
    }
}
 
开发者ID:mcoblenz,项目名称:Glacier,代码行数:32,代码来源:GlacierVisitor.java

示例3: createOverrideChecker

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
protected OverrideChecker createOverrideChecker(Tree overriderTree,
                                              AnnotatedExecutableType overrider,
                                              AnnotatedTypeMirror overridingType,
                                              AnnotatedTypeMirror overridingReturnType,
                                              AnnotatedExecutableType overridden,
                                              AnnotatedDeclaredType overriddenType,
                                              AnnotatedTypeMirror overriddenReturnType) {
    return new GlacierOverrideChecker(overriderTree,
            overrider,
            overridingType,
            overridingReturnType,
            overridden,
            overriddenType,
            overriddenReturnType);
}
 
开发者ID:mcoblenz,项目名称:Glacier,代码行数:17,代码来源:GlacierVisitor.java

示例4: GlacierOverrideChecker

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
GlacierOverrideChecker(
        Tree overriderTree,
        AnnotatedExecutableType overrider,
        AnnotatedTypeMirror overridingType,
        AnnotatedTypeMirror overridingReturnType,
        AnnotatedExecutableType overridden,
        AnnotatedDeclaredType overriddenType,
        AnnotatedTypeMirror overriddenReturnType) {
    super(overriderTree,
            overrider,
            overridingType,
            overridingReturnType,
            overridden,
            overriddenType,
            overriddenReturnType);
}
 
开发者ID:mcoblenz,项目名称:Glacier,代码行数:17,代码来源:GlacierVisitor.java

示例5: visitNewClass

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
public Void visitNewClass(NewClassTree node, AnnotatedTypeMirror p) {
    if (!hasImmutabilityAnnotation(p)) {
        AnnotatedTypeMirror ct = fromElement(
                ((AnnotatedDeclaredType)p).getUnderlyingType().asElement());

        if (!hasImmutabilityAnnotation(ct) || ct.hasAnnotationRelaxed(I)) {
            AnnotatedExecutableType con = getAnnotatedType(TreeUtils.elementFromUse(node));
            if (con.getReceiverType() != null &&
                    con.getReceiverType().hasEffectiveAnnotation(IMMUTABLE))
                p.replaceAnnotation(IMMUTABLE);
            else
                p.replaceAnnotation(MUTABLE);
        } else {
            // case 2: known immutability type
            p.addAnnotations(ct.getAnnotations());
        }
    }

    return null;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:22,代码来源:ImmutabilityAnnotatedTypeFactory.java

示例6: isSubtypeTypeArguments

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
/**
 * OIGJ Rule 6. <b>Same-class subtype definition</b>
 */
// TODO: Handle CoVariant(X_i, C)
@Override
protected boolean isSubtypeTypeArguments(AnnotatedDeclaredType rhs, AnnotatedDeclaredType lhs) {
    if (ignoreRawTypeArguments(rhs, lhs)) {
        return true;
    }

    if (lhs.hasEffectiveAnnotation(MUTABLE))
        return super.isSubtypeTypeArguments(rhs, lhs);

    if (!lhs.getTypeArguments().isEmpty()
            && !rhs.getTypeArguments().isEmpty()) {
        assert lhs.getTypeArguments().size() == rhs.getTypeArguments().size();
        for (int i = 0; i < lhs.getTypeArguments().size(); ++i) {
            if (!isSubtype(rhs.getTypeArguments().get(i), lhs.getTypeArguments().get(i)))
                return false;
        }
    }
    return true;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:24,代码来源:ImmutabilityAnnotatedTypeFactory.java

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

示例8: visitCompoundAssignment

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
/**
 * Case 2: Check String compound concatenation for valid Regex use.
 */
// TODO: Remove this. This should be handled by flow.
/*@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
    // Default behavior from superclass
}*/

@Override
public boolean isValidUse(AnnotatedDeclaredType declarationType,
                         AnnotatedDeclaredType useType, Tree tree) {
    // TODO: only allow Regex and PolyRegex annotations on types in legalReferenceTypes.
    // This is pending an implementation of AnnotatedTypeMirror.getExplicitAnnotations
    // that supports local variables, array types and parameterized types.
    /*// Only allow annotations on subtypes of the types in legalReferenceTypes.
    if (!useType.getExplicitAnnotations().isEmpty()) {
        Types typeUtils = env.getTypeUtils();
        for (TypeMirror type : legalReferenceTypes) {
            if (typeUtils.isSubtype(declarationType.getUnderlyingType(), type)) {
                return true;
            }
        }
        return false;
    }*/
    return super.isValidUse(declarationType, useType, tree);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:28,代码来源:RegexVisitor.java

示例9: checkOverride

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
protected boolean checkOverride(MethodTree overriderTree,
        AnnotatedDeclaredType enclosingType,
        AnnotatedExecutableType overridden,
        AnnotatedDeclaredType overriddenType,
        Void p) {

    List<String> overriderLocks = methodHolding(TreeUtils.elementFromDeclaration(overriderTree));
    List<String> overriddenLocks = methodHolding(overridden.getElement());

    boolean isValid = overriddenLocks.containsAll(overriderLocks);

    if (!isValid) {
        checker.report(Result.failure("override.holding.invalid",
                TreeUtils.elementFromDeclaration(overriderTree),
                overridden.getElement(),
                overriderLocks, overriddenLocks), overriderTree);
    }

    return super.checkOverride(overriderTree, enclosingType, overridden, overriddenType, p) && isValid;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:22,代码来源:LockVisitor.java

示例10: isValidUse

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
public boolean isValidUse(AnnotatedDeclaredType elemType, AnnotatedDeclaredType use, Tree tree) {
    return true;
    /*
    if (elemType.hasEffectiveAnnotation(atypeFactory.I) ||
            use.hasEffectiveAnnotation(atypeFactory.READONLY)) {
        return true;
    }
    if (use.hasEffectiveAnnotation(atypeFactory.ASSIGNS_FIELDS) &&
            tree.getKind() == Tree.Kind.METHOD &&
            TreeUtils.isConstructor((MethodTree) tree)) {
        return true;
    }

    return super.isValidUse(elemType, use, tree);
    */
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:18,代码来源:IGJVisitor.java

示例11: isSubtypeTypeArguments

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
/**
 * Uses the JLS specification (as implemented in {@link TypeHierarchy},
 * if the variable type, lhs, is mutable; otherwise, allows the type
 * arguments to change while maintaining subtype relationship.
 *
 * This allows for subtyping relationships of the kind:
 * <pre>  @Mutable List&lt;@Mutable Date&gt; &lt;: @ReadOnly List&lt;@ReadOnly Date&gt;<\pre>
 */
@Override
protected boolean isSubtypeTypeArguments(AnnotatedDeclaredType rhs, AnnotatedDeclaredType lhs) {
    if (ignoreRawTypeArguments(rhs, lhs)) {
        return true;
    }

    if (lhs.hasEffectiveAnnotation(MUTABLE))
        return super.isSubtypeTypeArguments(rhs, lhs);

    if (!lhs.getTypeArguments().isEmpty()
            && !rhs.getTypeArguments().isEmpty()) {
        assert lhs.getTypeArguments().size() == rhs.getTypeArguments().size();
        for (int i = 0; i < lhs.getTypeArguments().size(); ++i) {
            if (!isSubtype(rhs.getTypeArguments().get(i), lhs.getTypeArguments().get(i)))
                return false;
        }
    }
    return true;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:28,代码来源:IGJAnnotatedTypeFactory.java

示例12: visitArray

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
public Void visitArray(AnnotatedArrayType type, Tree tree) {
    // TODO: is there already or add a helper method
    // to determine the non-array component type
    AnnotatedTypeMirror comp = type;
    do {
        comp = ((AnnotatedArrayType) comp).getComponentType();
    } while (comp.getKind() == TypeKind.ARRAY);

    if (comp != null &&
            comp.getKind() == TypeKind.DECLARED &&
            checker.shouldSkipUses(((AnnotatedDeclaredType) comp)
                    .getUnderlyingType().asElement())) {
        return super.visitArray(type, tree);
    }

    if (!visitor.isValidUse(type, tree)) {
        reportError(type, tree);
    }

    return super.visitArray(type, tree);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:23,代码来源:BaseTypeValidator.java

示例13: visitParameterizedType

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
/**
 * Checks that the annotations on the type arguments supplied to a type or a
 * method invocation are within the bounds of the type variables as
 * declared, and issues the "type.argument.type.incompatible" error if they are
 * not.
 *
 * This method used to be visitParameterizedType, which incorrectly handles
 * the main annotation on generic types.
 */
protected Void visitParameterizedType(AnnotatedDeclaredType type,
        ParameterizedTypeTree tree) {
    // System.out.printf("TypeValidator.visitParameterizedType: type: %s, tree: %s\n",
    // type, tree);

    if (TreeUtils.isDiamondTree(tree))
        return null;

    final TypeElement element = (TypeElement) type.getUnderlyingType().asElement();
    if (checker.shouldSkipUses(element))
        return null;

    List<AnnotatedTypeVariable> typevars = atypeFactory.typeVariablesFromUse(type, element);

    visitor.checkTypeArguments(tree, typevars, type.getTypeArguments(),
            tree.getTypeArguments());

    return null;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:29,代码来源:BaseTypeValidator.java

示例14: visitType

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
public Void visitType(TypeElement e, Void p) {
    String prevIndent = indent;

        out.print(indent);
        out.print(typeIdentifier(e));
        out.print(' ');
        out.print(e.getSimpleName());
        out.print(' ');
        AnnotatedDeclaredType dt = factory.getAnnotatedType(e);
        printSupers(dt);
        out.println("{");

        indent += INDENTION;

        for (Element enclosed : e.getEnclosedElements())
            this.visit(enclosed);

        indent = prevIndent;
        out.print(indent);
        out.println("}");

        return null;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:25,代码来源:SignaturePrinter.java

示例15: visitMethod

import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType; //导入依赖的package包/类
@Override
public Void visitMethod(MethodTree node, Void p) {
    ExecutableElement method = TreeUtils.elementFromDeclaration(node);
    boolean report = false;

    // Check all overridden methods.
    Map<AnnotatedDeclaredType, ExecutableElement> overriddenMethods =
        AnnotatedTypes.overriddenMethods(elements, atypeFactory, method);
    for (Map.Entry<AnnotatedDeclaredType, ExecutableElement> pair: overriddenMethods.entrySet()) {
        // AnnotatedDeclaredType overriddenType = pair.getKey();
        ExecutableElement exe = pair.getValue();
        report = this.atypeFactory.getDeclAnnotation(exe, ReportOverride.class) != null;
        if (report) {
            // Set method to report the right method, if found.
            method = exe;
            break;
        }
    }

    if (report) {
        checker.report(Result.failure("override", node,
                ElementUtils.getVerboseName(method)), node);
    }
    return super.visitMethod(node, p);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:26,代码来源:ReportVisitor.java


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