public Pair<ClassRepr, Set<UsageRepr.Usage>> getResult() {
      final ClassRepr repr =
          myTakeIntoAccount
              ? new ClassRepr(
                  myContext,
                  myAccess,
                  myFileName,
                  myName,
                  myContext.get(mySignature),
                  myContext.get(mySuperClass),
                  myInterfaces,
                  myNestedClasses,
                  myFields,
                  myMethods,
                  myTargets,
                  myRetentionPolicy,
                  myContext.get(myOuterClassName.get()),
                  myLocalClassFlag.get(),
                  myUsages)
              : null;

      if (repr != null) {
        repr.updateClassUsages(myContext, myUsages);
      }

      return new Pair<ClassRepr, Set<UsageRepr.Usage>>(repr, myUsages);
    }
Example #2
0
 public static void main(String[] args) {
   Holder<Apple> Apple = new Holder<Apple>(new Apple());
   Apple d = Apple.get();
   Apple.set(d);
   Holder<? extends Fruit> fruit = Apple;
   Fruit p = fruit.get();
   d = (Apple) fruit.get();
   try {
     Orange c = (Orange) fruit.get();
   } catch (Exception e) {
     System.out.println(e);
   }
   System.out.println(fruit.equals(d));
 }
Example #3
0
  static void f2(List<Holder<?>> list) {
    System.out.println("Calling methods for the List: ");
    System.out.println("list = " + list);
    System.out.println("Adding Integer, String, Double");
    list.add(new Holder<Integer>(1));
    list.add(new Holder<String>("two"));
    list.add(new Holder<Double>(3.0));
    System.out.println("list = " + list);
    System.out.println("Elements of list: ");
    for (Holder h : list) System.out.println("h.get() = " + h.get());
    System.out.println("Adding Float");
    list.add(3, new Holder<Float>(4.0f));
    System.out.println("list = " + list);
    System.out.println("Elements of list: ");
    for (Holder h : list) System.out.println("h.get() = " + h.get());
    System.out.println("list.clear()");
    list.clear();
    System.out.println("list = " + list);
    Collection<Holder<?>> c = new ArrayList<Holder<?>>();
    c.add(new Holder<String>("one"));
    c.add(new Holder<Float>(2.0f));
    c.add(new Holder<Double>(3.0));
    list.addAll(c);
    System.out.println("Adding String, Float, Double");
    System.out.println("list = " + list);
    System.out.println("Elements of list: ");
    for (Holder h : list)
      System.out.println("h.get() = " + h.get().getClass().getSimpleName() + " " + h.get());
    list.add(3, new Holder<String>("four"));
    System.out.println("Elements of list: ");
    for (Holder h : list)
      System.out.println("h.get() = " + h.get().getClass().getSimpleName() + " " + h.get());
    Object listClone = ((ArrayList) list).clone();
    System.out.println("((ArrayList)list).clone() = " + listClone);
    System.out.println(
        "((ArrayList)list).clone().getClass() = " + ((ArrayList) list).clone().getClass());
    // Appears to be an ArrayList, but cannot assign:
    // ArrayList alistClone = ((ArrayList)list).clone(); // found Object
    System.out.println("Replacing element with h4, new Holder<Integer>(4)");
    Holder<Integer> h4 = new Holder<Integer>(4);
    list.set(3, h4);
    System.out.println("Elements of list Holders: ");
    for (Holder h : list) System.out.println(h.get().getClass().getSimpleName() + " " + h.get());
    System.out.println("list.contains(list.set(3, h4): " + list.contains(list.set(3, h4)));
    System.out.println("list.contains(4): " + list.contains(4));
    System.out.println("list.contains(h4): " + list.contains(h4));
    System.out.println("Adding null member to list");
    list.add(null);
    System.out.println("list.contains(null): " + list.contains(null));
    System.out.println("list.get(0).get(): " + list.get(0).get());
    System.out.println("list.indexOf(h4) = " + list.indexOf(h4));
    System.out.println("list.indexOf(null) = " + list.indexOf(null));
    System.out.println("list.isEmpty(): " + list.isEmpty());
    System.out.println("list.lastIndexOf(null) = " + list.lastIndexOf(null));
    System.out.println("Removing index 0");
    list.remove(0);
    System.out.println("Elements of list Holders: ");
    for (Holder h : list) {
      if (h == null) System.out.println("null");
      else System.out.println(h.get().getClass().getSimpleName() + " " + h.get());
    }
    System.out.println("Removing null");
    System.out.println("Elements of list Holders: ");
    for (Holder h : list) {
      if (h == null) System.out.println("null");
      else System.out.println(h.get().getClass().getSimpleName() + " " + h.get());
    }
    // Error: removeRange has protected access:
    // ((ArrayList)list).removeRange(0,2);
    System.out.println("list.size() = " + list.size());
    Object[] oa = list.toArray();
    System.out.println("list.toArray() = ");
    for (int i = 0; i < oa.length; i++) System.out.print(oa[i] + " ");
    System.out.println();
    Holder[] ha = ((ArrayList<Holder<?>>) list).toArray(new Holder[4]);
    System.out.println("(ArrayList<Holder<?>>list).toArray(new Holder[4]) = ");
    for (int i = 0; i < ha.length; i++) System.out.print(ha[i] + " ");
    System.out.println();
    System.out.println("Holder[4] Holders are holding: ");
    for (Holder h : ha) {
      if (h == null) System.out.println("null");
      else System.out.println(h.get());
    }
    System.out.println();

    System.out.println("Calling methods for the Holder: ");
    System.out.println("list = " + list);
    System.out.println("Three Holders (one null) in list:");
    for (int i = 0; i < list.size(); i++) {
      if (list.get(i) == null) System.out.println("null");
      else System.out.println(list.get(i).getClass().getSimpleName());
    }
    list.remove(3);
    System.out.println("Holders are holding:");
    for (Holder h : list) System.out.println(h.get());
    Holder<?> h1 = list.get(0);
    Holder<?> h2 = list.get(1);
    Holder<?> h3 = list.get(2);
    System.out.println(
        list.get(0).getClass()
            + ": "
            + list.get(0).get().getClass().getSimpleName()
            + ", "
            + list.get(0).get());
    System.out.println(
        list.get(1).getClass()
            + ": "
            + list.get(1).get().getClass().getSimpleName()
            + ", "
            + list.get(1).get());
    System.out.println(
        list.get(2).getClass()
            + ": "
            + list.get(2).get().getClass().getSimpleName()
            + ", "
            + list.get(2).get());
    // Error: cannot set <?> to int or Object:
    // h3.set(5);
    // h2.set(new Object());

  }
