Merge
This commit is contained in:
commit
c3dc5c472c
@ -180,7 +180,7 @@ public class ClassUseWriter extends SubWriterHolderWriter {
|
||||
Map<String,List<ProgramElementDoc>> map = new HashMap<>();
|
||||
List<? extends ProgramElementDoc> list= classMap.get(classdoc.qualifiedName());
|
||||
if (list != null) {
|
||||
list.sort(Util.makeComparatorForClassUse());
|
||||
Collections.sort(list, Util.makeComparatorForClassUse());
|
||||
for (ProgramElementDoc doc : list) {
|
||||
PackageDoc pkg = doc.containingPackage();
|
||||
pkgSet.add(pkg);
|
||||
|
@ -112,7 +112,7 @@ public class IndexBuilder {
|
||||
*/
|
||||
protected void sortIndexMap() {
|
||||
for (List<Doc> docs : indexmap.values()) {
|
||||
docs.sort(Util.makeComparatorForIndexUse());
|
||||
Collections.sort(docs, Util.makeComparatorForIndexUse());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,10 +694,10 @@ public abstract class Symbol extends AnnoConstruct implements Element {
|
||||
}
|
||||
|
||||
/**
|
||||
* A total ordering between type symbols that refines the
|
||||
* A partial ordering between type symbols that refines the
|
||||
* class inheritance graph.
|
||||
*
|
||||
* Typevariables always precede other kinds of symbols.
|
||||
* Type variables always precede other kinds of symbols.
|
||||
*/
|
||||
public final boolean precedes(TypeSymbol that, Types types) {
|
||||
if (this == that)
|
||||
|
@ -1446,11 +1446,19 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
|
||||
*/
|
||||
public enum InferenceBound {
|
||||
/** upper bounds */
|
||||
UPPER,
|
||||
UPPER {
|
||||
public InferenceBound complement() { return LOWER; }
|
||||
},
|
||||
/** lower bounds */
|
||||
LOWER,
|
||||
LOWER {
|
||||
public InferenceBound complement() { return UPPER; }
|
||||
},
|
||||
/** equality constraints */
|
||||
EQ
|
||||
EQ {
|
||||
public InferenceBound complement() { return EQ; }
|
||||
};
|
||||
|
||||
public abstract InferenceBound complement();
|
||||
}
|
||||
|
||||
/** inference variable bounds */
|
||||
@ -1636,6 +1644,9 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
|
||||
//only change bounds if request comes from substBounds
|
||||
super.addBound(ib, bound, types, update);
|
||||
}
|
||||
else if (bound.hasTag(UNDETVAR) && !((UndetVar) bound).isCaptured()) {
|
||||
((UndetVar) bound).addBound(ib.complement(), this, types, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,31 +151,31 @@ public class Types {
|
||||
};
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="lowerBound">
|
||||
// <editor-fold defaultstate="collapsed" desc="wildLowerBound">
|
||||
/**
|
||||
* The "lvalue conversion".<br>
|
||||
* The lower bound of most types is the type
|
||||
* itself. Wildcards, on the other hand have upper
|
||||
* and lower bounds.
|
||||
* @param t a type
|
||||
* @return the lower bound of the given type
|
||||
* Get a wildcard's lower bound, returning non-wildcards unchanged.
|
||||
* @param t a type argument, either a wildcard or a type
|
||||
*/
|
||||
public Type lowerBound(Type t) {
|
||||
return lowerBound.visit(t);
|
||||
public Type wildLowerBound(Type t) {
|
||||
if (t.hasTag(WILDCARD)) {
|
||||
WildcardType w = (WildcardType) t;
|
||||
return w.isExtendsBound() ? syms.botType : wildLowerBound(w.type);
|
||||
}
|
||||
else return t;
|
||||
}
|
||||
// where
|
||||
private final MapVisitor<Void> lowerBound = new MapVisitor<Void>() {
|
||||
// </editor-fold>
|
||||
|
||||
@Override
|
||||
public Type visitWildcardType(WildcardType t, Void ignored) {
|
||||
return t.isExtendsBound() ? syms.botType : visit(t.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitCapturedType(CapturedType t, Void ignored) {
|
||||
return visit(t.getLowerBound());
|
||||
}
|
||||
};
|
||||
// <editor-fold defaultstate="collapsed" desc="cvarLowerBound">
|
||||
/**
|
||||
* Get a capture variable's lower bound, returning other types unchanged.
|
||||
* @param t a type
|
||||
*/
|
||||
public Type cvarLowerBound(Type t) {
|
||||
if (t.hasTag(TYPEVAR) && ((TypeVar) t).isCaptured()) {
|
||||
return cvarLowerBound(t.getLowerBound());
|
||||
}
|
||||
else return t;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="isUnbounded">
|
||||
@ -827,9 +827,14 @@ public class Types {
|
||||
return true;
|
||||
}
|
||||
|
||||
Type lower = lowerBound(s);
|
||||
if (s != lower)
|
||||
return isSubtype(capture ? capture(t) : t, lower, false);
|
||||
// Generally, if 's' is a type variable, recur on lower bound; but
|
||||
// for alpha <: CAP, alpha should get upper bound CAP
|
||||
if (!t.hasTag(UNDETVAR)) {
|
||||
// TODO: JDK-8039198, bounds checking sometimes passes in a wildcard as s
|
||||
Type lower = cvarLowerBound(wildLowerBound(s));
|
||||
if (s != lower)
|
||||
return isSubtype(capture ? capture(t) : t, lower, false);
|
||||
}
|
||||
|
||||
return isSubtype.visit(capture ? capture(t) : t, s);
|
||||
}
|
||||
@ -1136,7 +1141,7 @@ public class Types {
|
||||
return visit(s, t);
|
||||
|
||||
if (s.isSuperBound() && !s.isExtendsBound())
|
||||
return visit(t, upperBound(s)) && visit(t, lowerBound(s));
|
||||
return visit(t, upperBound(s)) && visit(t, wildLowerBound(s));
|
||||
|
||||
if (t.isCompound() && s.isCompound()) {
|
||||
if (!visit(supertype(t), supertype(s)))
|
||||
@ -1291,7 +1296,7 @@ public class Types {
|
||||
break;
|
||||
}
|
||||
case SUPER: {
|
||||
Type bound = lowerBound(s);
|
||||
Type bound = wildLowerBound(s);
|
||||
undetvar.addBound(InferenceBound.LOWER, bound, this);
|
||||
break;
|
||||
}
|
||||
@ -1384,9 +1389,9 @@ public class Types {
|
||||
// t.isSuperBound()
|
||||
// || isSubtypeNoCapture(upperBound(s), U(t)));
|
||||
// System.err.format(" %s L(%s) <: L(%s) %s = %s%n",
|
||||
// L(t), t, s, lowerBound(s),
|
||||
// L(t), t, s, wildLowerBound(s),
|
||||
// t.isExtendsBound()
|
||||
// || isSubtypeNoCapture(L(t), lowerBound(s)));
|
||||
// || isSubtypeNoCapture(L(t), wildLowerBound(s)));
|
||||
// System.err.println();
|
||||
// }
|
||||
|
||||
@ -1398,7 +1403,7 @@ public class Types {
|
||||
// debugContainsType(t, s);
|
||||
return isSameWildcard(t, s)
|
||||
|| isCaptureOf(s, t)
|
||||
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) &&
|
||||
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), wildLowerBound(s))) &&
|
||||
(t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t))));
|
||||
}
|
||||
}
|
||||
@ -1760,7 +1765,7 @@ public class Types {
|
||||
if (s.isExtendsBound())
|
||||
return !isCastableRecursive(t.type, upperBound(s));
|
||||
else if (s.isSuperBound())
|
||||
return notSoftSubtypeRecursive(lowerBound(s), t.type);
|
||||
return notSoftSubtypeRecursive(wildLowerBound(s), t.type);
|
||||
} else if (t.isSuperBound()) {
|
||||
if (s.isExtendsBound())
|
||||
return notSoftSubtypeRecursive(t.type, upperBound(s));
|
||||
@ -1770,19 +1775,13 @@ public class Types {
|
||||
};
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="lowerBoundArgtypes">
|
||||
/**
|
||||
* Returns the lower bounds of the formals of a method.
|
||||
*/
|
||||
public List<Type> lowerBoundArgtypes(Type t) {
|
||||
return lowerBounds(t.getParameterTypes());
|
||||
// <editor-fold defaultstate="collapsed" desc="cvarLowerBounds">
|
||||
public List<Type> cvarLowerBounds(List<Type> ts) {
|
||||
return map(ts, cvarLowerBoundMapping);
|
||||
}
|
||||
public List<Type> lowerBounds(List<Type> ts) {
|
||||
return map(ts, lowerBoundMapping);
|
||||
}
|
||||
private final Mapping lowerBoundMapping = new Mapping("lowerBound") {
|
||||
private final Mapping cvarLowerBoundMapping = new Mapping("cvarLowerBound") {
|
||||
public Type apply(Type t) {
|
||||
return lowerBound(t);
|
||||
return cvarLowerBound(t);
|
||||
}
|
||||
};
|
||||
// </editor-fold>
|
||||
@ -2251,7 +2250,8 @@ public class Types {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="makeCompoundType">
|
||||
/**
|
||||
* Make a compound type from non-empty list of types
|
||||
* Make a compound type from non-empty list of types. The list should be
|
||||
* ordered according to {@link Symbol#precedes(TypeSymbol,Types)}.
|
||||
*
|
||||
* @param bounds the types from which the compound type is formed
|
||||
* @param supertype is objectType if all bounds are interfaces,
|
||||
@ -3340,12 +3340,15 @@ public class Types {
|
||||
* Insert a type in a closure
|
||||
*/
|
||||
public List<Type> insert(List<Type> cl, Type t) {
|
||||
if (cl.isEmpty() || t.tsym.precedes(cl.head.tsym, this)) {
|
||||
if (cl.isEmpty()) {
|
||||
return cl.prepend(t);
|
||||
} else if (cl.head.tsym.precedes(t.tsym, this)) {
|
||||
return insert(cl.tail, t).prepend(cl.head);
|
||||
} else {
|
||||
} else if (t.tsym == cl.head.tsym) {
|
||||
return cl;
|
||||
} else if (t.tsym.precedes(cl.head.tsym, this)) {
|
||||
return cl.prepend(t);
|
||||
} else {
|
||||
// t comes after head, or the two are unrelated
|
||||
return insert(cl.tail, t).prepend(cl.head);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3357,12 +3360,15 @@ public class Types {
|
||||
return cl2;
|
||||
} else if (cl2.isEmpty()) {
|
||||
return cl1;
|
||||
} else if (cl1.head.tsym == cl2.head.tsym) {
|
||||
return union(cl1.tail, cl2.tail).prepend(cl1.head);
|
||||
} else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) {
|
||||
return union(cl1.tail, cl2).prepend(cl1.head);
|
||||
} else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) {
|
||||
return union(cl1, cl2.tail).prepend(cl2.head);
|
||||
} else {
|
||||
return union(cl1.tail, cl2.tail).prepend(cl1.head);
|
||||
// unrelated types
|
||||
return union(cl1.tail, cl2).prepend(cl1.head);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3472,18 +3478,31 @@ public class Types {
|
||||
private List<Type> closureMin(List<Type> cl) {
|
||||
ListBuffer<Type> classes = new ListBuffer<>();
|
||||
ListBuffer<Type> interfaces = new ListBuffer<>();
|
||||
Set<Type> toSkip = new HashSet<>();
|
||||
while (!cl.isEmpty()) {
|
||||
Type current = cl.head;
|
||||
if (current.isInterface())
|
||||
interfaces.append(current);
|
||||
else
|
||||
classes.append(current);
|
||||
ListBuffer<Type> candidates = new ListBuffer<>();
|
||||
for (Type t : cl.tail) {
|
||||
if (!isSubtypeNoCapture(current, t))
|
||||
candidates.append(t);
|
||||
boolean keep = !toSkip.contains(current);
|
||||
if (keep && current.hasTag(TYPEVAR)) {
|
||||
// skip lower-bounded variables with a subtype in cl.tail
|
||||
for (Type t : cl.tail) {
|
||||
if (isSubtypeNoCapture(t, current)) {
|
||||
keep = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cl = candidates.toList();
|
||||
if (keep) {
|
||||
if (current.isInterface())
|
||||
interfaces.append(current);
|
||||
else
|
||||
classes.append(current);
|
||||
for (Type t : cl.tail) {
|
||||
// skip supertypes of 'current' in cl.tail
|
||||
if (isSubtypeNoCapture(current, t))
|
||||
toSkip.add(t);
|
||||
}
|
||||
}
|
||||
cl = cl.tail;
|
||||
}
|
||||
return classes.appendList(interfaces).toList();
|
||||
}
|
||||
@ -3643,7 +3662,19 @@ public class Types {
|
||||
return s;
|
||||
|
||||
List<Type> closure = union(closure(t), closure(s));
|
||||
List<Type> bounds = closureMin(closure);
|
||||
return glbFlattened(closure, t);
|
||||
}
|
||||
//where
|
||||
/**
|
||||
* Perform glb for a list of non-primitive, non-error, non-compound types;
|
||||
* redundant elements are removed. Bounds should be ordered according to
|
||||
* {@link Symbol#precedes(TypeSymbol,Types)}.
|
||||
*
|
||||
* @param flatBounds List of type to glb
|
||||
* @param errT Original type to use if the result is an error type
|
||||
*/
|
||||
private Type glbFlattened(List<Type> flatBounds, Type errT) {
|
||||
List<Type> bounds = closureMin(flatBounds);
|
||||
|
||||
if (bounds.isEmpty()) { // length == 0
|
||||
return syms.objectType;
|
||||
@ -3651,11 +3682,21 @@ public class Types {
|
||||
return bounds.head;
|
||||
} else { // length > 1
|
||||
int classCount = 0;
|
||||
for (Type bound : bounds)
|
||||
if (!bound.isInterface())
|
||||
List<Type> lowers = List.nil();
|
||||
for (Type bound : bounds) {
|
||||
if (!bound.isInterface()) {
|
||||
classCount++;
|
||||
if (classCount > 1)
|
||||
return createErrorType(t);
|
||||
Type lower = cvarLowerBound(bound);
|
||||
if (bound != lower && !lower.hasTag(BOT))
|
||||
lowers = insert(lowers, lower);
|
||||
}
|
||||
}
|
||||
if (classCount > 1) {
|
||||
if (lowers.isEmpty())
|
||||
return createErrorType(errT);
|
||||
else
|
||||
return glbFlattened(union(bounds, lowers), errT);
|
||||
}
|
||||
}
|
||||
return makeCompoundType(bounds);
|
||||
}
|
||||
@ -3929,8 +3970,13 @@ public class Types {
|
||||
Si.lower = Ti.getSuperBound();
|
||||
break;
|
||||
}
|
||||
if (Si.bound == Si.lower)
|
||||
Type tmpBound = Si.bound.hasTag(UNDETVAR) ? ((UndetVar)Si.bound).qtype : Si.bound;
|
||||
Type tmpLower = Si.lower.hasTag(UNDETVAR) ? ((UndetVar)Si.lower).qtype : Si.lower;
|
||||
if (!Si.bound.hasTag(ERROR) &&
|
||||
!Si.lower.hasTag(ERROR) &&
|
||||
isSameType(tmpBound, tmpLower, false)) {
|
||||
currentS.head = Si.bound;
|
||||
}
|
||||
}
|
||||
currentA = currentA.tail;
|
||||
currentT = currentT.tail;
|
||||
@ -4135,7 +4181,7 @@ public class Types {
|
||||
if (source.isExtendsBound())
|
||||
adaptRecursive(upperBound(source), upperBound(target));
|
||||
else if (source.isSuperBound())
|
||||
adaptRecursive(lowerBound(source), lowerBound(target));
|
||||
adaptRecursive(wildLowerBound(source), wildLowerBound(target));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -4147,7 +4193,7 @@ public class Types {
|
||||
Type val = mapping.get(source.tsym);
|
||||
if (val != null) {
|
||||
if (val.isSuperBound() && target.isSuperBound()) {
|
||||
val = isSubtype(lowerBound(val), lowerBound(target))
|
||||
val = isSubtype(wildLowerBound(val), wildLowerBound(target))
|
||||
? target : val;
|
||||
} else if (val.isExtendsBound() && target.isExtendsBound()) {
|
||||
val = isSubtype(upperBound(val), upperBound(target))
|
||||
@ -4261,7 +4307,7 @@ public class Types {
|
||||
}
|
||||
|
||||
public Type visitType(Type t, Void s) {
|
||||
return high ? upperBound(t) : lowerBound(t);
|
||||
return high ? upperBound(t) : t;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3214,6 +3214,14 @@ public class Attr extends JCTree.Visitor {
|
||||
result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo);
|
||||
}
|
||||
|
||||
/** Report dependencies.
|
||||
* @param from The enclosing class sym
|
||||
* @param to The found identifier that the class depends on.
|
||||
*/
|
||||
public void reportDependence(Symbol from, Symbol to) {
|
||||
// Override if you want to collect the reported dependencies.
|
||||
}
|
||||
|
||||
public void visitSelect(JCFieldAccess tree) {
|
||||
// Determine the expected kind of the qualifier expression.
|
||||
int skind = 0;
|
||||
@ -3341,6 +3349,10 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
env.info.selectSuper = selectSuperPrev;
|
||||
result = checkId(tree, site, sym, env, resultInfo);
|
||||
|
||||
if ((tree.sym.kind & TYP) != 0) {
|
||||
reportDependence(env.enclClass.sym, tree.sym);
|
||||
}
|
||||
}
|
||||
//where
|
||||
/** Determine symbol referenced by a Select expression,
|
||||
|
@ -626,7 +626,7 @@ public class Check {
|
||||
} else if (a.isExtendsBound()) {
|
||||
return types.isCastable(bound, types.upperBound(a), types.noWarnings);
|
||||
} else if (a.isSuperBound()) {
|
||||
return !types.notSoftSubtype(types.lowerBound(a), bound);
|
||||
return !types.notSoftSubtype(types.wildLowerBound(a), bound);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -2730,7 +2730,7 @@ public class Check {
|
||||
if (types.isSameType(type, syms.stringType)) return;
|
||||
if ((type.tsym.flags() & Flags.ENUM) != 0) return;
|
||||
if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return;
|
||||
if (types.lowerBound(type).tsym == syms.classType.tsym) return;
|
||||
if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return;
|
||||
if (types.isArray(type) && !types.isArray(types.elemtype(type))) {
|
||||
validateAnnotationType(pos, types.elemtype(type));
|
||||
return;
|
||||
|
@ -1458,7 +1458,7 @@ public class Infer {
|
||||
Type solve(UndetVar uv, InferenceContext inferenceContext) {
|
||||
Infer infer = inferenceContext.infer();
|
||||
List<Type> hibounds = filterBounds(uv, inferenceContext);
|
||||
//note: lobounds should have at least one element
|
||||
//note: hibounds should have at least one element
|
||||
Type owntype = hibounds.tail.tail == null ? hibounds.head : infer.types.glb(hibounds);
|
||||
if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
|
||||
throw infer.inferenceException
|
||||
|
@ -1552,7 +1552,7 @@ public class Resolve {
|
||||
currentResolutionContext.methodCheck =
|
||||
prevResolutionContext.methodCheck.mostSpecificCheck(actuals, !allowBoxing);
|
||||
Type mst = instantiate(env, site, m2, null,
|
||||
adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null,
|
||||
adjustArgs(types.cvarLowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null,
|
||||
allowBoxing, useVarargs, noteWarner);
|
||||
return mst != null &&
|
||||
!noteWarner.hasLint(Lint.LintCategory.UNCHECKED);
|
||||
|
@ -130,6 +130,12 @@ public class ClassReader {
|
||||
**/
|
||||
public boolean preferSource;
|
||||
|
||||
/**
|
||||
* Switch: Search classpath and sourcepath for classes before the
|
||||
* bootclasspath
|
||||
*/
|
||||
public boolean userPathsFirst;
|
||||
|
||||
/**
|
||||
* The currently selected profile.
|
||||
*/
|
||||
@ -270,6 +276,7 @@ public class ClassReader {
|
||||
saveParameterNames = options.isSet("save-parameter-names");
|
||||
cacheCompletionFailure = options.isUnset("dev");
|
||||
preferSource = "source".equals(options.get("-Xprefer"));
|
||||
userPathsFirst = options.isSet(XXUSERPATHSFIRST);
|
||||
|
||||
profile = Profile.instance(context);
|
||||
|
||||
@ -2649,7 +2656,7 @@ public class ClassReader {
|
||||
if (c.owner == p) // it might be an inner class
|
||||
p.members_field.enter(c);
|
||||
}
|
||||
} else if (c.classfile != null && (c.flags_field & seen) == 0) {
|
||||
} else if (!preferCurrent && c.classfile != null && (c.flags_field & seen) == 0) {
|
||||
// if c.classfile == null, we are currently compiling this class
|
||||
// and no further action is necessary.
|
||||
// if (c.flags_field & seen) != 0, we have already encountered
|
||||
@ -2695,20 +2702,33 @@ public class ClassReader {
|
||||
|
||||
private boolean verbosePath = true;
|
||||
|
||||
// Set to true when the currently selected file should be kept
|
||||
private boolean preferCurrent;
|
||||
|
||||
/** Load directory of package into members scope.
|
||||
*/
|
||||
private void fillIn(PackageSymbol p) throws IOException {
|
||||
if (p.members_field == null) p.members_field = new Scope(p);
|
||||
String packageName = p.fullname.toString();
|
||||
if (p.members_field == null)
|
||||
p.members_field = new Scope(p);
|
||||
|
||||
preferCurrent = false;
|
||||
if (userPathsFirst) {
|
||||
scanUserPaths(p);
|
||||
preferCurrent = true;
|
||||
scanPlatformPath(p);
|
||||
} else {
|
||||
scanPlatformPath(p);
|
||||
scanUserPaths(p);
|
||||
}
|
||||
verbosePath = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans class path and source path for files in given package.
|
||||
*/
|
||||
private void scanUserPaths(PackageSymbol p) throws IOException {
|
||||
Set<JavaFileObject.Kind> kinds = getPackageFileKinds();
|
||||
|
||||
fillIn(p, PLATFORM_CLASS_PATH,
|
||||
fileManager.list(PLATFORM_CLASS_PATH,
|
||||
packageName,
|
||||
EnumSet.of(JavaFileObject.Kind.CLASS),
|
||||
false));
|
||||
|
||||
Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
|
||||
classKinds.remove(JavaFileObject.Kind.SOURCE);
|
||||
boolean wantClassFiles = !classKinds.isEmpty();
|
||||
@ -2748,6 +2768,7 @@ public class ClassReader {
|
||||
}
|
||||
}
|
||||
|
||||
String packageName = p.fullname.toString();
|
||||
if (wantSourceFiles && !haveSourcePath) {
|
||||
fillIn(p, CLASS_PATH,
|
||||
fileManager.list(CLASS_PATH,
|
||||
@ -2768,7 +2789,17 @@ public class ClassReader {
|
||||
sourceKinds,
|
||||
false));
|
||||
}
|
||||
verbosePath = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans platform class path for files in given package.
|
||||
*/
|
||||
private void scanPlatformPath(PackageSymbol p) throws IOException {
|
||||
fillIn(p, PLATFORM_CLASS_PATH,
|
||||
fileManager.list(PLATFORM_CLASS_PATH,
|
||||
p.fullname.toString(),
|
||||
EnumSet.of(JavaFileObject.Kind.CLASS),
|
||||
false));
|
||||
}
|
||||
// where
|
||||
private void fillIn(PackageSymbol p,
|
||||
|
@ -416,6 +416,8 @@ public enum Option {
|
||||
|
||||
XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"),
|
||||
|
||||
XXUSERPATHSFIRST("-XXuserPathsFirst", "opt.userpathsfirst", HIDDEN, BASIC),
|
||||
|
||||
// see enum PkgInfo
|
||||
XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"),
|
||||
|
||||
|
@ -240,6 +240,8 @@ javac.opt.printRounds=\
|
||||
Print information about rounds of annotation processing
|
||||
javac.opt.printProcessorInfo=\
|
||||
Print information about which annotations a processor is asked to process
|
||||
javac.opt.userpathsfirst=\
|
||||
Search classpath and sourcepath for classes before the bootclasspath instead of after
|
||||
javac.opt.prefer=\
|
||||
Specify which file to read when both a source file and class file are found for an implicitly compiled class
|
||||
javac.opt.AT=\
|
||||
|
@ -313,7 +313,7 @@ public class Source implements Comparable<Source> {
|
||||
int sp = fn.lastIndexOf(File.separatorChar);
|
||||
String pkg = "";
|
||||
if (sp != -1) {
|
||||
pkg = fn.substring(0,sp);
|
||||
pkg = fn.substring(0,sp).replace('/','.');
|
||||
}
|
||||
// Is this a module-info.java file?
|
||||
if (fn.endsWith("module-info.java")) {
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.tools.sjavac.comp;
|
||||
|
||||
import com.sun.tools.javac.comp.Attr;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
|
||||
/** Subclass to Attr that overrides reportDepedence.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own
|
||||
* risk. This code and its internal interfaces are subject to change
|
||||
* or deletion without notice.</b></p>
|
||||
*/
|
||||
public class AttrWithDeps extends Attr {
|
||||
|
||||
/** The dependency database
|
||||
*/
|
||||
protected Dependencies deps;
|
||||
|
||||
protected AttrWithDeps(Context context) {
|
||||
super(context);
|
||||
deps = Dependencies.instance(context);
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(attrKey, new Context.Factory<Attr>() {
|
||||
public Attr make(Context c) {
|
||||
Attr instance = new AttrWithDeps(c);
|
||||
c.put(Attr.class, instance);
|
||||
return instance;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Collect dependencies in the enclosing class
|
||||
* @param from The enclosing class sym
|
||||
* @param to The enclosing classes references this sym.
|
||||
* */
|
||||
@Override
|
||||
public void reportDependence(Symbol from, Symbol to) {
|
||||
// Capture dependencies between the packages.
|
||||
deps.collect(from.packge().fullname, to.packge().fullname);
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
import com.sun.tools.javac.util.BaseFileManager;
|
||||
import com.sun.tools.javac.util.StringUtils;
|
||||
import com.sun.tools.sjavac.comp.AttrWithDeps;
|
||||
import com.sun.tools.sjavac.comp.Dependencies;
|
||||
import com.sun.tools.sjavac.comp.JavaCompilerWithDeps;
|
||||
import com.sun.tools.sjavac.comp.SmartFileManager;
|
||||
@ -131,6 +132,7 @@ public class CompilerThread implements Runnable {
|
||||
context = new Context();
|
||||
context.put(JavaFileManager.class, smartFileManager);
|
||||
ResolveWithDeps.preRegister(context);
|
||||
AttrWithDeps.preRegister(context);
|
||||
JavaCompilerWithDeps.preRegister(context, this);
|
||||
subTasks = new ArrayList<>();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 1234567
|
||||
* @bug 8026564
|
||||
* @summary The parts of a fully-qualified type can't be annotated.
|
||||
* @author Werner Dietl
|
||||
* @compile/fail/ref=CantAnnotatePackages.out -XDrawDiagnostics CantAnnotatePackages.java
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 1234567
|
||||
* @bug 8026564
|
||||
* @summary A missing annotation type in a type variable bound
|
||||
* should result in the same errors with and without an
|
||||
* annotation processor.
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary ensure that declaration annotations are not allowed on
|
||||
* new array expressions
|
||||
* @author Werner Dietl
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary ensure that declaration annotations are not allowed on
|
||||
* method receiver types
|
||||
* @author Werner Dietl
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary ensure that declaration annotations are not allowed on
|
||||
* wildcards
|
||||
* @author Werner Dietl
|
||||
|
@ -25,7 +25,7 @@ import java.lang.annotation.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary new type annotation location: anonymous class creation
|
||||
* @author Werner Dietl
|
||||
* @compile AnonymousClass.java
|
||||
|
@ -25,7 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary Test population of reference info for instance and class initializers
|
||||
* @author Werner Dietl
|
||||
* @compile -g Driver.java ReferenceInfoUtil.java Initializers.java
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for anonymous class.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main AnonymousClassTest
|
||||
*/
|
||||
|
||||
public class AnonymousClassTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new AnonymousClassTest().test(new Object(){}.getClass(), "AnonymousClassTest.java");
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for inner class.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main InnerClassTest
|
||||
*/
|
||||
|
||||
public class InnerClassTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new InnerClassTest().test(Inner.class, "InnerClassTest.java");
|
||||
}
|
||||
|
||||
class Inner {
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for local class.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main LocalClassTest
|
||||
*/
|
||||
|
||||
public class LocalClassTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
class Local {
|
||||
}
|
||||
new LocalClassTest().test(Local.class, "LocalClassTest.java");
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for complex structure of nested classes and other types.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main MixTest
|
||||
*/
|
||||
|
||||
public class MixTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new InnerClass();
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable run = () -> {
|
||||
class Local {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class innerInAnonymous {
|
||||
}
|
||||
};
|
||||
|
||||
new MixTest().run();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
String fileName = getClass().getName() + ".java";
|
||||
test("MixTest", fileName);
|
||||
test("MixTest$1", fileName);
|
||||
test("MixTest$InnerClass", fileName);
|
||||
test("MixTest$1$innerInAnonymous", fileName);
|
||||
test("MixTest$1$1Local", fileName);
|
||||
test("MixTest$InnerClass$innerEnum", fileName);
|
||||
test("MixTest$InnerClass$innerInterface", fileName);
|
||||
test("MixTest$InnerClass$innerEnum$innerClassInnerEnum", fileName);
|
||||
test("MixTest$InnerClass$innerEnum$innerClassInnerEnum$1InnerLocal", fileName);
|
||||
}
|
||||
|
||||
static class InnerClass {
|
||||
private InnerClass() {
|
||||
}
|
||||
|
||||
enum innerEnum {
|
||||
E;
|
||||
|
||||
class innerClassInnerEnum {
|
||||
void method() {
|
||||
class InnerLocal {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@interface innerInterface {
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for file compiled without debug information.
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @compile -g:none NoSourceFileAttribute.java
|
||||
* @run main NoSourceFileAttribute
|
||||
*/
|
||||
|
||||
import com.sun.tools.classfile.Attribute;
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
import com.sun.tools.classfile.ConstantPoolException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class NoSourceFileAttribute extends TestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new NoSourceFileAttribute().test();
|
||||
}
|
||||
|
||||
public void test() throws IOException, ConstantPoolException {
|
||||
assertNull(
|
||||
ClassFile.read(getClassFile(NoSourceFileAttribute.class)).getAttribute(Attribute.SourceFile),
|
||||
"Classfile should have no SourceFile attribute when compiled without debug information.");
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import com.sun.tools.classfile.Attribute;
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
import com.sun.tools.classfile.SourceFile_attribute;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
public class SourceFileTestBase extends TestBase {
|
||||
|
||||
protected void test(Class<?> classToTest, String fileName) throws Exception {
|
||||
assertAttributePresent(ClassFile.read(getClassFile(classToTest)), fileName);
|
||||
}
|
||||
|
||||
protected void test(String classToTest, String fileName) throws Exception {
|
||||
assertAttributePresent(ClassFile.read(getClassFile(classToTest + ".class")), fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile sourceCode and for all "classesToTest" checks SourceFile attribute.
|
||||
*/
|
||||
protected void compileAndTest(String sourceCode, String... classesToTest) throws Exception {
|
||||
|
||||
Map<String, ? extends JavaFileObject> classes = compile(sourceCode);
|
||||
String fileName = ToolBox.getJavaFileNameFromSource(sourceCode);
|
||||
for (String className : classesToTest) {
|
||||
assertAttributePresent(ClassFile.read(classes.get(className).openInputStream()), fileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertAttributePresent(ClassFile classFile, String fileName) throws Exception {
|
||||
|
||||
//We need to count attributes with the same names because there is no appropriate API in the ClassFile.
|
||||
|
||||
List<SourceFile_attribute> sourceFileAttributes = new ArrayList<>();
|
||||
for (Attribute a : classFile.attributes.attrs) {
|
||||
if (Attribute.SourceFile.equals(a.getName(classFile.constant_pool))) {
|
||||
sourceFileAttributes.add((SourceFile_attribute) a);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(sourceFileAttributes.size(), 1, "Should be the only SourceFile attribute");
|
||||
|
||||
SourceFile_attribute attribute = sourceFileAttributes.get(0);
|
||||
|
||||
assertEquals(classFile.constant_pool.getUTF8Info(attribute.attribute_name_index).value,
|
||||
Attribute.SourceFile, "Incorrect attribute name");
|
||||
assertEquals(classFile.constant_pool.getUTF8Info(attribute.sourcefile_index).value, fileName,
|
||||
"Incorrect source file name");
|
||||
assertEquals(attribute.attribute_length, 2, "Incorrect attribute length");
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for synthetic class.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main SyntheticClassTest
|
||||
*/
|
||||
|
||||
public class SyntheticClassTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Inner();
|
||||
|
||||
new SyntheticClassTest().test("SyntheticClassTest$1", "SyntheticClassTest.java");
|
||||
}
|
||||
|
||||
static class Inner {
|
||||
private Inner() {
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary sourcefile attribute test for two type in one file.
|
||||
* @bug 8040129
|
||||
* @library /tools/javac/lib ../lib
|
||||
* @build SourceFileTestBase TestBase InMemoryFileManager ToolBox
|
||||
* @run main TopLevelClassesOneFileTest
|
||||
*/
|
||||
|
||||
public class TopLevelClassesOneFileTest extends SourceFileTestBase {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TopLevelClassesOneFileTest().run();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
int failed = 0;
|
||||
for (Type firstType : Type.values()) {
|
||||
for (Type secondType : Type.values()) {
|
||||
if (firstType != secondType) {
|
||||
try {
|
||||
compileAndTest("public " + firstType.source + secondType.source,
|
||||
firstType.name(), secondType.name());
|
||||
} catch (AssertionFailedException | CompilationException ex) {
|
||||
System.err.println("Failed with public type " + firstType.name()
|
||||
+ " and type " + secondType.name());
|
||||
ex.printStackTrace();
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed > 0)
|
||||
throw new AssertionFailedException("Test failed. Failed cases count = " + failed + " .See log.");
|
||||
}
|
||||
|
||||
enum Type {
|
||||
CLASS("class CLASS{}"),
|
||||
INTERFACE("interface INTERFACE{}"),
|
||||
ENUM("enum ENUM{;}"),
|
||||
ANNOTATION("@interface ANNOTATION{}");
|
||||
|
||||
String source;
|
||||
|
||||
Type(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
T7086586.java:14:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>))
|
||||
T7086586.java:15:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>))
|
||||
T7086586.java:16:23: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>))
|
||||
T7086586.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>))
|
||||
T7086586.java:14:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.String)
|
||||
T7086586.java:15:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Number)
|
||||
T7086586.java:16:31: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Exception)
|
||||
T7086586.java:17:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistentMethod, , , (compiler.misc.location: kindname.interface, java.util.List<compiler.misc.type.captureof: 1, ?>, null)
|
||||
4 errors
|
||||
|
@ -23,9 +23,10 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7086586
|
||||
* @bug 7086586 8033718
|
||||
*
|
||||
* @summary Inference producing null type argument
|
||||
* @summary Inference producing null type argument; inference ignores capture
|
||||
* variable as upper bound
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
@ -40,8 +41,8 @@ public class T7086586b {
|
||||
assertionCount++;
|
||||
}
|
||||
|
||||
<T> void m(List<? super T> dummy) { assertTrue(false); }
|
||||
<T> void m(Object dummy) { assertTrue(true); }
|
||||
<T> void m(List<? super T> dummy) { assertTrue(true); }
|
||||
<T> void m(Object dummy) { assertTrue(false); }
|
||||
|
||||
void test(List<?> l) {
|
||||
m(l);
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8033718
|
||||
* @author dlsmith
|
||||
* @summary GLB for two capture variables with lower bounds
|
||||
* @compile LowerBoundGLB.java
|
||||
*/
|
||||
|
||||
public class LowerBoundGLB {
|
||||
|
||||
interface Box<T> {
|
||||
T get();
|
||||
void set(T arg);
|
||||
}
|
||||
|
||||
<T> T doGLB(Box<? super T> b1, Box<? super T> b2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
void test(Box<? super String> l1, Box<? super CharSequence> l2) {
|
||||
doGLB(l1, l2).substring(3);
|
||||
}
|
||||
|
||||
}
|
24
langtools/test/tools/javac/generics/wildcards/RefQueue.java
Normal file
24
langtools/test/tools/javac/generics/wildcards/RefQueue.java
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class RefQueue<S> { }
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8033437
|
||||
* @summary inconsistent generic types behaviour when compiling together vs. separate
|
||||
* @compile RefQueue.java
|
||||
* @compile RefQueueBug.java
|
||||
*/
|
||||
|
||||
public class RefQueueBug<T> {
|
||||
final RefQueue<? super T> queue = new RefQueue<>();
|
||||
public static void main(String[] args) {
|
||||
RefQueueBug<Object> r = new RefQueueBug<>();
|
||||
RefQueue<Object> q = r.queue;
|
||||
}
|
||||
}
|
385
langtools/test/tools/javac/options/xprefer/XPreferTest.java
Normal file
385
langtools/test/tools/javac/options/xprefer/XPreferTest.java
Normal file
@ -0,0 +1,385 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Tests which path is used to represent an implicit type given
|
||||
* various xprefer arguments and multiple .class / .java files involved.
|
||||
* @bug 8028196
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
import javax.tools.ToolProvider;
|
||||
|
||||
|
||||
public class XPreferTest {
|
||||
|
||||
enum Dir {
|
||||
SOURCE_PATH("src"),
|
||||
CLASS_PATH("cp"),
|
||||
BOOT_PATH("boot");
|
||||
|
||||
File file;
|
||||
Dir(String dir) {
|
||||
this.file = new File(dir);
|
||||
}
|
||||
}
|
||||
|
||||
enum ImplicitOption {
|
||||
XPREFER_SOURCE("-Xprefer:source"),
|
||||
XPREFER_NEWER("-Xprefer:newer"),
|
||||
XXUSERPATHSFIRST("-XXuserPathsFirst");
|
||||
|
||||
final String optionString;
|
||||
private ImplicitOption(String optionString) {
|
||||
this.optionString = optionString;
|
||||
}
|
||||
}
|
||||
|
||||
final static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
|
||||
final static File OUTPUT_DIR = new File("out");
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
|
||||
// Initialize test-directories
|
||||
OUTPUT_DIR.mkdir();
|
||||
for (Dir dir : Dir.values())
|
||||
dir.file.mkdir();
|
||||
|
||||
int testCaseCounter = 0;
|
||||
|
||||
for (List<Dir> dirSubset : SubseqIter.subseqsOf(Dir.values())) {
|
||||
|
||||
if (dirSubset.isEmpty())
|
||||
continue;
|
||||
|
||||
for (ImplicitOption policy : ImplicitOption.values()) {
|
||||
for (List<Dir> dirOrder : PermutationIterator.permutationsOf(dirSubset)) {
|
||||
new TestCase(dirOrder, policy, testCaseCounter++).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class TestCase {
|
||||
|
||||
String classId;
|
||||
List<Dir> dirs;
|
||||
ImplicitOption option;
|
||||
|
||||
public TestCase(List<Dir> dirs, ImplicitOption option, int testCaseNum) {
|
||||
this.dirs = dirs;
|
||||
this.option = option;
|
||||
this.classId = "XPreferTestImplicit" + testCaseNum;
|
||||
}
|
||||
|
||||
void run() throws Exception {
|
||||
|
||||
System.out.println("Test:");
|
||||
System.out.println(" Class id: " + classId);
|
||||
System.out.println(" Dirs: " + dirs);
|
||||
System.out.println(" Option: " + option);
|
||||
|
||||
createTestFiles();
|
||||
String compileOutput = compile();
|
||||
Dir actual = getChosenOrigin(compileOutput);
|
||||
Dir expected = getExpectedOrigin();
|
||||
|
||||
System.out.println(" Expected: " + expected);
|
||||
System.out.println(" Actual: " + actual);
|
||||
|
||||
if (actual != expected) {
|
||||
throw new RuntimeException(String.format(
|
||||
"Expected javac to choose %s but %s was chosen",
|
||||
expected == null ? "<none>" : expected.name(),
|
||||
actual == null ? "<none>" : actual.name()));
|
||||
}
|
||||
}
|
||||
|
||||
Dir getExpectedOrigin() {
|
||||
|
||||
Dir newest = dirs.get(0);
|
||||
|
||||
switch (option) {
|
||||
|
||||
case XPREFER_NEWER:
|
||||
|
||||
Dir cls = dirs.contains(Dir.BOOT_PATH) ? Dir.BOOT_PATH
|
||||
: dirs.contains(Dir.CLASS_PATH) ? Dir.CLASS_PATH
|
||||
: null;
|
||||
|
||||
Dir src = dirs.contains(Dir.SOURCE_PATH) ? Dir.SOURCE_PATH
|
||||
: null;
|
||||
|
||||
for (Dir dir : dirs)
|
||||
if (dir == cls || dir == src)
|
||||
return dir;
|
||||
|
||||
return null;
|
||||
|
||||
case XPREFER_SOURCE:
|
||||
return dirs.contains(Dir.SOURCE_PATH) ? Dir.SOURCE_PATH
|
||||
: dirs.contains(Dir.BOOT_PATH) ? Dir.BOOT_PATH
|
||||
: dirs.contains(Dir.CLASS_PATH) ? Dir.CLASS_PATH
|
||||
: null;
|
||||
|
||||
case XXUSERPATHSFIRST:
|
||||
|
||||
for (Dir dir : dirs)
|
||||
if (dir == Dir.SOURCE_PATH || dir == Dir.CLASS_PATH)
|
||||
return dir;
|
||||
|
||||
// Neither SOURCE_PATH nor CLASS_PATH among dirs. Safty check:
|
||||
if (newest != Dir.BOOT_PATH)
|
||||
throw new AssertionError("Expected to find BOOT_PATH");
|
||||
|
||||
return Dir.BOOT_PATH;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Unhandled policy case.");
|
||||
}
|
||||
}
|
||||
|
||||
Dir getChosenOrigin(String compilerOutput) {
|
||||
Scanner s = new Scanner(compilerOutput);
|
||||
while (s.hasNextLine()) {
|
||||
String line = s.nextLine();
|
||||
if (line.matches("\\[loading .*\\]"))
|
||||
for (Dir dir : Dir.values())
|
||||
if (line.contains(dir.file.getName() + "/" + classId))
|
||||
return dir;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String compile() throws IOException {
|
||||
|
||||
// Create a class that references classId
|
||||
File explicit = new File("ExplicitClass.java");
|
||||
FileWriter filewriter = new FileWriter(explicit);
|
||||
filewriter.append("class ExplicitClass { " + classId + " implicit; }");
|
||||
filewriter.close();
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
com.sun.tools.javac.Main.compile(new String[] {
|
||||
"-verbose",
|
||||
option.optionString,
|
||||
"-sourcepath", Dir.SOURCE_PATH.file.getPath(),
|
||||
"-classpath", Dir.CLASS_PATH.file.getPath(),
|
||||
"-Xbootclasspath/p:" + Dir.BOOT_PATH.file.getPath(),
|
||||
"-d", XPreferTest.OUTPUT_DIR.getPath(),
|
||||
explicit.getPath()
|
||||
}, new PrintWriter(sw));
|
||||
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
void createTestFiles() throws IOException {
|
||||
long t = 1390927988755L; // Tue Jan 28 17:53:08 CET 2014
|
||||
for (Dir dir : dirs) {
|
||||
createFile(dir).setLastModified(t);
|
||||
t -= 10000;
|
||||
}
|
||||
}
|
||||
|
||||
File createFile(Dir dir) throws IOException {
|
||||
File src = new File(dir.file, classId + ".java");
|
||||
try (FileWriter w = new FileWriter(src)) {
|
||||
w.append("public class " + classId + " {}");
|
||||
}
|
||||
// If we're after the ".java" representation, we're done...
|
||||
if(dir == Dir.SOURCE_PATH)
|
||||
return src;
|
||||
// ...otherwise compile into a ".class".
|
||||
CompilationTask task = comp.getTask(null, null, null, null, null,
|
||||
comp.getStandardFileManager(null, null, null).getJavaFileObjects(src));
|
||||
File dest = new File(dir.file, classId + ".class");
|
||||
if(!task.call() || !dest.exists())
|
||||
throw new RuntimeException("Compilation failure.");
|
||||
src.delete();
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Iterator for iteration over all subsequences of a given list.
|
||||
class SubseqIter<T> implements Iterator<List<T>> {
|
||||
|
||||
List<T> elements;
|
||||
boolean[] states;
|
||||
|
||||
public SubseqIter(Collection<T> c) {
|
||||
states = new boolean[c.size()];
|
||||
elements = new ArrayList<T>(c);
|
||||
}
|
||||
|
||||
public static <T> Iterable<List<T>> subseqsOf(final T[] t) {
|
||||
return new Iterable<List<T>>() {
|
||||
@Override
|
||||
public Iterator<List<T>> iterator() {
|
||||
return new SubseqIter<T>(Arrays.asList(t));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Roll values in 'states' from index i and forward.
|
||||
// Return true if we wrapped back to zero.
|
||||
private boolean roll(int i) {
|
||||
if (i == states.length)
|
||||
return true;
|
||||
if (!roll(i + 1))
|
||||
return false;
|
||||
states[i] = !states[i];
|
||||
return !states[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> next() {
|
||||
if (!hasNext())
|
||||
throw new NoSuchElementException();
|
||||
// Include element i if states[i] is true
|
||||
List<T> next = new ArrayList<T>();
|
||||
for (int i = 0; i < states.length; i++)
|
||||
if (states[i])
|
||||
next.add(elements.get(i));
|
||||
if (roll(0))
|
||||
states = null; // hasNext() == false from now on.
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return states != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
class PermutationIterator<T> implements Iterator<List<T>> {
|
||||
|
||||
DirInt head;
|
||||
boolean hasNext = true;
|
||||
|
||||
public PermutationIterator(List<T> toPermute) {
|
||||
ListIterator<T> iter = toPermute.listIterator();
|
||||
if (iter.hasNext())
|
||||
head = new DirInt(iter.nextIndex(), iter.next());
|
||||
DirInt prev = head;
|
||||
while (iter.hasNext()) {
|
||||
DirInt di = new DirInt(iter.nextIndex(), iter.next());
|
||||
di.left = prev;
|
||||
prev.right = di;
|
||||
prev = di;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Iterable<List<T>> permutationsOf(final List<T> list) {
|
||||
return new Iterable<List<T>>() {
|
||||
public Iterator<List<T>> iterator() {
|
||||
return new PermutationIterator<>(list);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> next() {
|
||||
// Prep return value based on current state
|
||||
List<T> result = new ArrayList<>();
|
||||
for (DirInt di = head; di != null; di = di.right)
|
||||
result.add(di.object);
|
||||
|
||||
// Step state forward
|
||||
DirInt maxMob = null;
|
||||
for (DirInt di = head; di != null; di = di.right)
|
||||
if (di.isMobile() && (maxMob == null || di.val > maxMob.val))
|
||||
maxMob = di;
|
||||
|
||||
if (maxMob == null) {
|
||||
hasNext = false;
|
||||
} else {
|
||||
maxMob.swapWithAdjacent();
|
||||
for (DirInt di = head; di != null; di = di.right)
|
||||
if (di.val > maxMob.val)
|
||||
di.facingLeft = !di.facingLeft;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final class DirInt {
|
||||
int val;
|
||||
T object;
|
||||
DirInt left, right;
|
||||
boolean facingLeft = true;
|
||||
|
||||
public DirInt(int val, T object) {
|
||||
this.val = val;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
boolean isMobile() {
|
||||
DirInt adjacent = facingLeft ? left : right;
|
||||
return adjacent != null && val > adjacent.val;
|
||||
}
|
||||
|
||||
public void swapWithAdjacent() {
|
||||
DirInt l = facingLeft ? left : this;
|
||||
DirInt r = facingLeft ? this : right;
|
||||
if (head == l) head = r;
|
||||
if (l.left != null) l.left.right = r;
|
||||
if (r.right != null) r.right.left = l;
|
||||
l.right = r.right;
|
||||
r.left = l.left;
|
||||
r.right = l;
|
||||
l.left = r;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 1234567
|
||||
* @bug 8013852
|
||||
* @summary Annotations on types
|
||||
* @library /tools/javac/lib
|
||||
* @ignore
|
||||
|
@ -83,6 +83,7 @@ class SJavac {
|
||||
compileWithInvisibleSources();
|
||||
compileCircularSources();
|
||||
compileExcludingDependency();
|
||||
incrementalCompileTestFullyQualifiedRef();
|
||||
|
||||
delete(gensrc);
|
||||
delete(gensrc2);
|
||||
@ -95,15 +96,15 @@ class SJavac {
|
||||
System.out.println("\nInitial compile of gensrc.");
|
||||
System.out.println("----------------------------");
|
||||
populate(gensrc,
|
||||
"alfa/AINT.java",
|
||||
"package alfa; public interface AINT { void aint(); }",
|
||||
"alfa/omega/AINT.java",
|
||||
"package alfa.omega; public interface AINT { void aint(); }",
|
||||
|
||||
"alfa/A.java",
|
||||
"package alfa; public class A implements AINT { "+
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A implements AINT { "+
|
||||
"public final static int DEFINITION = 17; public void aint() { } }",
|
||||
|
||||
"alfa/AA.java",
|
||||
"package alfa;"+
|
||||
"alfa/omega/AA.java",
|
||||
"package alfa.omega;"+
|
||||
"// A package private class, not contributing to the public api.\n"+
|
||||
"class AA {"+
|
||||
" // A properly nested static inner class.\n"+
|
||||
@ -127,7 +128,7 @@ class SJavac {
|
||||
"package beta;public interface BINT { void foo(); }",
|
||||
|
||||
"beta/B.java",
|
||||
"package beta; import alfa.A; public class B {"+
|
||||
"package beta; import alfa.omega.A; public class B {"+
|
||||
"private int b() { return A.DEFINITION; } native void foo(); }");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1",
|
||||
@ -151,16 +152,16 @@ class SJavac {
|
||||
System.out.println("\nTesting that deleting AA.java deletes all");
|
||||
System.out.println("generated inner class as well as AA.class");
|
||||
System.out.println("-----------------------------------------");
|
||||
removeFrom(gensrc, "alfa/AA.java");
|
||||
removeFrom(gensrc, "alfa/omega/AA.java");
|
||||
compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1",
|
||||
"--server:portfile=testserver,background=false", "--log=debug");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
verifyThatFilesHaveBeenRemoved(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/AA$1.class",
|
||||
"bin/alfa/AA$AAAA.class",
|
||||
"bin/alfa/AA$AAA.class",
|
||||
"bin/alfa/AAAAA.class",
|
||||
"bin/alfa/AA.class");
|
||||
"bin/alfa/omega/AA$1.class",
|
||||
"bin/alfa/omega/AA$AAAA.class",
|
||||
"bin/alfa/omega/AA$AAA.class",
|
||||
"bin/alfa/omega/AAAAA.class",
|
||||
"bin/alfa/omega/AA.class");
|
||||
|
||||
previous_bin_state = new_bin_state;
|
||||
Map<String,Long> new_headers_state = collectState(headers);
|
||||
@ -175,8 +176,8 @@ class SJavac {
|
||||
System.out.println("Since we did not modify the native api of B.");
|
||||
System.out.println("-------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,"alfa/A.java",
|
||||
"package alfa; public class A implements AINT { "+
|
||||
populate(gensrc,"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A implements AINT { "+
|
||||
"public final static int DEFINITION = 18; public void aint() { } private void foo() { } }");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1",
|
||||
@ -184,8 +185,8 @@ class SJavac {
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
|
||||
verifyNewerFiles(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/A.class",
|
||||
"bin/alfa/AINT.class",
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/alfa/omega/AINT.class",
|
||||
"bin/beta/B.class",
|
||||
"bin/beta/BINT.class",
|
||||
"bin/javac_state");
|
||||
@ -202,7 +203,7 @@ class SJavac {
|
||||
System.out.println("---------------------------------------------------------");
|
||||
|
||||
populate(gensrc,"beta/B.java",
|
||||
"package beta; import alfa.A; public class B {"+
|
||||
"package beta; import alfa.omega.A; public class B {"+
|
||||
"private int b() { return A.DEFINITION; } }");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1",
|
||||
@ -226,7 +227,7 @@ class SJavac {
|
||||
System.out.println("------------------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,"beta/B.java",
|
||||
"package beta; import alfa.A; public class B {"+
|
||||
"package beta; import alfa.omega.A; public class B {"+
|
||||
"private int b() { return A.DEFINITION; } "+
|
||||
"@java.lang.annotation.Native final static int alfa = 42; }");
|
||||
|
||||
@ -252,7 +253,7 @@ class SJavac {
|
||||
System.out.println("-------------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,"beta/B.java",
|
||||
"package beta; import alfa.A; public class B {"+
|
||||
"package beta; import alfa.omega.A; public class B {"+
|
||||
"private int b() { return A.DEFINITION; } "+
|
||||
"@java.lang.annotation.Native final static int alfa = 43; }");
|
||||
|
||||
@ -282,8 +283,8 @@ class SJavac {
|
||||
delete(bin);
|
||||
previous_bin_state = collectState(bin);
|
||||
|
||||
populate(gensrc,"alfa/A.java",
|
||||
"package alfa; import beta.B; import gamma.C; public class A { B b; C c; }",
|
||||
populate(gensrc,"alfa/omega/A.java",
|
||||
"package alfa.omega; import beta.B; import gamma.C; public class A { B b; C c; }",
|
||||
"beta/B.java",
|
||||
"package beta; public class B { broken",
|
||||
"gamma/C.java",
|
||||
@ -297,7 +298,7 @@ class SJavac {
|
||||
"--server:portfile=testserver,background=false");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/A.class",
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/beta/B.class",
|
||||
"bin/gamma/C.class",
|
||||
"bin/javac_state");
|
||||
@ -325,8 +326,8 @@ class SJavac {
|
||||
delete(bin);
|
||||
previous_bin_state = collectState(bin);
|
||||
|
||||
populate(gensrc,"alfa/A.java",
|
||||
"package alfa; import beta.B; import gamma.C; public class A { B b; C c; }");
|
||||
populate(gensrc,"alfa/omega/A.java",
|
||||
"package alfa.omega; import beta.B; import gamma.C; public class A { B b; C c; }");
|
||||
populate(gensrc2,"beta/B.java",
|
||||
"package beta; public class B { broken",
|
||||
"gamma/C.java",
|
||||
@ -341,7 +342,7 @@ class SJavac {
|
||||
System.out.println("The first compile went well!");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/A.class",
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/javac_state");
|
||||
|
||||
System.out.println("----- Compile with exluded beta went well!");
|
||||
@ -365,18 +366,18 @@ class SJavac {
|
||||
delete(bin);
|
||||
previous_bin_state = collectState(bin);
|
||||
|
||||
populate(gensrc,"alfa/A.java",
|
||||
"package alfa; public class A { beta.B b; }",
|
||||
populate(gensrc,"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { beta.B b; }",
|
||||
"beta/B.java",
|
||||
"package beta; public class B { gamma.C c; }",
|
||||
"gamma/C.java",
|
||||
"package gamma; public class C { alfa.A a; }");
|
||||
"package gamma; public class C { alfa.omega.A a; }");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-h", "headers", "-j", "3",
|
||||
"--server:portfile=testserver,background=false","--log=debug");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/A.class",
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/beta/B.class",
|
||||
"bin/gamma/C.class",
|
||||
"bin/javac_state");
|
||||
@ -396,20 +397,57 @@ class SJavac {
|
||||
previous_bin_state = collectState(bin);
|
||||
|
||||
populate(gensrc,
|
||||
"alfa/A.java",
|
||||
"package alfa; public class A { beta.B b; }",
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { beta.B b; }",
|
||||
"beta/B.java",
|
||||
"package beta; public class B { }");
|
||||
|
||||
compile("-x", "beta", "-src", "gensrc", "-x", "alfa", "-sourcepath", "gensrc",
|
||||
compile("-x", "beta", "-src", "gensrc", "-x", "alfa/omega", "-sourcepath", "gensrc",
|
||||
"-d", "bin", "--server:portfile=testserver,background=false");
|
||||
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/A.class",
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/javac_state");
|
||||
}
|
||||
|
||||
void incrementalCompileTestFullyQualifiedRef() throws Exception {
|
||||
System.out.println("Verify that \"alfa.omega.A a;\" does create a proper dependency.");
|
||||
System.out.println("----------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { "+
|
||||
" public final static int DEFINITION = 18; "+
|
||||
" public void hello() { }"+
|
||||
"}",
|
||||
"beta/B.java",
|
||||
"package beta; public class B { "+
|
||||
" public void world() { alfa.omega.A a; }"+
|
||||
"}");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-j", "1",
|
||||
"--server:portfile=testserver,background=false", "--log=debug");
|
||||
Map<String,Long> previous_bin_state = collectState(bin);
|
||||
|
||||
// Change pubapi of A, this should trigger a recompile of B.
|
||||
populate(gensrc,
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { "+
|
||||
" public final static int DEFINITION = 19; "+
|
||||
" public void hello() { }"+
|
||||
"}");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-j", "1",
|
||||
"--server:portfile=testserver,background=false", "--log=debug");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
|
||||
verifyNewerFiles(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/beta/B.class",
|
||||
"bin/javac_state");
|
||||
}
|
||||
|
||||
void removeFrom(Path dir, String... args) throws IOException {
|
||||
for (String filename : args) {
|
||||
Path p = dir.resolve(filename);
|
||||
|
@ -26,6 +26,8 @@
|
||||
* @summary Test all aspects of sjavac.
|
||||
*
|
||||
* @bug 8004658
|
||||
* @bug 8042441
|
||||
* @bug 8042699
|
||||
* @summary Add internal smart javac wrapper to solve JEP 139
|
||||
*
|
||||
* @run main SJavacWrapper
|
||||
|
Loading…
Reference in New Issue
Block a user