本文整理汇总了Java中org.checkerframework.checker.nullness.qual.KeyFor类的典型用法代码示例。如果您正苦于以下问题:Java KeyFor类的具体用法?Java KeyFor怎么用?Java KeyFor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyFor类属于org.checkerframework.checker.nullness.qual包,在下文中一共展示了KeyFor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyForInMap
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
private boolean keyForInMap(ExpressionTree key,
Element mapElement, TreePath path) {
AnnotatedTypeMirror keyForType = keyForFactory.getAnnotatedType(key);
AnnotationMirror anno = keyForType.getAnnotation(KeyFor.class);
if (anno == null)
return false;
List<String> maps = AnnotationUtils.getElementValueArray(anno, "value", String.class, false);
for (String map: maps) {
Element elt = resolver.findVariable(map, path);
if (elt.equals(mapElement) &&
!isSiteRequired(TreeUtils.getReceiverTree((ExpressionTree)path.getLeaf()), elt)) {
return true;
}
}
return false;
}
示例2: incorrect2
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void incorrect2() {
KFMap<String, Object> m = new KFHashMap<String, Object>();
m.put("a", new Object());
m.put("b", new Object());
m.put("c", new Object());
Collection<@KeyFor("m") String> coll = m.keySet();
@SuppressWarnings("assignment.type.incompatible")
@KeyFor("m") String newkey = "new";
coll.add(newkey);
// TODO: at this point, the @KeyFor annotation is violated
m.put("new", new Object());
}
示例3: correct2
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void correct2() {
KFMap<String, Object> m = new KFHashMap<String, Object>();
m.put("a", new Object());
m.put("b", new Object());
m.put("c", new Object());
Collection<@KeyFor("m") String> coll = m.keySet();
@SuppressWarnings("assignment.type.incompatible")
@KeyFor("m") String newkey = "new";
m.put(newkey, new Object());
coll.add(newkey);
}
示例4: getMostSpecificClass
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
/**
* Figures out the most specific class that is listed in the map. I.e. if A
* extends B and B is listed while requesting A, then B will be returned.
*
* @param map
* The map with the key collection to find a matching class in.
* @param key
* The class to search the most suitable key for.
* @return The most specific class from the key collection.
*/
private @Nullable @KeyFor("#1") Class<? extends Unit> getMostSpecificClass(
Map<Class<? extends Unit>, ?> map, Class<? extends Unit> key) {
List<Class<? extends Unit>> collideeInheritance = getInheritance(key);
for (Class<? extends Unit> pointer : collideeInheritance) {
if (map.containsKey(pointer)) {
return pointer;
}
}
return null;
}
示例5: visitDeclared
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
@Override
public Void visitDeclared(AnnotatedDeclaredType type, Tree p) {
AnnotationMirror kf = type.getAnnotation(KeyFor.class);
if (kf != null) {
List<String> maps = AnnotationUtils.getElementValueArray(kf, "value", String.class, false);
boolean inStatic = false;
if (p.getKind() == Kind.VARIABLE) {
ModifiersTree mt = ((VariableTree) p).getModifiers();
if (mt.getFlags().contains(Modifier.STATIC)) {
inStatic = true;
}
}
for (String map : maps) {
if (map.equals("this")) {
// this is not valid in static context
if (inStatic) {
checker.report(
Result.failure("keyfor.type.invalid",
type.getAnnotations(),
type.toString()), p);
}
} else if (map.matches("#(\\d+)")) {
// Accept parameter references
// TODO: look for total number of parameters and only
// allow the range 0 to n-1
} else {
// Only other option is local variable and field names?
// TODO: go through all possibilities.
}
}
}
// TODO: Should BaseTypeValidator be parametric in the ATF?
if (type.isAnnotatedInHierarchy(((KeyForAnnotatedTypeFactory)atypeFactory).KEYFOR)) {
return super.visitDeclared(type, p);
} else {
// TODO: Something went wrong...
return null;
}
}
示例6: substituteCall
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
private AnnotatedTypeMirror substituteCall(MethodInvocationTree call, AnnotatedTypeMirror inType) {
// System.out.println("input type: " + inType);
AnnotatedTypeMirror outType = inType.getCopy(true);
AnnotationMirror anno = inType.getAnnotation(KeyFor.class);
if (anno != null) {
List<String> inMaps = AnnotationUtils.getElementValueArray(anno, "value", String.class, false);
List<String> outMaps = new ArrayList<String>();
String receiver = receiver(call);
for (String inMapName : inMaps) {
if (parameterPtn.matcher(inMapName).matches()) {
int param = Integer.valueOf(inMapName.substring(1));
if (param <= 0 || param > call.getArguments().size()) {
// The failure should already have been reported, when the
// method declaration was processed.
// checker.report(Result.failure("param.index.nullness.parse.error", inMapName), call);
} else {
String res = call.getArguments().get(param-1).toString();
outMaps.add(res);
}
} else if (inMapName.equals("this")) {
outMaps.add(receiver);
} else {
// TODO: look at the code below, copied from NullnessFlow
// System.out.println("KeyFor argument unhandled: " + inMapName + " using " + receiver + "." + inMapName);
// do not always add the receiver, e.g. for local variables this creates a mess
// outMaps.add(receiver + "." + inMapName);
// just copy name for now, better than doing nothing
outMaps.add(inMapName);
}
// TODO: look at code in NullnessFlow and decide whether there
// are more cases to copy.
}
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, KeyFor.class);
builder.setValue("value", outMaps);
AnnotationMirror newAnno = builder.build();
outType.removeAnnotation(KeyFor.class);
outType.addAnnotation(newAnno);
}
if (outType.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType declaredType = (AnnotatedDeclaredType) outType;
Map<AnnotatedTypeMirror, AnnotatedTypeMirror> mapping = new HashMap<AnnotatedTypeMirror, AnnotatedTypeMirror>();
// Get the substituted type arguments
for (AnnotatedTypeMirror typeArgument : declaredType.getTypeArguments()) {
AnnotatedTypeMirror substTypeArgument = substituteCall(call, typeArgument);
mapping.put(typeArgument, substTypeArgument);
}
outType = declaredType.substitute(mapping);
} else if (outType.getKind() == TypeKind.ARRAY) {
AnnotatedArrayType arrayType = (AnnotatedArrayType) outType;
// Get the substituted component type
AnnotatedTypeMirror elemType = arrayType.getComponentType();
AnnotatedTypeMirror substElemType = substituteCall(call, elemType);
arrayType.setComponentType(substElemType);
// outType aliases arrayType
} else if(outType.getKind().isPrimitive() ||
outType.getKind() == TypeKind.WILDCARD ||
outType.getKind() == TypeKind.TYPEVAR) {
// TODO: for which of these should we also recursively substitute?
// System.out.println("KeyForATF: Intentionally unhandled Kind: " + outType.getKind());
} else {
// System.err.println("KeyForATF: Unknown getKind(): " + outType.getKind());
// assert false;
}
// System.out.println("result type: " + outType);
return outType;
}
示例7: incorrect1
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void incorrect1() {
String nonkey = "";
//:: error: (assignment.type.incompatible)
@KeyFor("map") String key = nonkey;
}
示例8: correct1
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void correct1() {
String nonkey = "";
@SuppressWarnings("assignment.type.incompatible")
@KeyFor("map") String key = nonkey;
}
示例9: entrySet
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void entrySet() {
KFMap<String, Object> emap = new KFHashMap<String, Object>();
Set<KFMap.Entry<@KeyFor("emap") String, Object>> es = emap.entrySet();
Set<KFMap.Entry<String, Object>> es2 = emap.entrySet();
}
示例10: method2
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
int method2(Map<Object, Foo> map, @KeyFor("map") Object key) {
return checkNotNull(map.get(key)).x;
}
示例11: KeyForAnnotatedTypeFactory
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
public KeyForAnnotatedTypeFactory(BaseTypeChecker checker) {
super(checker, false);
KEYFOR = AnnotationUtils.fromClass(elements, KeyFor.class);
UNKNOWN = AnnotationUtils.fromClass(elements, UnknownKeyFor.class);
this.postInit();
this.defaults.addAbsoluteDefault(UNKNOWN, DefaultLocation.ALL);
}
示例12: keySet
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
/**
* Returns a {@link Set} of the node ids present in this map.
*
* @return a {@link Set} of the node ids present in this map
*/
public Set<@KeyFor("this.nodeDistances") Integer> keySet() {
return nodeDistances.keySet();
}
示例13: entrySet
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
/**
* Returns a {@link Set} of the node-distance entries in this map.
*
* @return a {@link Set} of the node-distance entries in this map
*/
public Set<Map.Entry<@KeyFor("this.nodeDistances") Integer, Integer>> entrySet() {
return nodeDistances.entrySet();
}
示例14: keySet
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
@SideEffectFree public Set<@KeyFor("this") K> keySet() { throw new RuntimeException("skeleton method"); }
示例15: entrySet
import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
@SideEffectFree public Set<Map.Entry<@KeyFor("this") K, V>> entrySet() { throw new RuntimeException("skeleton method"); }