Example #4
0
 public static void main(String[] args) {
   Holder<Character> charHolder = new Holder<Character>();
   Holder<Byte> byteHolder = new Holder<Byte>();
   Holder<Short> shortHolder = new Holder<Short>();
   Holder<Integer> intHolder = new Holder<Integer>();
   Holder<Long> longHolder = new Holder<Long>();
   Holder<Float> floatHolder = new Holder<Float>();
   Holder<Double> doubleHolder = new Holder<Double>();
   // Autoboxing and autounboxing work:
   charHolder.set('a');
   print(charHolder.get() + ", ");
   println(charHolder.get().getClass());
   char c = charHolder.get();
   println("char c = charHolder.get() = " + c);
   byte b = 1;
   byteHolder.set(b);
   print(byteHolder.get() + ", ");
   println(byteHolder.get().getClass());
   byte bb = byteHolder.get();
   println("byte bb = byteHolder.get() = " + bb);
   short s = 1;
   shortHolder.set(s);
   print(shortHolder.get() + ", ");
   println(shortHolder.get().getClass());
   short ss = shortHolder.get();
   println("short ss = shortHolder.get() = " + ss);
   intHolder.set(1);
   print(intHolder.get() + ". ");
   println(intHolder.get().getClass());
   int i = intHolder.get();
   println("int i = intHolder.get() = " + i);
   long l = 2;
   longHolder.set(l);
   print(longHolder.get() + ", ");
   println(longHolder.get().getClass());
   long ll = longHolder.get();
   println("long ll = longHolder.get() = " + ll);
   float f = 1f;
   floatHolder.set(f);
   print(floatHolder.get() + ", ");
   println(floatHolder.get().getClass());
   float ff = floatHolder.get();
   println("float ff = floatHolder.get() = " + ff);
   double d = 1.1;
   doubleHolder.set(d);
   print(doubleHolder.get() + ", ");
   println(doubleHolder.get().getClass());
   double dd = doubleHolder.get();
   println("double dd = doubleHolder.get() = " + dd);
 }
Example #5
0
  public static void main(String[] args) {
    Holder<Apple> apple = new Holder<Apple>(new Apple());

    Apple a = apple.get();
    apple.set(a);
  }
Example #6
0
 private static <T> T get(Holder<T> holder, String type, boolean mappedOnly) {
   return holder.get(mappedOnly);
 }
Example #7
0
 /**
  * Gets the build if still in memory.
  *
  * @return the actual build, or null if it has been collected
  * @see Holder#get
  */
 public @CheckForNull R get() {
   Holder<R> h = holder; // capture
   return h != null ? h.get() : null;
 }