本文整理汇总了Java中org.checkerframework.framework.type.AnnotatedTypeFactory类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedTypeFactory类的具体用法?Java AnnotatedTypeFactory怎么用?Java AnnotatedTypeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedTypeFactory类属于org.checkerframework.framework.type包,在下文中一共展示了AnnotatedTypeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FormatCall
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
public FormatCall(MethodInvocationTree node, AnnotatedTypeFactory atypeFactory) {
this.node = node;
// TODO figure out how to make passing of environment
// objects such as atypeFactory, processingEnv, ... nicer
this.atypeFactory = atypeFactory;
List<? extends ExpressionTree> theargs;
theargs = node.getArguments();
if (typeMirrorToClass(atypeFactory.getAnnotatedType(theargs.get(0)).getUnderlyingType()) == Locale.class) {
// call with Locale as first argument
theargs = theargs.subList(1, theargs.size());
}
// TODO check that the first parameter exists and is a string
formatArg = theargs.get(0);
formatAnno = atypeFactory.getAnnotatedType(formatArg);
this.args = theargs.subList(1, theargs.size());
}
示例2: updateForMethodCall
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* <p>
* Additionally, the {@link InitializationStore} keeps all field values for
* fields that have the 'invariant' annotation.
*/
@Override
public void updateForMethodCall(MethodInvocationNode n,
AnnotatedTypeFactory atypeFactory, V val) {
AnnotationMirror fieldInvariantAnnotation = ((InitializationAnnotatedTypeFactory<?, ?, ?, ?>)atypeFactory).getFieldInvariantAnnotation();
// Are there fields that have the 'invariant' annotations and are in the
// store?
List<FlowExpressions.FieldAccess> invariantFields = new ArrayList<>();
for (Entry<FlowExpressions.FieldAccess, V> e : fieldValues.entrySet()) {
FlowExpressions.FieldAccess fieldAccess = e.getKey();
Set<AnnotationMirror> declaredAnnos = atypeFactory.getAnnotatedType(fieldAccess.getField()).getAnnotations();
if (AnnotationUtils.containsSame(declaredAnnos, fieldInvariantAnnotation)) {
invariantFields.add(fieldAccess);
}
}
super.updateForMethodCall(n, atypeFactory, val);
// Add invariant annotation again.
for (FieldAccess invariantField : invariantFields) {
insertValue(invariantField, fieldInvariantAnnotation);
}
}
示例3: createTypeFactory
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Constructs an instance of the appropriate type factory for the
* implemented type system.
*
* The default implementation uses the checker naming convention to create
* the appropriate type factory. If no factory is found, it returns
* {@link BaseAnnotatedTypeFactory}. It reflectively invokes the
* constructor that accepts this checker and compilation unit tree
* (in that order) as arguments.
*
* Subclasses have to override this method to create the appropriate
* visitor if they do not follow the checker naming convention.
*
* @return the appropriate type factory
*/
@SuppressWarnings("unchecked") // unchecked cast to type variable
protected Factory createTypeFactory() {
// Try to reflectively load the type factory.
Class<?> checkerClass = checker.getClass();
while (checkerClass != BaseTypeChecker.class) {
final String classToLoad =
checkerClass.getName().replace("Checker", "AnnotatedTypeFactory")
.replace("Subchecker", "AnnotatedTypeFactory");
AnnotatedTypeFactory result = BaseTypeChecker.invokeConstructorFor(classToLoad,
new Class<?>[] { BaseTypeChecker.class },
new Object[] { checker });
if (result != null) {
return (Factory) result;
}
checkerClass = checkerClass.getSuperclass();
}
return (Factory) new BaseAnnotatedTypeFactory(checker);
}
示例4: resolveReflectiveCall
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
@Override
public Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> resolveReflectiveCall(
AnnotatedTypeFactory factory, MethodInvocationTree tree,
Pair<AnnotatedExecutableType, List<AnnotatedTypeMirror>> origResult) {
assert shouldResolveReflection(tree);
// EDITED 1-2-14 by plvines
// added this if/else
if (TreeUtils.isMethodInvocation(tree, newInstance, processingEnv)) {
return resolveConstructorCall(factory, tree, origResult);
} else {
AnnotationMirror estimate = provider.getAnnotationMirror(
TreeUtils.getReceiverTree(tree), MethodVal.class);
List<String> listMethodNames = AnnotationUtils
.getElementValueArray(estimate, "methodName", String.class,
true);
if (INIT.equals(listMethodNames.get(0))) {
return resolveConstructorCall(factory, tree, origResult);
}
return resolveMethodCall(factory, tree, origResult);
}
}
示例5: printClassType
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Prints the types of the class and all of its enclosing
* fields, methods, and inner classes
*/
protected static void printClassType(TypeElement typeElt, AnnotatedTypeFactory atypeFactory) {
assert typeElt != null;
String simpleName = typeElt.getSimpleName().toString();
// Output class info
AnnotatedDeclaredType type = atypeFactory.fromElement(typeElt);
System.out.println(simpleName + "\t" + type + "\t" + type.directSuperTypes());
// output fields and methods
for (Element enclosedElt : typeElt.getEnclosedElements()) {
if (enclosedElt instanceof TypeElement)
printClassType((TypeElement)enclosedElt, atypeFactory);
if (!enclosedElt.getKind().isField()
&& !(enclosedElt instanceof ExecutableElement))
continue;
AnnotatedTypeMirror memberType = atypeFactory.fromElement(enclosedElt);
System.out.println(simpleName + "." + enclosedElt + "\t\t" + memberType);
}
}
示例6: buildFlowExprContextForDeclaration
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* @return A {@link FlowExpressionContext} for the method {@code node} as
* seen at the method declaration.
*/
public static FlowExpressionContext buildFlowExprContextForDeclaration(
MethodTree node, Tree classTree, AnnotatedTypeFactory factory) {
Node receiver = new ImplicitThisLiteralNode(
InternalUtils.typeOf(classTree));
Receiver internalReceiver = FlowExpressions.internalReprOf(factory,
receiver);
List<Receiver> internalArguments = new ArrayList<>();
for (VariableTree arg : node.getParameters()) {
internalArguments.add(FlowExpressions.internalReprOf(factory,
new LocalVariableNode(arg)));
}
FlowExpressionContext flowExprContext = new FlowExpressionContext(
internalReceiver, internalArguments, factory);
return flowExprContext;
}
示例7: asOuterSuper
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Return the base type of t or any of its outer types that starts
* with the given type. If none exists, return null.
*
* @param t a type
* @param elem a type
*/
private static AnnotatedTypeMirror asOuterSuper(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror t,
AnnotatedTypeMirror elem) {
switch (t.getKind()) {
case DECLARED:
AnnotatedDeclaredType dt = (AnnotatedDeclaredType) t;
do {
// Search among supers for a desired supertype
AnnotatedTypeMirror s = asSuper(types, atypeFactory, dt, elem);
if (s != null)
return s;
// if not found immediately, try enclosing type
// like A in A.B
dt = dt.getEnclosingType();
} while (dt != null);
return null;
case ARRAY: // intentional follow-through
case TYPEVAR: // intentional follow-through
case WILDCARD:
return asSuper(types, atypeFactory, t, elem);
default:
return null;
}
}
示例8: asMemberOf
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Returns the type of an element when that element is viewed as a member
* of, or otherwise directly contained by, a given type.
*
* For example, when viewed as a member of the parameterized type
* {@code Set<@NonNull String>}, the {@code Set.add} method is an
* {@code ExecutableType} whose parameter is of type
* {@code @NonNull String}.
*
* The result is customized according to the type system semantics,
* according to {@link AnnotatedTypeFactory#postAsMemberOf(
* AnnotatedTypeMirror, AnnotatedTypeMirror, Element)}.
*
* @param t a type
* @param elem an element
*/
public static AnnotatedTypeMirror asMemberOf(Types types, AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror t, Element elem) {
// asMemberOf is only for fields, variables, and methods!
// Otherwise, simply use fromElement.
switch (elem.getKind()) {
case PACKAGE:
case INSTANCE_INIT:
case OTHER:
case STATIC_INIT:
case TYPE_PARAMETER:
return atypeFactory.fromElement(elem);
default:
AnnotatedTypeMirror type = asMemberOfImpl(types, atypeFactory, t, elem);
if (!ElementUtils.isStatic(elem))
atypeFactory.postAsMemberOf(type, t, elem);
return type;
}
}
示例9: bottomsOnly
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
private static boolean bottomsOnly(Elements elements, AnnotatedTypeFactory atypeFactory,
Set<AnnotationMirror> annotations) {
Set<AnnotationMirror> bots = AnnotationUtils.createAnnotationSet();
bots.addAll(atypeFactory.getQualifierHierarchy().getBottomAnnotations());
// Return true if all the qualifiers that are present are
// bottom qualifiers. Allow fewer qualifiers to be present,
// which can happen for type variables and wildcards.
boolean allbot = true;
for (AnnotationMirror am : annotations) {
if (!bots.remove(am)) {
allbot = false;
}
}
return allbot;
}
示例10: expandVarArgs
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Returns the method parameters for the invoked method, with the same number
* of arguments passed in the methodInvocation tree.
*
* If the invoked method is not a vararg method or it is a vararg method
* but the invocation passes an array to the vararg parameter, it would simply
* return the method parameters.
*
* Otherwise, it would return the list of parameters as if the vararg is expanded
* to match the size of the passed arguments.
*
* @param method the method's type
* @param args the arguments to the method invocation
* @return the types that the method invocation arguments need to be subtype of
*/
public static List<AnnotatedTypeMirror> expandVarArgs(AnnotatedTypeFactory atypeFactory,
AnnotatedExecutableType method,
List<? extends ExpressionTree> args) {
List<AnnotatedTypeMirror> parameters = method.getParameterTypes();
if (!method.getElement().isVarArgs()) {
return parameters;
}
AnnotatedArrayType varargs = (AnnotatedArrayType)parameters.get(parameters.size() - 1);
if (parameters.size() == args.size()) {
// Check if one sent an element or an array
AnnotatedTypeMirror lastArg = atypeFactory.getAnnotatedType(args.get(args.size() - 1));
if (lastArg.getKind() == TypeKind.ARRAY &&
getArrayDepth(varargs) == getArrayDepth((AnnotatedArrayType)lastArg)) {
return parameters;
}
}
parameters = new ArrayList<AnnotatedTypeMirror>(parameters.subList(0, parameters.size() - 1));
for (int i = args.size() - parameters.size(); i > 0; --i)
parameters.add(varargs.getComponentType());
return parameters;
}
示例11: getAnnotatedTypes
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Return a list of the AnnotatedTypeMirror of the passed
* expression trees, in the same order as the trees.
*
* @param paramTypes The parameter types to use as assignment context
* @param trees the AST nodes
* @return a list with the AnnotatedTypeMirror of each tree in trees.
*/
public static List<AnnotatedTypeMirror> getAnnotatedTypes(AnnotatedTypeFactory atypeFactory,
List<AnnotatedTypeMirror> paramTypes, List<? extends ExpressionTree> trees) {
assert paramTypes.size() == trees.size() : "AnnotatedTypes.getAnnotatedTypes: size mismatch! " +
"Parameter types: " + paramTypes + " Arguments: " + trees;
List<AnnotatedTypeMirror> types = new ArrayList<AnnotatedTypeMirror>();
Pair<Tree, AnnotatedTypeMirror> preAssCtxt = atypeFactory.getVisitorState().getAssignmentContext();
try {
for (int i = 0; i < trees.size(); ++i) {
AnnotatedTypeMirror param = paramTypes.get(i);
atypeFactory.getVisitorState().setAssignmentContext(Pair.<Tree, AnnotatedTypeMirror>of((Tree) null, param));
ExpressionTree arg = trees.get(i);
types.add(atypeFactory.getAnnotatedType(arg));
}
} finally {
atypeFactory.getVisitorState().setAssignmentContext(preAssCtxt);
}
return types;
}
示例12: DataflowInferenceTreeAnnotator
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
public DataflowInferenceTreeAnnotator(
InferenceAnnotatedTypeFactory atypeFactory,
InferrableChecker realChecker,
AnnotatedTypeFactory realAnnotatedTypeFactory,
VariableAnnotator variableAnnotator, SlotManager slotManager) {
super(atypeFactory, realChecker, realAnnotatedTypeFactory,
variableAnnotator, slotManager);
this.variableAnnotator = variableAnnotator;
this.realTypeFactory = realAnnotatedTypeFactory;
this.slotManager = InferenceMain.getInstance().getSlotManager();
}
示例13: BaseTypeValidator
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
public BaseTypeValidator(BaseTypeChecker checker,
BaseTypeVisitor<?> visitor,
AnnotatedTypeFactory atypeFactory) {
this.checker = checker;
this.visitor = visitor;
this.atypeFactory = atypeFactory;
}
示例14: lub
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Build lub of the two sets <code>set1</code> and <code>set2</code> using
* the provided AnnotatedTypeFactory.
* <p>
* If <code>set1</code> is <code>null</code> or empty, <code>set2</code> is
* returned.
*/
private Set<? extends AnnotationMirror> lub(
Set<? extends AnnotationMirror> set1,
Set<? extends AnnotationMirror> set2, AnnotatedTypeFactory factory) {
if (set1 == null || set1.size() == 0) {
return set2;
} else {
return factory.getQualifierHierarchy().greatestLowerBounds(set1,
set2);
}
}
示例15: glb
import org.checkerframework.framework.type.AnnotatedTypeFactory; //导入依赖的package包/类
/**
* Build glb of the two sets <code>set1</code> and <code>set2</code> using
* the provided AnnotatedTypeFactory.
* <p>
* If <code>set1</code> is <code>null</code> or empty, <code>set2</code> is
* returned.
*/
private Set<? extends AnnotationMirror> glb(
Set<? extends AnnotationMirror> set1,
Set<? extends AnnotationMirror> set2, AnnotatedTypeFactory factory) {
if (set1 == null || set1.size() == 0) {
return set2;
} else {
return factory.getQualifierHierarchy().greatestLowerBounds(set1,
set2);
}
}