Merge
This commit is contained in:
commit
49be988925
@ -448,10 +448,10 @@ public enum Opcode {
|
||||
|
||||
}
|
||||
|
||||
private static Opcode[] stdOpcodes = new Opcode[256];
|
||||
private static Opcode[] wideOpcodes = new Opcode[256];
|
||||
private static Opcode[] nonPrivOpcodes = new Opcode[256];
|
||||
private static Opcode[] privOpcodes = new Opcode[256];
|
||||
private static final Opcode[] stdOpcodes = new Opcode[256];
|
||||
private static final Opcode[] wideOpcodes = new Opcode[256];
|
||||
private static final Opcode[] nonPrivOpcodes = new Opcode[256];
|
||||
private static final Opcode[] privOpcodes = new Opcode[256];
|
||||
static {
|
||||
for (Opcode o: values())
|
||||
getOpcodeBlock(o.opcode >> 8)[o.opcode & 0xff] = o;
|
||||
|
@ -46,7 +46,7 @@ import com.sun.tools.doclets.internal.toolkit.Configuration;
|
||||
* @since 1.8
|
||||
*/
|
||||
abstract class DocFileFactory {
|
||||
private static Map<Configuration, DocFileFactory> factories =
|
||||
private static final Map<Configuration, DocFileFactory> factories =
|
||||
new WeakHashMap<Configuration, DocFileFactory>();
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2012, 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
|
||||
@ -49,7 +49,7 @@ class Server implements Runnable {
|
||||
private final OutputStream out;
|
||||
private final boolean isSocket;
|
||||
private static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
private static Logger logger = Logger.getLogger("com.sun.tools.javac");
|
||||
private static final Logger logger = Logger.getLogger("com.sun.tools.javac");
|
||||
static class CwdFileManager extends ForwardingJavaFileManager<JavaFileManager> {
|
||||
String cwd;
|
||||
CwdFileManager(JavaFileManager fileManager) {
|
||||
@ -69,7 +69,7 @@ class Server implements Runnable {
|
||||
// }
|
||||
}
|
||||
// static CwdFileManager fm = new CwdFileManager(tool.getStandardFileManager());
|
||||
static StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
static final StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
static {
|
||||
// Use the same file manager for all compilations. This will
|
||||
// cache jar files in the standard file manager. Use
|
||||
|
@ -74,12 +74,12 @@ public class Annotations {
|
||||
*/
|
||||
private List<Attribute.Compound> attributes = NOT_STARTED;
|
||||
/*
|
||||
* The Symbol this Annotatios belong to
|
||||
* The Symbol this Annotations belong to
|
||||
*/
|
||||
private final Symbol s;
|
||||
private final Symbol sym;
|
||||
|
||||
public Annotations(Symbol s) {
|
||||
this.s = s;
|
||||
public Annotations(Symbol sym) {
|
||||
this.sym = sym;
|
||||
}
|
||||
|
||||
public List<Attribute.Compound> getAttributes() {
|
||||
@ -102,7 +102,7 @@ public class Annotations {
|
||||
}
|
||||
|
||||
public void setAttributesWithCompletion(final Annotate.AnnotateRepeatedContext ctx) {
|
||||
Assert.check(pendingCompletion() || (!isStarted() && s.kind == PCK));
|
||||
Assert.check(pendingCompletion() || (!isStarted() && sym.kind == PCK));
|
||||
|
||||
Map<Symbol.TypeSymbol, ListBuffer<Attribute.Compound>> annotated = ctx.annotated;
|
||||
boolean atLeastOneRepeated = false;
|
||||
@ -111,7 +111,7 @@ public class Annotations {
|
||||
if (lb.size() == 1) {
|
||||
buf = buf.prepend(lb.first());
|
||||
} else { // repeated
|
||||
buf = buf.prepend(new Placeholder(lb.toList(), s));
|
||||
buf = buf.prepend(new Placeholder(lb.toList(), sym));
|
||||
atLeastOneRepeated = true;
|
||||
}
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class Annotations {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "repeated annotation pass of: " + s + " in: " + s.owner;
|
||||
return "repeated annotation pass of: " + sym + " in: " + sym.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -253,7 +253,7 @@ public class Annotations {
|
||||
|
||||
// Process repeated annotations
|
||||
Attribute.Compound validRepeated =
|
||||
ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor());
|
||||
ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor(), sym);
|
||||
|
||||
if (validRepeated != null) {
|
||||
// Check that the container isn't manually
|
||||
|
@ -307,7 +307,7 @@ public class Flags {
|
||||
}
|
||||
|
||||
// Cache of modifier sets.
|
||||
private static Map<Long, Set<Modifier>> modifierSets =
|
||||
private static final Map<Long, Set<Modifier>> modifierSets =
|
||||
new java.util.concurrent.ConcurrentHashMap<Long, Set<Modifier>>(64);
|
||||
|
||||
public static boolean isStatic(Symbol symbol) {
|
||||
@ -356,7 +356,7 @@ public class Flags {
|
||||
VARARGS("varargs"),
|
||||
PACKAGE("package");
|
||||
|
||||
String name;
|
||||
private final String name;
|
||||
|
||||
Flag(String name) {
|
||||
this.name = name;
|
||||
|
@ -110,7 +110,7 @@ public class Kinds {
|
||||
INSTANCE_INIT("kindname.instance.init"),
|
||||
PACKAGE("kindname.package");
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
KindName(String name) {
|
||||
this.name = name;
|
||||
|
@ -28,11 +28,14 @@ package com.sun.tools.javac.code;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.Options;
|
||||
import com.sun.tools.javac.util.Pair;
|
||||
|
||||
import static com.sun.tools.javac.code.Flags.*;
|
||||
|
||||
|
||||
@ -95,7 +98,8 @@ public class Lint
|
||||
private final EnumSet<LintCategory> values;
|
||||
private final EnumSet<LintCategory> suppressedValues;
|
||||
|
||||
private static Map<String, LintCategory> map = new HashMap<String,LintCategory>();
|
||||
private static final Map<String, LintCategory> map =
|
||||
new java.util.concurrent.ConcurrentHashMap<String, LintCategory>(20);
|
||||
|
||||
|
||||
protected Lint(Context context) {
|
||||
|
@ -87,7 +87,7 @@ public enum Source {
|
||||
|
||||
public final String name;
|
||||
|
||||
private static Map<String,Source> tab = new HashMap<String,Source>();
|
||||
private static final Map<String,Source> tab = new HashMap<String,Source>();
|
||||
static {
|
||||
for (Source s : values()) {
|
||||
tab.put(s.name, s);
|
||||
|
@ -166,7 +166,7 @@ public enum TargetType {
|
||||
static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22;
|
||||
|
||||
private final int targetTypeValue;
|
||||
private Set<TargetAttribute> flags;
|
||||
private final Set<TargetAttribute> flags;
|
||||
|
||||
TargetType(int targetTypeValue, TargetAttribute... attributes) {
|
||||
if (targetTypeValue < Byte.MIN_VALUE
|
||||
@ -233,10 +233,10 @@ public enum TargetType {
|
||||
return this.targetTypeValue;
|
||||
}
|
||||
|
||||
private static TargetType[] targets = null;
|
||||
private static final TargetType[] targets;
|
||||
|
||||
private static TargetType[] buildTargets() {
|
||||
TargetType[] targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
|
||||
static {
|
||||
targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
|
||||
TargetType[] alltargets = values();
|
||||
for (TargetType target : alltargets) {
|
||||
if (target.targetTypeValue >= 0)
|
||||
@ -246,13 +246,9 @@ public enum TargetType {
|
||||
if (targets[i] == null)
|
||||
targets[i] = UNKNOWN;
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
public static boolean isValidTargetTypeValue(int tag) {
|
||||
if (targets == null)
|
||||
targets = buildTargets();
|
||||
|
||||
if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
|
||||
return true;
|
||||
|
||||
@ -260,9 +256,6 @@ public enum TargetType {
|
||||
}
|
||||
|
||||
public static TargetType fromTargetTypeValue(int tag) {
|
||||
if (targets == null)
|
||||
targets = buildTargets();
|
||||
|
||||
if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
|
||||
return UNKNOWN;
|
||||
|
||||
|
@ -135,9 +135,11 @@ public enum TypeTag {
|
||||
/** This field will only be used for tags related with numeric types for
|
||||
* optimization reasons.
|
||||
*/
|
||||
private int order = 0;
|
||||
private final int order;
|
||||
|
||||
private TypeTag() {}
|
||||
private TypeTag() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
private TypeTag(int order) {
|
||||
this.order = order;
|
||||
|
@ -2849,7 +2849,7 @@ public class Types {
|
||||
}
|
||||
return tvars1;
|
||||
}
|
||||
static private Mapping newInstanceFun = new Mapping("newInstanceFun") {
|
||||
private static final Mapping newInstanceFun = new Mapping("newInstanceFun") {
|
||||
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound()); }
|
||||
};
|
||||
// </editor-fold>
|
||||
|
@ -26,7 +26,6 @@
|
||||
package com.sun.tools.javac.comp;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.code.*;
|
||||
@ -171,8 +170,8 @@ public class Annotate {
|
||||
* @param repeatingAnnotations a List of repeating annotations
|
||||
* @return a new Attribute.Compound that is the container for the repeatingAnnotations
|
||||
*/
|
||||
public Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> repeatingAnnotations) {
|
||||
return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this);
|
||||
public Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> repeatingAnnotations, Symbol sym) {
|
||||
return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this, sym);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,10 +338,11 @@ public class Annotate {
|
||||
* annotation are invalid. This method reports errors/warnings.
|
||||
*/
|
||||
private Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> annotations,
|
||||
AnnotateRepeatedContext ctx) {
|
||||
AnnotateRepeatedContext ctx,
|
||||
Symbol on) {
|
||||
Attribute.Compound firstOccurrence = annotations.head;
|
||||
List<Attribute> repeated = List.nil();
|
||||
Type origAnnoType;
|
||||
Type origAnnoType = null;
|
||||
Type arrayOfOrigAnnoType = null;
|
||||
Type targetContainerType = null;
|
||||
MethodSymbol containerValueSymbol = null;
|
||||
@ -390,6 +390,13 @@ public class Annotate {
|
||||
new Attribute.Array(arrayOfOrigAnnoType, repeated));
|
||||
annoTree = m.Annotation(new Attribute.Compound(targetContainerType,
|
||||
List.of(p)));
|
||||
|
||||
if (!chk.annotationApplicable(annoTree, on))
|
||||
log.error(annoTree.pos(), "invalid.containedby.annotation.incompatible.target", targetContainerType, origAnnoType);
|
||||
|
||||
if (!chk.validateAnnotationDeferErrors(annoTree))
|
||||
log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
|
||||
|
||||
Attribute.Compound c = enterAnnotation(annoTree,
|
||||
targetContainerType,
|
||||
ctx.env);
|
||||
@ -410,7 +417,7 @@ public class Annotate {
|
||||
// annotation's declaration, or null if it has none
|
||||
Attribute.Compound ca = origAnnoDecl.attribute(syms.containedByType.tsym);
|
||||
if (ca == null) { // has no ContainedBy annotation
|
||||
log.error(pos, "duplicate.annotation.missing.container", origAnnoType);
|
||||
log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.containedByType);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1833,13 +1833,15 @@ public class Check {
|
||||
for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) {
|
||||
Symbol s1 = e1.sym;
|
||||
Type st1 = null;
|
||||
if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types)) continue;
|
||||
if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types) ||
|
||||
(s1.flags() & SYNTHETIC) != 0) continue;
|
||||
Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false);
|
||||
if (impl != null && (impl.flags() & ABSTRACT) == 0) continue;
|
||||
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) {
|
||||
Symbol s2 = e2.sym;
|
||||
if (s1 == s2) continue;
|
||||
if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types)) continue;
|
||||
if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types) ||
|
||||
(s2.flags() & SYNTHETIC) != 0) continue;
|
||||
if (st1 == null) st1 = types.memberType(t1, s1);
|
||||
Type st2 = types.memberType(t2, s2);
|
||||
if (types.overrideEquivalent(st1, st2)) {
|
||||
@ -2890,39 +2892,54 @@ public class Check {
|
||||
}
|
||||
|
||||
/** Check an annotation value.
|
||||
*
|
||||
* @param a The annotation tree to check
|
||||
* @return true if this annotation tree is valid, otherwise false
|
||||
*/
|
||||
public void validateAnnotation(JCAnnotation a) {
|
||||
// collect an inventory of the members (sorted alphabetically)
|
||||
Set<MethodSymbol> members = new TreeSet<MethodSymbol>(new Comparator<Symbol>() {
|
||||
public int compare(Symbol t, Symbol t1) {
|
||||
return t.name.compareTo(t1.name);
|
||||
}
|
||||
});
|
||||
public boolean validateAnnotationDeferErrors(JCAnnotation a) {
|
||||
boolean res = false;
|
||||
final Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
|
||||
try {
|
||||
res = validateAnnotation(a);
|
||||
} finally {
|
||||
log.popDiagnosticHandler(diagHandler);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean validateAnnotation(JCAnnotation a) {
|
||||
boolean isValid = true;
|
||||
// collect an inventory of the annotation elements
|
||||
Set<MethodSymbol> members = new LinkedHashSet<MethodSymbol>();
|
||||
for (Scope.Entry e = a.annotationType.type.tsym.members().elems;
|
||||
e != null;
|
||||
e = e.sibling)
|
||||
if (e.sym.kind == MTH)
|
||||
members.add((MethodSymbol) e.sym);
|
||||
|
||||
// count them off as they're annotated
|
||||
// remove the ones that are assigned values
|
||||
for (JCTree arg : a.args) {
|
||||
if (!arg.hasTag(ASSIGN)) continue; // recovery
|
||||
JCAssign assign = (JCAssign) arg;
|
||||
Symbol m = TreeInfo.symbol(assign.lhs);
|
||||
if (m == null || m.type.isErroneous()) continue;
|
||||
if (!members.remove(m))
|
||||
if (!members.remove(m)) {
|
||||
isValid = false;
|
||||
log.error(assign.lhs.pos(), "duplicate.annotation.member.value",
|
||||
m.name, a.type);
|
||||
}
|
||||
}
|
||||
|
||||
// all the remaining ones better have default values
|
||||
ListBuffer<Name> missingDefaults = ListBuffer.lb();
|
||||
List<Name> missingDefaults = List.nil();
|
||||
for (MethodSymbol m : members) {
|
||||
if (m.defaultValue == null && !m.type.isErroneous()) {
|
||||
missingDefaults.append(m.name);
|
||||
missingDefaults = missingDefaults.append(m.name);
|
||||
}
|
||||
}
|
||||
missingDefaults = missingDefaults.reverse();
|
||||
if (missingDefaults.nonEmpty()) {
|
||||
isValid = false;
|
||||
String key = (missingDefaults.size() > 1)
|
||||
? "annotation.missing.default.value.1"
|
||||
: "annotation.missing.default.value";
|
||||
@ -2933,21 +2950,23 @@ public class Check {
|
||||
// repeated values in its value member
|
||||
if (a.annotationType.type.tsym != syms.annotationTargetType.tsym ||
|
||||
a.args.tail == null)
|
||||
return;
|
||||
return isValid;
|
||||
|
||||
if (!a.args.head.hasTag(ASSIGN)) return; // error recovery
|
||||
if (!a.args.head.hasTag(ASSIGN)) return false; // error recovery
|
||||
JCAssign assign = (JCAssign) a.args.head;
|
||||
Symbol m = TreeInfo.symbol(assign.lhs);
|
||||
if (m.name != names.value) return;
|
||||
if (m.name != names.value) return false;
|
||||
JCTree rhs = assign.rhs;
|
||||
if (!rhs.hasTag(NEWARRAY)) return;
|
||||
if (!rhs.hasTag(NEWARRAY)) return false;
|
||||
JCNewArray na = (JCNewArray) rhs;
|
||||
Set<Symbol> targets = new HashSet<Symbol>();
|
||||
for (JCTree elem : na.elems) {
|
||||
if (!targets.add(TreeInfo.symbol(elem))) {
|
||||
isValid = false;
|
||||
log.error(elem.pos(), "repeated.annotation.target");
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) {
|
||||
|
@ -62,9 +62,9 @@ strictfp class ConstFold {
|
||||
syms = Symtab.instance(context);
|
||||
}
|
||||
|
||||
static Integer minusOne = -1;
|
||||
static Integer zero = 0;
|
||||
static Integer one = 1;
|
||||
static final Integer minusOne = -1;
|
||||
static final Integer zero = 0;
|
||||
static final Integer one = 1;
|
||||
|
||||
/** Convert boolean to integer (true = 1, false = 0).
|
||||
*/
|
||||
|
@ -246,8 +246,8 @@ public class Flow {
|
||||
*/
|
||||
SPECULATIVE_LOOP("var.might.be.assigned.in.loop", true);
|
||||
|
||||
String errKey;
|
||||
boolean isFinal;
|
||||
final String errKey;
|
||||
final boolean isFinal;
|
||||
|
||||
FlowKind(String errKey, boolean isFinal) {
|
||||
this.errKey = errKey;
|
||||
@ -295,7 +295,7 @@ public class Flow {
|
||||
}
|
||||
};
|
||||
|
||||
JCTree.Tag treeTag;
|
||||
final JCTree.Tag treeTag;
|
||||
|
||||
private JumpKind(Tag treeTag) {
|
||||
this.treeTag = treeTag;
|
||||
|
@ -156,7 +156,7 @@ public class Resolve {
|
||||
OBJECT_INIT("object-init"),
|
||||
INTERNAL("internal");
|
||||
|
||||
String opt;
|
||||
final String opt;
|
||||
|
||||
private VerboseResolutionMode(String opt) {
|
||||
this.opt = opt;
|
||||
@ -3381,8 +3381,8 @@ public class Resolve {
|
||||
}
|
||||
};
|
||||
|
||||
boolean isBoxingRequired;
|
||||
boolean isVarargsRequired;
|
||||
final boolean isBoxingRequired;
|
||||
final boolean isVarargsRequired;
|
||||
|
||||
MethodResolutionPhase(boolean isBoxingRequired, boolean isVarargsRequired) {
|
||||
this.isBoxingRequired = isBoxingRequired;
|
||||
|
@ -83,7 +83,7 @@ public class ZipFileIndex {
|
||||
public final static long NOT_MODIFIED = Long.MIN_VALUE;
|
||||
|
||||
|
||||
private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this.
|
||||
private static final boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this.
|
||||
|
||||
private Map<RelativeDirectory, DirectoryEntry> directories =
|
||||
Collections.<RelativeDirectory, DirectoryEntry>emptyMap();
|
||||
|
@ -1360,6 +1360,16 @@ public class ClassReader implements Completer {
|
||||
void attachAnnotationDefault(final Symbol sym) {
|
||||
final MethodSymbol meth = (MethodSymbol)sym; // only on methods
|
||||
final Attribute value = readAttributeValue();
|
||||
|
||||
// The default value is set later during annotation. It might
|
||||
// be the case that the Symbol sym is annotated _after_ the
|
||||
// repeating instances that depend on this default value,
|
||||
// because of this we set an interim value that tells us this
|
||||
// element (most likely) has a default.
|
||||
//
|
||||
// Set interim value for now, reset just before we do this
|
||||
// properly at annotate time.
|
||||
meth.defaultValue = value;
|
||||
annotate.normal(new AnnotationDefaultCompleter(meth, value));
|
||||
}
|
||||
|
||||
@ -1680,6 +1690,9 @@ public class ClassReader implements Completer {
|
||||
public void enterAnnotation() {
|
||||
JavaFileObject previousClassFile = currentClassFile;
|
||||
try {
|
||||
// Reset the interim value set earlier in
|
||||
// attachAnnotationDefault().
|
||||
sym.defaultValue = null;
|
||||
currentClassFile = classFile;
|
||||
sym.defaultValue = deproxy(sym.type.getReturnType(), value);
|
||||
} finally {
|
||||
|
@ -1545,10 +1545,10 @@ public class Code {
|
||||
public void compressCatchTable() {
|
||||
ListBuffer<char[]> compressedCatchInfo = ListBuffer.lb();
|
||||
List<Integer> handlerPcs = List.nil();
|
||||
for (char[] catchEntry : catchInfo.elems) {
|
||||
for (char[] catchEntry : catchInfo) {
|
||||
handlerPcs = handlerPcs.prepend((int)catchEntry[2]);
|
||||
}
|
||||
for (char[] catchEntry : catchInfo.elems) {
|
||||
for (char[] catchEntry : catchInfo) {
|
||||
int startpc = catchEntry[0];
|
||||
int endpc = catchEntry[1];
|
||||
if (startpc == endpc ||
|
||||
@ -1825,7 +1825,7 @@ public class Code {
|
||||
}
|
||||
}
|
||||
|
||||
static Type jsrReturnValue = new Type(INT, null);
|
||||
static final Type jsrReturnValue = new Type(INT, null);
|
||||
|
||||
|
||||
/* **************************************************************************
|
||||
|
@ -86,17 +86,15 @@ public enum Target {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static Target MIN;
|
||||
private static final Target MIN = values()[0];
|
||||
public static Target MIN() { return MIN; }
|
||||
|
||||
private static Target MAX;
|
||||
private static final Target MAX = values()[values().length - 1];
|
||||
public static Target MAX() { return MAX; }
|
||||
|
||||
private static Map<String,Target> tab = new HashMap<String,Target>();
|
||||
private static final Map<String,Target> tab = new HashMap<String,Target>();
|
||||
static {
|
||||
for (Target t : values()) {
|
||||
if (MIN == null) MIN = t;
|
||||
MAX = t;
|
||||
tab.put(t.name, t);
|
||||
}
|
||||
tab.put("5", JDK1_5);
|
||||
|
@ -189,7 +189,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
}
|
||||
}
|
||||
|
||||
private static CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO;
|
||||
private static final CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO;
|
||||
|
||||
protected static enum ImplicitSourcePolicy {
|
||||
/** Don't generate or process implicitly read source files. */
|
||||
@ -543,7 +543,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
|
||||
public static CompileState max(CompileState a, CompileState b) {
|
||||
return a.value > b.value ? a : b;
|
||||
}
|
||||
private int value;
|
||||
private final int value;
|
||||
};
|
||||
/** Partial map to record which compiler phases have been executed
|
||||
* for each compilation unit. Used for ATTR and FLOW phases.
|
||||
|
@ -167,7 +167,6 @@ public enum Option {
|
||||
ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) {
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option, String operand) {
|
||||
// System.err.println("process encoding " + operand);
|
||||
return super.process(helper, option, operand);
|
||||
}
|
||||
|
||||
@ -246,9 +245,7 @@ public enum Option {
|
||||
}
|
||||
},
|
||||
|
||||
A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC) {
|
||||
{ hasSuffix = true; }
|
||||
|
||||
A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC, true) {
|
||||
@Override
|
||||
public boolean matches(String arg) {
|
||||
return arg.startsWith("-A");
|
||||
@ -293,8 +290,6 @@ public enum Option {
|
||||
// This option exists only for the purpose of documenting itself.
|
||||
// It's actually implemented by the launcher.
|
||||
J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO) {
|
||||
{ hasSuffix = true; }
|
||||
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option) {
|
||||
throw new AssertionError
|
||||
@ -302,10 +297,6 @@ public enum Option {
|
||||
}
|
||||
},
|
||||
|
||||
// stop after parsing and attributing.
|
||||
// new HiddenOption("-attrparseonly"),
|
||||
|
||||
// new Option("-moreinfo", "opt.moreinfo") {
|
||||
MOREINFO("-moreinfo", null, HIDDEN, BASIC) {
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option) {
|
||||
@ -317,23 +308,6 @@ public enum Option {
|
||||
// treat warnings as errors
|
||||
WERROR("-Werror", "opt.Werror", STANDARD, BASIC),
|
||||
|
||||
// // use complex inference from context in the position of a method call argument
|
||||
// COMPLEXINFERENCE("-complexinference", null, HIDDEN, BASIC),
|
||||
|
||||
// generare source stubs
|
||||
// new HiddenOption("-stubs"),
|
||||
|
||||
// relax some constraints to allow compiling from stubs
|
||||
// new HiddenOption("-relax"),
|
||||
|
||||
// output source after translating away inner classes
|
||||
// new Option("-printflat", "opt.printflat"),
|
||||
// new HiddenOption("-printflat"),
|
||||
|
||||
// display scope search details
|
||||
// new Option("-printsearch", "opt.printsearch"),
|
||||
// new HiddenOption("-printsearch"),
|
||||
|
||||
// prompt after each error
|
||||
// new Option("-prompt", "opt.prompt"),
|
||||
PROMPT("-prompt", null, HIDDEN, BASIC),
|
||||
@ -342,13 +316,8 @@ public enum Option {
|
||||
DOE("-doe", null, HIDDEN, BASIC),
|
||||
|
||||
// output source after type erasure
|
||||
// new Option("-s", "opt.s"),
|
||||
PRINTSOURCE("-printsource", null, HIDDEN, BASIC),
|
||||
|
||||
// output shrouded class files
|
||||
// new Option("-scramble", "opt.scramble"),
|
||||
// new Option("-scrambleall", "opt.scrambleall"),
|
||||
|
||||
// display warnings for generic unchecked operations
|
||||
WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) {
|
||||
@Override
|
||||
@ -408,18 +377,16 @@ public enum Option {
|
||||
* -XDx sets the option x to the value x.
|
||||
*/
|
||||
XD("-XD", null, HIDDEN, BASIC) {
|
||||
String s;
|
||||
@Override
|
||||
public boolean matches(String s) {
|
||||
this.s = s;
|
||||
return s.startsWith(text);
|
||||
}
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option) {
|
||||
s = s.substring(text.length());
|
||||
int eq = s.indexOf('=');
|
||||
String key = (eq < 0) ? s : s.substring(0, eq);
|
||||
String value = (eq < 0) ? s : s.substring(eq+1);
|
||||
option = option.substring(text.length());
|
||||
int eq = option.indexOf('=');
|
||||
String key = (eq < 0) ? option : option.substring(0, eq);
|
||||
String value = (eq < 0) ? option : option.substring(eq+1);
|
||||
helper.put(key, value);
|
||||
return false;
|
||||
}
|
||||
@ -428,8 +395,6 @@ public enum Option {
|
||||
// This option exists only for the purpose of documenting itself.
|
||||
// It's actually implemented by the CommandLine class.
|
||||
AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO) {
|
||||
{ hasSuffix = true; }
|
||||
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option) {
|
||||
throw new AssertionError("the @ flag should be caught by CommandLine.");
|
||||
@ -445,17 +410,15 @@ public enum Option {
|
||||
* name to a separate list.
|
||||
*/
|
||||
SOURCEFILE("sourcefile", null, HIDDEN, INFO) {
|
||||
String s;
|
||||
@Override
|
||||
public boolean matches(String s) {
|
||||
this.s = s;
|
||||
return s.endsWith(".java") // Java source file
|
||||
|| SourceVersion.isName(s); // Legal type name
|
||||
}
|
||||
@Override
|
||||
public boolean process(OptionHelper helper, String option) {
|
||||
if (s.endsWith(".java") ) {
|
||||
File f = new File(s);
|
||||
if (option.endsWith(".java") ) {
|
||||
File f = new File(option);
|
||||
if (!f.exists()) {
|
||||
helper.error("err.file.not.found", f);
|
||||
return true;
|
||||
@ -465,9 +428,9 @@ public enum Option {
|
||||
return true;
|
||||
}
|
||||
helper.addFile(f);
|
||||
} else {
|
||||
helper.addClassName(option);
|
||||
}
|
||||
else
|
||||
helper.addClassName(s);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -521,7 +484,7 @@ public enum Option {
|
||||
|
||||
/** Suffix option (-foo=bar or -foo:bar)
|
||||
*/
|
||||
boolean hasSuffix;
|
||||
final boolean hasSuffix;
|
||||
|
||||
/** The kind of choices for this option, if any.
|
||||
*/
|
||||
@ -535,24 +498,30 @@ public enum Option {
|
||||
|
||||
Option(String text, String descrKey,
|
||||
OptionKind kind, OptionGroup group) {
|
||||
this(text, null, descrKey, kind, group, null, null);
|
||||
this(text, null, descrKey, kind, group, null, null, false);
|
||||
}
|
||||
|
||||
Option(String text, String argsNameKey, String descrKey,
|
||||
OptionKind kind, OptionGroup group) {
|
||||
this(text, argsNameKey, descrKey, kind, group, null, null);
|
||||
this(text, argsNameKey, descrKey, kind, group, null, null, false);
|
||||
}
|
||||
|
||||
Option(String text, String argsNameKey, String descrKey,
|
||||
OptionKind kind, OptionGroup group, boolean doHasSuffix) {
|
||||
this(text, argsNameKey, descrKey, kind, group, null, null, doHasSuffix);
|
||||
}
|
||||
|
||||
Option(String text, String descrKey,
|
||||
OptionKind kind, OptionGroup group,
|
||||
ChoiceKind choiceKind, Map<String,Boolean> choices) {
|
||||
this(text, null, descrKey, kind, group, choiceKind, choices);
|
||||
this(text, null, descrKey, kind, group, choiceKind, choices, false);
|
||||
}
|
||||
|
||||
Option(String text, String descrKey,
|
||||
OptionKind kind, OptionGroup group,
|
||||
ChoiceKind choiceKind, String... choices) {
|
||||
this(text, null, descrKey, kind, group, choiceKind, createChoices(choices));
|
||||
this(text, null, descrKey, kind, group, choiceKind,
|
||||
createChoices(choices), false);
|
||||
}
|
||||
// where
|
||||
private static Map<String,Boolean> createChoices(String... choices) {
|
||||
@ -564,7 +533,8 @@ public enum Option {
|
||||
|
||||
private Option(String text, String argsNameKey, String descrKey,
|
||||
OptionKind kind, OptionGroup group,
|
||||
ChoiceKind choiceKind, Map<String,Boolean> choices) {
|
||||
ChoiceKind choiceKind, Map<String,Boolean> choices,
|
||||
boolean doHasSuffix) {
|
||||
this.text = text;
|
||||
this.argsNameKey = argsNameKey;
|
||||
this.descrKey = descrKey;
|
||||
@ -573,7 +543,7 @@ public enum Option {
|
||||
this.choiceKind = choiceKind;
|
||||
this.choices = choices;
|
||||
char lastChar = text.charAt(text.length()-1);
|
||||
hasSuffix = lastChar == ':' || lastChar == '=';
|
||||
this.hasSuffix = doHasSuffix || lastChar == ':' || lastChar == '=';
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
|
@ -44,7 +44,7 @@ import static com.sun.tools.javac.util.LayoutCharacters.*;
|
||||
*/
|
||||
public class JavaTokenizer {
|
||||
|
||||
private static boolean scannerDebug = false;
|
||||
private static final boolean scannerDebug = false;
|
||||
|
||||
/** Allow hex floating-point literals.
|
||||
*/
|
||||
|
@ -818,9 +818,7 @@ public class JavacParser implements Parser {
|
||||
* | "*" | "/" | "%"
|
||||
*/
|
||||
JCExpression term2Rest(JCExpression t, int minprec) {
|
||||
List<JCExpression[]> savedOd = odStackSupply.elems;
|
||||
JCExpression[] odStack = newOdStack();
|
||||
List<Token[]> savedOp = opStackSupply.elems;
|
||||
Token[] opStack = newOpStack();
|
||||
|
||||
// optimization, was odStack = new Tree[...]; opStack = new Tree[...];
|
||||
@ -851,8 +849,8 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
odStackSupply.elems = savedOd; // optimization
|
||||
opStackSupply.elems = savedOp; // optimization
|
||||
odStackSupply.add(odStack);
|
||||
opStackSupply.add(opStack);
|
||||
return t;
|
||||
}
|
||||
//where
|
||||
@ -906,23 +904,19 @@ public class JavacParser implements Parser {
|
||||
/** optimization: To save allocating a new operand/operator stack
|
||||
* for every binary operation, we use supplys.
|
||||
*/
|
||||
ListBuffer<JCExpression[]> odStackSupply = new ListBuffer<JCExpression[]>();
|
||||
ListBuffer<Token[]> opStackSupply = new ListBuffer<Token[]>();
|
||||
ArrayList<JCExpression[]> odStackSupply = new ArrayList<JCExpression[]>();
|
||||
ArrayList<Token[]> opStackSupply = new ArrayList<Token[]>();
|
||||
|
||||
private JCExpression[] newOdStack() {
|
||||
if (odStackSupply.elems == odStackSupply.last)
|
||||
odStackSupply.append(new JCExpression[infixPrecedenceLevels + 1]);
|
||||
JCExpression[] odStack = odStackSupply.elems.head;
|
||||
odStackSupply.elems = odStackSupply.elems.tail;
|
||||
return odStack;
|
||||
if (odStackSupply.isEmpty())
|
||||
return new JCExpression[infixPrecedenceLevels + 1];
|
||||
return odStackSupply.remove(odStackSupply.size() - 1);
|
||||
}
|
||||
|
||||
private Token[] newOpStack() {
|
||||
if (opStackSupply.elems == opStackSupply.last)
|
||||
opStackSupply.append(new Token[infixPrecedenceLevels + 1]);
|
||||
Token[] opStack = opStackSupply.elems.head;
|
||||
opStackSupply.elems = opStackSupply.elems.tail;
|
||||
return opStack;
|
||||
if (opStackSupply.isEmpty())
|
||||
return new Token[infixPrecedenceLevels + 1];
|
||||
return opStackSupply.remove(opStackSupply.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2001,7 +1995,7 @@ public class JavacParser implements Parser {
|
||||
ListBuffer<JCStatement> stats =
|
||||
variableDeclarators(mods, t, new ListBuffer<JCStatement>());
|
||||
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
|
||||
storeEnd(stats.elems.last(), token.endPos);
|
||||
storeEnd(stats.last(), token.endPos);
|
||||
accept(SEMI);
|
||||
return stats.toList();
|
||||
}
|
||||
@ -2042,7 +2036,7 @@ public class JavacParser implements Parser {
|
||||
ListBuffer<JCStatement> stats =
|
||||
variableDeclarators(mods, t, new ListBuffer<JCStatement>());
|
||||
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
|
||||
storeEnd(stats.elems.last(), token.endPos);
|
||||
storeEnd(stats.last(), token.endPos);
|
||||
accept(SEMI);
|
||||
return stats.toList();
|
||||
} else {
|
||||
@ -2577,7 +2571,7 @@ public class JavacParser implements Parser {
|
||||
vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc));
|
||||
while (token.kind == COMMA) {
|
||||
// All but last of multiple declarators subsume a comma
|
||||
storeEnd((JCTree)vdefs.elems.last(), token.endPos);
|
||||
storeEnd((JCTree)vdefs.last(), token.endPos);
|
||||
nextToken();
|
||||
vdefs.append(variableDeclarator(mods, type, reqInit, dc));
|
||||
}
|
||||
@ -2632,7 +2626,7 @@ public class JavacParser implements Parser {
|
||||
defs.append(resource());
|
||||
while (token.kind == SEMI) {
|
||||
// All but last of multiple declarators must subsume a semicolon
|
||||
storeEnd(defs.elems.last(), token.endPos);
|
||||
storeEnd(defs.last(), token.endPos);
|
||||
int semiColonPos = token.pos;
|
||||
nextToken();
|
||||
if (token.kind == RPAREN) { // Optional trailing semicolon
|
||||
@ -2710,7 +2704,7 @@ public class JavacParser implements Parser {
|
||||
JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList());
|
||||
if (!consumedToplevelDoc)
|
||||
attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
|
||||
if (defs.elems.isEmpty())
|
||||
if (defs.isEmpty())
|
||||
storeEnd(toplevel, S.prevToken().endPos);
|
||||
if (keepDocComments)
|
||||
toplevel.docComments = docComments;
|
||||
|
@ -1336,7 +1336,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private static TreeScanner treeCleaner = new TreeScanner() {
|
||||
private static final TreeScanner treeCleaner = new TreeScanner() {
|
||||
public void scan(JCTree node) {
|
||||
super.scan(node);
|
||||
if (node != null)
|
||||
|
@ -307,13 +307,17 @@ compiler.err.doesnt.exist=\
|
||||
compiler.err.duplicate.annotation=\
|
||||
duplicate annotation
|
||||
|
||||
# 0: type
|
||||
compiler.err.duplicate.annotation.invalid.repeated=\
|
||||
annotation {0} cannot be repeated\nIt does not define a valid containing annotation.
|
||||
|
||||
# 0: name, 1: type
|
||||
compiler.err.duplicate.annotation.member.value=\
|
||||
duplicate annotation member value {0} in {1}
|
||||
|
||||
# 0: type
|
||||
# 0: type, 1: type
|
||||
compiler.err.duplicate.annotation.missing.container=\
|
||||
duplicate annotation, the declaration of {0} does not have a ContainedBy annotation
|
||||
duplicate annotation, the declaration of {0} does not have a valid {1} annotation
|
||||
|
||||
# 0: type, 1: type
|
||||
compiler.err.invalid.container.no.containedby=\
|
||||
|
@ -340,15 +340,17 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
*/
|
||||
LETEXPR; // ala scheme
|
||||
|
||||
private Tag noAssignTag;
|
||||
private final Tag noAssignTag;
|
||||
|
||||
private static int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
|
||||
private static final int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
|
||||
|
||||
private Tag(Tag noAssignTag) {
|
||||
this.noAssignTag = noAssignTag;
|
||||
}
|
||||
|
||||
private Tag() { }
|
||||
private Tag() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public static int getNumberOfOperators() {
|
||||
return numberOfOperators;
|
||||
@ -1838,8 +1840,8 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
/** Toplevel # new */
|
||||
TOPLEVEL(ReferenceMode.NEW, false);
|
||||
|
||||
ReferenceMode mode;
|
||||
boolean unbound;
|
||||
final ReferenceMode mode;
|
||||
final boolean unbound;
|
||||
|
||||
private ReferenceKind(ReferenceMode mode, boolean unbound) {
|
||||
this.mode = mode;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2012, 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
|
||||
@ -181,7 +181,7 @@ public abstract class BaseFileManager {
|
||||
return false;
|
||||
}
|
||||
// where
|
||||
private static Set<Option> javacFileManagerOptions =
|
||||
private static final Set<Option> javacFileManagerOptions =
|
||||
Option.getJavacFileManagerOptions();
|
||||
|
||||
public int isSupportedOption(String option) {
|
||||
|
@ -74,7 +74,7 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
|
||||
return (List<A>)EMPTY_LIST;
|
||||
}
|
||||
|
||||
private static List<?> EMPTY_LIST = new List<Object>(null,null) {
|
||||
private static final List<?> EMPTY_LIST = new List<Object>(null,null) {
|
||||
public List<Object> setTail(List<Object> tail) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -391,7 +391,7 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
|
||||
return (List<T>)list;
|
||||
}
|
||||
|
||||
private static Iterator<?> EMPTYITERATOR = new Iterator<Object>() {
|
||||
private static final Iterator<?> EMPTYITERATOR = new Iterator<Object>() {
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2012, 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
|
||||
@ -52,19 +52,20 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
|
||||
/** The list of elements of this buffer.
|
||||
*/
|
||||
public List<A> elems;
|
||||
private List<A> elems;
|
||||
|
||||
/** A pointer pointing to the last, sentinel element of `elems'.
|
||||
/** A pointer pointing to the last element of 'elems' containing data,
|
||||
* or null if the list is empty.
|
||||
*/
|
||||
public List<A> last;
|
||||
private List<A> last;
|
||||
|
||||
/** The number of element in this buffer.
|
||||
*/
|
||||
public int count;
|
||||
private int count;
|
||||
|
||||
/** Has a list been created from this buffer yet?
|
||||
*/
|
||||
public boolean shared;
|
||||
private boolean shared;
|
||||
|
||||
/** Create a new initially empty list buffer.
|
||||
*/
|
||||
@ -73,8 +74,8 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
this.elems = new List<A>(null,null);
|
||||
this.last = this.elems;
|
||||
this.elems = List.nil();
|
||||
this.last = null;
|
||||
count = 0;
|
||||
shared = false;
|
||||
}
|
||||
@ -103,22 +104,23 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
/** Copy list and sets last.
|
||||
*/
|
||||
private void copy() {
|
||||
List<A> p = elems = new List<A>(elems.head, elems.tail);
|
||||
while (true) {
|
||||
List<A> tail = p.tail;
|
||||
if (tail == null) break;
|
||||
tail = new List<A>(tail.head, tail.tail);
|
||||
p.setTail(tail);
|
||||
p = tail;
|
||||
if (elems.nonEmpty()) {
|
||||
List<A> orig = elems;
|
||||
|
||||
elems = last = List.<A>of(orig.head);
|
||||
|
||||
while ((orig = orig.tail).nonEmpty()) {
|
||||
last.tail = List.<A>of(orig.head);
|
||||
last = last.tail;
|
||||
}
|
||||
}
|
||||
last = p;
|
||||
shared = false;
|
||||
}
|
||||
|
||||
/** Prepend an element to buffer.
|
||||
*/
|
||||
public ListBuffer<A> prepend(A x) {
|
||||
elems = elems.prepend(x);
|
||||
if (last == null) last = elems;
|
||||
count++;
|
||||
return this;
|
||||
}
|
||||
@ -128,9 +130,13 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
public ListBuffer<A> append(A x) {
|
||||
x.getClass(); // null check
|
||||
if (shared) copy();
|
||||
last.head = x;
|
||||
last.setTail(new List<A>(null,null));
|
||||
last = last.tail;
|
||||
List<A> newLast = List.<A>of(x);
|
||||
if (last != null) {
|
||||
last.tail = newLast;
|
||||
last = newLast;
|
||||
} else {
|
||||
elems = last = newLast;
|
||||
}
|
||||
count++;
|
||||
return this;
|
||||
}
|
||||
@ -192,8 +198,9 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
*/
|
||||
public A next() {
|
||||
A x = elems.head;
|
||||
if (elems != last) {
|
||||
if (!elems.isEmpty()) {
|
||||
elems = elems.tail;
|
||||
if (elems.isEmpty()) last = null;
|
||||
count--;
|
||||
}
|
||||
return x;
|
||||
@ -205,10 +212,10 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
return new Iterator<A>() {
|
||||
List<A> elems = ListBuffer.this.elems;
|
||||
public boolean hasNext() {
|
||||
return elems != last;
|
||||
return !elems.isEmpty();
|
||||
}
|
||||
public A next() {
|
||||
if (elems == last)
|
||||
if (elems.isEmpty())
|
||||
throw new NoSuchElementException();
|
||||
A elem = elems.head;
|
||||
elems = elems.tail;
|
||||
@ -263,4 +270,8 @@ public class ListBuffer<A> extends AbstractQueue<A> {
|
||||
public A peek() {
|
||||
return first();
|
||||
}
|
||||
|
||||
public A last() {
|
||||
return last != null ? last.head : null;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2012, 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
|
||||
@ -91,7 +91,7 @@ public class MandatoryWarningHandler {
|
||||
DeferredDiagnosticKind(String v) { value = v; }
|
||||
String getKey(String prefix) { return prefix + value; }
|
||||
|
||||
private String value;
|
||||
private final String value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -249,7 +249,7 @@ public class RichDiagnosticFormatter extends
|
||||
INTERSECTION("where.description.intersection");
|
||||
|
||||
/** resource key for this where clause kind */
|
||||
private String key;
|
||||
private final String key;
|
||||
|
||||
WhereClauseKind(String key) {
|
||||
this.key = key;
|
||||
|
@ -27,13 +27,13 @@ package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Kinds;
|
||||
import com.sun.tools.javac.code.Scope;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.Names;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Represents an annotation type.
|
||||
@ -51,12 +51,11 @@ public class AnnotationTypeDocImpl
|
||||
extends ClassDocImpl implements AnnotationTypeDoc {
|
||||
|
||||
public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) {
|
||||
this(env, sym, null, null, null);
|
||||
this(env, sym, null);
|
||||
}
|
||||
|
||||
public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym,
|
||||
String doc, JCClassDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, doc, tree, lineMap);
|
||||
public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,9 +27,9 @@ package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Represents an element of an annotation type.
|
||||
@ -50,9 +50,8 @@ public class AnnotationTypeElementDocImpl
|
||||
super(env, sym);
|
||||
}
|
||||
|
||||
public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym,
|
||||
String doc, JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, doc, tree, lineMap);
|
||||
public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,13 +31,14 @@ import java.lang.reflect.Modifier;
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileManager.Location;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.Kinds;
|
||||
import com.sun.tools.javac.code.Scope;
|
||||
@ -45,22 +46,17 @@ import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.code.Type.ClassType;
|
||||
|
||||
import com.sun.tools.javac.comp.AttrContext;
|
||||
import com.sun.tools.javac.comp.Env;
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
||||
import com.sun.tools.javac.tree.JCTree.JCImport;
|
||||
import com.sun.tools.javac.tree.TreeInfo;
|
||||
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
import com.sun.tools.javac.util.Names;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
import static com.sun.tools.javac.code.Kinds.*;
|
||||
import static com.sun.tools.javac.code.TypeTag.CLASS;
|
||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||
@ -100,15 +96,14 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
|
||||
* Constructor
|
||||
*/
|
||||
public ClassDocImpl(DocEnv env, ClassSymbol sym) {
|
||||
this(env, sym, null, null, null);
|
||||
this(env, sym, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ClassDocImpl(DocEnv env, ClassSymbol sym, String documentation,
|
||||
JCClassDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, documentation, tree, lineMap);
|
||||
public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
this.type = (ClassType)sym.type;
|
||||
this.tsym = sym;
|
||||
}
|
||||
|
@ -27,10 +27,9 @@ package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
||||
import com.sun.tools.javac.code.Symbol.MethodSymbol;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Represents a constructor of a java class.
|
||||
@ -58,9 +57,8 @@ public class ConstructorDocImpl
|
||||
/**
|
||||
* constructor.
|
||||
*/
|
||||
public ConstructorDocImpl(DocEnv env, MethodSymbol sym,
|
||||
String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, docComment, tree, lineMap);
|
||||
public ConstructorDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,18 +27,20 @@ package com.sun.tools.javadoc;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
|
||||
import javax.tools.JavaFileManager;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.api.JavacTrees;
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type.ClassType;
|
||||
import com.sun.tools.javac.comp.Check;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Names;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Holds the environment for a run of javadoc.
|
||||
@ -104,6 +106,8 @@ public class DocEnv {
|
||||
JavaFileManager fileManager;
|
||||
Context context;
|
||||
|
||||
WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
|
||||
|
||||
/** Allow documenting from class files? */
|
||||
boolean docClasses = false;
|
||||
|
||||
@ -540,13 +544,12 @@ public class DocEnv {
|
||||
/**
|
||||
* Create the PackageDoc (or a subtype) for a package symbol.
|
||||
*/
|
||||
void makePackageDoc(PackageSymbol pack, String docComment, JCCompilationUnit tree) {
|
||||
void makePackageDoc(PackageSymbol pack, TreePath treePath) {
|
||||
PackageDocImpl result = packageMap.get(pack);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
} else {
|
||||
result = new PackageDocImpl(this, pack, docComment, tree);
|
||||
result = new PackageDocImpl(this, pack, treePath);
|
||||
packageMap.put(pack, result);
|
||||
}
|
||||
}
|
||||
@ -572,17 +575,16 @@ public class DocEnv {
|
||||
/**
|
||||
* Create the ClassDoc (or a subtype) for a class symbol.
|
||||
*/
|
||||
protected void makeClassDoc(ClassSymbol clazz, String docComment, JCClassDecl tree, Position.LineMap lineMap) {
|
||||
protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
|
||||
ClassDocImpl result = classMap.get(clazz);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
return;
|
||||
}
|
||||
if (isAnnotationType(tree)) { // flags of clazz may not yet be set
|
||||
result = new AnnotationTypeDocImpl(this, clazz, docComment, tree, lineMap);
|
||||
if (isAnnotationType((JCClassDecl) treePath.getLeaf())) { // flags of clazz may not yet be set
|
||||
result = new AnnotationTypeDocImpl(this, clazz, treePath);
|
||||
} else {
|
||||
result = new ClassDocImpl(this, clazz, docComment, tree, lineMap);
|
||||
result = new ClassDocImpl(this, clazz, treePath);
|
||||
}
|
||||
classMap.put(clazz, result);
|
||||
}
|
||||
@ -610,13 +612,12 @@ public class DocEnv {
|
||||
/**
|
||||
* Create a FieldDoc for a var symbol.
|
||||
*/
|
||||
protected void makeFieldDoc(VarSymbol var, String docComment, JCVariableDecl tree, Position.LineMap lineMap) {
|
||||
protected void makeFieldDoc(VarSymbol var, TreePath treePath) {
|
||||
FieldDocImpl result = fieldMap.get(var);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
} else {
|
||||
result = new FieldDocImpl(this, var, docComment, tree, lineMap);
|
||||
result = new FieldDocImpl(this, var, treePath);
|
||||
fieldMap.put(var, result);
|
||||
}
|
||||
}
|
||||
@ -627,14 +628,12 @@ public class DocEnv {
|
||||
* Create a MethodDoc for this MethodSymbol.
|
||||
* Should be called only on symbols representing methods.
|
||||
*/
|
||||
protected void makeMethodDoc(MethodSymbol meth, String docComment,
|
||||
JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) {
|
||||
MethodDocImpl result = (MethodDocImpl)methodMap.get(meth);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
} else {
|
||||
result = new MethodDocImpl(this, meth, docComment, tree, lineMap);
|
||||
result = new MethodDocImpl(this, meth, treePath);
|
||||
methodMap.put(meth, result);
|
||||
}
|
||||
}
|
||||
@ -656,14 +655,12 @@ public class DocEnv {
|
||||
* Create the ConstructorDoc for a MethodSymbol.
|
||||
* Should be called only on symbols representing constructors.
|
||||
*/
|
||||
protected void makeConstructorDoc(MethodSymbol meth, String docComment,
|
||||
JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) {
|
||||
ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
} else {
|
||||
result = new ConstructorDocImpl(this, meth, docComment, tree, lineMap);
|
||||
result = new ConstructorDocImpl(this, meth, treePath);
|
||||
methodMap.put(meth, result);
|
||||
}
|
||||
}
|
||||
@ -685,16 +682,14 @@ public class DocEnv {
|
||||
* Create the AnnotationTypeElementDoc for a MethodSymbol.
|
||||
* Should be called only on symbols representing annotation type elements.
|
||||
*/
|
||||
protected void makeAnnotationTypeElementDoc(MethodSymbol meth,
|
||||
String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) {
|
||||
AnnotationTypeElementDocImpl result =
|
||||
(AnnotationTypeElementDocImpl)methodMap.get(meth);
|
||||
if (result != null) {
|
||||
if (docComment != null) result.setRawCommentText(docComment);
|
||||
if (tree != null) result.setTree(tree);
|
||||
if (treePath != null) result.setTreePath(treePath);
|
||||
} else {
|
||||
result =
|
||||
new AnnotationTypeElementDocImpl(this, meth, docComment, tree, lineMap);
|
||||
new AnnotationTypeElementDocImpl(this, meth, treePath);
|
||||
methodMap.put(meth, result);
|
||||
}
|
||||
}
|
||||
@ -730,6 +725,18 @@ public class DocEnv {
|
||||
// return result;
|
||||
}
|
||||
|
||||
TreePath getTreePath(JCCompilationUnit tree) {
|
||||
TreePath p = treePaths.get(tree);
|
||||
if (p == null)
|
||||
treePaths.put(tree, p = new TreePath(tree));
|
||||
return p;
|
||||
}
|
||||
|
||||
TreePath getTreePath(JCCompilationUnit toplevel, JCTree tree) {
|
||||
// don't bother to cache paths for classes and members
|
||||
return new TreePath(getTreePath(toplevel), tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the encoding.
|
||||
*/
|
||||
|
@ -35,6 +35,9 @@ import java.util.regex.Pattern;
|
||||
import javax.tools.FileObject;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
@ -60,6 +63,12 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
|
||||
*/
|
||||
protected final DocEnv env; //### Rename this everywhere to 'docenv' ?
|
||||
|
||||
/**
|
||||
* Back pointer to the tree node for this doc item.
|
||||
* May be null if there is no associated tree.
|
||||
*/
|
||||
protected TreePath treePath;
|
||||
|
||||
/**
|
||||
* The complex comment object, lazily initialized.
|
||||
*/
|
||||
@ -88,11 +97,21 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
DocImpl(DocEnv env, String documentation) {
|
||||
this.documentation = documentation;
|
||||
DocImpl(DocEnv env, TreePath treePath) {
|
||||
this.treePath = treePath;
|
||||
this.documentation = getCommentText(treePath);
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
private static String getCommentText(TreePath p) {
|
||||
if (p == null)
|
||||
return null;
|
||||
|
||||
JCCompilationUnit topLevel = (JCCompilationUnit) p.getCompilationUnit();
|
||||
JCTree tree = (JCTree) p.getLeaf();
|
||||
return topLevel.docComments.getCommentText(tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* So subclasses have the option to do lazy initialization of
|
||||
* "documentation" string.
|
||||
@ -213,10 +232,20 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
|
||||
* operations like internalization.
|
||||
*/
|
||||
public void setRawCommentText(String rawDocumentation) {
|
||||
treePath = null;
|
||||
documentation = rawDocumentation;
|
||||
comment = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the full unprocessed text of the comment and tree path.
|
||||
*/
|
||||
void setTreePath(TreePath treePath) {
|
||||
this.treePath = treePath;
|
||||
documentation = getCommentText(treePath);
|
||||
comment = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a key for sorting.
|
||||
*/
|
||||
|
@ -30,13 +30,12 @@ import java.text.CollationKey;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Represents a method or constructor of a java class.
|
||||
@ -60,9 +59,8 @@ public abstract class ExecutableMemberDocImpl
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym,
|
||||
String rawDocs, JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, rawDocs, tree, lineMap);
|
||||
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
this.sym = sym;
|
||||
}
|
||||
|
||||
@ -70,7 +68,7 @@ public abstract class ExecutableMemberDocImpl
|
||||
* Constructor.
|
||||
*/
|
||||
public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
|
||||
this(env, sym, null, null, null);
|
||||
this(env, sym, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
@ -61,9 +62,8 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public FieldDocImpl(DocEnv env, VarSymbol sym,
|
||||
String rawDocs, JCVariableDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, rawDocs, tree, lineMap);
|
||||
public FieldDocImpl(DocEnv env, VarSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
this.sym = sym;
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
|
||||
* Constructor.
|
||||
*/
|
||||
public FieldDocImpl(DocEnv env, VarSymbol sym) {
|
||||
this(env, sym, null, null, null);
|
||||
this(env, sym, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,13 +25,14 @@
|
||||
|
||||
package com.sun.tools.javadoc;
|
||||
|
||||
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Kinds;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.comp.Enter;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.tree.TreeInfo;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
import com.sun.tools.javac.util.List;
|
||||
@ -85,8 +86,7 @@ public class JavadocEnter extends Enter {
|
||||
public void visitTopLevel(JCCompilationUnit tree) {
|
||||
super.visitTopLevel(tree);
|
||||
if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
|
||||
String comment = TreeInfo.getCommentText(env, tree);
|
||||
docenv.makePackageDoc(tree.packge, comment, tree);
|
||||
docenv.makePackageDoc(tree.packge, docenv.getTreePath(tree));
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,9 +95,8 @@ public class JavadocEnter extends Enter {
|
||||
super.visitClassDef(tree);
|
||||
if (tree.sym == null) return;
|
||||
if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) {
|
||||
String comment = TreeInfo.getCommentText(env, tree);
|
||||
ClassSymbol c = tree.sym;
|
||||
docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap);
|
||||
docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,13 @@
|
||||
|
||||
package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.code.Kinds;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.comp.MemberEnter;
|
||||
import com.sun.tools.javac.tree.JCTree.*;
|
||||
import com.sun.tools.javac.tree.TreeInfo;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Javadoc's own memberEnter phase does a few things above and beyond that
|
||||
@ -73,14 +72,13 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||
super.visitMethodDef(tree);
|
||||
MethodSymbol meth = tree.sym;
|
||||
if (meth == null || meth.kind != Kinds.MTH) return;
|
||||
String docComment = TreeInfo.getCommentText(env, tree);
|
||||
Position.LineMap lineMap = env.toplevel.lineMap;
|
||||
TreePath treePath = docenv.getTreePath(env.toplevel, tree);
|
||||
if (meth.isConstructor())
|
||||
docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
|
||||
docenv.makeConstructorDoc(meth, treePath);
|
||||
else if (isAnnotationTypeElement(meth))
|
||||
docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap);
|
||||
docenv.makeAnnotationTypeElementDoc(meth, treePath);
|
||||
else
|
||||
docenv.makeMethodDoc(meth, docComment, tree, lineMap);
|
||||
docenv.makeMethodDoc(meth, treePath);
|
||||
|
||||
// release resources
|
||||
tree.body = null;
|
||||
@ -92,9 +90,7 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||
if (tree.sym != null &&
|
||||
tree.sym.kind == Kinds.VAR &&
|
||||
!isParameter(tree.sym)) {
|
||||
String docComment = TreeInfo.getCommentText(env, tree);
|
||||
Position.LineMap lineMap = env.toplevel.lineMap;
|
||||
docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
|
||||
docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, tree));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,8 @@ package com.sun.tools.javadoc;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
* Represents a member of a java class: field, constructor, or method.
|
||||
@ -57,8 +56,8 @@ public abstract class MemberDocImpl
|
||||
/**
|
||||
* constructor.
|
||||
*/
|
||||
public MemberDocImpl(DocEnv env, Symbol sym, String doc, JCTree tree, Position.LineMap lineMap) {
|
||||
super(env, sym, doc, tree, lineMap);
|
||||
public MemberDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,12 +28,10 @@ package com.sun.tools.javadoc;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.code.Symbol.*;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
import static com.sun.tools.javac.code.TypeTag.CLASS;
|
||||
|
||||
/**
|
||||
@ -62,9 +60,8 @@ public class MethodDocImpl
|
||||
/**
|
||||
* constructor.
|
||||
*/
|
||||
public MethodDocImpl(DocEnv env, MethodSymbol sym,
|
||||
String docComment, JCMethodDecl tree, Position.LineMap lineMap) {
|
||||
super(env, sym, docComment, tree, lineMap);
|
||||
public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
|
||||
super(env, sym, treePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ import java.io.InputStream;
|
||||
import javax.tools.FileObject;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Attribute;
|
||||
import com.sun.tools.javac.code.Scope;
|
||||
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
||||
@ -75,17 +76,16 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||
* Constructor
|
||||
*/
|
||||
public PackageDocImpl(DocEnv env, PackageSymbol sym) {
|
||||
this(env, sym, null, null);
|
||||
this(env, sym, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public PackageDocImpl(DocEnv env, PackageSymbol sym,
|
||||
String documentation, JCTree tree) {
|
||||
super(env, documentation);
|
||||
public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
|
||||
super(env, treePath);
|
||||
this.sym = sym;
|
||||
this.tree = (JCCompilationUnit) tree;
|
||||
this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
|
||||
foundDoc = (documentation != null);
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||
this.tree = (JCCompilationUnit) tree;
|
||||
}
|
||||
|
||||
public void setRawCommentText(String rawDocumentation) {
|
||||
super.setRawCommentText(rawDocumentation);
|
||||
public void setTreePath(TreePath treePath) {
|
||||
super.setTreePath(treePath);
|
||||
checkDoc();
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,12 @@ import java.lang.reflect.Modifier;
|
||||
import java.text.CollationKey;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.tools.javac.code.Attribute;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
import com.sun.tools.javac.util.Position;
|
||||
|
||||
/**
|
||||
@ -66,16 +68,20 @@ public abstract class ProgramElementDocImpl
|
||||
// Cache for getModifiers().
|
||||
private int modifiers = -1;
|
||||
|
||||
protected ProgramElementDocImpl(DocEnv env, Symbol sym,
|
||||
String doc, JCTree tree, Position.LineMap lineMap) {
|
||||
super(env, doc);
|
||||
protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
|
||||
super(env, treePath);
|
||||
this.sym = sym;
|
||||
this.tree = tree;
|
||||
this.lineMap = lineMap;
|
||||
if (treePath != null) {
|
||||
tree = (JCTree) treePath.getLeaf();
|
||||
lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
|
||||
}
|
||||
}
|
||||
|
||||
void setTree(JCTree tree) {
|
||||
this.tree = tree;
|
||||
@Override
|
||||
void setTreePath(TreePath treePath) {
|
||||
super.setTreePath(treePath);
|
||||
this.tree = (JCTree) treePath.getLeaf();
|
||||
this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -331,7 +331,6 @@ public class RootDocImpl extends DocImpl implements RootDoc {
|
||||
@Override
|
||||
protected String documentation() {
|
||||
if (documentation == null) {
|
||||
int cnt = options.length();
|
||||
JavaFileObject overviewPath = getOverviewPath();
|
||||
if (overviewPath == null) {
|
||||
// no doc file to be had
|
||||
|
@ -147,7 +147,7 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
}
|
||||
}
|
||||
|
||||
static Option[] recognizedOptions = {
|
||||
static final Option[] recognizedOptions = {
|
||||
new Option(true, "-o") {
|
||||
void process(JavahTask task, String opt, String arg) {
|
||||
task.ofile = new File(arg);
|
||||
|
@ -117,7 +117,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
|
||||
final String[] aliases;
|
||||
}
|
||||
|
||||
static Option[] recognizedOptions = {
|
||||
static final Option[] recognizedOptions = {
|
||||
|
||||
new Option(false, "-help", "--help", "-?") {
|
||||
void process(JavapTask task, String opt, String arg) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2012, 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
|
||||
@ -61,16 +61,10 @@ public enum Modifier {
|
||||
/** The modifier {@code native} */ NATIVE,
|
||||
/** The modifier {@code strictfp} */ STRICTFP;
|
||||
|
||||
|
||||
private String lowercase = null; // modifier name in lowercase
|
||||
|
||||
/**
|
||||
* Returns this modifier's name in lowercase.
|
||||
*/
|
||||
public String toString() {
|
||||
if (lowercase == null) {
|
||||
lowercase = name().toLowerCase(java.util.Locale.US);
|
||||
}
|
||||
return lowercase;
|
||||
return name().toLowerCase(java.util.Locale.US);
|
||||
}
|
||||
}
|
||||
|
@ -66,19 +66,19 @@ import javax.lang.model.element.*;
|
||||
public class ElementFilter {
|
||||
private ElementFilter() {} // Do not instantiate.
|
||||
|
||||
private static Set<ElementKind> CONSTRUCTOR_KIND =
|
||||
private static final Set<ElementKind> CONSTRUCTOR_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.CONSTRUCTOR));
|
||||
|
||||
private static Set<ElementKind> FIELD_KINDS =
|
||||
private static final Set<ElementKind> FIELD_KINDS =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.FIELD,
|
||||
ElementKind.ENUM_CONSTANT));
|
||||
private static Set<ElementKind> METHOD_KIND =
|
||||
private static final Set<ElementKind> METHOD_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.METHOD));
|
||||
|
||||
private static Set<ElementKind> PACKAGE_KIND =
|
||||
private static final Set<ElementKind> PACKAGE_KIND =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.PACKAGE));
|
||||
|
||||
private static Set<ElementKind> TYPE_KINDS =
|
||||
private static final Set<ElementKind> TYPE_KINDS =
|
||||
Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS,
|
||||
ElementKind.ENUM,
|
||||
ElementKind.INTERFACE,
|
||||
|
@ -97,7 +97,7 @@ public enum StandardLocation implements Location {
|
||||
return locations.get(name);
|
||||
}
|
||||
//where
|
||||
private static ConcurrentMap<String,Location> locations
|
||||
private static final ConcurrentMap<String,Location> locations
|
||||
= new ConcurrentHashMap<String,Location>();
|
||||
|
||||
public String getName() { return name(); }
|
||||
|
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2012, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8003967
|
||||
* @summary detect and remove all mutable implicit static enum fields in langtools
|
||||
* @run main DetectMutableStaticFields
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.tools.ToolProvider;
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
import com.sun.tools.classfile.ConstantPoolException;
|
||||
import com.sun.tools.classfile.Descriptor;
|
||||
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
|
||||
import com.sun.tools.classfile.Field;
|
||||
|
||||
import static javax.tools.JavaFileObject.Kind.CLASS;
|
||||
import static com.sun.tools.classfile.AccessFlags.ACC_ENUM;
|
||||
import static com.sun.tools.classfile.AccessFlags.ACC_FINAL;
|
||||
import static com.sun.tools.classfile.AccessFlags.ACC_STATIC;
|
||||
|
||||
public class DetectMutableStaticFields {
|
||||
|
||||
private static final String keyResource =
|
||||
"com/sun/tools/javac/tree/JCTree.class";
|
||||
|
||||
private String[] packagesToSeekFor = new String[] {
|
||||
"javax.tools",
|
||||
"javax.lang.model",
|
||||
"com.sun.javadoc",
|
||||
"com.sun.source",
|
||||
"com.sun.tools.classfile",
|
||||
"com.sun.tools.doclets",
|
||||
"com.sun.tools.javac",
|
||||
"com.sun.tools.javadoc",
|
||||
"com.sun.tools.javah",
|
||||
"com.sun.tools.javap",
|
||||
};
|
||||
|
||||
private static final Map<String, List<String>> classFieldsToIgnoreMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
classFieldsToIgnoreMap.
|
||||
put("javax/tools/ToolProvider",
|
||||
Arrays.asList("instance"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javah/JavahTask",
|
||||
Arrays.asList("versionRB"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/classfile/Dependencies$DefaultFilter",
|
||||
Arrays.asList("instance"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javap/JavapTask",
|
||||
Arrays.asList("versionRB"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/doclets/formats/html/HtmlDoclet",
|
||||
Arrays.asList("docletToStart"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/util/JCDiagnostic",
|
||||
Arrays.asList("fragmentFormatter"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/util/JavacMessages",
|
||||
Arrays.asList("defaultBundle", "defaultMessages"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/file/ZipFileIndexCache",
|
||||
Arrays.asList("sharedInstance"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/main/JavaCompiler",
|
||||
Arrays.asList("versionRB"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/code/Type",
|
||||
Arrays.asList("moreInfo"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/util/SharedNameTable",
|
||||
Arrays.asList("freelist"));
|
||||
classFieldsToIgnoreMap.
|
||||
put("com/sun/tools/javac/util/Log",
|
||||
Arrays.asList("useRawMessages"));
|
||||
}
|
||||
|
||||
private List<String> errors = new ArrayList<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new DetectMutableStaticFields().run();
|
||||
} catch (Exception ex) {
|
||||
throw new AssertionError(
|
||||
"Exception during test execution with cause ",
|
||||
ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
private void run()
|
||||
throws
|
||||
IOException,
|
||||
ConstantPoolException,
|
||||
InvalidDescriptor,
|
||||
URISyntaxException {
|
||||
|
||||
URI resource = findResource(keyResource);
|
||||
if (resource == null) {
|
||||
throw new AssertionError("Resource " + keyResource +
|
||||
"not found in the class path");
|
||||
}
|
||||
analyzeResource(resource);
|
||||
|
||||
if (errors.size() > 0) {
|
||||
for (String error: errors) {
|
||||
System.err.println(error);
|
||||
}
|
||||
throw new AssertionError("There are mutable fields, "
|
||||
+ "please check output");
|
||||
}
|
||||
}
|
||||
|
||||
URI findResource(String className) throws URISyntaxException {
|
||||
URI uri = getClass().getClassLoader().getResource(className).toURI();
|
||||
if (uri.getScheme().equals("jar")) {
|
||||
String ssp = uri.getRawSchemeSpecificPart();
|
||||
int sep = ssp.lastIndexOf("!");
|
||||
uri = new URI(ssp.substring(0, sep));
|
||||
} else if (uri.getScheme().equals("file")) {
|
||||
uri = new URI(uri.getPath().substring(0,
|
||||
uri.getPath().length() - keyResource.length()));
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
boolean shouldAnalyzePackage(String packageName) {
|
||||
for (String aPackage: packagesToSeekFor) {
|
||||
if (packageName.contains(aPackage)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void analyzeResource(URI resource)
|
||||
throws
|
||||
IOException,
|
||||
ConstantPoolException,
|
||||
InvalidDescriptor {
|
||||
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
|
||||
JavaFileManager.Location location =
|
||||
StandardLocation.locationFor(resource.getPath());
|
||||
fm.setLocation(location, com.sun.tools.javac.util.List.of(
|
||||
new File(resource.getPath())));
|
||||
|
||||
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
|
||||
String className = fm.inferBinaryName(location, file);
|
||||
int index = className.lastIndexOf('.');
|
||||
String pckName = index == -1 ? "" : className.substring(0, index);
|
||||
if (shouldAnalyzePackage(pckName)) {
|
||||
analyzeClassFile(ClassFile.read(file.openInputStream()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> currentFieldsToIgnore;
|
||||
|
||||
boolean ignoreField(String field) {
|
||||
if (currentFieldsToIgnore != null) {
|
||||
for (String fieldToIgnore : currentFieldsToIgnore) {
|
||||
if (field.equals(fieldToIgnore)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void analyzeClassFile(ClassFile classFileToCheck)
|
||||
throws
|
||||
IOException,
|
||||
ConstantPoolException,
|
||||
Descriptor.InvalidDescriptor {
|
||||
boolean enumClass =
|
||||
(classFileToCheck.access_flags.flags & ACC_ENUM) != 0;
|
||||
boolean nonFinalStaticEnumField;
|
||||
boolean nonFinalStaticField;
|
||||
|
||||
currentFieldsToIgnore =
|
||||
classFieldsToIgnoreMap.get(classFileToCheck.getName());
|
||||
|
||||
for (Field field : classFileToCheck.fields) {
|
||||
if (ignoreField(field.getName(classFileToCheck.constant_pool))) {
|
||||
continue;
|
||||
}
|
||||
nonFinalStaticEnumField =
|
||||
(field.access_flags.flags & (ACC_ENUM | ACC_FINAL)) == 0;
|
||||
nonFinalStaticField =
|
||||
(field.access_flags.flags & ACC_STATIC) != 0 &&
|
||||
(field.access_flags.flags & ACC_FINAL) == 0;
|
||||
if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
|
||||
errors.add("There is a mutable field named " +
|
||||
field.getName(classFileToCheck.constant_pool) +
|
||||
", at class " +
|
||||
classFileToCheck.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,4 +20,3 @@ import java.lang.annotation.ContainerFor;
|
||||
|
||||
@Foo @Foo
|
||||
public class MissingDefaultCase1 {}
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
MissingDefaultCase1.java:21:1: compiler.err.duplicate.annotation.invalid.repeated: Foo
|
||||
MissingDefaultCase1.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
|
||||
1 error
|
||||
2 errors
|
||||
|
@ -20,4 +20,3 @@ import java.lang.annotation.ContainerFor;
|
||||
|
||||
@Foo @Foo
|
||||
public class MissingDefaultCase2 {}
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
MissingDefaultCase2.java:21:1: compiler.err.duplicate.annotation.invalid.repeated: Foo
|
||||
MissingDefaultCase2.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
|
||||
1 error
|
||||
2 errors
|
||||
|
@ -1,3 +1,3 @@
|
||||
NoRepeatableAnno.java:11:1: compiler.err.duplicate.annotation.missing.container: Foo
|
||||
NoRepeatableAnno.java:11:6: compiler.err.duplicate.annotation.missing.container: Foo
|
||||
NoRepeatableAnno.java:11:1: compiler.err.duplicate.annotation.missing.container: Foo, java.lang.annotation.ContainedBy
|
||||
NoRepeatableAnno.java:11:6: compiler.err.duplicate.annotation.missing.container: Foo, java.lang.annotation.ContainedBy
|
||||
2 errors
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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 Container annotation is not checked for semantic correctness
|
||||
* @bug 8001114
|
||||
*
|
||||
* @compile/fail/ref=RepeatingTargetNotAllowed.out -XDrawDiagnostics RepeatingTargetNotAllowed.java
|
||||
*/
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@ContainedBy(Foos.class)
|
||||
@interface Foo {}
|
||||
|
||||
@ContainerFor(Foo.class)
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@interface Foos {
|
||||
Foo[] value();
|
||||
}
|
||||
|
||||
public class RepeatingTargetNotAllowed {
|
||||
@Foo @Foo int f = 0;
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
RepeatingTargetNotAllowed.java:44:5: compiler.err.invalid.containedby.annotation.incompatible.target: Foos, Foo
|
||||
1 error
|
@ -31,6 +31,4 @@ import java.lang.annotation.*;
|
||||
@ContainerFor(Anno.class)
|
||||
@interface Annos { Anno[] value(); String foo(); }
|
||||
|
||||
@Anno
|
||||
@Anno
|
||||
class ContainedByNonDefault { }
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
|
||||
// key: compiler.err.duplicate.annotation.invalid.repeated
|
||||
// key: compiler.err.invalid.containedby.annotation.elem.nondefault
|
||||
//
|
||||
// We need an almost valid containing annotation. The easiest way to get
|
||||
// one close enough to valid is by forgetting a default.
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@ContainedBy(Annos.class)
|
||||
@interface Anno { }
|
||||
|
||||
@ContainerFor(Anno.class)
|
||||
@interface Annos { Anno[] value(); String foo(); }
|
||||
|
||||
@Anno
|
||||
@Anno
|
||||
class InvalidDuplicateAnnotation { }
|
47
langtools/test/tools/javac/generics/8004094/B.java
Normal file
47
langtools/test/tools/javac/generics/8004094/B.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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.
|
||||
*/
|
||||
abstract class A {
|
||||
|
||||
private static String s = null;
|
||||
|
||||
static void test() {
|
||||
new Object() {
|
||||
void m() {
|
||||
Object o = s;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class B<T> extends A {
|
||||
|
||||
private static Integer i = null;
|
||||
|
||||
static void test() {
|
||||
new Object() {
|
||||
void m() {
|
||||
Object o = i;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
32
langtools/test/tools/javac/generics/8004094/T8004094.java
Normal file
32
langtools/test/tools/javac/generics/8004094/T8004094.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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 8004094
|
||||
* @summary Javac compiler error - synthetic method accessor generated with duplicate name
|
||||
*
|
||||
* @compile B.java T8004094.java
|
||||
*/
|
||||
|
||||
public class T8004094 extends B<Object> { }
|
112
langtools/test/tools/javac/util/list/ListBufferTest.java
Normal file
112
langtools/test/tools/javac/util/list/ListBufferTest.java
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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 8004504
|
||||
* @summary Ensure that ListBuffer is working properly
|
||||
*/
|
||||
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ListBufferTest {
|
||||
public static void main(String... args) {
|
||||
testRemove();
|
||||
testCopiedEndsWithList_nil();
|
||||
}
|
||||
|
||||
private static void testCopiedEndsWithList_nil() {
|
||||
ListBuffer<String> lb = new ListBuffer<>();
|
||||
|
||||
lb.add("a");
|
||||
lb.add("b");
|
||||
lb.add("c");
|
||||
|
||||
List<String> l1 = lb.toList();
|
||||
|
||||
assertListEquals(l1, "a", "b", "c");
|
||||
assertEndsWithNil(l1);
|
||||
|
||||
lb.add("d");
|
||||
|
||||
List<String> l2 = lb.toList();
|
||||
assertListEquals(l2, "a", "b", "c", "d");
|
||||
assertEndsWithNil(l2);
|
||||
assertListEquals(l1, "a", "b", "c");
|
||||
}
|
||||
|
||||
private static void testRemove() {
|
||||
ListBuffer<String> lb1 = new ListBuffer<>();
|
||||
|
||||
lb1.add("a");
|
||||
lb1.add("b");
|
||||
lb1.add("c");
|
||||
|
||||
assertListEquals(lb1.toList(), "a", "b", "c");
|
||||
assertEquals(lb1.next(), "a");
|
||||
assertListEquals(lb1.toList(), "b", "c");
|
||||
assertEquals(lb1.next(), "b");
|
||||
assertListEquals(lb1.toList(), "c");
|
||||
assertEquals(lb1.next(), "c");
|
||||
assertListEquals(lb1.toList());
|
||||
assertEquals(lb1.next(), null);
|
||||
|
||||
lb1.add("d");
|
||||
|
||||
assertEquals(lb1.next(), "d");
|
||||
}
|
||||
|
||||
private static void assertEndsWithNil(List<?> list) {
|
||||
while (!list.isEmpty()) {
|
||||
list = list.tail;
|
||||
}
|
||||
|
||||
if (list != List.nil()) throw new IllegalStateException("Not ending with List.nil()");
|
||||
}
|
||||
|
||||
private static <T> void assertListEquals(Iterable<T> list, T... data) {
|
||||
int i = 0;
|
||||
Iterator<T> it = list.iterator();
|
||||
|
||||
while (it.hasNext() && i < data.length) {
|
||||
assertEquals(it.next(), data[i++]);
|
||||
}
|
||||
|
||||
if (it.hasNext()) {
|
||||
throw new IllegalStateException("Too many elements in the list");
|
||||
}
|
||||
|
||||
if (i < data.length) {
|
||||
throw new IllegalStateException("Too few elements in the list");
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertEquals(Object expected, Object actual) {
|
||||
if (!Objects.equals(expected, actual)) {
|
||||
throw new IllegalStateException("Incorrect content. Expected: " + expected + ", actual: " + actual);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user