langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java
--- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java Fri Jun 06 16:00:59 2014 -0400
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java Fri Jun 06 16:08:46 2014 -0400
@@ -41,7 +41,7 @@
public static final int IGNORE_VALUE = -321;
public static List<TypeAnnotation> extendedAnnotationsOf(ClassFile cf) {
- List<TypeAnnotation> annos = new ArrayList<TypeAnnotation>();
+ List<TypeAnnotation> annos = new ArrayList<>();
findAnnotations(cf, annos);
return annos;
}
@@ -119,128 +119,6 @@
}
}
- /////////////////// TA Position Builder ///////////////////////
- /* TODO: comment out this dead code. Was this unfinished code that was
- * supposed to be used somewhere? The tests pass without this.
- private static class TAPositionBuilder {
- private TypeAnnotation.Position pos = new TypeAnnotation.Position();
-
- private TAPositionBuilder() { }
-
- public TypeAnnotation.Position build() { return pos; }
-
- public static TAPositionBuilder ofType(TypeAnnotation.TargetType type) {
- TAPositionBuilder builder = new TAPositionBuilder();
- builder.pos.type = type;
- return builder;
- }
-
- public TAPositionBuilder atOffset(int offset) {
- switch (pos.type) {
- // type cast
- case TYPECAST:
- // instanceof
- case INSTANCEOF:
- // new expression
- case NEW:
- pos.offset = offset;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atLocalPosition(int offset, int length, int index) {
- switch (pos.type) {
- // local variable
- case LOCAL_VARIABLE:
- pos.lvarOffset = new int[] { offset };
- pos.lvarLength = new int[] { length };
- pos.lvarIndex = new int[] { index };
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atParameterIndex(int index) {
- switch (pos.type) {
- // type parameters
- case CLASS_TYPE_PARAMETER:
- case METHOD_TYPE_PARAMETER:
- // method parameter
- case METHOD_FORMAL_PARAMETER:
- pos.parameter_index = index;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atParamBound(int param, int bound) {
- switch (pos.type) {
- // type parameters bounds
- case CLASS_TYPE_PARAMETER_BOUND:
- case METHOD_TYPE_PARAMETER_BOUND:
- pos.parameter_index = param;
- pos.bound_index = bound;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atWildcardPosition(TypeAnnotation.Position pos) {
- switch (pos.type) {
- // wildcards
- case WILDCARD_BOUND:
- pos.wildcard_position = pos;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atTypeIndex(int index) {
- switch (pos.type) {
- // class extends or implements clauses
- case CLASS_EXTENDS:
- // throws
- case THROWS:
- pos.type_index = index;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atOffsetWithIndex(int offset, int index) {
- switch (pos.type) {
- // method type argument: wasn't specified
- case NEW_TYPE_ARGUMENT:
- case METHOD_TYPE_ARGUMENT:
- pos.offset = offset;
- pos.type_index = index;
- break;
- default:
- throw new IllegalArgumentException("invalid field for given type: " + pos.type);
- }
- return this;
- }
-
- public TAPositionBuilder atGenericLocation(Integer ...loc) {
- pos.location = Arrays.asList(loc);
- pos.type = pos.type.getGenericComplement();
- return this;
- }
- }*/
-
/////////////////////// Equality testing /////////////////////
private static boolean areEquals(int a, int b) {
return a == b || a == IGNORE_VALUE || b == IGNORE_VALUE;
@@ -264,21 +142,18 @@
}
public static boolean areEquals(TypeAnnotation.Position p1, TypeAnnotation.Position p2) {
- if (p1 == p2)
- return true;
- if (p1 == null || p2 == null)
- return false;
+ return p1 == p2 || !(p1 == null || p2 == null) &&
+ p1.type == p2.type &&
+ (p1.location.equals(p2.location)) &&
+ areEquals(p1.offset, p2.offset) &&
+ areEquals(p1.lvarOffset, p2.lvarOffset) &&
+ areEquals(p1.lvarLength, p2.lvarLength) &&
+ areEquals(p1.lvarIndex, p2.lvarIndex) &&
+ areEquals(p1.bound_index, p2.bound_index) &&
+ areEquals(p1.parameter_index, p2.parameter_index) &&
+ areEquals(p1.type_index, p2.type_index) &&
+ areEquals(p1.exception_index, p2.exception_index);
- return ((p1.type == p2.type)
- && (p1.location.equals(p2.location))
- && areEquals(p1.offset, p2.offset)
- && areEquals(p1.lvarOffset, p2.lvarOffset)
- && areEquals(p1.lvarLength, p2.lvarLength)
- && areEquals(p1.lvarIndex, p2.lvarIndex)
- && areEquals(p1.bound_index, p2.bound_index)
- && areEquals(p1.parameter_index, p2.parameter_index)
- && areEquals(p1.type_index, p2.type_index)
- && areEquals(p1.exception_index, p2.exception_index));
}
private static TypeAnnotation findAnnotation(String name, List<TypeAnnotation> annotations, ClassFile cf) throws InvalidIndex, UnexpectedEntry {
@@ -306,9 +181,6 @@
if (actual == null)
throw new ComparisionException("Expected annotation not found: " + aName);
- // TODO: you currently get an exception if the test case does not use all necessary
- // annotation attributes, e.g. forgetting the offset for a local variable.
- // It would be nicer to give an understandable warning instead.
if (!areEquals(expected, actual.position)) {
throw new ComparisionException("Unexpected position for annotation : " + aName +
"\n Expected: " + expected.toString() +