62 * deletion without notice.</b>
63 */
64 public class Check {
65 protected static final Context.Key<Check> checkKey =
66 new Context.Key<Check>();
67
68 private final Names names;
69 private final Log log;
70 private final Resolve rs;
71 private final Symtab syms;
72 private final Enter enter;
73 private final DeferredAttr deferredAttr;
74 private final Infer infer;
75 private final Types types;
76 private final JCDiagnostic.Factory diags;
77 private boolean warnOnSyntheticConflicts;
78 private boolean suppressAbortOnBadClassFile;
79 private boolean enableSunApiLintControl;
80 private final TreeInfo treeinfo;
81 private final JavaFileManager fileManager;
82
83 // The set of lint options currently in effect. It is initialized
84 // from the context, and then is set/reset as needed by Attr as it
85 // visits all the various parts of the trees during attribution.
86 private Lint lint;
87
88 // The method being analyzed in Attr - it is set/reset as needed by
89 // Attr as it visits new method declarations.
90 private MethodSymbol method;
91
92 public static Check instance(Context context) {
93 Check instance = context.get(checkKey);
94 if (instance == null)
95 instance = new Check(context);
96 return instance;
97 }
98
99 protected Check(Context context) {
100 context.put(checkKey, this);
101
102 names = Names.instance(context);
103 log = Log.instance(context);
104 rs = Resolve.instance(context);
105 syms = Symtab.instance(context);
106 enter = Enter.instance(context);
107 deferredAttr = DeferredAttr.instance(context);
108 infer = Infer.instance(context);
109 this.types = Types.instance(context);
110 diags = JCDiagnostic.Factory.instance(context);
111 Options options = Options.instance(context);
112 lint = Lint.instance(context);
113 treeinfo = TreeInfo.instance(context);
114 fileManager = context.get(JavaFileManager.class);
115
116 Source source = Source.instance(context);
117 allowGenerics = source.allowGenerics();
118 allowVarargs = source.allowVarargs();
119 allowAnnotations = source.allowAnnotations();
120 allowCovariantReturns = source.allowCovariantReturns();
121 allowSimplifiedVarargs = source.allowSimplifiedVarargs();
122 allowDefaultMethods = source.allowDefaultMethods();
123 allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
124 complexInference = options.isSet("complexinference");
125 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
126 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
127 enableSunApiLintControl = options.isSet("enableSunApiLintControl");
128
129 Target target = Target.instance(context);
130 syntheticNameChar = target.syntheticNameChar();
131
132 boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
133 boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
134 boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI);
135 boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
136
137 deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
138 enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
139 uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
140 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
141 sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
142 enforceMandatoryWarnings, "sunapi", null);
143
144 deferredLintHandler = DeferredLintHandler.immediateHandler;
145 }
146
147 /** Switch: generics enabled?
148 */
149 boolean allowGenerics;
150
151 /** Switch: varargs enabled?
2986 s.outermostClass() != other.outermostClass()) {
2987 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
2988 @Override
2989 public void report() {
2990 warnDeprecated(pos, s);
2991 }
2992 });
2993 }
2994 }
2995
2996 void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
2997 if ((s.flags() & PROPRIETARY) != 0) {
2998 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
2999 public void report() {
3000 if (enableSunApiLintControl)
3001 warnSunApi(pos, "sun.proprietary", s);
3002 else
3003 log.mandatoryWarning(pos, "sun.proprietary", s);
3004 }
3005 });
3006 }
3007 }
3008
3009 /* *************************************************************************
3010 * Check for recursive annotation elements.
3011 **************************************************************************/
3012
3013 /** Check for cycles in the graph of annotation elements.
3014 */
3015 void checkNonCyclicElements(JCClassDecl tree) {
3016 if ((tree.sym.flags_field & ANNOTATION) == 0) return;
3017 Assert.check((tree.sym.flags_field & LOCKED) == 0);
3018 try {
3019 tree.sym.flags_field |= LOCKED;
3020 for (JCTree def : tree.defs) {
3021 if (!def.hasTag(METHODDEF)) continue;
3022 JCMethodDecl meth = (JCMethodDecl)def;
3023 checkAnnotationResType(meth.pos(), meth.restype.type);
3024 }
3025 } finally {
|
62 * deletion without notice.</b>
63 */
64 public class Check {
65 protected static final Context.Key<Check> checkKey =
66 new Context.Key<Check>();
67
68 private final Names names;
69 private final Log log;
70 private final Resolve rs;
71 private final Symtab syms;
72 private final Enter enter;
73 private final DeferredAttr deferredAttr;
74 private final Infer infer;
75 private final Types types;
76 private final JCDiagnostic.Factory diags;
77 private boolean warnOnSyntheticConflicts;
78 private boolean suppressAbortOnBadClassFile;
79 private boolean enableSunApiLintControl;
80 private final TreeInfo treeinfo;
81 private final JavaFileManager fileManager;
82 private final Profile profile;
83
84 // The set of lint options currently in effect. It is initialized
85 // from the context, and then is set/reset as needed by Attr as it
86 // visits all the various parts of the trees during attribution.
87 private Lint lint;
88
89 // The method being analyzed in Attr - it is set/reset as needed by
90 // Attr as it visits new method declarations.
91 private MethodSymbol method;
92
93 public static Check instance(Context context) {
94 Check instance = context.get(checkKey);
95 if (instance == null)
96 instance = new Check(context);
97 return instance;
98 }
99
100 protected Check(Context context) {
101 context.put(checkKey, this);
102
103 names = Names.instance(context);
104 log = Log.instance(context);
105 rs = Resolve.instance(context);
106 syms = Symtab.instance(context);
107 enter = Enter.instance(context);
108 deferredAttr = DeferredAttr.instance(context);
109 infer = Infer.instance(context);
110 types = Types.instance(context);
111 diags = JCDiagnostic.Factory.instance(context);
112 Options options = Options.instance(context);
113 lint = Lint.instance(context);
114 treeinfo = TreeInfo.instance(context);
115 fileManager = context.get(JavaFileManager.class);
116
117 Source source = Source.instance(context);
118 allowGenerics = source.allowGenerics();
119 allowVarargs = source.allowVarargs();
120 allowAnnotations = source.allowAnnotations();
121 allowCovariantReturns = source.allowCovariantReturns();
122 allowSimplifiedVarargs = source.allowSimplifiedVarargs();
123 allowDefaultMethods = source.allowDefaultMethods();
124 allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
125 complexInference = options.isSet("complexinference");
126 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
127 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
128 enableSunApiLintControl = options.isSet("enableSunApiLintControl");
129
130 Target target = Target.instance(context);
131 syntheticNameChar = target.syntheticNameChar();
132
133 profile = Profile.instance(context);
134
135 boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
136 boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
137 boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI);
138 boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
139
140 deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
141 enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
142 uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
143 enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
144 sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
145 enforceMandatoryWarnings, "sunapi", null);
146
147 deferredLintHandler = DeferredLintHandler.immediateHandler;
148 }
149
150 /** Switch: generics enabled?
151 */
152 boolean allowGenerics;
153
154 /** Switch: varargs enabled?
2989 s.outermostClass() != other.outermostClass()) {
2990 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
2991 @Override
2992 public void report() {
2993 warnDeprecated(pos, s);
2994 }
2995 });
2996 }
2997 }
2998
2999 void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
3000 if ((s.flags() & PROPRIETARY) != 0) {
3001 deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
3002 public void report() {
3003 if (enableSunApiLintControl)
3004 warnSunApi(pos, "sun.proprietary", s);
3005 else
3006 log.mandatoryWarning(pos, "sun.proprietary", s);
3007 }
3008 });
3009 }
3010 }
3011
3012 void checkProfile(final DiagnosticPosition pos, final Symbol s) {
3013 if (profile != Profile.DEFAULT && (s.flags() & NOT_IN_PROFILE) != 0) {
3014 log.error(pos, "not.in.profile", s, profile);
3015 }
3016 }
3017
3018 /* *************************************************************************
3019 * Check for recursive annotation elements.
3020 **************************************************************************/
3021
3022 /** Check for cycles in the graph of annotation elements.
3023 */
3024 void checkNonCyclicElements(JCClassDecl tree) {
3025 if ((tree.sym.flags_field & ANNOTATION) == 0) return;
3026 Assert.check((tree.sym.flags_field & LOCKED) == 0);
3027 try {
3028 tree.sym.flags_field |= LOCKED;
3029 for (JCTree def : tree.defs) {
3030 if (!def.hasTag(METHODDEF)) continue;
3031 JCMethodDecl meth = (JCMethodDecl)def;
3032 checkAnnotationResType(meth.pos(), meth.restype.type);
3033 }
3034 } finally {
|