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


Java KeyFor类代码示例

本文整理汇总了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;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:20,代码来源:MapGetHeuristics.java

示例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());
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:16,代码来源:KeyForChecked.java

示例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);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:15,代码来源:KeyForChecked.java

示例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;
}
 
开发者ID:SERG-Delft,项目名称:jpacman-framework,代码行数:21,代码来源:CollisionInteractionMap.java

示例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;
    }
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:43,代码来源:KeyForVisitor.java

示例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;
  }
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:80,代码来源:KeyForAnnotatedTypeFactory.java

示例7: incorrect1

import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void incorrect1() {
    String nonkey = "";
    //:: error: (assignment.type.incompatible)
    @KeyFor("map") String key = nonkey;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:6,代码来源:KeyForChecked.java

示例8: correct1

import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
void correct1() {
    String nonkey = "";
    @SuppressWarnings("assignment.type.incompatible")
    @KeyFor("map") String key = nonkey;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:6,代码来源:KeyForChecked.java

示例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();
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:6,代码来源:KeyForChecked.java

示例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;
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:4,代码来源:DependentCrash.java

示例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);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:11,代码来源:KeyForAnnotatedTypeFactory.java

示例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();
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:9,代码来源:NodeDistanceMap.java

示例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();
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:9,代码来源:NodeDistanceMap.java

示例14: keySet

import org.checkerframework.checker.nullness.qual.KeyFor; //导入依赖的package包/类
@SideEffectFree public Set<@KeyFor("this") K> keySet() { throw new RuntimeException("skeleton method"); } 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:2,代码来源:WeakHashMap.java

示例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"); } 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:2,代码来源:WeakHashMap.java


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