1 /*******************************************************************************
2 * Copyright (c) 2000, 2020 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 * Benjamin Muskalla - Contribution for bug 239066
14 * Stephan Herrmann - Contributions for
15 * bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used
16 * bug 338303 - Warning about Redundant assignment conflicts with definite assignment
17 * bug 349326 - [1.7] new warning for missing try-with-resources
18 * bug 186342 - [compiler][null] Using annotations for null checking
19 * bug 365519 - editorial cleanup after bug 186342 and bug 365387
20 * bug 365662 - [compiler][null] warn on contradictory and redundant null annotations
21 * bug 365531 - [compiler][null] investigate alternative strategy for internally encoding nullness defaults
22 * bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
23 * bug 374605 - Unreasonable warning for enum-based switch statements
24 * bug 382353 - [1.8][compiler] Implementation property modifiers should be accepted on default methods.
25 * bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance
26 * bug 388281 - [compiler][null] inheritance of null annotations as an option
27 * bug 376053 - [compiler][resource] Strange potential resource leak problems
28 * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated
29 * bug 393719 - [compiler] inconsistent warnings on iteration variables
30 * bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types
31 * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract
32 * bug 331649 - [compiler][null] consider null annotations for fields
33 * bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null
34 * bug 376590 - Private fields with @Inject are ignored by unused field validation
35 * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
36 * bug 402028 - [1.8][compiler] null analysis for reference expressions
37 * bug 401796 - [1.8][compiler] don't treat default methods as overriding an independent inherited abstract method
38 * bug 404649 - [1.8][compiler] detect illegal reference to indirect or redundant super
39 * bug 392384 - [1.8][compiler][null] Restore nullness info from type annotations in class files
40 * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis
41 * Bug 415043 - [1.8][null] Follow-up re null type annotations after bug 392099
42 * Bug 415291 - [1.8][null] differentiate type incompatibilities due to null annotations
43 * Bug 415850 - [1.8] Ensure RunJDTCoreTests can cope with null annotations enabled
44 * Bug 414380 - [compiler][internal] QualifiedNameReference#indexOfFirstFieldBinding does not point to the first field
45 * Bug 392238 - [1.8][compiler][null] Detect semantically invalid null type annotations
46 * Bug 416307 - [1.8][compiler][null] subclass with type parameter substitution confuses null checking
47 * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec)
48 * Bug 424637 - [1.8][compiler][null] AIOOB in ReferenceExpression.resolveType with a method reference to Files::walk
49 * Bug 428294 - [1.8][compiler] Type mismatch: cannot convert from List<Object> to Collection<Object[]>
50 * Bug 428366 - [1.8] [compiler] The method valueAt(ObservableList<Object>, int) is ambiguous for the type Bindings
51 * Bug 416190 - [1.8][null] detect incompatible overrides due to null type annotations
52 * Bug 392245 - [1.8][compiler][null] Define whether / how @NonNullByDefault applies to TYPE_USE locations
53 * Bug 390889 - [1.8][compiler] Evaluate options to support 1.7- projects against 1.8 JRE.
54 * Bug 430150 - [1.8][null] stricter checking against type variables
55 * Bug 434600 - Incorrect null analysis error reporting on type parameters
56 * Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type
57 * Bug 438467 - [compiler][null] Better error position for "The method _ cannot implement the corresponding method _ due to incompatible nullness constraints"
58 * Bug 439298 - [null] "Missing code implementation in the compiler" when using @NonNullByDefault in package-info.java
59 * Bug 435805 - [1.8][compiler][null] Java 8 compiler does not recognize declaration style null annotations
60 * Bug 446442 - [1.8] merge null annotations from super methods
61 * Bug 455723 - Nonnull argument not correctly inferred in loop
62 * Bug 458361 - [1.8][null] reconciler throws NPE in ProblemReporter.illegalReturnRedefinition()
63 * Bug 459967 - [null] compiler should know about nullness of special methods like MyEnum.valueOf()
64 * Bug 461878 - [1.7][1.8][compiler][null] ECJ compiler does not allow to use null annotations on annotations
65 * Bug 410218 - Optional warning for arguments of "unexpected" types to Map#get(Object), Collection#remove(Object) et al.
66 * Jesper S Moller <jesper@selskabet.org> - Contributions for
67 * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression
68 * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment
69 * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration
70 * bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable
71 * bug 412151 - [1.8][compiler] Check repeating annotation's collection type
72 * bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains
73 * Bug 429384 - [1.8][null] implement conformance rules for null-annotated lower / upper type bounds
74 * Bug 416182 - [1.8][compiler][null] Contradictory null annotations not rejected
75 * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type
76 * Ulrich Grave <ulrich.grave@gmx.de> - Contributions for
77 * bug 386692 - Missing "unused" warning on "autowired" fields
78 ********************************************************************************/
79 package org.eclipse.jdt.internal.compiler.problem;
80
81 import java.io.CharConversionException;
82 import java.io.PrintWriter;
83 import java.io.StringWriter;
84 import java.util.Iterator;
85 import java.util.List;
86 import java.util.Set;
87 import java.util.function.Supplier;
88 import java.util.stream.Collectors;
89
90 import org.eclipse.jdt.core.compiler.CategorizedProblem;
91 import org.eclipse.jdt.core.compiler.CharOperation;
92 import org.eclipse.jdt.core.compiler.IProblem;
93 import org.eclipse.jdt.core.compiler.InvalidInputException;
94 import org.eclipse.jdt.internal.compiler.CompilationResult;
95 import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
96 import org.eclipse.jdt.internal.compiler.IProblemFactory;
97 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
98 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
99 import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
100 import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
101 import org.eclipse.jdt.internal.compiler.ast.Annotation;
102 import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration;
103 import org.eclipse.jdt.internal.compiler.ast.Argument;
104 import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;
105 import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
106 import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
107 import org.eclipse.jdt.internal.compiler.ast.ArrayReference;
108 import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
109 import org.eclipse.jdt.internal.compiler.ast.Assignment;
110 import org.eclipse.jdt.internal.compiler.ast.BinaryExpression;
111 import org.eclipse.jdt.internal.compiler.ast.Block;
112 import org.eclipse.jdt.internal.compiler.ast.BranchStatement;
113 import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
114 import org.eclipse.jdt.internal.compiler.ast.CastExpression;
115 import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
116 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
117 import org.eclipse.jdt.internal.compiler.ast.CompoundAssignment;
118 import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
119 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
120 import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
121 import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
122 import org.eclipse.jdt.internal.compiler.ast.Expression;
123 import org.eclipse.jdt.internal.compiler.ast.ExpressionContext;
124 import org.eclipse.jdt.internal.compiler.ast.FakedTrackingVariable;
125 import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
126 import org.eclipse.jdt.internal.compiler.ast.FieldReference;
127 import org.eclipse.jdt.internal.compiler.ast.FunctionalExpression;
128 import org.eclipse.jdt.internal.compiler.ast.ImportReference;
129 import org.eclipse.jdt.internal.compiler.ast.Initializer;
130 import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression;
131 import org.eclipse.jdt.internal.compiler.ast.LabeledStatement;
132 import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
133 import org.eclipse.jdt.internal.compiler.ast.Literal;
134 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
135 import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
136 import org.eclipse.jdt.internal.compiler.ast.MessageSend;
137 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
138 import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration;
139 import org.eclipse.jdt.internal.compiler.ast.ModuleReference;
140 import org.eclipse.jdt.internal.compiler.ast.NameReference;
141 import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching;
142 import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
143 import org.eclipse.jdt.internal.compiler.ast.OpensStatement;
144 import org.eclipse.jdt.internal.compiler.ast.PackageVisibilityStatement;
145 import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
146 import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
147 import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression;
148 import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
149 import org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference;
150 import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
151 import org.eclipse.jdt.internal.compiler.ast.Receiver;
152 import org.eclipse.jdt.internal.compiler.ast.RecordComponent;
153 import org.eclipse.jdt.internal.compiler.ast.Reference;
154 import org.eclipse.jdt.internal.compiler.ast.ReferenceExpression;
155 import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
156 import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
157 import org.eclipse.jdt.internal.compiler.ast.Statement;
158 import org.eclipse.jdt.internal.compiler.ast.SwitchExpression;
159 import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
160 import org.eclipse.jdt.internal.compiler.ast.ThisReference;
161 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
162 import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
163 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
164 import org.eclipse.jdt.internal.compiler.ast.UnaryExpression;
165 import org.eclipse.jdt.internal.compiler.ast.Wildcard;
166 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
167 import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
168 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
169 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
170 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
171 import org.eclipse.jdt.internal.compiler.impl.Constant;
172 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
173 import org.eclipse.jdt.internal.compiler.impl.StringConstant;
174 import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
175 import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
176 import org.eclipse.jdt.internal.compiler.lookup.Binding;
177 import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
178 import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
179 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
180 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
181 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
182 import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
183 import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
184 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
185 import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
186 import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
187 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
188 import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
189 import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
190 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
191 import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
192 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
193 import org.eclipse.jdt.internal.compiler.lookup.Scope;
194 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
195 import org.eclipse.jdt.internal.compiler.lookup.SplitPackageBinding;
196 import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding;
197 import org.eclipse.jdt.internal.compiler.lookup.TagBits;
198 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
199 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
200 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants.DangerousMethod;
201 import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
202 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
203 import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
204 import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding;
205 import org.eclipse.jdt.internal.compiler.parser.JavadocTagConstants;
206 import org.eclipse.jdt.internal.compiler.parser.Parser;
207 import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
208 import org.eclipse.jdt.internal.compiler.parser.Scanner;
209 import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
210 import org.eclipse.jdt.internal.compiler.util.Messages;
211 import org.eclipse.jdt.internal.compiler.util.Util;
212
213 @SuppressWarnings("rawtypes")
214 public class ProblemReporter extends ProblemHandler {
215
216 public ReferenceContext referenceContext;
217 private Scanner positionScanner;
218 private boolean underScoreIsError;
219 private final static byte
220 // TYPE_ACCESS = 0x0,
221 FIELD_ACCESS = 0x4,
222 CONSTRUCTOR_ACCESS = 0x8,
223 METHOD_ACCESS = 0xC;
224
225 private static String RESTRICTED_IDENTIFIER_RECORD = "RestrictedIdentifierrecord"; //$NON-NLS-1$
226 private static String RECORD = "record"; //$NON-NLS-1$
227
ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory)228 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
229 super(policy, options, problemFactory);
230 }
231
getElaborationId(int leadProblemId, byte elaborationVariant)232 private static int getElaborationId (int leadProblemId, byte elaborationVariant) {
233 return leadProblemId << 8 | elaborationVariant; // leadProblemId comes into the higher order bytes
234 }
getIrritant(int problemID)235 public static int getIrritant(int problemID) {
236 switch(problemID){
237
238 case IProblem.MaskedCatch :
239 return CompilerOptions.MaskedCatchBlock;
240
241 case IProblem.UnusedImport :
242 return CompilerOptions.UnusedImport;
243
244 case IProblem.MethodButWithConstructorName :
245 return CompilerOptions.MethodWithConstructorName;
246
247 case IProblem.OverridingNonVisibleMethod :
248 return CompilerOptions.OverriddenPackageDefaultMethod;
249
250 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
251 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
252 return CompilerOptions.IncompatibleNonInheritedInterfaceMethod;
253
254 case IProblem.OverridingDeprecatedMethod :
255 case IProblem.UsingDeprecatedType :
256 case IProblem.UsingDeprecatedMethod :
257 case IProblem.UsingDeprecatedConstructor :
258 case IProblem.UsingDeprecatedField :
259 case IProblem.UsingDeprecatedModule :
260 case IProblem.OverridingDeprecatedSinceVersionMethod :
261 case IProblem.UsingDeprecatedSinceVersionType :
262 case IProblem.UsingDeprecatedSinceVersionMethod :
263 case IProblem.UsingDeprecatedSinceVersionConstructor :
264 case IProblem.UsingDeprecatedSinceVersionField :
265 case IProblem.UsingDeprecatedSinceVersionModule :
266 return CompilerOptions.UsingDeprecatedAPI;
267
268 case IProblem.OverridingTerminallyDeprecatedMethod :
269 case IProblem.UsingTerminallyDeprecatedType :
270 case IProblem.UsingTerminallyDeprecatedMethod :
271 case IProblem.UsingTerminallyDeprecatedConstructor :
272 case IProblem.UsingTerminallyDeprecatedField :
273 case IProblem.UsingTerminallyDeprecatedModule :
274 case IProblem.OverridingTerminallyDeprecatedSinceVersionMethod :
275 case IProblem.UsingTerminallyDeprecatedSinceVersionType :
276 case IProblem.UsingTerminallyDeprecatedSinceVersionMethod :
277 case IProblem.UsingTerminallyDeprecatedSinceVersionConstructor :
278 case IProblem.UsingTerminallyDeprecatedSinceVersionField :
279 case IProblem.UsingTerminallyDeprecatedSinceVersionModule :
280 return CompilerOptions.UsingTerminallyDeprecatedAPI;
281
282 case IProblem.LocalVariableIsNeverUsed :
283 return CompilerOptions.UnusedLocalVariable;
284
285 case IProblem.ArgumentIsNeverUsed :
286 return CompilerOptions.UnusedArgument;
287
288 case IProblem.ExceptionParameterIsNeverUsed :
289 return CompilerOptions.UnusedExceptionParameter;
290
291 case IProblem.NoImplicitStringConversionForCharArrayExpression :
292 return CompilerOptions.NoImplicitStringConversion;
293
294 case IProblem.NeedToEmulateFieldReadAccess :
295 case IProblem.NeedToEmulateFieldWriteAccess :
296 case IProblem.NeedToEmulateMethodAccess :
297 case IProblem.NeedToEmulateConstructorAccess :
298 return CompilerOptions.AccessEmulation;
299
300 case IProblem.NonExternalizedStringLiteral :
301 case IProblem.UnnecessaryNLSTag :
302 return CompilerOptions.NonExternalizedString;
303
304 case IProblem.UseAssertAsAnIdentifier :
305 return CompilerOptions.AssertUsedAsAnIdentifier;
306
307 case IProblem.UseEnumAsAnIdentifier :
308 return CompilerOptions.EnumUsedAsAnIdentifier;
309
310 case IProblem.NonStaticAccessToStaticMethod :
311 case IProblem.NonStaticAccessToStaticField :
312 return CompilerOptions.NonStaticAccessToStatic;
313
314 case IProblem.IndirectAccessToStaticMethod :
315 case IProblem.IndirectAccessToStaticField :
316 case IProblem.IndirectAccessToStaticType :
317 return CompilerOptions.IndirectStaticAccess;
318
319 case IProblem.AssignmentHasNoEffect:
320 return CompilerOptions.NoEffectAssignment;
321
322 case IProblem.UnusedPrivateConstructor:
323 case IProblem.UnusedPrivateMethod:
324 case IProblem.UnusedPrivateField:
325 case IProblem.UnusedPrivateType:
326 return CompilerOptions.UnusedPrivateMember;
327
328 case IProblem.LocalVariableHidingLocalVariable:
329 case IProblem.LocalVariableHidingField:
330 case IProblem.ArgumentHidingLocalVariable:
331 case IProblem.ArgumentHidingField:
332 return CompilerOptions.LocalVariableHiding;
333
334 case IProblem.FieldHidingLocalVariable:
335 case IProblem.FieldHidingField:
336 return CompilerOptions.FieldHiding;
337
338 case IProblem.TypeParameterHidingType:
339 case IProblem.TypeHidingTypeParameterFromType:
340 case IProblem.TypeHidingTypeParameterFromMethod:
341 case IProblem.TypeHidingType:
342 return CompilerOptions.TypeHiding;
343
344 case IProblem.PossibleAccidentalBooleanAssignment:
345 return CompilerOptions.AccidentalBooleanAssign;
346
347 case IProblem.SuperfluousSemicolon:
348 case IProblem.EmptyControlFlowStatement:
349 return CompilerOptions.EmptyStatement;
350
351 case IProblem.UndocumentedEmptyBlock:
352 return CompilerOptions.UndocumentedEmptyBlock;
353
354 case IProblem.UnnecessaryCast:
355 case IProblem.UnnecessaryInstanceof:
356 return CompilerOptions.UnnecessaryTypeCheck;
357
358 case IProblem.FinallyMustCompleteNormally:
359 return CompilerOptions.FinallyBlockNotCompleting;
360
361 case IProblem.UnusedMethodDeclaredThrownException:
362 case IProblem.UnusedConstructorDeclaredThrownException:
363 return CompilerOptions.UnusedDeclaredThrownException;
364
365 case IProblem.UnqualifiedFieldAccess:
366 return CompilerOptions.UnqualifiedFieldAccess;
367
368 case IProblem.UnnecessaryElse:
369 return CompilerOptions.UnnecessaryElse;
370
371 case IProblem.UnsafeRawConstructorInvocation:
372 case IProblem.UnsafeRawMethodInvocation:
373 case IProblem.UnsafeTypeConversion:
374 case IProblem.UnsafeElementTypeConversion:
375 case IProblem.UnsafeRawFieldAssignment:
376 case IProblem.UnsafeGenericCast:
377 case IProblem.UnsafeReturnTypeOverride:
378 case IProblem.UnsafeRawGenericMethodInvocation:
379 case IProblem.UnsafeRawGenericConstructorInvocation:
380 case IProblem.UnsafeGenericArrayForVarargs:
381 case IProblem.PotentialHeapPollutionFromVararg:
382 return CompilerOptions.UncheckedTypeOperation;
383
384 case IProblem.RawTypeReference:
385 return CompilerOptions.RawTypeReference;
386
387 case IProblem.MissingOverrideAnnotation:
388 case IProblem.MissingOverrideAnnotationForInterfaceMethodImplementation:
389 return CompilerOptions.MissingOverrideAnnotation;
390
391 case IProblem.FieldMissingDeprecatedAnnotation:
392 case IProblem.MethodMissingDeprecatedAnnotation:
393 case IProblem.TypeMissingDeprecatedAnnotation:
394 return CompilerOptions.MissingDeprecatedAnnotation;
395
396 case IProblem.FinalBoundForTypeVariable:
397 return CompilerOptions.FinalParameterBound;
398
399 case IProblem.MissingSerialVersion:
400 return CompilerOptions.MissingSerialVersion;
401
402 case IProblem.ForbiddenReference:
403 return CompilerOptions.ForbiddenReference;
404
405 case IProblem.DiscouragedReference:
406 return CompilerOptions.DiscouragedReference;
407
408 case IProblem.MethodVarargsArgumentNeedCast :
409 case IProblem.ConstructorVarargsArgumentNeedCast :
410 return CompilerOptions.VarargsArgumentNeedCast;
411
412 case IProblem.NullLocalVariableReference:
413 case IProblem.NullExpressionReference:
414 case IProblem.NullUnboxing:
415 return CompilerOptions.NullReference;
416
417 case IProblem.PotentialNullLocalVariableReference:
418 case IProblem.PotentialNullMessageSendReference:
419 case IProblem.ArrayReferencePotentialNullReference:
420 case IProblem.NullableFieldReference:
421 case IProblem.DereferencingNullableExpression:
422 case IProblem.PotentialNullExpressionReference:
423 case IProblem.PotentialNullUnboxing:
424 return CompilerOptions.PotentialNullReference;
425
426 case IProblem.RedundantLocalVariableNullAssignment:
427 case IProblem.RedundantNullCheckOnNonNullLocalVariable:
428 case IProblem.RedundantNullCheckOnNullLocalVariable:
429 case IProblem.NonNullLocalVariableComparisonYieldsFalse:
430 case IProblem.NullLocalVariableComparisonYieldsFalse:
431 case IProblem.NullLocalVariableInstanceofYieldsFalse:
432 case IProblem.RedundantNullCheckOnNonNullExpression:
433 case IProblem.NonNullExpressionComparisonYieldsFalse:
434 case IProblem.RedundantNullCheckOnNonNullMessageSend:
435 case IProblem.RedundantNullCheckOnSpecdNonNullLocalVariable:
436 case IProblem.SpecdNonNullLocalVariableComparisonYieldsFalse:
437 case IProblem.NonNullMessageSendComparisonYieldsFalse:
438 case IProblem.RedundantNullCheckOnNonNullSpecdField:
439 case IProblem.NonNullSpecdFieldComparisonYieldsFalse:
440 case IProblem.RedundantNullCheckAgainstNonNullType:
441 case IProblem.RedundantNullCheckOnField:
442 case IProblem.RedundantNullCheckOnConstNonNullField:
443 case IProblem.ConstNonNullFieldComparisonYieldsFalse:
444 case IProblem.FieldComparisonYieldsFalse:
445 return CompilerOptions.RedundantNullCheck;
446
447 case IProblem.RequiredNonNullButProvidedNull:
448 case IProblem.RequiredNonNullButProvidedSpecdNullable:
449 case IProblem.IllegalReturnNullityRedefinition:
450 case IProblem.IllegalReturnNullityRedefinitionFreeTypeVariable:
451 case IProblem.IllegalRedefinitionToNonNullParameter:
452 case IProblem.IllegalRedefinitionOfTypeVariable:
453 case IProblem.IllegalDefinitionToNonNullParameter:
454 case IProblem.ParameterLackingNullableAnnotation:
455 case IProblem.CannotImplementIncompatibleNullness:
456 case IProblem.ConflictingNullAnnotations:
457 case IProblem.ConflictingInheritedNullAnnotations:
458 case IProblem.NullityMismatchingTypeAnnotation:
459 case IProblem.NullityMismatchingTypeAnnotationSuperHint:
460 case IProblem.NullityMismatchTypeArgument:
461 case IProblem.UninitializedNonNullField:
462 case IProblem.UninitializedNonNullFieldHintMissingDefault:
463 case IProblem.ReferenceExpressionParameterNullityMismatch:
464 case IProblem.ReferenceExpressionReturnNullRedef:
465 case IProblem.ContradictoryNullAnnotations:
466 case IProblem.ContradictoryNullAnnotationsOnBound:
467 case IProblem.ContradictoryNullAnnotationsInferred:
468 case IProblem.ContradictoryNullAnnotationsInferredFunctionType:
469 case IProblem.IllegalParameterNullityRedefinition:
470 return CompilerOptions.NullSpecViolation;
471
472 case IProblem.NullNotCompatibleToFreeTypeVariable:
473 case IProblem.NullityMismatchAgainstFreeTypeVariable:
474 case IProblem.UncheckedAccessOfValueOfFreeTypeVariable:
475 case IProblem.RequiredNonNullButProvidedFreeTypeVariable:
476 case IProblem.UninitializedFreeTypeVariableField:
477 case IProblem.UninitializedFreeTypeVariableFieldHintMissingDefault:
478 return CompilerOptions.PessimisticNullAnalysisForFreeTypeVariables;
479
480 case IProblem.NonNullTypeVariableFromLegacyMethod:
481 case IProblem.NonNullMethodTypeVariableFromLegacyMethod:
482 return CompilerOptions.NonNullTypeVariableFromLegacyInvocation;
483
484 case IProblem.ParameterLackingNonNullAnnotation:
485 case IProblem.InheritedParameterLackingNonNullAnnotation:
486 return CompilerOptions.NonnullParameterAnnotationDropped;
487
488 case IProblem.RequiredNonNullButProvidedPotentialNull:
489 return CompilerOptions.NullAnnotationInferenceConflict;
490 case IProblem.RequiredNonNullButProvidedUnknown:
491 case IProblem.NullityUncheckedTypeAnnotationDetail:
492 case IProblem.NullityUncheckedTypeAnnotationDetailSuperHint:
493 case IProblem.ReferenceExpressionParameterNullityUnchecked:
494 case IProblem.ReferenceExpressionReturnNullRedefUnchecked:
495 case IProblem.UnsafeNullnessCast:
496 return CompilerOptions.NullUncheckedConversion;
497 case IProblem.AnnotatedTypeArgumentToUnannotated:
498 case IProblem.AnnotatedTypeArgumentToUnannotatedSuperHint:
499 return CompilerOptions.AnnotatedTypeArgumentToUnannotated;
500 case IProblem.RedundantNullAnnotation:
501 case IProblem.RedundantNullDefaultAnnotation:
502 case IProblem.RedundantNullDefaultAnnotationModule:
503 case IProblem.RedundantNullDefaultAnnotationPackage:
504 case IProblem.RedundantNullDefaultAnnotationType:
505 case IProblem.RedundantNullDefaultAnnotationMethod:
506 case IProblem.RedundantNullDefaultAnnotationLocal:
507 case IProblem.RedundantNullDefaultAnnotationField:
508 return CompilerOptions.RedundantNullAnnotation;
509
510 case IProblem.BoxingConversion :
511 case IProblem.UnboxingConversion :
512 return CompilerOptions.AutoBoxing;
513
514 case IProblem.MissingEnumConstantCase :
515 case IProblem.MissingEnumConstantCaseDespiteDefault : // this one is further protected by CompilerOptions.reportMissingEnumCaseDespiteDefault
516 return CompilerOptions.MissingEnumConstantCase;
517
518 case IProblem.MissingDefaultCase :
519 case IProblem.MissingEnumDefaultCase :
520 return CompilerOptions.MissingDefaultCase;
521
522 case IProblem.AnnotationTypeUsedAsSuperInterface :
523 return CompilerOptions.AnnotationSuperInterface;
524
525 case IProblem.UnhandledWarningToken :
526 return CompilerOptions.UnhandledWarningToken;
527
528 case IProblem.UnusedWarningToken :
529 return CompilerOptions.UnusedWarningToken;
530
531 case IProblem.UnusedLabel :
532 return CompilerOptions.UnusedLabel;
533
534 case IProblem.JavadocUnexpectedTag:
535 case IProblem.JavadocDuplicateTag:
536 case IProblem.JavadocDuplicateReturnTag:
537 case IProblem.JavadocInvalidThrowsClass:
538 case IProblem.JavadocInvalidSeeReference:
539 case IProblem.JavadocInvalidParamTagName:
540 case IProblem.JavadocInvalidParamTagTypeParameter:
541 case IProblem.JavadocMalformedSeeReference:
542 case IProblem.JavadocInvalidSeeHref:
543 case IProblem.JavadocInvalidSeeArgs:
544 case IProblem.JavadocInvalidTag:
545 case IProblem.JavadocUnterminatedInlineTag:
546 case IProblem.JavadocMissingHashCharacter:
547 case IProblem.JavadocEmptyReturnTag:
548 case IProblem.JavadocUnexpectedText:
549 case IProblem.JavadocInvalidParamName:
550 case IProblem.JavadocDuplicateParamName:
551 case IProblem.JavadocMissingParamName:
552 case IProblem.JavadocMissingIdentifier:
553 case IProblem.JavadocInvalidMemberTypeQualification:
554 case IProblem.JavadocInvalidThrowsClassName:
555 case IProblem.JavadocDuplicateThrowsClassName:
556 case IProblem.JavadocMissingThrowsClassName:
557 case IProblem.JavadocDuplicateProvidesTag:
558 case IProblem.JavadocDuplicateUsesTag:
559 case IProblem.JavadocInvalidUsesClass:
560 case IProblem.JavadocInvalidUsesClassName:
561 case IProblem.JavadocInvalidProvidesClass:
562 case IProblem.JavadocInvalidProvidesClassName:
563 case IProblem.JavadocMissingProvidesClassName:
564 case IProblem.JavadocMissingUsesClassName:
565 case IProblem.JavadocMissingSeeReference:
566 case IProblem.JavadocInvalidValueReference:
567 case IProblem.JavadocUndefinedField:
568 case IProblem.JavadocAmbiguousField:
569 case IProblem.JavadocUndefinedConstructor:
570 case IProblem.JavadocAmbiguousConstructor:
571 case IProblem.JavadocUndefinedMethod:
572 case IProblem.JavadocAmbiguousMethod:
573 case IProblem.JavadocAmbiguousMethodReference:
574 case IProblem.JavadocParameterMismatch:
575 case IProblem.JavadocUndefinedType:
576 case IProblem.JavadocAmbiguousType:
577 case IProblem.JavadocInternalTypeNameProvided:
578 case IProblem.JavadocNoMessageSendOnArrayType:
579 case IProblem.JavadocNoMessageSendOnBaseType:
580 case IProblem.JavadocInheritedMethodHidesEnclosingName:
581 case IProblem.JavadocInheritedFieldHidesEnclosingName:
582 case IProblem.JavadocInheritedNameHidesEnclosingTypeName:
583 case IProblem.JavadocNonStaticTypeFromStaticInvocation:
584 case IProblem.JavadocGenericMethodTypeArgumentMismatch:
585 case IProblem.JavadocNonGenericMethod:
586 case IProblem.JavadocIncorrectArityForParameterizedMethod:
587 case IProblem.JavadocParameterizedMethodArgumentTypeMismatch:
588 case IProblem.JavadocTypeArgumentsForRawGenericMethod:
589 case IProblem.JavadocGenericConstructorTypeArgumentMismatch:
590 case IProblem.JavadocNonGenericConstructor:
591 case IProblem.JavadocIncorrectArityForParameterizedConstructor:
592 case IProblem.JavadocParameterizedConstructorArgumentTypeMismatch:
593 case IProblem.JavadocTypeArgumentsForRawGenericConstructor:
594 case IProblem.JavadocNotAccessibleType:
595 case IProblem.JavadocNotVisibleField:
596 case IProblem.JavadocNotVisibleConstructor:
597 case IProblem.JavadocNotVisibleMethod:
598 case IProblem.JavadocNotVisibleType:
599 case IProblem.JavadocUsingDeprecatedField:
600 case IProblem.JavadocUsingDeprecatedConstructor:
601 case IProblem.JavadocUsingDeprecatedMethod:
602 case IProblem.JavadocUsingDeprecatedType:
603 case IProblem.JavadocHiddenReference:
604 case IProblem.JavadocMissingTagDescription:
605 case IProblem.JavadocInvalidSeeUrlReference:
606 return CompilerOptions.InvalidJavadoc;
607
608 case IProblem.JavadocMissingParamTag:
609 case IProblem.JavadocMissingProvidesTag:
610 case IProblem.JavadocMissingReturnTag:
611 case IProblem.JavadocMissingThrowsTag:
612 case IProblem.JavadocMissingUsesTag:
613 return CompilerOptions.MissingJavadocTags;
614
615 case IProblem.JavadocMissing:
616 return CompilerOptions.MissingJavadocComments;
617
618 case IProblem.ParameterAssignment:
619 return CompilerOptions.ParameterAssignment;
620
621 case IProblem.FallthroughCase:
622 return CompilerOptions.FallthroughCase;
623
624 case IProblem.OverridingMethodWithoutSuperInvocation:
625 return CompilerOptions.OverridingMethodWithoutSuperInvocation;
626
627 case IProblem.UnusedTypeArgumentsForMethodInvocation:
628 case IProblem.UnusedTypeArgumentsForConstructorInvocation:
629 return CompilerOptions.UnusedTypeArguments;
630
631 case IProblem.RedundantSuperinterface:
632 return CompilerOptions.RedundantSuperinterface;
633
634 case IProblem.ComparingIdentical:
635 return CompilerOptions.ComparingIdentical;
636
637 case IProblem.MissingSynchronizedModifierInInheritedMethod:
638 return CompilerOptions.MissingSynchronizedModifierInInheritedMethod;
639
640 case IProblem.ShouldImplementHashcode:
641 return CompilerOptions.ShouldImplementHashcode;
642
643 case IProblem.DeadCode:
644 return CompilerOptions.DeadCode;
645
646 case IProblem.Task :
647 return CompilerOptions.Tasks;
648
649 case IProblem.UnusedObjectAllocation:
650 return CompilerOptions.UnusedObjectAllocation;
651
652 case IProblem.MethodCanBeStatic:
653 return CompilerOptions.MethodCanBeStatic;
654
655 case IProblem.MethodCanBePotentiallyStatic:
656 return CompilerOptions.MethodCanBePotentiallyStatic;
657
658 case IProblem.UnclosedCloseable:
659 case IProblem.UnclosedCloseableAtExit:
660 return CompilerOptions.UnclosedCloseable;
661 case IProblem.PotentiallyUnclosedCloseable:
662 case IProblem.PotentiallyUnclosedCloseableAtExit:
663 return CompilerOptions.PotentiallyUnclosedCloseable;
664 case IProblem.ExplicitlyClosedAutoCloseable:
665 return CompilerOptions.ExplicitlyClosedAutoCloseable;
666
667 case IProblem.RedundantSpecificationOfTypeArguments:
668 return CompilerOptions.RedundantSpecificationOfTypeArguments;
669
670 case IProblem.MissingNonNullByDefaultAnnotationOnPackage:
671 case IProblem.MissingNonNullByDefaultAnnotationOnType:
672 return CompilerOptions.MissingNonNullByDefaultAnnotation;
673
674 case IProblem.UnusedTypeParameter:
675 return CompilerOptions.UnusedTypeParameter;
676
677 case IProblem.UnlikelyCollectionMethodArgumentType:
678 return CompilerOptions.UnlikelyCollectionMethodArgumentType;
679 case IProblem.UnlikelyEqualsArgumentType:
680 return CompilerOptions.UnlikelyEqualsArgumentType;
681
682 case IProblem.NonPublicTypeInAPI:
683 case IProblem.NotExportedTypeInAPI:
684 case IProblem.MissingRequiresTransitiveForTypeInAPI:
685 return CompilerOptions.APILeak;
686 case IProblem.UnstableAutoModuleName:
687 return CompilerOptions.UnstableAutoModuleName;
688 case IProblem.PreviewFeatureUsed:
689 return CompilerOptions.PreviewFeatureUsed;
690
691 case IProblem.ProblemNotAnalysed:
692 return CompilerOptions.SuppressWarningsNotAnalysed;
693 }
694 return 0;
695 }
696 /**
697 * Compute problem category ID based on problem ID
698 * @param problemID
699 * @return a category ID
700 * @see CategorizedProblem
701 */
getProblemCategory(int severity, int problemID)702 public static int getProblemCategory(int severity, int problemID) {
703 categorizeOnIrritant: {
704 // fatal problems even if optional are all falling into same category (not irritant based)
705 if ((severity & ProblemSeverities.Fatal) != 0)
706 break categorizeOnIrritant;
707 int irritant = getIrritant(problemID);
708 switch (irritant) {
709 case CompilerOptions.MethodWithConstructorName :
710 case CompilerOptions.AccessEmulation :
711 case CompilerOptions.AssertUsedAsAnIdentifier :
712 case CompilerOptions.NonStaticAccessToStatic :
713 case CompilerOptions.UnqualifiedFieldAccess :
714 case CompilerOptions.UndocumentedEmptyBlock :
715 case CompilerOptions.IndirectStaticAccess :
716 case CompilerOptions.FinalParameterBound :
717 case CompilerOptions.EnumUsedAsAnIdentifier :
718 case CompilerOptions.AnnotationSuperInterface :
719 case CompilerOptions.AutoBoxing :
720 case CompilerOptions.MissingOverrideAnnotation :
721 case CompilerOptions.MissingDeprecatedAnnotation :
722 case CompilerOptions.ParameterAssignment :
723 case CompilerOptions.MethodCanBeStatic :
724 case CompilerOptions.MethodCanBePotentiallyStatic :
725 case CompilerOptions.ExplicitlyClosedAutoCloseable :
726 return CategorizedProblem.CAT_CODE_STYLE;
727
728 case CompilerOptions.MaskedCatchBlock :
729 case CompilerOptions.NoImplicitStringConversion :
730 case CompilerOptions.NoEffectAssignment :
731 case CompilerOptions.AccidentalBooleanAssign :
732 case CompilerOptions.EmptyStatement :
733 case CompilerOptions.FinallyBlockNotCompleting :
734 case CompilerOptions.MissingSerialVersion :
735 case CompilerOptions.VarargsArgumentNeedCast :
736 case CompilerOptions.NullReference :
737 case CompilerOptions.PotentialNullReference :
738 case CompilerOptions.RedundantNullCheck :
739 case CompilerOptions.MissingEnumConstantCase :
740 case CompilerOptions.MissingDefaultCase :
741 case CompilerOptions.FallthroughCase :
742 case CompilerOptions.OverridingMethodWithoutSuperInvocation :
743 case CompilerOptions.ComparingIdentical :
744 case CompilerOptions.MissingSynchronizedModifierInInheritedMethod :
745 case CompilerOptions.ShouldImplementHashcode :
746 case CompilerOptions.DeadCode :
747 case CompilerOptions.UnusedObjectAllocation :
748 case CompilerOptions.UnclosedCloseable :
749 case CompilerOptions.PotentiallyUnclosedCloseable :
750 case CompilerOptions.PessimisticNullAnalysisForFreeTypeVariables :
751 case CompilerOptions.NonNullTypeVariableFromLegacyInvocation :
752 case CompilerOptions.UnlikelyCollectionMethodArgumentType :
753 case CompilerOptions.UnlikelyEqualsArgumentType:
754 case CompilerOptions.APILeak:
755 case CompilerOptions.UnstableAutoModuleName:
756 return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
757
758 case CompilerOptions.OverriddenPackageDefaultMethod :
759 case CompilerOptions.IncompatibleNonInheritedInterfaceMethod :
760 case CompilerOptions.LocalVariableHiding :
761 case CompilerOptions.FieldHiding :
762 case CompilerOptions.TypeHiding :
763 return CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT;
764
765 case CompilerOptions.UnusedLocalVariable :
766 case CompilerOptions.UnusedArgument :
767 case CompilerOptions.UnusedExceptionParameter :
768 case CompilerOptions.UnusedImport :
769 case CompilerOptions.UnusedPrivateMember :
770 case CompilerOptions.UnusedDeclaredThrownException :
771 case CompilerOptions.UnnecessaryTypeCheck :
772 case CompilerOptions.UnnecessaryElse :
773 case CompilerOptions.UnhandledWarningToken :
774 case CompilerOptions.UnusedWarningToken :
775 case CompilerOptions.UnusedLabel :
776 case CompilerOptions.RedundantSuperinterface :
777 case CompilerOptions.RedundantSpecificationOfTypeArguments :
778 case CompilerOptions.UnusedTypeParameter:
779 return CategorizedProblem.CAT_UNNECESSARY_CODE;
780
781 case CompilerOptions.UsingDeprecatedAPI :
782 case CompilerOptions.UsingTerminallyDeprecatedAPI :
783 return CategorizedProblem.CAT_DEPRECATION;
784
785 case CompilerOptions.NonExternalizedString :
786 return CategorizedProblem.CAT_NLS;
787
788 case CompilerOptions.Task :
789 return CategorizedProblem.CAT_UNSPECIFIED; // TODO may want to improve
790
791 case CompilerOptions.MissingJavadocComments :
792 case CompilerOptions.MissingJavadocTags :
793 case CompilerOptions.InvalidJavadoc :
794 case CompilerOptions.InvalidJavadoc|CompilerOptions.UsingDeprecatedAPI :
795 case CompilerOptions.InvalidJavadoc|CompilerOptions.UsingTerminallyDeprecatedAPI :
796 return CategorizedProblem.CAT_JAVADOC;
797
798 case CompilerOptions.UncheckedTypeOperation :
799 case CompilerOptions.RawTypeReference :
800 return CategorizedProblem.CAT_UNCHECKED_RAW;
801
802 case CompilerOptions.ForbiddenReference :
803 case CompilerOptions.DiscouragedReference :
804 return CategorizedProblem.CAT_RESTRICTION;
805
806 case CompilerOptions.NullSpecViolation :
807 case CompilerOptions.NullAnnotationInferenceConflict :
808 case CompilerOptions.NullUncheckedConversion :
809 case CompilerOptions.MissingNonNullByDefaultAnnotation:
810 case CompilerOptions.NonnullParameterAnnotationDropped:
811 case CompilerOptions.AnnotatedTypeArgumentToUnannotated:
812 return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
813 case CompilerOptions.RedundantNullAnnotation :
814 return CategorizedProblem.CAT_UNNECESSARY_CODE;
815
816 default:
817 break categorizeOnIrritant;
818 }
819 }
820 // categorize fatal problems per ID
821 switch (problemID) {
822 case IProblem.IsClassPathCorrect :
823 case IProblem.CorruptedSignature :
824 case IProblem.UndefinedModuleAddReads :
825 case IProblem.MissingNullAnnotationImplicitlyUsed :
826 return CategorizedProblem.CAT_BUILDPATH;
827 case IProblem.ProblemNotAnalysed :
828 return CategorizedProblem.CAT_UNNECESSARY_CODE;
829 default :
830 if ((problemID & IProblem.Syntax) != 0)
831 return CategorizedProblem.CAT_SYNTAX;
832 if ((problemID & IProblem.ImportRelated) != 0)
833 return CategorizedProblem.CAT_IMPORT;
834 if ((problemID & IProblem.TypeRelated) != 0)
835 return CategorizedProblem.CAT_TYPE;
836 if ((problemID & (IProblem.FieldRelated|IProblem.MethodRelated|IProblem.ConstructorRelated)) != 0)
837 return CategorizedProblem.CAT_MEMBER;
838 if ((problemID & IProblem.ModuleRelated) != 0)
839 return CategorizedProblem.CAT_MODULE;
840 if ((problemID & IProblem.Compliance) != 0)
841 return CategorizedProblem.CAT_COMPLIANCE;
842 if ((problemID & IProblem.PreviewRelated) != 0)
843 return CategorizedProblem.CAT_PREVIEW_RELATED;
844 }
845 return CategorizedProblem.CAT_INTERNAL;
846 }
abortDueToInternalError(String errorMessage)847 public void abortDueToInternalError(String errorMessage) {
848 this.abortDueToInternalError(errorMessage, null);
849 }
abortDueToInternalError(String errorMessage, ASTNode location)850 public void abortDueToInternalError(String errorMessage, ASTNode location) {
851 String[] arguments = new String[] {errorMessage};
852 this.handle(
853 IProblem.Unclassified,
854 arguments,
855 arguments,
856 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
857 location == null ? 0 : location.sourceStart,
858 location == null ? 0 : location.sourceEnd);
859 }
abortDueToPreviewEnablingNotAllowed(String sourceLevel, String expectedSourceLevel)860 public void abortDueToPreviewEnablingNotAllowed(String sourceLevel, String expectedSourceLevel) {
861 String[] args = new String[] {sourceLevel, expectedSourceLevel};
862 this.handle(
863 IProblem.PreviewFeaturesNotAllowed,
864 args,
865 args,
866 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
867 0,
868 0);
869 }
abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod)870 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
871
872 this.handle(
873 // %1 must be abstract since it cannot override the inherited package-private abstract method %2
874 IProblem.AbstractMethodCannotBeOverridden,
875 new String[] {
876 new String(type.sourceName()),
877 new String(
878 CharOperation.concat(
879 concreteMethod.declaringClass.readableName(),
880 concreteMethod.readableName(),
881 '.'))},
882 new String[] {
883 new String(type.sourceName()),
884 new String(
885 CharOperation.concat(
886 concreteMethod.declaringClass.shortReadableName(),
887 concreteMethod.shortReadableName(),
888 '.'))},
889 type.sourceStart(),
890 type.sourceEnd());
891 }
abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl)892 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
893 if (type.isEnum() && type.isLocalType()) {
894 FieldBinding field = type.scope.enclosingMethodScope().initializedField;
895 FieldDeclaration decl = field.sourceField();
896 String[] arguments = new String[] {new String(decl.name), new String(methodDecl.selector)};
897 this.handle(
898 IProblem.AbstractMethodInEnum,
899 arguments,
900 arguments,
901 methodDecl.sourceStart,
902 methodDecl.sourceEnd);
903 } else {
904 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
905 this.handle(
906 IProblem.AbstractMethodInAbstractClass,
907 arguments,
908 arguments,
909 methodDecl.sourceStart,
910 methodDecl.sourceEnd);
911 }
912 }
abstractMethodInConcreteClass(SourceTypeBinding type)913 public void abstractMethodInConcreteClass(SourceTypeBinding type) {
914 if (type.isEnum() && type.isLocalType()) {
915 FieldBinding field = type.scope.enclosingMethodScope().initializedField;
916 FieldDeclaration decl = field.sourceField();
917 String[] arguments = new String[] {new String(decl.name)};
918 this.handle(
919 IProblem.EnumConstantCannotDefineAbstractMethod,
920 arguments,
921 arguments,
922 decl.sourceStart(),
923 decl.sourceEnd());
924 } else {
925 String[] arguments = new String[] {new String(type.sourceName())};
926 this.handle(
927 IProblem.AbstractMethodsInConcreteClass,
928 arguments,
929 arguments,
930 type.sourceStart(),
931 type.sourceEnd());
932 }
933 }
abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod)934 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
935 if (type.isEnum() && type.isLocalType()) {
936 FieldBinding field = type.scope.enclosingMethodScope().initializedField;
937 FieldDeclaration decl = field.sourceField();
938 this.handle(
939 // Must implement the inherited abstract method %1
940 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
941 IProblem.EnumConstantMustImplementAbstractMethod,
942 new String[] {
943 new String(abstractMethod.selector),
944 typesAsString(abstractMethod, false),
945 new String(decl.name),
946 },
947 new String[] {
948 new String(abstractMethod.selector),
949 typesAsString(abstractMethod, true),
950 new String(decl.name),
951 },
952 decl.sourceStart(),
953 decl.sourceEnd());
954 } else {
955 this.handle(
956 // Must implement the inherited abstract method %1
957 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
958 IProblem.AbstractMethodMustBeImplemented,
959 new String[] {
960 new String(abstractMethod.selector),
961 typesAsString(abstractMethod, false),
962 new String(abstractMethod.declaringClass.readableName()),
963 new String(type.readableName()),
964 },
965 new String[] {
966 new String(abstractMethod.selector),
967 typesAsString(abstractMethod, true),
968 new String(abstractMethod.declaringClass.shortReadableName()),
969 new String(type.shortReadableName()),
970 },
971 type.sourceStart(),
972 type.sourceEnd());
973 }
974 }
abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod, MethodBinding concreteMethod)975 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod, MethodBinding concreteMethod) {
976 this.handle(
977 // Must implement the inherited abstract method %1
978 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
979 IProblem.AbstractMethodMustBeImplementedOverConcreteMethod,
980 new String[] {
981 new String(abstractMethod.selector),
982 typesAsString(abstractMethod, false),
983 new String(abstractMethod.declaringClass.readableName()),
984 new String(type.readableName()),
985 new String(concreteMethod.selector),
986 typesAsString(concreteMethod, false),
987 new String(concreteMethod.declaringClass.readableName()),
988 },
989 new String[] {
990 new String(abstractMethod.selector),
991 typesAsString(abstractMethod, true),
992 new String(abstractMethod.declaringClass.shortReadableName()),
993 new String(type.shortReadableName()),
994 new String(concreteMethod.selector),
995 typesAsString(concreteMethod, true),
996 new String(concreteMethod.declaringClass.shortReadableName()),
997 },
998 type.sourceStart(),
999 type.sourceEnd());
1000 }
abstractMethodNeedingNoBody(AbstractMethodDeclaration method)1001 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
1002 this.handle(
1003 IProblem.BodyForAbstractMethod,
1004 NoArgument,
1005 NoArgument,
1006 method.sourceStart,
1007 method.sourceEnd,
1008 method,
1009 method.compilationResult());
1010 }
alreadyDefinedLabel(char[] labelName, ASTNode location)1011 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
1012 String[] arguments = new String[] {new String(labelName)};
1013 this.handle(
1014 IProblem.DuplicateLabel,
1015 arguments,
1016 arguments,
1017 location.sourceStart,
1018 location.sourceEnd);
1019 }
annotationCannotOverrideMethod(MethodBinding overrideMethod, MethodBinding inheritedMethod)1020 public void annotationCannotOverrideMethod(MethodBinding overrideMethod, MethodBinding inheritedMethod) {
1021 ASTNode location = overrideMethod.sourceMethod();
1022 this.handle(
1023 IProblem.AnnotationCannotOverrideMethod,
1024 new String[] {
1025 new String(overrideMethod.declaringClass.readableName()),
1026 new String(inheritedMethod.declaringClass.readableName()),
1027 new String(inheritedMethod.selector),
1028 typesAsString(inheritedMethod, false)},
1029 new String[] {
1030 new String(overrideMethod.declaringClass.shortReadableName()),
1031 new String(inheritedMethod.declaringClass.shortReadableName()),
1032 new String(inheritedMethod.selector),
1033 typesAsString(inheritedMethod, true)},
1034 location.sourceStart,
1035 location.sourceEnd);
1036 }
annotationCircularity(TypeBinding sourceType, TypeBinding otherType, TypeReference reference)1037 public void annotationCircularity(TypeBinding sourceType, TypeBinding otherType, TypeReference reference) {
1038 if (TypeBinding.equalsEquals(sourceType, otherType))
1039 this.handle(
1040 IProblem.AnnotationCircularitySelfReference,
1041 new String[] {new String(sourceType.readableName())},
1042 new String[] {new String(sourceType.shortReadableName())},
1043 reference.sourceStart,
1044 reference.sourceEnd);
1045 else
1046 this.handle(
1047 IProblem.AnnotationCircularity,
1048 new String[] {new String(sourceType.readableName()), new String(otherType.readableName())},
1049 new String[] {new String(sourceType.shortReadableName()), new String(otherType.shortReadableName())},
1050 reference.sourceStart,
1051 reference.sourceEnd);
1052 }
annotationMembersCannotHaveParameters(AnnotationMethodDeclaration annotationMethodDeclaration)1053 public void annotationMembersCannotHaveParameters(AnnotationMethodDeclaration annotationMethodDeclaration) {
1054 this.handle(
1055 IProblem.AnnotationMembersCannotHaveParameters,
1056 NoArgument,
1057 NoArgument,
1058 annotationMethodDeclaration.sourceStart,
1059 annotationMethodDeclaration.sourceEnd);
1060 }
annotationMembersCannotHaveTypeParameters(AnnotationMethodDeclaration annotationMethodDeclaration)1061 public void annotationMembersCannotHaveTypeParameters(AnnotationMethodDeclaration annotationMethodDeclaration) {
1062 this.handle(
1063 IProblem.AnnotationMembersCannotHaveTypeParameters,
1064 NoArgument,
1065 NoArgument,
1066 annotationMethodDeclaration.sourceStart,
1067 annotationMethodDeclaration.sourceEnd);
1068 }
annotationTypeDeclarationCannotHaveConstructor(ConstructorDeclaration constructorDeclaration)1069 public void annotationTypeDeclarationCannotHaveConstructor(ConstructorDeclaration constructorDeclaration) {
1070 this.handle(
1071 IProblem.AnnotationTypeDeclarationCannotHaveConstructor,
1072 NoArgument,
1073 NoArgument,
1074 constructorDeclaration.sourceStart,
1075 constructorDeclaration.sourceEnd);
1076 }
annotationTypeDeclarationCannotHaveSuperclass(TypeDeclaration typeDeclaration)1077 public void annotationTypeDeclarationCannotHaveSuperclass(TypeDeclaration typeDeclaration) {
1078 this.handle(
1079 IProblem.AnnotationTypeDeclarationCannotHaveSuperclass,
1080 NoArgument,
1081 NoArgument,
1082 typeDeclaration.sourceStart,
1083 typeDeclaration.sourceEnd);
1084 }
annotationTypeDeclarationCannotHaveSuperinterfaces(TypeDeclaration typeDeclaration)1085 public void annotationTypeDeclarationCannotHaveSuperinterfaces(TypeDeclaration typeDeclaration) {
1086 this.handle(
1087 IProblem.AnnotationTypeDeclarationCannotHaveSuperinterfaces,
1088 NoArgument,
1089 NoArgument,
1090 typeDeclaration.sourceStart,
1091 typeDeclaration.sourceEnd);
1092 }
annotationTypeUsedAsSuperinterface(SourceTypeBinding type, TypeReference superInterfaceRef, ReferenceBinding superType)1093 public void annotationTypeUsedAsSuperinterface(SourceTypeBinding type, TypeReference superInterfaceRef, ReferenceBinding superType) {
1094 this.handle(
1095 IProblem.AnnotationTypeUsedAsSuperInterface,
1096 new String[] {new String(superType.readableName()), new String(type.sourceName())},
1097 new String[] {new String(superType.shortReadableName()), new String(type.sourceName())},
1098 superInterfaceRef.sourceStart,
1099 superInterfaceRef.sourceEnd);
1100 }
annotationValueMustBeAnnotation(TypeBinding annotationType, char[] name, Expression value, TypeBinding expectedType)1101 public void annotationValueMustBeAnnotation(TypeBinding annotationType, char[] name, Expression value, TypeBinding expectedType) {
1102 String str = new String(name);
1103 this.handle(
1104 IProblem.AnnotationValueMustBeAnnotation,
1105 new String[] { new String(annotationType.readableName()), str, new String(expectedType.readableName()), },
1106 new String[] { new String(annotationType.shortReadableName()), str, new String(expectedType.readableName()), },
1107 value.sourceStart,
1108 value.sourceEnd);
1109 }
annotationValueMustBeArrayInitializer(TypeBinding annotationType, char[] name, Expression value)1110 public void annotationValueMustBeArrayInitializer(TypeBinding annotationType, char[] name, Expression value) {
1111 String str = new String(name);
1112 this.handle(
1113 IProblem.AnnotationValueMustBeArrayInitializer,
1114 new String[] { new String(annotationType.readableName()), str },
1115 new String[] { new String(annotationType.shortReadableName()), str},
1116 value.sourceStart,
1117 value.sourceEnd);
1118 }
annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value)1119 public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) {
1120 String str = new String(name);
1121 this.handle(
1122 IProblem.AnnotationValueMustBeClassLiteral,
1123 new String[] { new String(annotationType.readableName()), str },
1124 new String[] { new String(annotationType.shortReadableName()), str},
1125 value.sourceStart,
1126 value.sourceEnd);
1127 }
annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value, boolean isEnum)1128 public void annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value, boolean isEnum) {
1129 String str = new String(name);
1130 if (isEnum) {
1131 this.handle(
1132 IProblem.AnnotationValueMustBeAnEnumConstant,
1133 new String[] { new String(annotationType.readableName()), str },
1134 new String[] { new String(annotationType.shortReadableName()), str},
1135 value.sourceStart,
1136 value.sourceEnd);
1137 } else {
1138 this.handle(
1139 IProblem.AnnotationValueMustBeConstant,
1140 new String[] { new String(annotationType.readableName()), str },
1141 new String[] { new String(annotationType.shortReadableName()), str},
1142 value.sourceStart,
1143 value.sourceEnd);
1144 }
1145 }
anonymousClassCannotExtendFinalClass(TypeReference reference, TypeBinding type)1146 public void anonymousClassCannotExtendFinalClass(TypeReference reference, TypeBinding type) {
1147 this.handle(
1148 IProblem.AnonymousClassCannotExtendFinalClass,
1149 new String[] {new String(type.readableName())},
1150 new String[] {new String(type.shortReadableName())},
1151 reference.sourceStart,
1152 reference.sourceEnd);
1153 }
argumentTypeCannotBeVoid(ASTNode methodDecl, Argument arg)1154 public void argumentTypeCannotBeVoid(ASTNode methodDecl, Argument arg) {
1155 String[] arguments = new String[] { new String(arg.name) };
1156 this.handle(
1157 IProblem.ArgumentTypeCannotBeVoid,
1158 arguments,
1159 arguments,
1160 methodDecl.sourceStart,
1161 methodDecl.sourceEnd);
1162 }
argumentTypeCannotBeVoidArray(Argument arg)1163 public void argumentTypeCannotBeVoidArray(Argument arg) {
1164 this.handle(
1165 IProblem.CannotAllocateVoidArray,
1166 NoArgument,
1167 NoArgument,
1168 arg.type.sourceStart,
1169 arg.type.sourceEnd);
1170 }
arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd)1171 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
1172 this.handle(
1173 IProblem.ArrayConstantsOnlyInArrayInitializers,
1174 NoArgument,
1175 NoArgument,
1176 sourceStart,
1177 sourceEnd);
1178 }
assignmentHasNoEffect(AbstractVariableDeclaration location, char[] name)1179 public void assignmentHasNoEffect(AbstractVariableDeclaration location, char[] name){
1180 int severity = computeSeverity(IProblem.AssignmentHasNoEffect);
1181 if (severity == ProblemSeverities.Ignore) return;
1182 String[] arguments = new String[] { new String(name) };
1183 int start = location.sourceStart;
1184 int end = location.sourceEnd;
1185 if (location.initialization != null) {
1186 end = location.initialization.sourceEnd;
1187 }
1188 this.handle(
1189 IProblem.AssignmentHasNoEffect,
1190 arguments,
1191 arguments,
1192 severity,
1193 start,
1194 end);
1195 }
assignmentHasNoEffect(Assignment location, char[] name)1196 public void assignmentHasNoEffect(Assignment location, char[] name){
1197 int severity = computeSeverity(IProblem.AssignmentHasNoEffect);
1198 if (severity == ProblemSeverities.Ignore) return;
1199 String[] arguments = new String[] { new String(name) };
1200 this.handle(
1201 IProblem.AssignmentHasNoEffect,
1202 arguments,
1203 arguments,
1204 severity,
1205 location.sourceStart,
1206 location.sourceEnd);
1207 }
1208
attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType)1209 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
1210 this.handle(
1211 IProblem.VoidMethodReturnsValue,
1212 new String[] {new String(expectedType.readableName())},
1213 new String[] {new String(expectedType.shortReadableName())},
1214 returnStatement.sourceStart,
1215 returnStatement.sourceEnd);
1216 }
1217
1218
attemptToReturnVoidValue(ReturnStatement returnStatement)1219 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
1220 this.handle(
1221 IProblem.MethodReturnsVoid,
1222 NoArgument,
1223 NoArgument,
1224 returnStatement.sourceStart,
1225 returnStatement.sourceEnd);
1226 }
autoboxing(Expression expression, TypeBinding originalType, TypeBinding convertedType)1227 public void autoboxing(Expression expression, TypeBinding originalType, TypeBinding convertedType) {
1228 if (this.options.getSeverity(CompilerOptions.AutoBoxing) == ProblemSeverities.Ignore) return;
1229 this.handle(
1230 originalType.isBaseType() ? IProblem.BoxingConversion : IProblem.UnboxingConversion,
1231 new String[] { new String(originalType.readableName()), new String(convertedType.readableName()), },
1232 new String[] { new String(originalType.shortReadableName()), new String(convertedType.shortReadableName()), },
1233 expression.sourceStart,
1234 expression.sourceEnd);
1235 }
boundCannotBeArray(ASTNode location, TypeBinding type)1236 public void boundCannotBeArray(ASTNode location, TypeBinding type) {
1237 this.handle(
1238 IProblem.BoundCannotBeArray,
1239 new String[] {new String(type.readableName())},
1240 new String[] {new String(type.shortReadableName())},
1241 location.sourceStart,
1242 location.sourceEnd);
1243 }
boundMustBeAnInterface(ASTNode location, TypeBinding type)1244 public void boundMustBeAnInterface(ASTNode location, TypeBinding type) {
1245 this.handle(
1246 IProblem.BoundMustBeAnInterface,
1247 new String[] {new String(type.readableName())},
1248 new String[] {new String(type.shortReadableName())},
1249 location.sourceStart,
1250 location.sourceEnd);
1251 }
bytecodeExceeds64KLimit(SwitchStatement switchStatement)1252 public void bytecodeExceeds64KLimit(SwitchStatement switchStatement) {
1253 TypeBinding enumType = switchStatement.expression.resolvedType;
1254 this.handle(
1255 IProblem.BytecodeExceeds64KLimitForSwitchTable,
1256 new String[] {new String(enumType.readableName())},
1257 new String[] {new String(enumType.shortReadableName())},
1258 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1259 switchStatement.sourceStart(),
1260 switchStatement.sourceEnd());
1261 }
bytecodeExceeds64KLimit(MethodBinding method, int start, int end)1262 public void bytecodeExceeds64KLimit(MethodBinding method, int start, int end) {
1263 this.handle(
1264 IProblem.BytecodeExceeds64KLimit,
1265 new String[] {new String(method.selector), typesAsString(method, false)},
1266 new String[] {new String(method.selector), typesAsString(method, true)},
1267 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1268 start,
1269 end);
1270 }
bytecodeExceeds64KLimit(AbstractMethodDeclaration location)1271 public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location) {
1272 MethodBinding method = location.binding;
1273 if (location.isConstructor()) {
1274 this.handle(
1275 IProblem.BytecodeExceeds64KLimitForConstructor,
1276 new String[] {new String(location.selector), typesAsString(method, false)},
1277 new String[] {new String(location.selector), typesAsString(method, true)},
1278 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1279 location.sourceStart,
1280 location.sourceEnd);
1281 } else {
1282 bytecodeExceeds64KLimit(method, location.sourceStart, location.sourceEnd);
1283 }
1284 }
bytecodeExceeds64KLimit(LambdaExpression location)1285 public void bytecodeExceeds64KLimit(LambdaExpression location) {
1286 bytecodeExceeds64KLimit(location.binding, location.sourceStart, location.diagnosticsSourceEnd());
1287 }
bytecodeExceeds64KLimit(TypeDeclaration location)1288 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
1289 this.handle(
1290 IProblem.BytecodeExceeds64KLimitForClinit,
1291 NoArgument,
1292 NoArgument,
1293 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1294 location.sourceStart,
1295 location.sourceEnd);
1296 }
cannotAllocateVoidArray(Expression expression)1297 public void cannotAllocateVoidArray(Expression expression) {
1298 this.handle(
1299 IProblem.CannotAllocateVoidArray,
1300 NoArgument,
1301 NoArgument,
1302 expression.sourceStart,
1303 expression.sourceEnd);
1304 }
cannotAssignToFinalField(FieldBinding field, ASTNode location)1305 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
1306 this.handle(
1307 IProblem.FinalFieldAssignment,
1308 new String[] {
1309 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
1310 new String(field.readableName())},
1311 new String[] {
1312 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
1313 new String(field.shortReadableName())},
1314 nodeSourceStart(field, location),
1315 nodeSourceEnd(field, location));
1316 }
cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location)1317 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
1318 int problemId = 0;
1319 if ((local.tagBits & TagBits.MultiCatchParameter) != 0) {
1320 problemId = IProblem.AssignmentToMultiCatchParameter;
1321 } else if ((local.tagBits & TagBits.IsResource) != 0) {
1322 problemId = IProblem.AssignmentToResource;
1323 } else {
1324 problemId = IProblem.NonBlankFinalLocalAssignment;
1325 }
1326 String[] arguments = new String[] { new String(local.readableName())};
1327 this.handle(
1328 problemId,
1329 arguments,
1330 arguments,
1331 nodeSourceStart(local, location),
1332 nodeSourceEnd(local, location));
1333 }
cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location)1334 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
1335 String[] arguments = new String[] {new String(local.readableName())};
1336 this.handle(
1337 IProblem.FinalOuterLocalAssignment,
1338 arguments,
1339 arguments,
1340 nodeSourceStart(local, location),
1341 nodeSourceEnd(local, location));
1342 }
cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion)1343 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
1344 this.handle(
1345 IProblem.CannotDefineDimensionExpressionsWithInit,
1346 NoArgument,
1347 NoArgument,
1348 expresssion.sourceStart,
1349 expresssion.sourceEnd);
1350 }
cannotDireclyInvokeAbstractMethod(ASTNode invocationSite, MethodBinding method)1351 public void cannotDireclyInvokeAbstractMethod(ASTNode invocationSite, MethodBinding method) {
1352 this.handle(
1353 IProblem.DirectInvocationOfAbstractMethod,
1354 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method, false)},
1355 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method, true)},
1356 invocationSite.sourceStart,
1357 invocationSite.sourceEnd);
1358 }
cannotExtendEnum(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding)1359 public void cannotExtendEnum(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding) {
1360 String name = new String(type.sourceName());
1361 String superTypeFullName = new String(superTypeBinding.readableName());
1362 String superTypeShortName = new String(superTypeBinding.shortReadableName());
1363 if (superTypeShortName.equals(name)) superTypeShortName = superTypeFullName;
1364 this.handle(
1365 IProblem.CannotExtendEnum,
1366 new String[] {superTypeFullName, name},
1367 new String[] {superTypeShortName, name},
1368 superclass.sourceStart,
1369 superclass.sourceEnd);
1370 }
cannotImportPackage(ImportReference importRef)1371 public void cannotImportPackage(ImportReference importRef) {
1372 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
1373 this.handleUntagged(
1374 IProblem.CannotImportPackage,
1375 arguments,
1376 arguments,
1377 importRef.sourceStart,
1378 importRef.sourceEnd);
1379 }
cannotInstantiate(Expression typeRef, TypeBinding type)1380 public void cannotInstantiate(Expression typeRef, TypeBinding type) {
1381 this.handle(
1382 IProblem.InvalidClassInstantiation,
1383 new String[] {new String(type.readableName())},
1384 new String[] {new String(type.shortReadableName())},
1385 typeRef.sourceStart,
1386 typeRef.sourceEnd);
1387 }
cannotInvokeSuperConstructorInEnum(ExplicitConstructorCall constructorCall, MethodBinding enumConstructor)1388 public void cannotInvokeSuperConstructorInEnum(ExplicitConstructorCall constructorCall, MethodBinding enumConstructor) {
1389 this.handle(
1390 IProblem.CannotInvokeSuperConstructorInEnum,
1391 new String[] {
1392 new String(enumConstructor.declaringClass.sourceName()),
1393 typesAsString(enumConstructor, false),
1394 },
1395 new String[] {
1396 new String(enumConstructor.declaringClass.sourceName()),
1397 typesAsString(enumConstructor, true),
1398 },
1399 constructorCall.sourceStart,
1400 constructorCall.sourceEnd);
1401 }
cannotReadSource(CompilationUnitDeclaration unit, AbortCompilationUnit abortException, boolean verbose)1402 public void cannotReadSource(CompilationUnitDeclaration unit, AbortCompilationUnit abortException, boolean verbose) {
1403 String fileName = new String(unit.compilationResult.fileName);
1404 if (abortException.exception instanceof CharConversionException) {
1405 // specific encoding issue
1406 String encoding = abortException.encoding;
1407 if (encoding == null) {
1408 encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
1409 }
1410 String[] arguments = new String[]{ fileName, encoding };
1411 this.handle(
1412 IProblem.InvalidEncoding,
1413 arguments,
1414 arguments,
1415 0,
1416 0);
1417 return;
1418 }
1419 StringWriter stringWriter = new StringWriter();
1420 PrintWriter writer = new PrintWriter(stringWriter);
1421 if (verbose) {
1422 abortException.exception.printStackTrace(writer);
1423 System.err.println(stringWriter.toString());
1424 stringWriter = new StringWriter();
1425 writer = new PrintWriter(stringWriter);
1426 }
1427 writer.print(abortException.exception.getClass().getName());
1428 writer.print(':');
1429 writer.print(abortException.exception.getMessage());
1430 String exceptionTrace = stringWriter.toString();
1431 String[] arguments = new String[]{ fileName, exceptionTrace };
1432 this.handle(
1433 IProblem.CannotReadSource,
1434 arguments,
1435 arguments,
1436 0,
1437 0);
1438 }
cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location)1439 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
1440 String[] arguments =new String[]{ new String(local.readableName())};
1441 this.handle(
1442 IProblem.OuterLocalMustBeFinal,
1443 arguments,
1444 arguments,
1445 nodeSourceStart(local, location),
1446 nodeSourceEnd(local, location));
1447 }
cannotReferToNonEffectivelyFinalOuterLocal(VariableBinding local, ASTNode location)1448 public void cannotReferToNonEffectivelyFinalOuterLocal(VariableBinding local, ASTNode location) {
1449 String[] arguments = new String[] { new String(local.readableName()) };
1450 this.handle(
1451 IProblem.OuterLocalMustBeEffectivelyFinal,
1452 arguments,
1453 arguments,
1454 nodeSourceStart(local, location),
1455 nodeSourceEnd(local, location));
1456 }
cannotReferToNonFinalField(VariableBinding local, ASTNode location)1457 public void cannotReferToNonFinalField(VariableBinding local, ASTNode location) {
1458 String[] arguments = new String[] { new String(local.readableName()) };
1459 this.handle(
1460 IProblem.FieldMustBeFinal,
1461 arguments,
1462 arguments,
1463 nodeSourceStart(local, location),
1464 nodeSourceEnd(local, location));
1465 }
cannotReturnInInitializer(ASTNode location)1466 public void cannotReturnInInitializer(ASTNode location) {
1467 this.handle(
1468 IProblem.CannotReturnInInitializer,
1469 NoArgument,
1470 NoArgument,
1471 location.sourceStart,
1472 location.sourceEnd);
1473 }
cannotThrowNull(ASTNode expression)1474 public void cannotThrowNull(ASTNode expression) {
1475 this.handle(
1476 IProblem.CannotThrowNull,
1477 NoArgument,
1478 NoArgument,
1479 expression.sourceStart,
1480 expression.sourceEnd);
1481 }
cannotThrowType(ASTNode exception, TypeBinding expectedType)1482 public void cannotThrowType(ASTNode exception, TypeBinding expectedType) {
1483 this.handle(
1484 IProblem.CannotThrowType,
1485 new String[] {new String(expectedType.readableName())},
1486 new String[] {new String(expectedType.shortReadableName())},
1487 exception.sourceStart,
1488 exception.sourceEnd);
1489 }
1490 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
illegalArrayOfUnionType(char[] identifierName, TypeReference typeReference)1491 public void illegalArrayOfUnionType(char[] identifierName, TypeReference typeReference) {
1492 this.handle(
1493 IProblem.IllegalArrayOfUnionType,
1494 NoArgument,
1495 NoArgument,
1496 typeReference.sourceStart,
1497 typeReference.sourceEnd);
1498 }
cannotUseQualifiedEnumConstantInCaseLabel(Reference location, FieldBinding field)1499 public void cannotUseQualifiedEnumConstantInCaseLabel(Reference location, FieldBinding field) {
1500 this.handle(
1501 IProblem.IllegalQualifiedEnumConstantLabel,
1502 new String[]{ String.valueOf(field.declaringClass.readableName()), String.valueOf(field.name) },
1503 new String[]{ String.valueOf(field.declaringClass.shortReadableName()), String.valueOf(field.name) },
1504 location.sourceStart(),
1505 location.sourceEnd());
1506 }
cannotUseSuperInCodeSnippet(int start, int end)1507 public void cannotUseSuperInCodeSnippet(int start, int end) {
1508 this.handle(
1509 IProblem.CannotUseSuperInCodeSnippet,
1510 NoArgument,
1511 NoArgument,
1512 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1513 start,
1514 end);
1515 }
cannotUseSuperInJavaLangObject(ASTNode reference)1516 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
1517 this.handle(
1518 IProblem.ObjectHasNoSuperclass,
1519 NoArgument,
1520 NoArgument,
1521 reference.sourceStart,
1522 reference.sourceEnd);
1523 }
targetTypeIsNotAFunctionalInterface(FunctionalExpression target)1524 public void targetTypeIsNotAFunctionalInterface(FunctionalExpression target) {
1525 this.handle(
1526 IProblem.TargetTypeNotAFunctionalInterface,
1527 NoArgument,
1528 NoArgument,
1529 target.sourceStart,
1530 target.diagnosticsSourceEnd());
1531 }
illFormedParameterizationOfFunctionalInterface(FunctionalExpression target)1532 public void illFormedParameterizationOfFunctionalInterface(FunctionalExpression target) {
1533 this.handle(
1534 IProblem.illFormedParameterizationOfFunctionalInterface,
1535 NoArgument,
1536 NoArgument,
1537 target.sourceStart,
1538 target.diagnosticsSourceEnd());
1539 }
lambdaSignatureMismatched(LambdaExpression target)1540 public void lambdaSignatureMismatched(LambdaExpression target) {
1541 this.handle(
1542 IProblem.lambdaSignatureMismatched,
1543 new String[] { new String(target.descriptor.readableName()) },
1544 new String[] { new String(target.descriptor.shortReadableName()) },
1545 target.sourceStart,
1546 target.diagnosticsSourceEnd());
1547 }
1548
lambdaParameterTypeMismatched(Argument argument, TypeReference type, TypeBinding expectedParameterType)1549 public void lambdaParameterTypeMismatched(Argument argument, TypeReference type, TypeBinding expectedParameterType) {
1550 String name = new String(argument.name);
1551 String expectedTypeFullName = new String(expectedParameterType.readableName());
1552 String expectedTypeShortName = new String(expectedParameterType.shortReadableName());
1553 this.handle(
1554 expectedParameterType.isTypeVariable() ? IProblem.IncompatibleLambdaParameterType : IProblem.lambdaParameterTypeMismatched,
1555 new String[] { name, expectedTypeFullName },
1556 new String[] { name, expectedTypeShortName },
1557 type.sourceStart,
1558 type.sourceEnd);
1559 }
lambdaExpressionCannotImplementGenericMethod(LambdaExpression lambda, MethodBinding sam)1560 public void lambdaExpressionCannotImplementGenericMethod(LambdaExpression lambda, MethodBinding sam) {
1561 final String selector = new String(sam.selector);
1562 this.handle(
1563 IProblem.NoGenericLambda,
1564 new String[] { selector, new String(sam.declaringClass.readableName())},
1565 new String[] { selector, new String(sam.declaringClass.shortReadableName())},
1566 lambda.sourceStart,
1567 lambda.diagnosticsSourceEnd());
1568 }
missingValueFromLambda(LambdaExpression lambda, TypeBinding returnType)1569 public void missingValueFromLambda(LambdaExpression lambda, TypeBinding returnType) {
1570 this.handle(IProblem.MissingValueFromLambda,
1571 new String[] {new String(returnType.readableName())},
1572 new String[] {new String(returnType.shortReadableName())},
1573 lambda.sourceStart,
1574 lambda.diagnosticsSourceEnd());
1575 }
caseExpressionMustBeConstant(Expression expression)1576 public void caseExpressionMustBeConstant(Expression expression) {
1577 this.handle(
1578 IProblem.NonConstantExpression,
1579 NoArgument,
1580 NoArgument,
1581 expression.sourceStart,
1582 expression.sourceEnd);
1583 }
classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding)1584 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding superTypeBinding) {
1585 String name = new String(type.sourceName());
1586 String superTypeFullName = new String(superTypeBinding.readableName());
1587 String superTypeShortName = new String(superTypeBinding.shortReadableName());
1588 if (superTypeShortName.equals(name)) superTypeShortName = superTypeFullName;
1589 this.handle(
1590 IProblem.ClassExtendFinalClass,
1591 new String[] {superTypeFullName, name},
1592 new String[] {superTypeShortName, name},
1593 superclass.sourceStart,
1594 superclass.sourceEnd);
1595 }
codeSnippetMissingClass(String missing, int start, int end)1596 public void codeSnippetMissingClass(String missing, int start, int end) {
1597 String[] arguments = new String[]{missing};
1598 this.handle(
1599 IProblem.CodeSnippetMissingClass,
1600 arguments,
1601 arguments,
1602 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1603 start,
1604 end);
1605 }
codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end)1606 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
1607 String[] arguments = new String[]{ className, missingMethod, argumentTypes };
1608 this.handle(
1609 IProblem.CodeSnippetMissingMethod,
1610 arguments,
1611 arguments,
1612 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1613 start,
1614 end);
1615 }
comparingIdenticalExpressions(Expression comparison)1616 public void comparingIdenticalExpressions(Expression comparison){
1617 int severity = computeSeverity(IProblem.ComparingIdentical);
1618 if (severity == ProblemSeverities.Ignore) return;
1619 this.handle(
1620 IProblem.ComparingIdentical,
1621 NoArgument,
1622 NoArgument,
1623 severity,
1624 comparison.sourceStart,
1625 comparison.sourceEnd);
1626 }
1627 /*
1628 * Given the current configuration, answers which category the problem
1629 * falls into:
1630 * ProblemSeverities.Error | ProblemSeverities.Warning | ProblemSeverities.Ignore
1631 * when different from Ignore, severity can be coupled with ProblemSeverities.Optional
1632 * to indicate that this problem is configurable through options
1633 */
1634 @Override
computeSeverity(int problemID)1635 public int computeSeverity(int problemID){
1636
1637 switch (problemID) {
1638 case IProblem.VarargsConflict :
1639 case IProblem.SwitchExpressionsYieldUnqualifiedMethodWarning:
1640 case IProblem.SwitchExpressionsYieldRestrictedGeneralWarning:
1641 case IProblem.SwitchExpressionsYieldTypeDeclarationWarning:
1642 return ProblemSeverities.Warning;
1643 case IProblem.TypeCollidesWithPackage :
1644 return ProblemSeverities.Error;
1645
1646 /*
1647 * Javadoc tags resolved references errors
1648 */
1649 case IProblem.JavadocInvalidParamName:
1650 case IProblem.JavadocDuplicateParamName:
1651 case IProblem.JavadocMissingParamName:
1652 case IProblem.JavadocInvalidMemberTypeQualification:
1653 case IProblem.JavadocInvalidThrowsClassName:
1654 case IProblem.JavadocDuplicateThrowsClassName:
1655 case IProblem.JavadocMissingThrowsClassName:
1656 case IProblem.JavadocMissingSeeReference:
1657 case IProblem.JavadocInvalidValueReference:
1658 case IProblem.JavadocUndefinedField:
1659 case IProblem.JavadocAmbiguousField:
1660 case IProblem.JavadocUndefinedConstructor:
1661 case IProblem.JavadocAmbiguousConstructor:
1662 case IProblem.JavadocUndefinedMethod:
1663 case IProblem.JavadocAmbiguousMethod:
1664 case IProblem.JavadocAmbiguousMethodReference:
1665 case IProblem.JavadocParameterMismatch:
1666 case IProblem.JavadocUndefinedType:
1667 case IProblem.JavadocAmbiguousType:
1668 case IProblem.JavadocInternalTypeNameProvided:
1669 case IProblem.JavadocNoMessageSendOnArrayType:
1670 case IProblem.JavadocNoMessageSendOnBaseType:
1671 case IProblem.JavadocInheritedMethodHidesEnclosingName:
1672 case IProblem.JavadocInheritedFieldHidesEnclosingName:
1673 case IProblem.JavadocInheritedNameHidesEnclosingTypeName:
1674 case IProblem.JavadocNonStaticTypeFromStaticInvocation:
1675 case IProblem.JavadocGenericMethodTypeArgumentMismatch:
1676 case IProblem.JavadocNonGenericMethod:
1677 case IProblem.JavadocIncorrectArityForParameterizedMethod:
1678 case IProblem.JavadocParameterizedMethodArgumentTypeMismatch:
1679 case IProblem.JavadocTypeArgumentsForRawGenericMethod:
1680 case IProblem.JavadocGenericConstructorTypeArgumentMismatch:
1681 case IProblem.JavadocNonGenericConstructor:
1682 case IProblem.JavadocIncorrectArityForParameterizedConstructor:
1683 case IProblem.JavadocParameterizedConstructorArgumentTypeMismatch:
1684 case IProblem.JavadocTypeArgumentsForRawGenericConstructor:
1685 if (!this.options.reportInvalidJavadocTags) {
1686 return ProblemSeverities.Ignore;
1687 }
1688 break;
1689 /*
1690 * Javadoc invalid tags due to deprecated references
1691 */
1692 case IProblem.JavadocUsingDeprecatedField:
1693 case IProblem.JavadocUsingDeprecatedConstructor:
1694 case IProblem.JavadocUsingDeprecatedMethod:
1695 case IProblem.JavadocUsingDeprecatedType:
1696 if (!(this.options.reportInvalidJavadocTags && this.options.reportInvalidJavadocTagsDeprecatedRef)) {
1697 return ProblemSeverities.Ignore;
1698 }
1699 break;
1700 /*
1701 * Javadoc invalid tags due to non-visible references
1702 */
1703 case IProblem.JavadocNotVisibleField:
1704 case IProblem.JavadocNotVisibleConstructor:
1705 case IProblem.JavadocNotVisibleMethod:
1706 case IProblem.JavadocNotVisibleType:
1707 case IProblem.JavadocHiddenReference:
1708 if (!(this.options.reportInvalidJavadocTags && this.options.reportInvalidJavadocTagsNotVisibleRef)) {
1709 return ProblemSeverities.Ignore;
1710 }
1711 break;
1712 /*
1713 * Javadoc missing tag descriptions
1714 */
1715 case IProblem.JavadocEmptyReturnTag:
1716 if (CompilerOptions.NO_TAG.equals(this.options.reportMissingJavadocTagDescription)) {
1717 return ProblemSeverities.Ignore;
1718 }
1719 break;
1720 case IProblem.JavadocMissingTagDescription:
1721 if (! CompilerOptions.ALL_STANDARD_TAGS.equals(this.options.reportMissingJavadocTagDescription)) {
1722 return ProblemSeverities.Ignore;
1723 }
1724 break;
1725 // For compatibility with javac 8b111 for now.
1726 case IProblem.RepeatableAnnotationWithRepeatingContainerAnnotation:
1727 case IProblem.ToleratedMisplacedTypeAnnotations:
1728 return ProblemSeverities.Warning;
1729 case IProblem.IllegalUseOfUnderscoreAsAnIdentifier:
1730 return this.underScoreIsError ? ProblemSeverities.Error : ProblemSeverities.Warning;
1731 }
1732 int irritant = getIrritant(problemID);
1733 if (irritant != 0) {
1734 if ((problemID & IProblem.Javadoc) != 0 && !this.options.docCommentSupport)
1735 return ProblemSeverities.Ignore;
1736 return this.options.getSeverity(irritant);
1737 }
1738 return ProblemSeverities.Error | ProblemSeverities.Fatal;
1739 }
conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType)1740 public void conditionalArgumentsIncompatibleTypes(ConditionalExpression expression, TypeBinding trueType, TypeBinding falseType) {
1741 this.handle(
1742 IProblem.IncompatibleTypesInConditionalOperator,
1743 new String[] {new String(trueType.readableName()), new String(falseType.readableName())},
1744 new String[] {new String(trueType.shortReadableName()), new String(falseType.shortReadableName())},
1745 expression.sourceStart,
1746 expression.sourceEnd);
1747 }
conflictingImport(ImportReference importRef)1748 public void conflictingImport(ImportReference importRef) {
1749 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
1750 this.handleUntagged(
1751 IProblem.ConflictingImport,
1752 arguments,
1753 arguments,
1754 importRef.sourceStart,
1755 importRef.sourceEnd);
1756 }
constantOutOfRange(Literal literal, TypeBinding literalType)1757 public void constantOutOfRange(Literal literal, TypeBinding literalType) {
1758 String[] arguments = new String[] {new String(literalType.readableName()), new String(literal.source())};
1759 this.handle(
1760 IProblem.NumericValueOutOfRange,
1761 arguments,
1762 arguments,
1763 literal.sourceStart,
1764 literal.sourceEnd);
1765 }
corruptedSignature(TypeBinding enclosingType, char[] signature, int position)1766 public void corruptedSignature(TypeBinding enclosingType, char[] signature, int position) {
1767 this.handle(
1768 IProblem.CorruptedSignature,
1769 new String[] { new String(enclosingType.readableName()), new String(signature), String.valueOf(position) },
1770 new String[] { new String(enclosingType.shortReadableName()), new String(signature), String.valueOf(position) },
1771 ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
1772 0,
1773 0);
1774 }
defaultMethodOverridesObjectMethod(MethodBinding currentMethod)1775 public void defaultMethodOverridesObjectMethod(MethodBinding currentMethod) {
1776 // Java 8 feature
1777 AbstractMethodDeclaration method = currentMethod.sourceMethod();
1778 int sourceStart = 0;
1779 int sourceEnd = 0;
1780 if (method != null) {
1781 sourceStart = method.sourceStart;
1782 sourceEnd = method.sourceEnd;
1783 }
1784 this.handle(
1785 IProblem.DefaultMethodOverridesObjectMethod,
1786 NoArgument, NoArgument,
1787 sourceStart, sourceEnd);
1788 }
1789
defaultModifierIllegallySpecified(int sourceStart, int sourceEnd)1790 public void defaultModifierIllegallySpecified(int sourceStart, int sourceEnd) {
1791 this.handle(
1792 IProblem.IllegalDefaultModifierSpecification,
1793 NoArgument, NoArgument,
1794 sourceStart, sourceEnd);
1795 }
1796
deprecatedField(final FieldBinding field, ASTNode location)1797 public void deprecatedField(final FieldBinding field, ASTNode location) {
1798 String fieldName = new String(field.name);
1799 int sourceStart = nodeSourceStart(field, location);
1800 int sourceEnd = nodeSourceEnd(field, location);
1801 String sinceValue = deprecatedSinceValue(() -> field.getAnnotations());
1802 if (sinceValue != null) {
1803 this.handle(
1804 (field.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0 ? IProblem.UsingDeprecatedSinceVersionField : IProblem.UsingTerminallyDeprecatedSinceVersionField,
1805 new String[] {new String(field.declaringClass.readableName()), fieldName, sinceValue},
1806 new String[] {new String(field.declaringClass.shortReadableName()), fieldName, sinceValue},
1807 sourceStart, sourceEnd);
1808 } else {
1809 this.handle(
1810 (field.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0 ? IProblem.UsingDeprecatedField : IProblem.UsingTerminallyDeprecatedField,
1811 new String[] {new String(field.declaringClass.readableName()), fieldName},
1812 new String[] {new String(field.declaringClass.shortReadableName()), fieldName},
1813 sourceStart, sourceEnd);
1814 }
1815 }
1816
deprecatedMethod(final MethodBinding method, ASTNode location)1817 public void deprecatedMethod(final MethodBinding method, ASTNode location) {
1818 // common arguments:
1819 String readableClassName = new String(method.declaringClass.readableName());
1820 String shortReadableClassName = new String(method.declaringClass.shortReadableName());
1821 String selector = new String(method.selector);
1822 String signature = typesAsString(method, false);
1823 String shortSignature = typesAsString(method, true);
1824
1825 boolean isConstructor = method.isConstructor();
1826 int start = -1;
1827 if (isConstructor) {
1828 if(location instanceof AllocationExpression) {
1829 // omit the new keyword from the warning marker
1830 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300031
1831 AllocationExpression allocationExpression = (AllocationExpression) location;
1832 start = allocationExpression.nameSourceStart();
1833 }
1834 } else {
1835 if (location instanceof MessageSend) {
1836 // start the warning marker from the location where the name of the method starts
1837 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300031
1838 start = (int) (((MessageSend)location).nameSourcePosition >>> 32);
1839 }
1840 }
1841 int sourceStart = (start == -1) ? location.sourceStart : start;
1842 int sourceEnd = location.sourceEnd;
1843
1844 // discriminate:
1845 boolean terminally = (method.tagBits & TagBits.AnnotationTerminallyDeprecated) != 0;
1846 String sinceValue = deprecatedSinceValue(() -> method.getAnnotations());
1847 if (sinceValue == null && method.isConstructor()) {
1848 sinceValue = deprecatedSinceValue(() -> method.declaringClass.getAnnotations()); // for default ctor
1849 }
1850 if (sinceValue != null) {
1851 if (isConstructor) {
1852 this.handle(
1853 terminally ? IProblem.UsingTerminallyDeprecatedSinceVersionConstructor : IProblem.UsingDeprecatedSinceVersionConstructor,
1854 new String[] {readableClassName, signature, sinceValue},
1855 new String[] {shortReadableClassName, shortSignature, sinceValue},
1856 sourceStart, sourceEnd);
1857 } else {
1858 this.handle(
1859 terminally ? IProblem.UsingTerminallyDeprecatedSinceVersionMethod : IProblem.UsingDeprecatedSinceVersionMethod,
1860 new String[] {readableClassName, selector, signature, sinceValue},
1861 new String[] {shortReadableClassName, selector, shortSignature, sinceValue},
1862 sourceStart, sourceEnd);
1863 }
1864 } else {
1865 if (isConstructor) {
1866 this.handle(
1867 terminally ? IProblem.UsingTerminallyDeprecatedConstructor : IProblem.UsingDeprecatedConstructor,
1868 new String[] {readableClassName, signature},
1869 new String[] {shortReadableClassName, shortSignature},
1870 sourceStart, sourceEnd);
1871 } else {
1872 this.handle(
1873 terminally ? IProblem.UsingTerminallyDeprecatedMethod : IProblem.UsingDeprecatedMethod,
1874 new String[] {readableClassName, selector, signature},
1875 new String[] {shortReadableClassName, selector, shortSignature},
1876 sourceStart, sourceEnd);
1877 }
1878 }
1879 }
deprecatedType(TypeBinding type, ASTNode location)1880 public void deprecatedType(TypeBinding type, ASTNode location) {
1881 deprecatedType(type, location, Integer.MAX_VALUE);
1882 }
1883 // The argument 'index' makes sure that we demarcate partial types correctly while marking off
1884 // a deprecated type in a qualified reference (see bug 292510)
deprecatedType(TypeBinding type, ASTNode location, int index)1885 public void deprecatedType(TypeBinding type, ASTNode location, int index) {
1886 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
1887 final TypeBinding leafType = type.leafComponentType();
1888 int sourceStart = -1;
1889 if (location instanceof QualifiedTypeReference) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300031
1890 QualifiedTypeReference ref = (QualifiedTypeReference) location;
1891 if (index < Integer.MAX_VALUE) {
1892 sourceStart = (int) (ref.sourcePositions[index] >> 32);
1893 }
1894 }
1895 String sinceValue = deprecatedSinceValue(() -> leafType.getAnnotations());
1896 if (sinceValue != null) {
1897 this.handle(
1898 ((leafType.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0) ? IProblem.UsingDeprecatedSinceVersionType : IProblem.UsingTerminallyDeprecatedSinceVersionType,
1899 new String[] {new String(leafType.readableName()), sinceValue},
1900 new String[] {new String(leafType.shortReadableName()), sinceValue},
1901 (sourceStart == -1) ? location.sourceStart : sourceStart,
1902 nodeSourceEnd(null, location, index));
1903 } else {
1904 this.handle(
1905 ((leafType.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0) ? IProblem.UsingDeprecatedType : IProblem.UsingTerminallyDeprecatedType,
1906 new String[] {new String(leafType.readableName())},
1907 new String[] {new String(leafType.shortReadableName())},
1908 (sourceStart == -1) ? location.sourceStart : sourceStart,
1909 nodeSourceEnd(null, location, index));
1910 }
1911 }
deprecatedModule(ModuleReference moduleReference, ModuleBinding requiredModule)1912 public void deprecatedModule(ModuleReference moduleReference, ModuleBinding requiredModule) {
1913 String sinceValue = deprecatedSinceValue(() -> requiredModule.getAnnotations());
1914 boolean isTerminally = (requiredModule.tagBits & TagBits.AnnotationTerminallyDeprecated) != 0;
1915 if (sinceValue != null) {
1916 String[] args = { String.valueOf(requiredModule.name()), sinceValue };
1917 handle( isTerminally ? IProblem.UsingTerminallyDeprecatedSinceVersionModule : IProblem.UsingDeprecatedSinceVersionModule,
1918 args,
1919 args,
1920 moduleReference.sourceStart,
1921 moduleReference.sourceEnd);
1922 } else {
1923 String[] args = { String.valueOf(requiredModule.name()) };
1924 handle( isTerminally ? IProblem.UsingTerminallyDeprecatedModule : IProblem.UsingDeprecatedModule,
1925 args,
1926 args,
1927 moduleReference.sourceStart,
1928 moduleReference.sourceEnd);
1929 }
1930 }
deprecatedSinceValue(Supplier<AnnotationBinding[]> annotations)1931 String deprecatedSinceValue(Supplier<AnnotationBinding[]> annotations) {
1932 if (this.options != null && this.options.complianceLevel >= ClassFileConstants.JDK9) {
1933 ReferenceContext contextSave = this.referenceContext;
1934 try {
1935 for (AnnotationBinding annotationBinding : annotations.get()) {
1936 if (annotationBinding.getAnnotationType().id == TypeIds.T_JavaLangDeprecated) {
1937 for (ElementValuePair elementValuePair : annotationBinding.getElementValuePairs()) {
1938 if (CharOperation.equals(elementValuePair.getName(), TypeConstants.SINCE) && elementValuePair.value instanceof StringConstant)
1939 return ((StringConstant) elementValuePair.value).stringValue();
1940 }
1941 break;
1942 }
1943 }
1944 } finally {
1945 this.referenceContext = contextSave;
1946 }
1947 }
1948 return null;
1949 }
disallowedTargetForAnnotation(Annotation annotation)1950 public void disallowedTargetForAnnotation(Annotation annotation) {
1951 this.handle(
1952 IProblem.DisallowedTargetForAnnotation,
1953 new String[] {new String(annotation.resolvedType.readableName())},
1954 new String[] {new String(annotation.resolvedType.shortReadableName())},
1955 annotation.sourceStart,
1956 annotation.sourceEnd);
1957 }
polymorphicMethodNotBelow17(ASTNode node)1958 public void polymorphicMethodNotBelow17(ASTNode node) {
1959 this.handle(
1960 IProblem.PolymorphicMethodNotBelow17,
1961 NoArgument,
1962 NoArgument,
1963 node.sourceStart,
1964 node.sourceEnd);
1965 }
multiCatchNotBelow17(ASTNode node)1966 public void multiCatchNotBelow17(ASTNode node) {
1967 this.handle(
1968 IProblem.MultiCatchNotBelow17,
1969 NoArgument,
1970 NoArgument,
1971 node.sourceStart,
1972 node.sourceEnd);
1973 }
duplicateAnnotation(Annotation annotation, long sourceLevel)1974 public void duplicateAnnotation(Annotation annotation, long sourceLevel) {
1975 this.handle(
1976 sourceLevel >= ClassFileConstants.JDK1_8 ? IProblem.DuplicateAnnotationNotMarkedRepeatable : IProblem.DuplicateAnnotation,
1977 new String[] {new String(annotation.resolvedType.readableName())},
1978 new String[] {new String(annotation.resolvedType.shortReadableName())},
1979 annotation.sourceStart,
1980 annotation.sourceEnd);
1981 }
duplicateAnnotationValue(TypeBinding annotationType, MemberValuePair memberValuePair)1982 public void duplicateAnnotationValue(TypeBinding annotationType, MemberValuePair memberValuePair) {
1983 String name = new String(memberValuePair.name);
1984 this.handle(
1985 IProblem.DuplicateAnnotationMember,
1986 new String[] { name, new String(annotationType.readableName())},
1987 new String[] { name, new String(annotationType.shortReadableName())},
1988 memberValuePair.sourceStart,
1989 memberValuePair.sourceEnd);
1990 }
duplicateBounds(ASTNode location, TypeBinding type)1991 public void duplicateBounds(ASTNode location, TypeBinding type) {
1992 this.handle(
1993 IProblem.DuplicateBounds,
1994 new String[] {new String(type.readableName())},
1995 new String[] {new String(type.shortReadableName())},
1996 location.sourceStart,
1997 location.sourceEnd);
1998 }
duplicateCase(CaseStatement caseStatement)1999 public void duplicateCase(CaseStatement caseStatement) {
2000 this.handle(
2001 IProblem.DuplicateCase,
2002 NoArgument,
2003 NoArgument,
2004 caseStatement.sourceStart,
2005 caseStatement.sourceEnd);
2006 }
duplicateDefaultCase(ASTNode statement)2007 public void duplicateDefaultCase(ASTNode statement) {
2008 this.handle(
2009 IProblem.DuplicateDefaultCase,
2010 NoArgument,
2011 NoArgument,
2012 statement.sourceStart,
2013 statement.sourceEnd);
2014 }
duplicateEnumSpecialMethod(SourceTypeBinding type, AbstractMethodDeclaration methodDecl)2015 public void duplicateEnumSpecialMethod(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
2016 MethodBinding method = methodDecl.binding;
2017 this.handle(
2018 IProblem.CannotDeclareEnumSpecialMethod,
2019 new String[] {
2020 new String(methodDecl.selector),
2021 new String(method.declaringClass.readableName()),
2022 typesAsString(method, false)},
2023 new String[] {
2024 new String(methodDecl.selector),
2025 new String(method.declaringClass.shortReadableName()),
2026 typesAsString(method, true)},
2027 methodDecl.sourceStart,
2028 methodDecl.sourceEnd);
2029 }
2030
duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl)2031 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2032 this.handle(
2033 IProblem.DuplicateField,
2034 new String[] {new String(type.sourceName()), new String(fieldDecl.name)},
2035 new String[] {new String(type.shortReadableName()), new String(fieldDecl.name)},
2036 fieldDecl.sourceStart,
2037 fieldDecl.sourceEnd);
2038 }
duplicateImport(ImportReference importRef)2039 public void duplicateImport(ImportReference importRef) {
2040 String[] arguments = new String[] {CharOperation.toString(importRef.tokens)};
2041 this.handleUntagged(
2042 IProblem.DuplicateImport,
2043 arguments,
2044 arguments,
2045 importRef.sourceStart,
2046 importRef.sourceEnd);
2047 }
2048
duplicateInheritedMethods(SourceTypeBinding type, MethodBinding inheritedMethod1, MethodBinding inheritedMethod2, boolean isJava8)2049 public void duplicateInheritedMethods(SourceTypeBinding type, MethodBinding inheritedMethod1, MethodBinding inheritedMethod2, boolean isJava8) {
2050 if (TypeBinding.notEquals(inheritedMethod1.declaringClass, inheritedMethod2.declaringClass)) {
2051 int problemID = IProblem.DuplicateInheritedMethods;
2052 if (inheritedMethod1.isDefaultMethod() && inheritedMethod2.isDefaultMethod()) {
2053 if (isJava8)
2054 problemID = IProblem.DuplicateInheritedDefaultMethods;
2055 else
2056 return; // don't report this error at 1.7-
2057 }
2058 this.handle(
2059 problemID,
2060 new String[] {
2061 new String(inheritedMethod1.selector),
2062 typesAsString(inheritedMethod1, inheritedMethod1.original().parameters, false),
2063 typesAsString(inheritedMethod2, inheritedMethod2.original().parameters, false),
2064 new String(inheritedMethod1.declaringClass.readableName()),
2065 new String(inheritedMethod2.declaringClass.readableName()),
2066 },
2067 new String[] {
2068 new String(inheritedMethod1.selector),
2069 typesAsString(inheritedMethod1, inheritedMethod1.original().parameters, true),
2070 typesAsString(inheritedMethod2, inheritedMethod2.original().parameters, true),
2071 new String(inheritedMethod1.declaringClass.shortReadableName()),
2072 new String(inheritedMethod2.declaringClass.shortReadableName()),
2073 },
2074 type.sourceStart(),
2075 type.sourceEnd());
2076 return;
2077 }
2078 // Handle duplicates from same class.
2079 this.handle(
2080 IProblem.DuplicateParameterizedMethods,
2081 new String[] {
2082 new String(inheritedMethod1.selector),
2083 new String(inheritedMethod1.declaringClass.readableName()),
2084 typesAsString(inheritedMethod1, inheritedMethod1.original().parameters, false),
2085 typesAsString(inheritedMethod2, inheritedMethod2.original().parameters, false)},
2086 new String[] {
2087 new String(inheritedMethod1.selector),
2088 new String(inheritedMethod1.declaringClass.shortReadableName()),
2089 typesAsString(inheritedMethod1, inheritedMethod1.original().parameters, true),
2090 typesAsString(inheritedMethod2, inheritedMethod2.original().parameters, true)},
2091 type.sourceStart(),
2092 type.sourceEnd());
2093 }
duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference)2094 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
2095 String[] arguments = new String[]{ new String(field.readableName())};
2096 this.handle(
2097 IProblem.DuplicateBlankFinalFieldInitialization,
2098 arguments,
2099 arguments,
2100 nodeSourceStart(field, reference),
2101 nodeSourceEnd(field, reference));
2102 }
duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location)2103 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
2104 String[] arguments = new String[] { new String(local.readableName())};
2105 if ((local.modifiers & ExtraCompilerModifiers.AccPatternVariable) == 0) {
2106 this.handle(
2107 IProblem.DuplicateFinalLocalInitialization,
2108 arguments,
2109 arguments,
2110 nodeSourceStart(local, location),
2111 nodeSourceEnd(local, location));
2112 } else {
2113 this.handle(IProblem.PatternVariableNotInScope,
2114 arguments,
2115 arguments,
2116 nodeSourceStart(local, location),
2117 nodeSourceEnd(local, location));
2118 }
2119 }
duplicateMethodInType(AbstractMethodDeclaration methodDecl, boolean equalParameters, int severity)2120 public void duplicateMethodInType(AbstractMethodDeclaration methodDecl, boolean equalParameters, int severity) {
2121 MethodBinding method = methodDecl.binding;
2122 if (equalParameters) {
2123 this.handle(
2124 IProblem.DuplicateMethod,
2125 new String[] {
2126 new String(methodDecl.selector),
2127 new String(method.declaringClass.readableName()),
2128 typesAsString(method, false)},
2129 new String[] {
2130 new String(methodDecl.selector),
2131 new String(method.declaringClass.shortReadableName()),
2132 typesAsString(method, true)},
2133 severity,
2134 methodDecl.sourceStart,
2135 methodDecl.sourceEnd);
2136 } else {
2137 this.handle(
2138 IProblem.DuplicateMethodErasure,
2139 new String[] {
2140 new String(methodDecl.selector),
2141 new String(method.declaringClass.readableName()),
2142 typesAsString(method, false)},
2143 new String[] {
2144 new String(methodDecl.selector),
2145 new String(method.declaringClass.shortReadableName()),
2146 typesAsString(method, true)},
2147 severity,
2148 methodDecl.sourceStart,
2149 methodDecl.sourceEnd);
2150 }
2151 }
2152
duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl)2153 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
2154 /* to highlight modifiers use:
2155 this.handle(
2156 new Problem(
2157 DuplicateModifierForField,
2158 new String[] {new String(fieldDecl.name)},
2159 fieldDecl.modifiers.sourceStart,
2160 fieldDecl.modifiers.sourceEnd));
2161 */
2162 String[] arguments = new String[] {new String(fieldDecl.name)};
2163 this.handle(
2164 IProblem.DuplicateModifierForField,
2165 arguments,
2166 arguments,
2167 fieldDecl.sourceStart,
2168 fieldDecl.sourceEnd);
2169 }
duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl)2170 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2171 this.handle(
2172 IProblem.DuplicateModifierForMethod,
2173 new String[] {new String(type.sourceName()), new String(methodDecl.selector)},
2174 new String[] {new String(type.shortReadableName()), new String(methodDecl.selector)},
2175 methodDecl.sourceStart,
2176 methodDecl.sourceEnd);
2177 }
duplicateModifierForType(SourceTypeBinding type)2178 public void duplicateModifierForType(SourceTypeBinding type) {
2179 String[] arguments = new String[] {new String(type.sourceName())};
2180 this.handle(
2181 IProblem.DuplicateModifierForType,
2182 arguments,
2183 arguments,
2184 type.sourceStart(),
2185 type.sourceEnd());
2186 }
duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument)2187 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
2188 String[] arguments = new String[] {new String(localDecl.name)};
2189 this.handle(
2190 complainForArgument
2191 ? IProblem.DuplicateModifierForArgument
2192 : IProblem.DuplicateModifierForVariable,
2193 arguments,
2194 arguments,
2195 localDecl.sourceStart,
2196 localDecl.sourceEnd);
2197 }
duplicateNestedType(TypeDeclaration typeDecl)2198 public void duplicateNestedType(TypeDeclaration typeDecl) {
2199 String[] arguments = new String[] {new String(typeDecl.name)};
2200 this.handle(
2201 IProblem.DuplicateNestedType,
2202 arguments,
2203 arguments,
2204 typeDecl.sourceStart,
2205 typeDecl.sourceEnd);
2206 }
duplicateSuperinterface(SourceTypeBinding type, TypeReference reference, ReferenceBinding superType)2207 public void duplicateSuperinterface(SourceTypeBinding type, TypeReference reference, ReferenceBinding superType) {
2208 this.handle(
2209 IProblem.DuplicateSuperInterface,
2210 new String[] {
2211 new String(superType.readableName()),
2212 new String(type.sourceName())},
2213 new String[] {
2214 new String(superType.shortReadableName()),
2215 new String(type.sourceName())},
2216 reference.sourceStart,
2217 reference.sourceEnd);
2218 }
duplicateTargetInTargetAnnotation(TypeBinding annotationType, NameReference reference)2219 public void duplicateTargetInTargetAnnotation(TypeBinding annotationType, NameReference reference) {
2220 FieldBinding field = reference.fieldBinding();
2221 String name = new String(field.name);
2222 this.handle(
2223 IProblem.DuplicateTargetInTargetAnnotation,
2224 new String[] { name, new String(annotationType.readableName())},
2225 new String[] { name, new String(annotationType.shortReadableName())},
2226 nodeSourceStart(field, reference),
2227 nodeSourceEnd(field, reference));
2228 }
duplicateTypeParameterInType(TypeParameter typeParameter)2229 public void duplicateTypeParameterInType(TypeParameter typeParameter) {
2230 this.handle(
2231 IProblem.DuplicateTypeVariable,
2232 new String[] { new String(typeParameter.name)},
2233 new String[] { new String(typeParameter.name)},
2234 typeParameter.sourceStart,
2235 typeParameter.sourceEnd);
2236 }
duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl)2237 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2238 String[] arguments = new String[] {new String(compUnitDecl.getFileName()), new String(typeDecl.name)};
2239 this.referenceContext = typeDecl; // report the problem against the type not the entire compilation unit
2240 int end = typeDecl.sourceEnd;
2241 if (end <= 0) {
2242 end = -1;
2243 }
2244 this.handle(
2245 IProblem.DuplicateTypes,
2246 arguments,
2247 arguments,
2248 typeDecl.sourceStart,
2249 end,
2250 compUnitDecl.compilationResult);
2251 }
emptyControlFlowStatement(int sourceStart, int sourceEnd)2252 public void emptyControlFlowStatement(int sourceStart, int sourceEnd) {
2253 this.handle(
2254 IProblem.EmptyControlFlowStatement,
2255 NoArgument,
2256 NoArgument,
2257 sourceStart,
2258 sourceEnd);
2259 }
enumAbstractMethodMustBeImplemented(AbstractMethodDeclaration method)2260 public void enumAbstractMethodMustBeImplemented(AbstractMethodDeclaration method) {
2261 MethodBinding abstractMethod = method.binding;
2262 this.handle(
2263 // Must implement the inherited abstract method %1
2264 // 8.4.3 - Every non-abstract subclass of an abstract type, A, must provide a concrete implementation of all of A's methods.
2265 IProblem.EnumAbstractMethodMustBeImplemented,
2266 new String[] {
2267 new String(abstractMethod.selector),
2268 typesAsString(abstractMethod, false),
2269 new String(abstractMethod.declaringClass.readableName()),
2270 },
2271 new String[] {
2272 new String(abstractMethod.selector),
2273 typesAsString(abstractMethod, true),
2274 new String(abstractMethod.declaringClass.shortReadableName()),
2275 },
2276 method.sourceStart(),
2277 method.sourceEnd());
2278 }
enumConstantMustImplementAbstractMethod(AbstractMethodDeclaration method, FieldDeclaration field)2279 public void enumConstantMustImplementAbstractMethod(AbstractMethodDeclaration method, FieldDeclaration field) {
2280 MethodBinding abstractMethod = method.binding;
2281 this.handle(
2282 IProblem.EnumConstantMustImplementAbstractMethod,
2283 new String[] {
2284 new String(abstractMethod.selector),
2285 typesAsString(abstractMethod, false),
2286 new String(field.name),
2287 },
2288 new String[] {
2289 new String(abstractMethod.selector),
2290 typesAsString(abstractMethod, true),
2291 new String(field.name),
2292 },
2293 field.sourceStart(),
2294 field.sourceEnd());
2295 }
enumConstantsCannotBeSurroundedByParenthesis(Expression expression)2296 public void enumConstantsCannotBeSurroundedByParenthesis(Expression expression) {
2297 this.handle(
2298 IProblem.EnumConstantsCannotBeSurroundedByParenthesis,
2299 NoArgument,
2300 NoArgument,
2301 expression.sourceStart,
2302 expression.sourceEnd);
2303 }
enumStaticFieldUsedDuringInitialization(FieldBinding field, ASTNode location)2304 public void enumStaticFieldUsedDuringInitialization(FieldBinding field, ASTNode location) {
2305 this.handle(
2306 IProblem.EnumStaticFieldInInInitializerContext,
2307 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
2308 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
2309 nodeSourceStart(field, location),
2310 nodeSourceEnd(field, location));
2311 }
enumSwitchCannotTargetField(Reference reference, FieldBinding field)2312 public void enumSwitchCannotTargetField(Reference reference, FieldBinding field) {
2313 this.handle(
2314 IProblem.EnumSwitchCannotTargetField,
2315 new String[]{ String.valueOf(field.declaringClass.readableName()), String.valueOf(field.name) },
2316 new String[]{ String.valueOf(field.declaringClass.shortReadableName()), String.valueOf(field.name) },
2317 nodeSourceStart(field, reference),
2318 nodeSourceEnd(field, reference));
2319 }
errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params)2320 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
2321 StringBuffer buffer = new StringBuffer();
2322 StringBuffer shortBuffer = new StringBuffer();
2323 for (int i = 0, length = params.length; i < length; i++) {
2324 if (i != 0){
2325 buffer.append(", "); //$NON-NLS-1$
2326 shortBuffer.append(", "); //$NON-NLS-1$
2327 }
2328 buffer.append(new String(params[i].readableName()));
2329 shortBuffer.append(new String(params[i].shortReadableName()));
2330 }
2331
2332 int id = recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType;
2333 this.handle(
2334 id,
2335 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
2336 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
2337 messageSend.sourceStart,
2338 messageSend.sourceEnd);
2339 }
errorNoMethodFor(Expression expression, TypeBinding recType, char [] selector, TypeBinding[] params)2340 public void errorNoMethodFor(Expression expression, TypeBinding recType, char [] selector, TypeBinding[] params) {
2341 StringBuffer buffer = new StringBuffer();
2342 StringBuffer shortBuffer = new StringBuffer();
2343 for (int i = 0, length = params.length; i < length; i++) {
2344 if (i != 0){
2345 buffer.append(", "); //$NON-NLS-1$
2346 shortBuffer.append(", "); //$NON-NLS-1$
2347 }
2348 buffer.append(new String(params[i].readableName()));
2349 shortBuffer.append(new String(params[i].shortReadableName()));
2350 }
2351
2352 int id = recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType;
2353 this.handle(
2354 id,
2355 new String[] { new String(recType.readableName()), new String(selector), buffer.toString() },
2356 new String[] { new String(recType.shortReadableName()), new String(selector), shortBuffer.toString() },
2357 expression.sourceStart,
2358 expression.sourceEnd);
2359 }
errorThisSuperInStatic(ASTNode reference)2360 public void errorThisSuperInStatic(ASTNode reference) {
2361 String[] arguments = new String[] {reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
2362 this.handle(
2363 IProblem.ThisInStaticContext,
2364 arguments,
2365 arguments,
2366 reference.sourceStart,
2367 reference.sourceEnd);
2368 }
errorNoSuperInInterface(ASTNode reference)2369 public void errorNoSuperInInterface(ASTNode reference) {
2370 this.handle(
2371 IProblem.NoSuperInInterfaceContext,
2372 NoArgument,
2373 NoArgument,
2374 reference.sourceStart,
2375 reference.sourceEnd);
2376 }
expressionShouldBeAVariable(Expression expression)2377 public void expressionShouldBeAVariable(Expression expression) {
2378 this.handle(
2379 IProblem.ExpressionShouldBeAVariable,
2380 NoArgument,
2381 NoArgument,
2382 expression.sourceStart,
2383 expression.sourceEnd);
2384 }
fakeReachable(ASTNode location)2385 public void fakeReachable(ASTNode location) {
2386 int sourceStart = location.sourceStart;
2387 int sourceEnd = location.sourceEnd;
2388 if (location instanceof LocalDeclaration) {
2389 LocalDeclaration declaration = (LocalDeclaration) location;
2390 sourceStart = declaration.declarationSourceStart;
2391 sourceEnd = declaration.declarationSourceEnd;
2392 }
2393 this.handle(
2394 IProblem.DeadCode,
2395 NoArgument,
2396 NoArgument,
2397 sourceStart,
2398 sourceEnd);
2399 }
fieldHiding(FieldDeclaration fieldDecl, Binding hiddenVariable)2400 public void fieldHiding(FieldDeclaration fieldDecl, Binding hiddenVariable) {
2401 FieldBinding field = fieldDecl.binding;
2402 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2403 && field.isStatic()
2404 && field.isPrivate()
2405 && field.isFinal()
2406 && TypeBinding.equalsEquals(TypeBinding.LONG, field.type)) {
2407 ReferenceBinding referenceBinding = field.declaringClass;
2408 if (referenceBinding != null) {
2409 if (referenceBinding.findSuperTypeOriginatingFrom(TypeIds.T_JavaIoSerializable, false /*Serializable is not a class*/) != null) {
2410 return; // do not report field hiding for serialVersionUID field for class that implements Serializable
2411 }
2412 }
2413 }
2414 if (CharOperation.equals(TypeConstants.SERIALPERSISTENTFIELDS, field.name)
2415 && field.isStatic()
2416 && field.isPrivate()
2417 && field.isFinal()
2418 && field.type.dimensions() == 1
2419 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTSTREAMFIELD, field.type.leafComponentType().readableName())) {
2420 ReferenceBinding referenceBinding = field.declaringClass;
2421 if (referenceBinding != null) {
2422 if (referenceBinding.findSuperTypeOriginatingFrom(TypeIds.T_JavaIoSerializable, false /*Serializable is not a class*/) != null) {
2423 return; // do not report field hiding for serialPersistenFields field for class that implements Serializable
2424 }
2425 }
2426 }
2427 boolean isLocal = hiddenVariable instanceof LocalVariableBinding;
2428 int severity = computeSeverity(isLocal ? IProblem.FieldHidingLocalVariable : IProblem.FieldHidingField);
2429 if (severity == ProblemSeverities.Ignore) return;
2430 if (isLocal) {
2431 this.handle(
2432 IProblem.FieldHidingLocalVariable,
2433 new String[] {new String(field.declaringClass.readableName()), new String(field.name) },
2434 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name) },
2435 severity,
2436 nodeSourceStart(hiddenVariable, fieldDecl),
2437 nodeSourceEnd(hiddenVariable, fieldDecl));
2438 } else if (hiddenVariable instanceof FieldBinding) {
2439 FieldBinding hiddenField = (FieldBinding) hiddenVariable;
2440 this.handle(
2441 IProblem.FieldHidingField,
2442 new String[] {new String(field.declaringClass.readableName()), new String(field.name) , new String(hiddenField.declaringClass.readableName()) },
2443 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name) , new String(hiddenField.declaringClass.shortReadableName()) },
2444 severity,
2445 nodeSourceStart(hiddenField, fieldDecl),
2446 nodeSourceEnd(hiddenField, fieldDecl));
2447 }
2448 }
fieldsOrThisBeforeConstructorInvocation(ASTNode reference)2449 public void fieldsOrThisBeforeConstructorInvocation(ASTNode reference) {
2450 this.handle(
2451 IProblem.ThisSuperDuringConstructorInvocation,
2452 NoArgument,
2453 NoArgument,
2454 reference.sourceStart,
2455 reference instanceof LambdaExpression ? ((LambdaExpression) reference).diagnosticsSourceEnd() : reference.sourceEnd);
2456 }
finallyMustCompleteNormally(Block finallyBlock)2457 public void finallyMustCompleteNormally(Block finallyBlock) {
2458 this.handle(
2459 IProblem.FinallyMustCompleteNormally,
2460 NoArgument,
2461 NoArgument,
2462 finallyBlock.sourceStart,
2463 finallyBlock.sourceEnd);
2464 }
finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod)2465 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2466 this.handle(
2467 // Cannot override the final method from %1
2468 // 8.4.3.3 - Final methods cannot be overridden or hidden.
2469 IProblem.FinalMethodCannotBeOverridden,
2470 new String[] {new String(inheritedMethod.declaringClass.readableName())},
2471 new String[] {new String(inheritedMethod.declaringClass.shortReadableName())},
2472 currentMethod.sourceStart(),
2473 currentMethod.sourceEnd());
2474 }
finalVariableBound(TypeVariableBinding typeVariable, TypeReference typeRef)2475 public void finalVariableBound(TypeVariableBinding typeVariable, TypeReference typeRef) {
2476 if (this.options.sourceLevel < ClassFileConstants.JDK1_5) return;
2477 int severity = computeSeverity(IProblem.FinalBoundForTypeVariable);
2478 if (severity == ProblemSeverities.Ignore) return;
2479 this.handle(
2480 IProblem.FinalBoundForTypeVariable,
2481 new String[] { new String(typeVariable.sourceName()), new String(typeRef.resolvedType.readableName())},
2482 new String[] { new String(typeVariable.sourceName()), new String(typeRef.resolvedType.shortReadableName())},
2483 severity,
2484 typeRef.sourceStart,
2485 typeRef.sourceEnd);
2486 }
2487 /** @param classpathEntryType one of {@link AccessRestriction#COMMAND_LINE},
2488 * {@link AccessRestriction#LIBRARY}, {@link AccessRestriction#PROJECT} */
forbiddenReference(FieldBinding field, ASTNode location, byte classpathEntryType, String classpathEntryName, int problemId)2489 public void forbiddenReference(FieldBinding field, ASTNode location,
2490 byte classpathEntryType, String classpathEntryName, int problemId) {
2491 int severity = computeSeverity(problemId);
2492 if (severity == ProblemSeverities.Ignore) return;
2493 this.handle(
2494 problemId,
2495 new String[] { new String(field.readableName()) }, // distinct from msg arg for quickfix purpose
2496 getElaborationId(IProblem.ForbiddenReference, (byte) (FIELD_ACCESS | classpathEntryType)),
2497 new String[] {
2498 classpathEntryName,
2499 new String(field.shortReadableName()),
2500 new String(field.declaringClass.shortReadableName())},
2501 severity,
2502 nodeSourceStart(field, location),
2503 nodeSourceEnd(field, location));
2504 }
2505 /** @param classpathEntryType one of {@link AccessRestriction#COMMAND_LINE},
2506 * {@link AccessRestriction#LIBRARY}, {@link AccessRestriction#PROJECT} */
forbiddenReference(MethodBinding method, InvocationSite location, byte classpathEntryType, String classpathEntryName, int problemId)2507 public void forbiddenReference(MethodBinding method, InvocationSite location,
2508 byte classpathEntryType, String classpathEntryName, int problemId) {
2509 int severity = computeSeverity(problemId);
2510 if (severity == ProblemSeverities.Ignore) return;
2511 if (method.isConstructor())
2512 this.handle(
2513 problemId,
2514 new String[] { new String(method.readableName()) }, // distinct from msg arg for quickfix purpose
2515 getElaborationId(IProblem.ForbiddenReference, (byte) (CONSTRUCTOR_ACCESS | classpathEntryType)),
2516 new String[] {
2517 classpathEntryName,
2518 new String(method.shortReadableName())},
2519 severity,
2520 location.nameSourceStart(),
2521 location.nameSourceEnd());
2522 else
2523 this.handle(
2524 problemId,
2525 new String[] { new String(method.readableName()) }, // distinct from msg arg for quickfix purpose
2526 getElaborationId(IProblem.ForbiddenReference, (byte) (METHOD_ACCESS | classpathEntryType)),
2527 new String[] {
2528 classpathEntryName,
2529 new String(method.shortReadableName()),
2530 new String(method.declaringClass.shortReadableName())},
2531 severity,
2532 location.nameSourceStart(),
2533 location.nameSourceEnd());
2534 }
2535 /** @param classpathEntryType one of {@link AccessRestriction#COMMAND_LINE},
2536 * {@link AccessRestriction#LIBRARY}, {@link AccessRestriction#PROJECT} */
forbiddenReference(TypeBinding type, ASTNode location, byte classpathEntryType, String classpathEntryName, int problemId)2537 public void forbiddenReference(TypeBinding type, ASTNode location,
2538 byte classpathEntryType, String classpathEntryName, int problemId) {
2539 if (location == null) return;
2540 int severity = computeSeverity(problemId);
2541 if (severity == ProblemSeverities.Ignore) return;
2542 this.handle(
2543 problemId,
2544 new String[] { new String(type.readableName()) }, // distinct from msg arg for quickfix purpose
2545 getElaborationId(IProblem.ForbiddenReference, /* TYPE_ACCESS | */ classpathEntryType), // TYPE_ACCESS values to 0
2546 new String[] {
2547 classpathEntryName,
2548 new String(type.shortReadableName())},
2549 severity,
2550 location.sourceStart,
2551 location.sourceEnd);
2552 }
forwardReference(Reference reference, int indexInQualification, FieldBinding field)2553 public void forwardReference(Reference reference, int indexInQualification, FieldBinding field) {
2554 this.handle(
2555 IProblem.ReferenceToForwardField,
2556 NoArgument,
2557 NoArgument,
2558 nodeSourceStart(field, reference, indexInQualification),
2559 nodeSourceEnd(field, reference, indexInQualification));
2560 }
forwardTypeVariableReference(ASTNode location, TypeVariableBinding type)2561 public void forwardTypeVariableReference(ASTNode location, TypeVariableBinding type) {
2562 this.handle(
2563 IProblem.ReferenceToForwardTypeVariable,
2564 new String[] {new String(type.readableName())},
2565 new String[] {new String(type.shortReadableName())},
2566 location.sourceStart,
2567 location.sourceEnd);
2568 }
genericTypeCannotExtendThrowable(TypeDeclaration typeDecl)2569 public void genericTypeCannotExtendThrowable(TypeDeclaration typeDecl) {
2570 ASTNode location = typeDecl.binding.isAnonymousType() ? typeDecl.allocation.type : typeDecl.superclass;
2571 this.handle(
2572 IProblem.GenericTypeCannotExtendThrowable,
2573 new String[]{ new String(typeDecl.binding.readableName()) },
2574 new String[]{ new String(typeDecl.binding.shortReadableName()) },
2575 location.sourceStart,
2576 location.sourceEnd);
2577 }
2578 // use this private API when the compilation unit result can be found through the
2579 // reference context. Otherwise, use the other API taking a problem and a compilation result
2580 // as arguments
handle( int problemId, String[] problemArguments, int elaborationId, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition)2581 private void handle(
2582 int problemId,
2583 String[] problemArguments,
2584 int elaborationId,
2585 String[] messageArguments,
2586 int severity,
2587 int problemStartPosition,
2588 int problemEndPosition){
2589 this.handle(
2590 problemId,
2591 problemArguments,
2592 elaborationId,
2593 messageArguments,
2594 severity,
2595 problemStartPosition,
2596 problemEndPosition,
2597 this.referenceContext,
2598 this.referenceContext == null ? null : this.referenceContext.compilationResult());
2599 this.referenceContext = null;
2600 }
2601 // use this private API when the compilation unit result can be found through the
2602 // reference context. Otherwise, use the other API taking a problem and a compilation result
2603 // as arguments
handle( int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition, int problemEndPosition)2604 private void handle(
2605 int problemId,
2606 String[] problemArguments,
2607 String[] messageArguments,
2608 int problemStartPosition,
2609 int problemEndPosition){
2610
2611 this.handle(
2612 problemId,
2613 problemArguments,
2614 messageArguments,
2615 problemStartPosition,
2616 problemEndPosition,
2617 this.referenceContext,
2618 this.referenceContext == null ? null : this.referenceContext.compilationResult());
2619 this.referenceContext = null;
2620 }
2621 // use this private API when the compilation unit result cannot be found through the
2622 // reference context.
handle( int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition, int problemEndPosition, CompilationResult unitResult)2623 private void handle(
2624 int problemId,
2625 String[] problemArguments,
2626 String[] messageArguments,
2627 int problemStartPosition,
2628 int problemEndPosition,
2629 CompilationResult unitResult){
2630
2631 this.handle(
2632 problemId,
2633 problemArguments,
2634 messageArguments,
2635 problemStartPosition,
2636 problemEndPosition,
2637 this.referenceContext,
2638 unitResult);
2639 this.referenceContext = null;
2640 }
2641 // use this private API when the compilation unit result can be found through the
2642 // reference context. Otherwise, use the other API taking a problem and a compilation result
2643 // as arguments
handle( int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition)2644 private void handle(
2645 int problemId,
2646 String[] problemArguments,
2647 String[] messageArguments,
2648 int severity,
2649 int problemStartPosition,
2650 int problemEndPosition){
2651
2652 this.handle(
2653 problemId,
2654 problemArguments,
2655 0, // no elaboration
2656 messageArguments,
2657 severity,
2658 problemStartPosition,
2659 problemEndPosition);
2660 }
2661
handleUntagged( int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition, int problemEndPosition)2662 protected void handleUntagged(
2663 int problemId,
2664 String[] problemArguments,
2665 String[] messageArguments,
2666 int problemStartPosition,
2667 int problemEndPosition) {
2668 boolean oldSuppressing = this.suppressTagging;
2669 this.suppressTagging = true;
2670 try {
2671 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition);
2672 } finally {
2673 this.suppressTagging = oldSuppressing;
2674 }
2675 }
hiddenCatchBlock(ReferenceBinding exceptionType, ASTNode location)2676 public void hiddenCatchBlock(ReferenceBinding exceptionType, ASTNode location) {
2677 this.handle(
2678 IProblem.MaskedCatch,
2679 new String[] {
2680 new String(exceptionType.readableName()),
2681 },
2682 new String[] {
2683 new String(exceptionType.shortReadableName()),
2684 },
2685 location.sourceStart,
2686 location.sourceEnd);
2687 }
2688
hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference)2689 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
2690 int start = 0;
2691 int end = 0;
2692
2693 if (reference == null) { // can only happen when java.lang.Object is busted
2694 start = sourceType.sourceStart();
2695 end = sourceType.sourceEnd();
2696 } else {
2697 start = reference.sourceStart;
2698 end = reference.sourceEnd;
2699 }
2700
2701 if (TypeBinding.equalsEquals(sourceType, superType))
2702 this.handle(
2703 IProblem.HierarchyCircularitySelfReference,
2704 new String[] {new String(sourceType.readableName()) },
2705 new String[] {new String(sourceType.shortReadableName()) },
2706 start,
2707 end);
2708 else
2709 this.handle(
2710 IProblem.HierarchyCircularity,
2711 new String[] {new String(sourceType.readableName()), new String(superType.readableName())},
2712 new String[] {new String(sourceType.shortReadableName()), new String(superType.shortReadableName())},
2713 start,
2714 end);
2715 }
2716
hierarchyCircularity(TypeVariableBinding type, ReferenceBinding superType, TypeReference reference)2717 public void hierarchyCircularity(TypeVariableBinding type, ReferenceBinding superType, TypeReference reference) {
2718 int start = 0;
2719 int end = 0;
2720
2721 start = reference.sourceStart;
2722 end = reference.sourceEnd;
2723
2724 if (TypeBinding.equalsEquals(type, superType))
2725 this.handle(
2726 IProblem.HierarchyCircularitySelfReference,
2727 new String[] {new String(type.readableName()) },
2728 new String[] {new String(type.shortReadableName()) },
2729 start,
2730 end);
2731 else
2732 this.handle(
2733 IProblem.HierarchyCircularity,
2734 new String[] {new String(type.readableName()), new String(superType.readableName())},
2735 new String[] {new String(type.shortReadableName()), new String(superType.shortReadableName())},
2736 start,
2737 end);
2738 }
2739
hierarchyHasProblems(SourceTypeBinding type)2740 public void hierarchyHasProblems(SourceTypeBinding type) {
2741 String[] arguments = new String[] {new String(type.sourceName())};
2742 this.handle(
2743 IProblem.HierarchyHasProblems,
2744 arguments,
2745 arguments,
2746 type.sourceStart(),
2747 type.sourceEnd());
2748 }
illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl)2749 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2750 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
2751 this.handle(
2752 IProblem.IllegalAbstractModifierCombinationForMethod,
2753 arguments,
2754 arguments,
2755 methodDecl.sourceStart,
2756 methodDecl.sourceEnd);
2757 }
illegalAbstractModifierCombinationForMethod(AbstractMethodDeclaration methodDecl)2758 public void illegalAbstractModifierCombinationForMethod(AbstractMethodDeclaration methodDecl) {
2759 String[] arguments = new String[] {new String(methodDecl.selector)};
2760 this.handle(
2761 IProblem.IllegalStrictfpForAbstractInterfaceMethod,
2762 arguments,
2763 arguments,
2764 methodDecl.sourceStart,
2765 methodDecl.sourceEnd);
2766 }
illegalAccessFromTypeVariable(TypeVariableBinding variable, ASTNode location)2767 public void illegalAccessFromTypeVariable(TypeVariableBinding variable, ASTNode location) {
2768 if ((location.bits & ASTNode.InsideJavadoc)!= 0) {
2769 javadocInvalidReference(location.sourceStart, location.sourceEnd);
2770 } else {
2771 String[] arguments = new String[] { new String(variable.sourceName) };
2772 this.handle(
2773 IProblem.IllegalAccessFromTypeVariable,
2774 arguments,
2775 arguments,
2776 location.sourceStart,
2777 location.sourceEnd);
2778 }
2779 }
illegalClassLiteralForTypeVariable(TypeVariableBinding variable, ASTNode location)2780 public void illegalClassLiteralForTypeVariable(TypeVariableBinding variable, ASTNode location) {
2781 String[] arguments = new String[] { new String(variable.sourceName) };
2782 this.handle(
2783 IProblem.IllegalClassLiteralForTypeVariable,
2784 arguments,
2785 arguments,
2786 location.sourceStart,
2787 location.sourceEnd);
2788 }
illegalExtendedDimensions(AnnotationMethodDeclaration annotationTypeMemberDeclaration)2789 public void illegalExtendedDimensions(AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
2790 this.handle(
2791 IProblem.IllegalExtendedDimensions,
2792 NoArgument,
2793 NoArgument,
2794 annotationTypeMemberDeclaration.sourceStart,
2795 annotationTypeMemberDeclaration.sourceEnd);
2796 }
illegalExtendedDimensions(AbstractVariableDeclaration aVarDecl)2797 public void illegalExtendedDimensions(AbstractVariableDeclaration aVarDecl) {
2798 this.handle(
2799 IProblem.IllegalExtendedDimensionsForVarArgs,
2800 NoArgument,
2801 NoArgument,
2802 aVarDecl.sourceStart,
2803 aVarDecl.sourceEnd);
2804 }
illegalGenericArray(TypeBinding leafComponentType, ASTNode location)2805 public void illegalGenericArray(TypeBinding leafComponentType, ASTNode location) {
2806 this.handle(
2807 IProblem.IllegalGenericArray,
2808 new String[]{ new String(leafComponentType.readableName())},
2809 new String[]{ new String(leafComponentType.shortReadableName())},
2810 location.sourceStart,
2811 location.sourceEnd);
2812 }
illegalInstanceOfGenericType(TypeBinding checkedType, ASTNode location)2813 public void illegalInstanceOfGenericType(TypeBinding checkedType, ASTNode location) {
2814 TypeBinding erasedType = checkedType.leafComponentType().erasure();
2815 StringBuffer recommendedFormBuffer = new StringBuffer(10);
2816 if (erasedType instanceof ReferenceBinding) {
2817 ReferenceBinding referenceBinding = (ReferenceBinding) erasedType;
2818 recommendedFormBuffer.append(referenceBinding.qualifiedSourceName());
2819 } else {
2820 recommendedFormBuffer.append(erasedType.sourceName());
2821 }
2822 int count = erasedType.typeVariables().length;
2823 if (count > 0) {
2824 recommendedFormBuffer.append('<');
2825 for (int i = 0; i < count; i++) {
2826 if (i > 0) {
2827 recommendedFormBuffer.append(',');
2828 }
2829 recommendedFormBuffer.append('?');
2830 }
2831 recommendedFormBuffer.append('>');
2832 }
2833 for (int i = 0, dim = checkedType.dimensions(); i < dim; i++) {
2834 recommendedFormBuffer.append("[]"); //$NON-NLS-1$
2835 }
2836 String recommendedForm = recommendedFormBuffer.toString();
2837 if (checkedType.leafComponentType().isTypeVariable()) {
2838 this.handle(
2839 IProblem.IllegalInstanceofTypeParameter,
2840 new String[] { new String(checkedType.readableName()), recommendedForm, },
2841 new String[] { new String(checkedType.shortReadableName()), recommendedForm, },
2842 location.sourceStart,
2843 location.sourceEnd);
2844 return;
2845 }
2846 this.handle(
2847 IProblem.IllegalInstanceofParameterizedType,
2848 new String[] { new String(checkedType.readableName()), recommendedForm, },
2849 new String[] { new String(checkedType.shortReadableName()), recommendedForm, },
2850 location.sourceStart,
2851 location.sourceEnd);
2852 }
illegalLocalTypeDeclaration(TypeDeclaration typeDeclaration)2853 public void illegalLocalTypeDeclaration(TypeDeclaration typeDeclaration) {
2854 if (isRecoveredName(typeDeclaration.name)) return;
2855
2856 int problemID = 0;
2857 if ((typeDeclaration.modifiers & ClassFileConstants.AccEnum) != 0) {
2858 problemID = IProblem.CannotDefineEnumInLocalType;
2859 } else if ((typeDeclaration.modifiers & ClassFileConstants.AccAnnotation) != 0) {
2860 problemID = IProblem.CannotDefineAnnotationInLocalType;
2861 } else if ((typeDeclaration.modifiers & ClassFileConstants.AccInterface) != 0) {
2862 problemID = IProblem.CannotDefineInterfaceInLocalType;
2863 } else if (typeDeclaration.isRecord()) {
2864 problemID = IProblem.RecordCannotDefineRecordInLocalType;
2865 }
2866 if (problemID != 0) {
2867 String[] arguments = new String[] {new String(typeDeclaration.name)};
2868 this.handle(
2869 problemID,
2870 arguments,
2871 arguments,
2872 typeDeclaration.sourceStart,
2873 typeDeclaration.sourceEnd);
2874 }
2875 }
illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type)2876 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
2877 String[] arguments = new String[] {new String(type.sourceName())};
2878 this.handle(
2879 IProblem.IllegalModifierCombinationFinalAbstractForClass,
2880 arguments,
2881 arguments,
2882 type.sourceStart(),
2883 type.sourceEnd());
2884 }
illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl)2885 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
2886 String[] arguments = new String[] {new String(fieldDecl.name)};
2887
2888 this.handle(
2889 IProblem.IllegalModifierCombinationFinalVolatileForField,
2890 arguments,
2891 arguments,
2892 fieldDecl.sourceStart,
2893 fieldDecl.sourceEnd);
2894 }
illegalModifierCombinationForInterfaceMethod(AbstractMethodDeclaration methodDecl)2895 public void illegalModifierCombinationForInterfaceMethod(AbstractMethodDeclaration methodDecl) {
2896 String[] arguments = new String[] {new String(methodDecl.selector)};
2897 this.handle(
2898 IProblem.IllegalModifierCombinationForInterfaceMethod,
2899 arguments,
2900 arguments,
2901 methodDecl.sourceStart,
2902 methodDecl.sourceEnd);
2903 }
illegalModifierCombinationForPrivateInterfaceMethod(AbstractMethodDeclaration methodDecl)2904 public void illegalModifierCombinationForPrivateInterfaceMethod(AbstractMethodDeclaration methodDecl) {
2905 String[] arguments = new String[] {new String(methodDecl.selector)};
2906 this.handle(
2907 IProblem.IllegalModifierCombinationForPrivateInterfaceMethod9,
2908 arguments,
2909 arguments,
2910 methodDecl.sourceStart,
2911 methodDecl.sourceEnd);
2912 }
2913
illegalModifierForAnnotationField(FieldDeclaration fieldDecl)2914 public void illegalModifierForAnnotationField(FieldDeclaration fieldDecl) {
2915 String name = new String(fieldDecl.name);
2916 this.handle(
2917 IProblem.IllegalModifierForAnnotationField,
2918 new String[] {
2919 new String(fieldDecl.binding.declaringClass.readableName()),
2920 name,
2921 },
2922 new String[] {
2923 new String(fieldDecl.binding.declaringClass.shortReadableName()),
2924 name,
2925 },
2926 fieldDecl.sourceStart,
2927 fieldDecl.sourceEnd);
2928 }
illegalModifierForAnnotationMember(AbstractMethodDeclaration methodDecl)2929 public void illegalModifierForAnnotationMember(AbstractMethodDeclaration methodDecl) {
2930 this.handle(
2931 IProblem.IllegalModifierForAnnotationMethod,
2932 new String[] {
2933 new String(methodDecl.binding.declaringClass.readableName()),
2934 new String(methodDecl.selector),
2935 },
2936 new String[] {
2937 new String(methodDecl.binding.declaringClass.shortReadableName()),
2938 new String(methodDecl.selector),
2939 },
2940 methodDecl.sourceStart,
2941 methodDecl.sourceEnd);
2942 }
illegalModifierForAnnotationMemberType(SourceTypeBinding type)2943 public void illegalModifierForAnnotationMemberType(SourceTypeBinding type) {
2944 String[] arguments = new String[] {new String(type.sourceName())};
2945 this.handle(
2946 IProblem.IllegalModifierForAnnotationMemberType,
2947 arguments,
2948 arguments,
2949 type.sourceStart(),
2950 type.sourceEnd());
2951 }
illegalModifierForAnnotationType(SourceTypeBinding type)2952 public void illegalModifierForAnnotationType(SourceTypeBinding type) {
2953 String[] arguments = new String[] {new String(type.sourceName())};
2954 this.handle(
2955 IProblem.IllegalModifierForAnnotationType,
2956 arguments,
2957 arguments,
2958 type.sourceStart(),
2959 type.sourceEnd());
2960 }
illegalModifierForClass(SourceTypeBinding type)2961 public void illegalModifierForClass(SourceTypeBinding type) {
2962 String[] arguments = new String[] {new String(type.sourceName())};
2963 this.handle(
2964 IProblem.IllegalModifierForClass,
2965 arguments,
2966 arguments,
2967 type.sourceStart(),
2968 type.sourceEnd());
2969 }
illegalModifierForModule(ModuleDeclaration module)2970 public void illegalModifierForModule(ModuleDeclaration module) {
2971 String[] arguments = new String[] {new String(module.moduleName)};
2972 this.handle(
2973 IProblem.IllegalModifierForModule,
2974 arguments,
2975 arguments,
2976 module.sourceStart(),
2977 module.sourceEnd());
2978 }
illegalModifierForEnum(SourceTypeBinding type)2979 public void illegalModifierForEnum(SourceTypeBinding type) {
2980 String[] arguments = new String[] {new String(type.sourceName())};
2981 this.handle(
2982 IProblem.IllegalModifierForEnum,
2983 arguments,
2984 arguments,
2985 type.sourceStart(),
2986 type.sourceEnd());
2987 }
illegalModifierForEnumConstant(ReferenceBinding type, FieldDeclaration fieldDecl)2988 public void illegalModifierForEnumConstant(ReferenceBinding type, FieldDeclaration fieldDecl) {
2989 String[] arguments = new String[] {new String(fieldDecl.name)};
2990 this.handle(
2991 IProblem.IllegalModifierForEnumConstant,
2992 arguments,
2993 arguments,
2994 fieldDecl.sourceStart,
2995 fieldDecl.sourceEnd);
2996 }
2997
illegalModifierForEnumConstructor(AbstractMethodDeclaration constructor)2998 public void illegalModifierForEnumConstructor(AbstractMethodDeclaration constructor) {
2999 this.handle(
3000 IProblem.IllegalModifierForEnumConstructor,
3001 NoArgument,
3002 NoArgument,
3003 constructor.sourceStart,
3004 constructor.sourceEnd);
3005 }
illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl)3006 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
3007 String[] arguments = new String[] {new String(fieldDecl.name)};
3008 this.handle(
3009 IProblem.IllegalModifierForField,
3010 arguments,
3011 arguments,
3012 fieldDecl.sourceStart,
3013 fieldDecl.sourceEnd);
3014 }
illegalModifierForInterface(SourceTypeBinding type)3015 public void illegalModifierForInterface(SourceTypeBinding type) {
3016 String[] arguments = new String[] {new String(type.sourceName())};
3017 this.handle(
3018 IProblem.IllegalModifierForInterface,
3019 arguments,
3020 arguments,
3021 type.sourceStart(),
3022 type.sourceEnd());
3023 }
3024
illegalModifierForInterfaceField(FieldDeclaration fieldDecl)3025 public void illegalModifierForInterfaceField(FieldDeclaration fieldDecl) {
3026 String name = new String(fieldDecl.name);
3027 this.handle(
3028 IProblem.IllegalModifierForInterfaceField,
3029 new String[] {
3030 new String(fieldDecl.binding.declaringClass.readableName()),
3031 name,
3032 },
3033 new String[] {
3034 new String(fieldDecl.binding.declaringClass.shortReadableName()),
3035 name,
3036 },
3037 fieldDecl.sourceStart,
3038 fieldDecl.sourceEnd);
3039 }
illegalModifierForInterfaceMethod(AbstractMethodDeclaration methodDecl, long level)3040 public void illegalModifierForInterfaceMethod(AbstractMethodDeclaration methodDecl, long level) {
3041
3042 int problem = level < ClassFileConstants.JDK1_8 ? IProblem.IllegalModifierForInterfaceMethod :
3043 level < ClassFileConstants.JDK9 ? IProblem.IllegalModifierForInterfaceMethod18 : IProblem.IllegalModifierForInterfaceMethod9;
3044 // cannot include parameter types since they are not resolved yet
3045 // and the error message would be too long
3046 this.handle(
3047 problem,
3048 new String[] {
3049 new String(methodDecl.selector)
3050 },
3051 new String[] {
3052 new String(methodDecl.selector)
3053 },
3054 methodDecl.sourceStart,
3055 methodDecl.sourceEnd);
3056 }
3057 public void illegalModifierForLocalClass(SourceTypeBinding type) {
3058 String[] arguments = new String[] {new String(type.sourceName())};
3059 this.handle(
3060 IProblem.IllegalModifierForLocalClass,
3061 arguments,
3062 arguments,
3063 type.sourceStart(),
3064 type.sourceEnd());
3065 }
3066 public void illegalModifierForMemberClass(SourceTypeBinding type) {
3067 String[] arguments = new String[] {new String(type.sourceName())};
3068 this.handle(
3069 IProblem.IllegalModifierForMemberClass,
3070 arguments,
3071 arguments,
3072 type.sourceStart(),
3073 type.sourceEnd());
3074 }
3075 public void illegalModifierForMemberEnum(SourceTypeBinding type) {
3076 String[] arguments = new String[] {new String(type.sourceName())};
3077 this.handle(
3078 IProblem.IllegalModifierForMemberEnum,
3079 arguments,
3080 arguments,
3081 type.sourceStart(),
3082 type.sourceEnd());
3083 }
3084 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
3085 String[] arguments = new String[] {new String(type.sourceName())};
3086 this.handle(
3087 IProblem.IllegalModifierForMemberInterface,
3088 arguments,
3089 arguments,
3090 type.sourceStart(),
3091 type.sourceEnd());
3092 }
3093 public void illegalModifierForMethod(AbstractMethodDeclaration methodDecl) {
3094 // cannot include parameter types since they are not resolved yet
3095 // and the error message would be too long
3096 this.handle(
3097 methodDecl.isConstructor() ? IProblem.IllegalModifierForConstructor : IProblem.IllegalModifierForMethod,
3098 new String[] {
3099 new String(methodDecl.selector)
3100 },
3101 new String[] {
3102 new String(methodDecl.selector)
3103 },
3104 methodDecl.sourceStart,
3105 methodDecl.sourceEnd);
3106 }
3107 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
3108 String[] arguments = new String[] {new String(localDecl.name)};
3109 this.handle(
3110 complainAsArgument
3111 ? IProblem.IllegalModifierForArgument
3112 : IProblem.IllegalModifierForVariable,
3113 arguments,
3114 arguments,
3115 localDecl.sourceStart,
3116 localDecl.sourceEnd);
3117 }
3118 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
3119 this.handle(
3120 IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
3121 new String[] {new String(enclosingType.readableName())},
3122 new String[] {new String(enclosingType.shortReadableName())},
3123 location.sourceStart,
3124 location.sourceEnd);
3125 }
3126 public void illegalQualifiedParameterizedTypeAllocation(TypeReference qualifiedTypeReference, TypeBinding allocatedType) {
3127 this.handle(
3128 IProblem.IllegalQualifiedParameterizedTypeAllocation,
3129 new String[] { new String(allocatedType.readableName()), new String(allocatedType.enclosingType().readableName()), },
3130 new String[] { new String(allocatedType.shortReadableName()), new String(allocatedType.enclosingType().shortReadableName()), },
3131 qualifiedTypeReference.sourceStart,
3132 qualifiedTypeReference.sourceEnd);
3133 }
3134 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
3135 String[] arguments = new String[] {new String(type.sourceName())};
3136 this.handle(
3137 IProblem.IllegalStaticModifierForMemberType,
3138 arguments,
3139 arguments,
3140 type.sourceStart(),
3141 type.sourceEnd());
3142 }
3143 public void illegalUsageOfQualifiedTypeReference(QualifiedTypeReference qualifiedTypeReference) {
3144 StringBuffer buffer = new StringBuffer();
3145 char[][] tokens = qualifiedTypeReference.tokens;
3146 for (int i = 0; i < tokens.length; i++) {
3147 if (i > 0) buffer.append('.');
3148 buffer.append(tokens[i]);
3149 }
3150 String[] arguments = new String[] { String.valueOf(buffer)};
3151 this.handle(
3152 IProblem.IllegalUsageOfQualifiedTypeReference,
3153 arguments,
3154 arguments,
3155 qualifiedTypeReference.sourceStart,
3156 qualifiedTypeReference.sourceEnd);
3157 }
3158 public void illegalUsageOfWildcard(TypeReference wildcard) {
3159 this.handle(
3160 IProblem.InvalidUsageOfWildcard,
3161 NoArgument,
3162 NoArgument,
3163 wildcard.sourceStart,
3164 wildcard.sourceEnd);
3165 }
3166 public void illegalVararg(Argument argType, AbstractMethodDeclaration methodDecl) {
3167 String[] arguments = new String[] {CharOperation.toString(argType.type.getTypeName()), new String(methodDecl.selector)};
3168 this.handle(
3169 IProblem.IllegalVararg,
3170 arguments,
3171 arguments,
3172 argType.sourceStart,
3173 argType.sourceEnd);
3174 }
3175 public void illegalVarargInLambda(Argument argType) {
3176 String[] arguments = new String[] { CharOperation.toString(argType.type.getTypeName())};
3177 this.handle(
3178 IProblem.IllegalVarargInLambda,
3179 arguments,
3180 arguments,
3181 argType.sourceStart,
3182 argType.sourceEnd);
3183 }
3184 public void illegalThisDeclaration(Argument argument) {
3185 String[] arguments = NoArgument;
3186 this.handle(
3187 IProblem.IllegalDeclarationOfThisParameter,
3188 arguments,
3189 arguments,
3190 argument.sourceStart,
3191 argument.sourceEnd);
3192 }
3193 public void illegalSourceLevelForThis(Argument argument) {
3194 String[] arguments = NoArgument;
3195 this.handle(
3196 IProblem.ExplicitThisParameterNotBelow18,
3197 arguments,
3198 arguments,
3199 argument.sourceStart,
3200 argument.sourceEnd);
3201 }
3202 public void disallowedThisParameter(Receiver receiver) {
3203 String[] arguments = NoArgument;
3204 this.handle(
3205 IProblem.DisallowedExplicitThisParameter,
3206 arguments,
3207 arguments,
3208 receiver.sourceStart,
3209 receiver.sourceEnd);
3210 }
3211 public void illegalQualifierForExplicitThis(Receiver receiver, TypeBinding expectedType) {
3212 String[] problemArguments = new String[] { new String(expectedType.sourceName())};
3213 this.handle(
3214 IProblem.IllegalQualifierForExplicitThis,
3215 problemArguments,
3216 problemArguments,
3217 (receiver.qualifyingName == null) ? receiver.sourceStart : receiver.qualifyingName.sourceStart,
3218 receiver.sourceEnd);
3219 }
3220 public void illegalQualifierForExplicitThis2(Receiver receiver) {
3221 this.handle(
3222 IProblem.IllegalQualifierForExplicitThis2,
3223 NoArgument,
3224 NoArgument,
3225 receiver.qualifyingName.sourceStart,
3226 receiver.sourceEnd);
3227 }
3228 public void illegalTypeForExplicitThis(Receiver receiver, TypeBinding expectedType) {
3229 this.handle(
3230 IProblem.IllegalTypeForExplicitThis,
3231 new String[] { new String(expectedType.readableName())},
3232 new String[] { new String(expectedType.shortReadableName())},
3233 receiver.type.sourceStart,
3234 receiver.type.sourceEnd);
3235 }
3236 public void illegalThis(Argument argument) {
3237 String[] arguments = NoArgument;
3238 this.handle(
3239 IProblem.ExplicitThisParameterNotInLambda,
3240 arguments,
3241 arguments,
3242 argument.sourceStart,
3243 argument.sourceEnd);
3244 }
3245 public void defaultMethodsNotBelow18(MethodDeclaration md) {
3246 this.handle(
3247 IProblem.DefaultMethodNotBelow18,
3248 NoArgument,
3249 NoArgument,
3250 md.sourceStart,
3251 md.sourceEnd);
3252 }
3253 public void interfaceSuperInvocationNotBelow18(QualifiedSuperReference qualifiedSuperReference) {
3254 this.handle(
3255 IProblem.InterfaceSuperInvocationNotBelow18,
3256 NoArgument,
3257 NoArgument,
3258 qualifiedSuperReference.sourceStart,
3259 qualifiedSuperReference.sourceEnd);
3260 }
3261 public void staticInterfaceMethodsNotBelow18(MethodDeclaration md) {
3262 this.handle(
3263 IProblem.StaticInterfaceMethodNotBelow18,
3264 NoArgument,
3265 NoArgument,
3266 md.sourceStart,
3267 md.sourceEnd);
3268 }
3269 public void referenceExpressionsNotBelow18(ReferenceExpression rexp) {
3270 this.handle(
3271 rexp.isMethodReference() ? IProblem.MethodReferenceNotBelow18 : IProblem.ConstructorReferenceNotBelow18,
3272 NoArgument,
3273 NoArgument,
3274 rexp.sourceStart,
3275 rexp.sourceEnd);
3276 }
3277 public void lambdaExpressionsNotBelow18(LambdaExpression lexp) {
3278 this.handle(
3279 IProblem.LambdaExpressionNotBelow18,
3280 NoArgument,
3281 NoArgument,
3282 lexp.sourceStart,
3283 lexp.diagnosticsSourceEnd());
3284 }
3285 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
3286 String[] arguments = new String[] {new String(fieldDecl.name)};
3287 this.handle(
3288 IProblem.IllegalVisibilityModifierCombinationForField,
3289 arguments,
3290 arguments,
3291 fieldDecl.sourceStart,
3292 fieldDecl.sourceEnd);
3293 }
3294 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
3295 String[] arguments = new String[] {new String(type.sourceName())};
3296 this.handle(
3297 IProblem.IllegalVisibilityModifierCombinationForMemberType,
3298 arguments,
3299 arguments,
3300 type.sourceStart(),
3301 type.sourceEnd());
3302 }
3303 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
3304 String[] arguments = new String[] {new String(type.sourceName()), new String(methodDecl.selector)};
3305 this.handle(
3306 IProblem.IllegalVisibilityModifierCombinationForMethod,
3307 arguments,
3308 arguments,
3309 methodDecl.sourceStart,
3310 methodDecl.sourceEnd);
3311 }
3312 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
3313 String[] arguments = new String[] {new String(type.sourceName())};
3314 this.handle(
3315 IProblem.IllegalVisibilityModifierForInterfaceMemberType,
3316 arguments,
3317 arguments,
3318 type.sourceStart(),
3319 type.sourceEnd());
3320 }
3321 public void illegalVoidExpression(ASTNode location) {
3322 this.handle(
3323 IProblem.InvalidVoidExpression,
3324 NoArgument,
3325 NoArgument,
3326 location.sourceStart,
3327 location.sourceEnd);
3328 }
3329 public void importProblem(ImportReference importRef, Binding expectedImport) {
3330 if (expectedImport instanceof FieldBinding) {
3331 int id = IProblem.UndefinedField;
3332 FieldBinding field = (FieldBinding) expectedImport;
3333 String[] readableArguments = null;
3334 String[] shortArguments = null;
3335 switch (expectedImport.problemId()) {
3336 case ProblemReasons.NotVisible :
3337 case ProblemReasons.NotAccessible :
3338 id = (expectedImport.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleField : IProblem.NotAccessibleField;
3339 readableArguments = new String[] {CharOperation.toString(importRef.tokens), new String(field.declaringClass.readableName())};
3340 shortArguments = new String[] {CharOperation.toString(importRef.tokens), new String(field.declaringClass.shortReadableName())};
3341 break;
3342 case ProblemReasons.Ambiguous :
3343 id = IProblem.AmbiguousField;
3344 readableArguments = new String[] {new String(field.readableName())};
3345 shortArguments = new String[] {new String(field.readableName())};
3346 break;
3347 case ProblemReasons.ReceiverTypeNotVisible :
3348 id = IProblem.NotVisibleType;
3349 readableArguments = new String[] {new String(field.declaringClass.leafComponentType().readableName())};
3350 shortArguments = new String[] {new String(field.declaringClass.leafComponentType().shortReadableName())};
3351 break;
3352 }
3353 this.handleUntagged(
3354 id,
3355 readableArguments,
3356 shortArguments,
3357 nodeSourceStart(field, importRef),
3358 nodeSourceEnd(field, importRef));
3359 return;
3360 }
3361
3362 if (expectedImport instanceof PackageBinding && expectedImport.problemId() == ProblemReasons.NotAccessible) {
3363 char[][] compoundName = ((PackageBinding)expectedImport).compoundName;
3364 String[] arguments = new String[] {CharOperation.toString(compoundName)};
3365 this.handleUntagged(
3366 IProblem.NotAccessiblePackage,
3367 arguments,
3368 arguments,
3369 importRef.sourceStart,
3370 (int) importRef.sourcePositions[compoundName.length - 1]);
3371 return;
3372 }
3373
3374 if (expectedImport.problemId() == ProblemReasons.NotFound) {
3375 char[][] tokens = expectedImport instanceof ProblemReferenceBinding
3376 ? ((ProblemReferenceBinding) expectedImport).compoundName
3377 : importRef.tokens;
3378 String[] arguments = new String[]{CharOperation.toString(tokens)};
3379 this.handleUntagged(
3380 IProblem.ImportNotFound,
3381 arguments,
3382 arguments,
3383 importRef.sourceStart,
3384 (int) importRef.sourcePositions[tokens.length - 1]);
3385 return;
3386 }
3387 if (expectedImport.problemId() == ProblemReasons.InvalidTypeForStaticImport) {
3388 char[][] tokens = importRef.tokens;
3389 String[] arguments = new String[]{CharOperation.toString(tokens)};
3390 this.handleUntagged(
3391 IProblem.InvalidTypeForStaticImport,
3392 arguments,
3393 arguments,
3394 importRef.sourceStart,
3395 (int) importRef.sourcePositions[tokens.length - 1]);
3396 return;
3397 }
3398 invalidType(importRef, (TypeBinding)expectedImport);
3399 }
3400 public void conflictingPackagesFromModules(SplitPackageBinding splitPackage, ModuleBinding focusModule, int sourceStart, int sourceEnd) {
3401 String modules = splitPackage.incarnations.stream()
3402 .filter(focusModule::canAccess)
3403 .map(p -> String.valueOf(p.enclosingModule.readableName()))
3404 .sorted()
3405 .collect(Collectors.joining(", ")); //$NON-NLS-1$
3406 String[] arguments = new String[] {
3407 CharOperation.toString(splitPackage.compoundName),
3408 modules };
3409 this.handle(
3410 IProblem.ConflictingPackageFromModules,
3411 arguments,
3412 arguments,
3413 sourceStart,
3414 sourceEnd);
3415 }
3416 public void conflictingPackagesFromModules(PackageBinding pack, Set<ModuleBinding> modules, int sourceStart, int sourceEnd) {
3417 String moduleNames = modules.stream()
3418 .map(p -> String.valueOf(p.name()))
3419 .sorted()
3420 .collect(Collectors.joining(", ")); //$NON-NLS-1$
3421 String[] arguments = new String[] {
3422 CharOperation.toString(pack.compoundName),
3423 moduleNames };
3424 this.handle(
3425 IProblem.ConflictingPackageFromModules,
3426 arguments,
3427 arguments,
3428 sourceStart,
3429 sourceEnd);
3430 }
conflictingPackagesFromOtherModules(ImportReference currentPackage, Set<ModuleBinding> declaringModules)3431 public void conflictingPackagesFromOtherModules(ImportReference currentPackage, Set<ModuleBinding> declaringModules) {
3432 String moduleNames = declaringModules.stream()
3433 .map(p -> String.valueOf(p.name()))
3434 .sorted()
3435 .collect(Collectors.joining(", ")); //$NON-NLS-1$
3436 String[] arguments = new String[] { CharOperation.toString(currentPackage.tokens), moduleNames };
3437 this.handle(IProblem.ConflictingPackageFromOtherModules, arguments, arguments, currentPackage.sourceStart, currentPackage.sourceEnd);
3438 }
incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType)3439 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod, MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
3440 if (TypeBinding.equalsEquals(type, currentMethod.declaringClass)) {
3441 int id;
3442 if (currentMethod.declaringClass.isInterface()
3443 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
3444 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
3445 } else {
3446 id = IProblem.IncompatibleExceptionInThrowsClause;
3447 }
3448 this.handle(
3449 // Exception %1 is not compatible with throws clause in %2
3450 // 9.4.4 - The type of exception in the throws clause is incompatible.
3451 id,
3452 new String[] {
3453 new String(exceptionType.sourceName()),
3454 new String(
3455 CharOperation.concat(
3456 inheritedMethod.declaringClass.readableName(),
3457 inheritedMethod.readableName(),
3458 '.'))},
3459 new String[] {
3460 new String(exceptionType.sourceName()),
3461 new String(
3462 CharOperation.concat(
3463 inheritedMethod.declaringClass.shortReadableName(),
3464 inheritedMethod.shortReadableName(),
3465 '.'))},
3466 currentMethod.sourceStart(),
3467 currentMethod.sourceEnd());
3468 } else
3469 this.handle(
3470 // Exception %1 in throws clause of %2 is not compatible with %3
3471 // 9.4.4 - The type of exception in the throws clause is incompatible.
3472 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
3473 new String[] {
3474 new String(exceptionType.sourceName()),
3475 new String(
3476 CharOperation.concat(
3477 currentMethod.declaringClass.sourceName(),
3478 currentMethod.readableName(),
3479 '.')),
3480 new String(
3481 CharOperation.concat(
3482 inheritedMethod.declaringClass.readableName(),
3483 inheritedMethod.readableName(),
3484 '.'))},
3485 new String[] {
3486 new String(exceptionType.sourceName()),
3487 new String(
3488 CharOperation.concat(
3489 currentMethod.declaringClass.sourceName(),
3490 currentMethod.shortReadableName(),
3491 '.')),
3492 new String(
3493 CharOperation.concat(
3494 inheritedMethod.declaringClass.shortReadableName(),
3495 inheritedMethod.shortReadableName(),
3496 '.'))},
3497 type.sourceStart(),
3498 type.sourceEnd());
3499 }
incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod)3500 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
3501 StringBuffer methodSignature = new StringBuffer();
3502 methodSignature
3503 .append(inheritedMethod.declaringClass.readableName())
3504 .append('.')
3505 .append(inheritedMethod.readableName());
3506
3507 StringBuffer shortSignature = new StringBuffer();
3508 shortSignature
3509 .append(inheritedMethod.declaringClass.shortReadableName())
3510 .append('.')
3511 .append(inheritedMethod.shortReadableName());
3512
3513 int id;
3514 final ReferenceBinding declaringClass = currentMethod.declaringClass;
3515 if (declaringClass.isInterface()
3516 && !inheritedMethod.isPublic()){ // interface inheriting Object protected method
3517 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
3518 } else {
3519 id = IProblem.IncompatibleReturnType;
3520 }
3521 AbstractMethodDeclaration method = currentMethod.sourceMethod();
3522 int sourceStart = 0;
3523 int sourceEnd = 0;
3524 if (method == null) {
3525 if (declaringClass instanceof SourceTypeBinding) {
3526 SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) declaringClass;
3527 sourceStart = sourceTypeBinding.sourceStart();
3528 sourceEnd = sourceTypeBinding.sourceEnd();
3529 }
3530 } else if (method.isConstructor()){
3531 sourceStart = method.sourceStart;
3532 sourceEnd = method.sourceEnd;
3533 } else {
3534 TypeReference returnType = ((MethodDeclaration) method).returnType;
3535 sourceStart = returnType.sourceStart;
3536 if (returnType instanceof ParameterizedSingleTypeReference) {
3537 ParameterizedSingleTypeReference typeReference = (ParameterizedSingleTypeReference) returnType;
3538 TypeReference[] typeArguments = typeReference.typeArguments;
3539 if (typeArguments[typeArguments.length - 1].sourceEnd > typeReference.sourceEnd) {
3540 sourceEnd = retrieveClosingAngleBracketPosition(typeReference.sourceEnd);
3541 } else {
3542 sourceEnd = returnType.sourceEnd;
3543 }
3544 } else if (returnType instanceof ParameterizedQualifiedTypeReference) {
3545 ParameterizedQualifiedTypeReference typeReference = (ParameterizedQualifiedTypeReference) returnType;
3546 sourceEnd = retrieveClosingAngleBracketPosition(typeReference.sourceEnd);
3547 } else {
3548 sourceEnd = returnType.sourceEnd;
3549 }
3550 }
3551 this.handle(
3552 id,
3553 new String[] {methodSignature.toString()},
3554 new String[] {shortSignature.toString()},
3555 sourceStart,
3556 sourceEnd);
3557 }
incorrectArityForParameterizedType(ASTNode location, TypeBinding type, TypeBinding[] argumentTypes)3558 public void incorrectArityForParameterizedType(ASTNode location, TypeBinding type, TypeBinding[] argumentTypes) {
3559 incorrectArityForParameterizedType(location, type, argumentTypes, Integer.MAX_VALUE);
3560 }
incorrectArityForParameterizedType(ASTNode location, TypeBinding type, TypeBinding[] argumentTypes, int index)3561 public void incorrectArityForParameterizedType(ASTNode location, TypeBinding type, TypeBinding[] argumentTypes, int index) {
3562 if (location == null) {
3563 this.handle(
3564 IProblem.IncorrectArityForParameterizedType,
3565 new String[] {new String(type.readableName()), typesAsString(argumentTypes, false)},
3566 new String[] {new String(type.shortReadableName()), typesAsString(argumentTypes, true)},
3567 ProblemSeverities.AbortCompilation | ProblemSeverities.Error | ProblemSeverities.Fatal,
3568 0,
3569 0);
3570 return; // not reached since aborted above
3571 }
3572 this.handle(
3573 IProblem.IncorrectArityForParameterizedType,
3574 new String[] {new String(type.readableName()), typesAsString(argumentTypes, false)},
3575 new String[] {new String(type.shortReadableName()), typesAsString(argumentTypes, true)},
3576 location.sourceStart,
3577 nodeSourceEnd(null, location, index));
3578 }
diamondNotBelow17(ASTNode location)3579 public void diamondNotBelow17(ASTNode location) {
3580 diamondNotBelow17(location, Integer.MAX_VALUE);
3581 }
diamondNotBelow17(ASTNode location, int index)3582 public void diamondNotBelow17(ASTNode location, int index) {
3583 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348493
3584 if (location == null) {
3585 this.handle(
3586 IProblem.DiamondNotBelow17,
3587 NoArgument,
3588 NoArgument,
3589 ProblemSeverities.AbortCompilation | ProblemSeverities.Error | ProblemSeverities.Fatal,
3590 0,
3591 0);
3592 return; // not reached since aborted above
3593 }
3594 this.handle(
3595 IProblem.DiamondNotBelow17,
3596 NoArgument,
3597 NoArgument,
3598 location.sourceStart,
3599 nodeSourceEnd(null, location, index));
3600 }
incorrectLocationForNonEmptyDimension(ArrayAllocationExpression expression, int index)3601 public void incorrectLocationForNonEmptyDimension(ArrayAllocationExpression expression, int index) {
3602 this.handle(
3603 IProblem.IllegalDimension,
3604 NoArgument,
3605 NoArgument,
3606 expression.dimensions[index].sourceStart,
3607 expression.dimensions[index].sourceEnd);
3608 }
incorrectSwitchType(Expression expression, TypeBinding testType)3609 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
3610 if (this.options.sourceLevel < ClassFileConstants.JDK1_7) {
3611 if (testType.id == TypeIds.T_JavaLangString) {
3612 this.handle(
3613 IProblem.SwitchOnStringsNotBelow17,
3614 new String[] {new String(testType.readableName())},
3615 new String[] {new String(testType.shortReadableName())},
3616 expression.sourceStart,
3617 expression.sourceEnd);
3618 } else {
3619 if (this.options.sourceLevel < ClassFileConstants.JDK1_5 && testType.isEnum()) {
3620 this.handle(
3621 IProblem.SwitchOnEnumNotBelow15,
3622 new String[] {new String(testType.readableName())},
3623 new String[] {new String(testType.shortReadableName())},
3624 expression.sourceStart,
3625 expression.sourceEnd);
3626 } else {
3627 this.handle(
3628 IProblem.IncorrectSwitchType,
3629 new String[] {new String(testType.readableName())},
3630 new String[] {new String(testType.shortReadableName())},
3631 expression.sourceStart,
3632 expression.sourceEnd);
3633 }
3634 }
3635 } else {
3636 this.handle(
3637 IProblem.IncorrectSwitchType17,
3638 new String[] {new String(testType.readableName())},
3639 new String[] {new String(testType.shortReadableName())},
3640 expression.sourceStart,
3641 expression.sourceEnd);
3642 }
3643 }
indirectAccessToStaticField(ASTNode location, FieldBinding field)3644 public void indirectAccessToStaticField(ASTNode location, FieldBinding field){
3645 int severity = computeSeverity(IProblem.IndirectAccessToStaticField);
3646 if (severity == ProblemSeverities.Ignore) return;
3647 this.handle(
3648 IProblem.IndirectAccessToStaticField,
3649 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
3650 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
3651 severity,
3652 nodeSourceStart(field, location),
3653 nodeSourceEnd(field, location));
3654 }
indirectAccessToStaticMethod(ASTNode location, MethodBinding method)3655 public void indirectAccessToStaticMethod(ASTNode location, MethodBinding method) {
3656 int severity = computeSeverity(IProblem.IndirectAccessToStaticMethod);
3657 if (severity == ProblemSeverities.Ignore) return;
3658 this.handle(
3659 IProblem.IndirectAccessToStaticMethod,
3660 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method, false)},
3661 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method, true)},
3662 severity,
3663 location.sourceStart,
3664 location.sourceEnd);
3665 }
inheritedDefaultMethodConflictsWithOtherInherited(SourceTypeBinding type, MethodBinding defaultMethod, MethodBinding otherMethod)3666 public void inheritedDefaultMethodConflictsWithOtherInherited(SourceTypeBinding type, MethodBinding defaultMethod, MethodBinding otherMethod) {
3667 TypeDeclaration typeDecl = type.scope.referenceContext;
3668 String[] problemArguments = new String[] {
3669 String.valueOf(defaultMethod.readableName()),
3670 String.valueOf(defaultMethod.declaringClass.readableName()),
3671 String.valueOf(otherMethod.declaringClass.readableName()) };
3672 String[] messageArguments = new String[] {
3673 String.valueOf(defaultMethod.shortReadableName()),
3674 String.valueOf(defaultMethod.declaringClass.shortReadableName()),
3675 String.valueOf(otherMethod.declaringClass.shortReadableName()) };
3676 this.handle(IProblem.InheritedDefaultMethodConflictsWithOtherInherited,
3677 problemArguments,
3678 messageArguments,
3679 typeDecl.sourceStart,
3680 typeDecl.sourceEnd);
3681 }
inheritedMethodReducesVisibility(int sourceStart, int sourceEnd, MethodBinding concreteMethod, MethodBinding[] abstractMethods)3682 private void inheritedMethodReducesVisibility(int sourceStart, int sourceEnd, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3683 StringBuffer concreteSignature = new StringBuffer();
3684 concreteSignature
3685 .append(concreteMethod.declaringClass.readableName())
3686 .append('.')
3687 .append(concreteMethod.readableName());
3688 StringBuffer shortSignature = new StringBuffer();
3689 shortSignature
3690 .append(concreteMethod.declaringClass.shortReadableName())
3691 .append('.')
3692 .append(concreteMethod.shortReadableName());
3693 this.handle(
3694 // The inherited method %1 cannot hide the public abstract method in %2
3695 IProblem.InheritedMethodReducesVisibility,
3696 new String[] {
3697 concreteSignature.toString(),
3698 new String(abstractMethods[0].declaringClass.readableName())},
3699 new String[] {
3700 shortSignature.toString(),
3701 new String(abstractMethods[0].declaringClass.shortReadableName())},
3702 sourceStart,
3703 sourceEnd);
3704 }
inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods)3705 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3706 inheritedMethodReducesVisibility(type.sourceStart(), type.sourceEnd(), concreteMethod, abstractMethods);
3707 }
inheritedMethodReducesVisibility(TypeParameter typeParameter, MethodBinding concreteMethod, MethodBinding[] abstractMethods)3708 public void inheritedMethodReducesVisibility(TypeParameter typeParameter, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3709 inheritedMethodReducesVisibility(typeParameter.sourceStart(), typeParameter.sourceEnd(), concreteMethod, abstractMethods);
3710 }
inheritedMethodsHaveIncompatibleReturnTypes(ASTNode location, MethodBinding[] inheritedMethods, int length)3711 public void inheritedMethodsHaveIncompatibleReturnTypes(ASTNode location, MethodBinding[] inheritedMethods, int length) {
3712 StringBuffer methodSignatures = new StringBuffer();
3713 StringBuffer shortSignatures = new StringBuffer();
3714 for (int i = length; --i >= 0;) {
3715 methodSignatures
3716 .append(inheritedMethods[i].declaringClass.readableName())
3717 .append('.')
3718 .append(inheritedMethods[i].readableName());
3719 shortSignatures
3720 .append(inheritedMethods[i].declaringClass.shortReadableName())
3721 .append('.')
3722 .append(inheritedMethods[i].shortReadableName());
3723 if (i != 0){
3724 methodSignatures.append(", "); //$NON-NLS-1$
3725 shortSignatures.append(", "); //$NON-NLS-1$
3726 }
3727 }
3728
3729 this.handle(
3730 // Return type is incompatible with %1
3731 // 9.4.2 - The return type from the method is incompatible with the declaration.
3732 IProblem.InheritedIncompatibleReturnType,
3733 new String[] {methodSignatures.toString()},
3734 new String[] {shortSignatures.toString()},
3735 location.sourceStart,
3736 location.sourceEnd);
3737 }
inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length, boolean[] isOverridden)3738 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length, boolean[] isOverridden) {
3739 StringBuffer methodSignatures = new StringBuffer();
3740 StringBuffer shortSignatures = new StringBuffer();
3741 for (int i = length; --i >= 0;) {
3742 if (isOverridden[i]) continue;
3743 methodSignatures
3744 .append(inheritedMethods[i].declaringClass.readableName())
3745 .append('.')
3746 .append(inheritedMethods[i].readableName());
3747 shortSignatures
3748 .append(inheritedMethods[i].declaringClass.shortReadableName())
3749 .append('.')
3750 .append(inheritedMethods[i].shortReadableName());
3751 if (i != 0){
3752 methodSignatures.append(", "); //$NON-NLS-1$
3753 shortSignatures.append(", "); //$NON-NLS-1$
3754 }
3755 }
3756
3757 this.handle(
3758 // Return type is incompatible with %1
3759 // 9.4.2 - The return type from the method is incompatible with the declaration.
3760 IProblem.InheritedIncompatibleReturnType,
3761 new String[] {methodSignatures.toString()},
3762 new String[] {shortSignatures.toString()},
3763 type.sourceStart(),
3764 type.sourceEnd());
3765 }
inheritedMethodsHaveNameClash(SourceTypeBinding type, MethodBinding oneMethod, MethodBinding twoMethod)3766 public void inheritedMethodsHaveNameClash(SourceTypeBinding type, MethodBinding oneMethod, MethodBinding twoMethod) {
3767 this.handle(
3768 IProblem.MethodNameClash,
3769 new String[] {
3770 new String(oneMethod.selector),
3771 typesAsString(oneMethod.original(), false),
3772 new String(oneMethod.declaringClass.readableName()),
3773 typesAsString(twoMethod.original(), false),
3774 new String(twoMethod.declaringClass.readableName()),
3775 },
3776 new String[] {
3777 new String(oneMethod.selector),
3778 typesAsString(oneMethod.original(), true),
3779 new String(oneMethod.declaringClass.shortReadableName()),
3780 typesAsString(twoMethod.original(), true),
3781 new String(twoMethod.declaringClass.shortReadableName()),
3782 },
3783 type.sourceStart(),
3784 type.sourceEnd());
3785 }
initializerMustCompleteNormally(FieldDeclaration fieldDecl)3786 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
3787 this.handle(
3788 IProblem.InitializerMustCompleteNormally,
3789 NoArgument,
3790 NoArgument,
3791 fieldDecl.sourceStart,
3792 fieldDecl.sourceEnd);
3793 }
innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, Initializer initializer)3794 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, Initializer initializer) {
3795 this.handle(
3796 IProblem.CannotDefineStaticInitializerInLocalType,
3797 new String[] {new String(innerType.readableName())},
3798 new String[] {new String(innerType.shortReadableName())},
3799 initializer.sourceStart,
3800 initializer.sourceStart);
3801 }
interfaceCannotHaveConstructors(ConstructorDeclaration constructor)3802 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
3803 this.handle(
3804 IProblem.InterfaceCannotHaveConstructors,
3805 NoArgument,
3806 NoArgument,
3807 constructor.sourceStart,
3808 constructor.sourceEnd,
3809 constructor,
3810 constructor.compilationResult());
3811 }
interfaceCannotHaveInitializers(char [] sourceName, FieldDeclaration fieldDecl)3812 public void interfaceCannotHaveInitializers(char [] sourceName, FieldDeclaration fieldDecl) {
3813 String[] arguments = new String[] {new String(sourceName)};
3814
3815 this.handle(
3816 IProblem.InterfaceCannotHaveInitializers,
3817 arguments,
3818 arguments,
3819 fieldDecl.sourceStart,
3820 fieldDecl.sourceEnd);
3821 }
invalidAnnotationMemberType(MethodDeclaration methodDecl)3822 public void invalidAnnotationMemberType(MethodDeclaration methodDecl) {
3823 this.handle(
3824 IProblem.InvalidAnnotationMemberType,
3825 new String[] {
3826 new String(methodDecl.binding.returnType.readableName()),
3827 new String(methodDecl.selector),
3828 new String(methodDecl.binding.declaringClass.readableName()),
3829 },
3830 new String[] {
3831 new String(methodDecl.binding.returnType.shortReadableName()),
3832 new String(methodDecl.selector),
3833 new String(methodDecl.binding.declaringClass.shortReadableName()),
3834 },
3835 methodDecl.returnType.sourceStart,
3836 methodDecl.returnType.sourceEnd);
3837
3838 }
invalidBreak(ASTNode location)3839 public void invalidBreak(ASTNode location) {
3840 this.handle(
3841 IProblem.InvalidBreak,
3842 NoArgument,
3843 NoArgument,
3844 location.sourceStart,
3845 location.sourceEnd);
3846 }
invalidConstructor(Statement statement, MethodBinding targetConstructor)3847 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
3848 boolean insideDefaultConstructor =
3849 (this.referenceContext instanceof ConstructorDeclaration)
3850 && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
3851 boolean insideImplicitConstructorCall =
3852 (statement instanceof ExplicitConstructorCall)
3853 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
3854
3855 int sourceStart = statement.sourceStart;
3856 int sourceEnd = statement.sourceEnd;
3857 if (statement instanceof AllocationExpression) {
3858 AllocationExpression allocation = (AllocationExpression)statement;
3859 if (allocation.enumConstant != null) {
3860 sourceStart = allocation.enumConstant.sourceStart;
3861 sourceEnd = allocation.enumConstant.sourceEnd;
3862 }
3863 }
3864
3865 int id = IProblem.UndefinedConstructor; //default...
3866 MethodBinding shownConstructor = targetConstructor;
3867 switch (targetConstructor.problemId()) {
3868 case ProblemReasons.NotFound :
3869 ProblemMethodBinding problemConstructor = (ProblemMethodBinding) targetConstructor;
3870 if (problemConstructor.closestMatch != null) {
3871 if ((problemConstructor.closestMatch.tagBits & TagBits.HasMissingType) != 0) {
3872 missingTypeInConstructor(statement, problemConstructor.closestMatch);
3873 return;
3874 }
3875 }
3876
3877 if (insideDefaultConstructor){
3878 id = IProblem.UndefinedConstructorInDefaultConstructor;
3879 } else if (insideImplicitConstructorCall){
3880 id = IProblem.UndefinedConstructorInImplicitConstructorCall;
3881 } else {
3882 id = IProblem.UndefinedConstructor;
3883 }
3884 break;
3885 case ProblemReasons.NotVisible :
3886 if (insideDefaultConstructor){
3887 id = IProblem.NotVisibleConstructorInDefaultConstructor;
3888 } else if (insideImplicitConstructorCall){
3889 id = IProblem.NotVisibleConstructorInImplicitConstructorCall;
3890 } else {
3891 id = IProblem.NotVisibleConstructor;
3892 }
3893 problemConstructor = (ProblemMethodBinding) targetConstructor;
3894 if (problemConstructor.closestMatch != null) {
3895 shownConstructor = problemConstructor.closestMatch.original();
3896 }
3897 break;
3898 case ProblemReasons.NotAccessible :
3899 id = IProblem.NotAccessibleConstructor;
3900 problemConstructor = (ProblemMethodBinding) targetConstructor;
3901 if (problemConstructor.closestMatch != null) {
3902 shownConstructor = problemConstructor.closestMatch.original();
3903 }
3904 break;
3905 case ProblemReasons.Ambiguous :
3906 if (insideDefaultConstructor){
3907 id = IProblem.AmbiguousConstructorInDefaultConstructor;
3908 } else if (insideImplicitConstructorCall){
3909 id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
3910 } else {
3911 id = IProblem.AmbiguousConstructor;
3912 }
3913 break;
3914 case ProblemReasons.ParameterBoundMismatch :
3915 problemConstructor = (ProblemMethodBinding) targetConstructor;
3916 ParameterizedGenericMethodBinding substitutedConstructor = (ParameterizedGenericMethodBinding) problemConstructor.closestMatch;
3917 shownConstructor = substitutedConstructor.original();
3918 int augmentedLength = problemConstructor.parameters.length;
3919 TypeBinding inferredTypeArgument = problemConstructor.parameters[augmentedLength-2];
3920 TypeVariableBinding typeParameter = (TypeVariableBinding) problemConstructor.parameters[augmentedLength-1];
3921 TypeBinding[] invocationArguments = new TypeBinding[augmentedLength-2]; // remove extra info from the end
3922 System.arraycopy(problemConstructor.parameters, 0, invocationArguments, 0, augmentedLength-2);
3923 this.handle(
3924 IProblem.GenericConstructorTypeArgumentMismatch,
3925 new String[] {
3926 new String(shownConstructor.declaringClass.sourceName()),
3927 typesAsString(shownConstructor, false),
3928 new String(shownConstructor.declaringClass.readableName()),
3929 typesAsString(invocationArguments, false),
3930 new String(inferredTypeArgument.readableName()),
3931 new String(typeParameter.sourceName()),
3932 parameterBoundAsString(typeParameter, false) },
3933 new String[] {
3934 new String(shownConstructor.declaringClass.sourceName()),
3935 typesAsString(shownConstructor, true),
3936 new String(shownConstructor.declaringClass.shortReadableName()),
3937 typesAsString(invocationArguments, true),
3938 new String(inferredTypeArgument.shortReadableName()),
3939 new String(typeParameter.sourceName()),
3940 parameterBoundAsString(typeParameter, true) },
3941 sourceStart,
3942 sourceEnd);
3943 return;
3944
3945 case ProblemReasons.TypeParameterArityMismatch :
3946 problemConstructor = (ProblemMethodBinding) targetConstructor;
3947 shownConstructor = problemConstructor.closestMatch;
3948 if (shownConstructor.typeVariables == Binding.NO_TYPE_VARIABLES) {
3949 this.handle(
3950 IProblem.NonGenericConstructor,
3951 new String[] {
3952 new String(shownConstructor.declaringClass.sourceName()),
3953 typesAsString(shownConstructor, false),
3954 new String(shownConstructor.declaringClass.readableName()),
3955 typesAsString(targetConstructor, false) },
3956 new String[] {
3957 new String(shownConstructor.declaringClass.sourceName()),
3958 typesAsString(shownConstructor, true),
3959 new String(shownConstructor.declaringClass.shortReadableName()),
3960 typesAsString(targetConstructor, true) },
3961 sourceStart,
3962 sourceEnd);
3963 } else {
3964 this.handle(
3965 IProblem.IncorrectArityForParameterizedConstructor ,
3966 new String[] {
3967 new String(shownConstructor.declaringClass.sourceName()),
3968 typesAsString(shownConstructor, false),
3969 new String(shownConstructor.declaringClass.readableName()),
3970 typesAsString(shownConstructor.typeVariables, false),
3971 typesAsString(targetConstructor, false) },
3972 new String[] {
3973 new String(shownConstructor.declaringClass.sourceName()),
3974 typesAsString(shownConstructor, true),
3975 new String(shownConstructor.declaringClass.shortReadableName()),
3976 typesAsString(shownConstructor.typeVariables, true),
3977 typesAsString(targetConstructor, true) },
3978 sourceStart,
3979 sourceEnd);
3980 }
3981 return;
3982 case ProblemReasons.ParameterizedMethodTypeMismatch :
3983 problemConstructor = (ProblemMethodBinding) targetConstructor;
3984 shownConstructor = problemConstructor.closestMatch;
3985 this.handle(
3986 IProblem.ParameterizedConstructorArgumentTypeMismatch,
3987 new String[] {
3988 new String(shownConstructor.declaringClass.sourceName()),
3989 typesAsString(shownConstructor, false),
3990 new String(shownConstructor.declaringClass.readableName()),
3991 typesAsString(((ParameterizedGenericMethodBinding)shownConstructor).typeArguments, false),
3992 typesAsString(targetConstructor, false) },
3993 new String[] {
3994 new String(shownConstructor.declaringClass.sourceName()),
3995 typesAsString(shownConstructor, true),
3996 new String(shownConstructor.declaringClass.shortReadableName()),
3997 typesAsString(((ParameterizedGenericMethodBinding)shownConstructor).typeArguments, true),
3998 typesAsString(targetConstructor, true) },
3999 sourceStart,
4000 sourceEnd);
4001 return;
4002 case ProblemReasons.TypeArgumentsForRawGenericMethod :
4003 problemConstructor = (ProblemMethodBinding) targetConstructor;
4004 shownConstructor = problemConstructor.closestMatch;
4005 this.handle(
4006 IProblem.TypeArgumentsForRawGenericConstructor,
4007 new String[] {
4008 new String(shownConstructor.declaringClass.sourceName()),
4009 typesAsString(shownConstructor, false),
4010 new String(shownConstructor.declaringClass.readableName()),
4011 typesAsString(targetConstructor, false) },
4012 new String[] {
4013 new String(shownConstructor.declaringClass.sourceName()),
4014 typesAsString(shownConstructor, true),
4015 new String(shownConstructor.declaringClass.shortReadableName()),
4016 typesAsString(targetConstructor, true) },
4017 sourceStart,
4018 sourceEnd);
4019 return;
4020 case ProblemReasons.VarargsElementTypeNotVisible :
4021 problemConstructor = (ProblemMethodBinding) targetConstructor;
4022 shownConstructor = problemConstructor.closestMatch;
4023 TypeBinding varargsElementType = shownConstructor.parameters[shownConstructor.parameters.length - 1].leafComponentType();
4024 this.handle(
4025 IProblem.VarargsElementTypeNotVisibleForConstructor,
4026 new String[] {
4027 new String(shownConstructor.declaringClass.sourceName()),
4028 typesAsString(shownConstructor, false),
4029 new String(shownConstructor.declaringClass.readableName()),
4030 new String(varargsElementType.readableName())
4031 },
4032 new String[] {
4033 new String(shownConstructor.declaringClass.sourceName()),
4034 typesAsString(shownConstructor, true),
4035 new String(shownConstructor.declaringClass.shortReadableName()),
4036 new String(varargsElementType.shortReadableName())
4037 },
4038 sourceStart,
4039 sourceEnd);
4040 return;
4041 case ProblemReasons.InferredApplicableMethodInapplicable:
4042 case ProblemReasons.InvocationTypeInferenceFailure:
4043 // FIXME(stephan): construct suitable message (https://bugs.eclipse.org/404675)
4044 problemConstructor = (ProblemMethodBinding) targetConstructor;
4045 shownConstructor = problemConstructor.closestMatch;
4046 this.handle(
4047 IProblem.TypeMismatch,
4048 new String[] {
4049 String.valueOf(shownConstructor.returnType.readableName()),
4050 (problemConstructor.returnType != null ? String.valueOf(problemConstructor.returnType.readableName()) : "<unknown>")}, //$NON-NLS-1$
4051 new String[] {
4052 String.valueOf(shownConstructor.returnType.shortReadableName()),
4053 (problemConstructor.returnType != null ? String.valueOf(problemConstructor.returnType.shortReadableName()) : "<unknown>")}, //$NON-NLS-1$
4054 statement.sourceStart,
4055 statement.sourceEnd);
4056 return;
4057 case ProblemReasons.ContradictoryNullAnnotations:
4058 problemConstructor = (ProblemMethodBinding) targetConstructor;
4059 contradictoryNullAnnotationsInferred(problemConstructor.closestMatch, statement);
4060 return;
4061 case ProblemReasons.NoError : // 0
4062 default :
4063 needImplementation(statement); // want to fail to see why we were here...
4064 break;
4065 }
4066
4067 this.handle(
4068 id,
4069 new String[] {new String(targetConstructor.declaringClass.readableName()), typesAsString(shownConstructor, false)},
4070 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), typesAsString(shownConstructor, true)},
4071 sourceStart,
4072 sourceEnd);
4073 }
invalidContinue(ASTNode location)4074 public void invalidContinue(ASTNode location) {
4075 this.handle(
4076 IProblem.InvalidContinue,
4077 NoArgument,
4078 NoArgument,
4079 location.sourceStart,
4080 location.sourceEnd);
4081 }
invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType)4082 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
4083
4084 if (enclosingType.isAnonymousType()) enclosingType = enclosingType.superclass();
4085 if (enclosingType.sourceName != null && enclosingType.sourceName.length == 0) return;
4086
4087 int flag = IProblem.UndefinedType; // default
4088 switch (type.problemId()) {
4089 case ProblemReasons.NotFound : // 1
4090 flag = IProblem.UndefinedType;
4091 break;
4092 case ProblemReasons.NotVisible : // 2
4093 flag = IProblem.NotVisibleType;
4094 break;
4095 case ProblemReasons.Ambiguous : // 3
4096 flag = IProblem.AmbiguousType;
4097 break;
4098 case ProblemReasons.InternalNameProvided :
4099 flag = IProblem.InternalTypeNameProvided;
4100 break;
4101 case ProblemReasons.NoError : // 0
4102 default :
4103 needImplementation(expression); // want to fail to see why we were here...
4104 break;
4105 }
4106
4107 this.handle(
4108 flag,
4109 new String[] {new String(enclosingType.readableName()) + "." + new String(type.readableName())}, //$NON-NLS-1$
4110 new String[] {new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName())}, //$NON-NLS-1$
4111 expression.sourceStart,
4112 expression.sourceEnd);
4113 }
invalidExplicitConstructorCall(ASTNode location)4114 public void invalidExplicitConstructorCall(ASTNode location) {
4115
4116 this.handle(
4117 IProblem.InvalidExplicitConstructorCall,
4118 NoArgument,
4119 NoArgument,
4120 location.sourceStart,
4121 location.sourceEnd);
4122 }
invalidExpressionAsStatement(Expression expression)4123 public void invalidExpressionAsStatement(Expression expression){
4124 this.handle(
4125 IProblem.InvalidExpressionAsStatement,
4126 NoArgument,
4127 NoArgument,
4128 expression.sourceStart,
4129 expression.sourceEnd);
4130 }
invalidField(FieldReference fieldRef, TypeBinding searchedType)4131 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
4132 if(isRecoveredName(fieldRef.token)) return;
4133
4134 int id = IProblem.UndefinedField;
4135 FieldBinding field = fieldRef.binding;
4136 switch (field.problemId()) {
4137 case ProblemReasons.NotFound :
4138 if ((searchedType.tagBits & TagBits.HasMissingType) != 0) {
4139 this.handle(
4140 IProblem.UndefinedType,
4141 new String[] {new String(searchedType.leafComponentType().readableName())},
4142 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
4143 fieldRef.receiver.sourceStart,
4144 fieldRef.receiver.sourceEnd);
4145 return;
4146 }
4147 id = IProblem.UndefinedField;
4148 /* also need to check that the searchedType is the receiver type
4149 if (searchedType.isHierarchyInconsistent())
4150 severity = SecondaryError;
4151 */
4152 break;
4153 case ProblemReasons.NotVisible :
4154 case ProblemReasons.NotAccessible :
4155 this.handle(
4156 (field.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleField : IProblem.NotAccessibleField,
4157 new String[] {new String(fieldRef.token), new String(field.declaringClass.readableName())},
4158 new String[] {new String(fieldRef.token), new String(field.declaringClass.shortReadableName())},
4159 nodeSourceStart(field, fieldRef),
4160 nodeSourceEnd(field, fieldRef));
4161 return;
4162 case ProblemReasons.Ambiguous :
4163 id = IProblem.AmbiguousField;
4164 break;
4165 case ProblemReasons.NoProperEnclosingInstance:
4166 noSuchEnclosingInstance(fieldRef.actualReceiverType, fieldRef.receiver, false);
4167 return;
4168 case ProblemReasons.NonStaticReferenceInStaticContext :
4169 id = IProblem.NonStaticFieldFromStaticInvocation;
4170 break;
4171 case ProblemReasons.NonStaticReferenceInConstructorInvocation :
4172 id = IProblem.InstanceFieldDuringConstructorInvocation;
4173 break;
4174 case ProblemReasons.InheritedNameHidesEnclosingName :
4175 id = IProblem.InheritedFieldHidesEnclosingName;
4176 break;
4177 case ProblemReasons.ReceiverTypeNotVisible :
4178 this.handle(
4179 IProblem.NotVisibleType, // cannot occur in javadoc comments
4180 new String[] {new String(searchedType.leafComponentType().readableName())},
4181 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
4182 fieldRef.receiver.sourceStart,
4183 fieldRef.receiver.sourceEnd);
4184 return;
4185
4186 case ProblemReasons.NoError : // 0
4187 default :
4188 needImplementation(fieldRef); // want to fail to see why we were here...
4189 break;
4190 }
4191
4192 String[] arguments = new String[] {new String(field.readableName())};
4193 this.handle(
4194 id,
4195 arguments,
4196 arguments,
4197 nodeSourceStart(field, fieldRef),
4198 nodeSourceEnd(field, fieldRef));
4199 }
invalidField(NameReference nameRef, FieldBinding field)4200 public void invalidField(NameReference nameRef, FieldBinding field) {
4201 if (nameRef instanceof QualifiedNameReference) {
4202 QualifiedNameReference ref = (QualifiedNameReference) nameRef;
4203 if (isRecoveredName(ref.tokens)) return;
4204 } else {
4205 SingleNameReference ref = (SingleNameReference) nameRef;
4206 if (isRecoveredName(ref.token)) return;
4207 }
4208 int id = IProblem.UndefinedField;
4209 switch (field.problemId()) {
4210 case ProblemReasons.NotFound :
4211 TypeBinding declaringClass = field.declaringClass;
4212 if (declaringClass != null && (declaringClass.tagBits & TagBits.HasMissingType) != 0) {
4213 this.handle(
4214 IProblem.UndefinedType,
4215 new String[] {new String(field.declaringClass.readableName())},
4216 new String[] {new String(field.declaringClass.shortReadableName())},
4217 nameRef.sourceStart,
4218 nameRef.sourceEnd);
4219 return;
4220 }
4221 String[] arguments = new String[] {new String(field.readableName())};
4222 this.handle(
4223 id,
4224 arguments,
4225 arguments,
4226 nodeSourceStart(field, nameRef),
4227 nodeSourceEnd(field, nameRef));
4228 return;
4229 case ProblemReasons.NotVisible :
4230 case ProblemReasons.NotAccessible :
4231 char[] name = field.readableName();
4232 name = CharOperation.lastSegment(name, '.');
4233 this.handle(
4234 (field.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleField : IProblem.NotAccessibleField,
4235 new String[] {new String(name), new String(field.declaringClass.readableName())},
4236 new String[] {new String(name), new String(field.declaringClass.shortReadableName())},
4237 nodeSourceStart(field, nameRef),
4238 nodeSourceEnd(field, nameRef));
4239 return;
4240 case ProblemReasons.Ambiguous :
4241 id = IProblem.AmbiguousField;
4242 break;
4243 case ProblemReasons.NonStaticReferenceInStaticContext :
4244 id = IProblem.NonStaticFieldFromStaticInvocation;
4245 break;
4246 case ProblemReasons.NonStaticReferenceInConstructorInvocation :
4247 id = IProblem.InstanceFieldDuringConstructorInvocation;
4248 break;
4249 case ProblemReasons.InheritedNameHidesEnclosingName :
4250 id = IProblem.InheritedFieldHidesEnclosingName;
4251 break;
4252 case ProblemReasons.ReceiverTypeNotVisible :
4253 this.handle(
4254 IProblem.NotVisibleType,
4255 new String[] {new String(field.declaringClass.readableName())},
4256 new String[] {new String(field.declaringClass.shortReadableName())},
4257 nameRef.sourceStart,
4258 nameRef.sourceEnd);
4259 return;
4260 case ProblemReasons.NoError : // 0
4261 default :
4262 needImplementation(nameRef); // want to fail to see why we were here...
4263 break;
4264 }
4265 String[] arguments = new String[] {new String(field.readableName())};
4266 this.handle(
4267 id,
4268 arguments,
4269 arguments,
4270 nameRef.sourceStart,
4271 nameRef.sourceEnd);
4272 }
invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType)4273 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
4274 //the resolution of the index-th field of qname failed
4275 //qname.otherBindings[index] is the binding that has produced the error
4276
4277 //The different targetted errors should be :
4278 //UndefinedField
4279 //NotVisibleField
4280 //AmbiguousField
4281
4282 if (isRecoveredName(nameRef.tokens)) return;
4283
4284 if (searchedType.isBaseType()) {
4285 this.handle(
4286 IProblem.NoFieldOnBaseType,
4287 new String[] {
4288 new String(searchedType.readableName()),
4289 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
4290 new String(nameRef.tokens[index])},
4291 new String[] {
4292 new String(searchedType.sourceName()),
4293 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)),
4294 new String(nameRef.tokens[index])},
4295 nameRef.sourceStart,
4296 (int) nameRef.sourcePositions[index]);
4297 return;
4298 }
4299
4300 int id = IProblem.UndefinedField;
4301 switch (field.problemId()) {
4302 case ProblemReasons.NotFound :
4303 if ((searchedType.tagBits & TagBits.HasMissingType) != 0) {
4304 this.handle(
4305 IProblem.UndefinedType,
4306 new String[] {new String(searchedType.leafComponentType().readableName())},
4307 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
4308 nameRef.sourceStart,
4309 (int) nameRef.sourcePositions[index-1]);
4310 return;
4311 }
4312 String fieldName = new String(nameRef.tokens[index]);
4313 String[] arguments = new String[] {fieldName };
4314 this.handle(
4315 id,
4316 arguments,
4317 arguments,
4318 nodeSourceStart(field, nameRef),
4319 nodeSourceEnd(field, nameRef));
4320 return;
4321 case ProblemReasons.NotVisible :
4322 case ProblemReasons.NotAccessible :
4323 fieldName = new String(nameRef.tokens[index]);
4324 this.handle(
4325 (field.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleField : IProblem.NotAccessibleField,
4326 new String[] {fieldName, new String(field.declaringClass.readableName())},
4327 new String[] {fieldName, new String(field.declaringClass.shortReadableName())},
4328 nodeSourceStart(field, nameRef),
4329 nodeSourceEnd(field, nameRef));
4330 return;
4331 case ProblemReasons.Ambiguous :
4332 id = IProblem.AmbiguousField;
4333 break;
4334 case ProblemReasons.NonStaticReferenceInStaticContext :
4335 id = IProblem.NonStaticFieldFromStaticInvocation;
4336 break;
4337 case ProblemReasons.NonStaticReferenceInConstructorInvocation :
4338 id = IProblem.InstanceFieldDuringConstructorInvocation;
4339 break;
4340 case ProblemReasons.InheritedNameHidesEnclosingName :
4341 id = IProblem.InheritedFieldHidesEnclosingName;
4342 break;
4343 case ProblemReasons.ReceiverTypeNotVisible :
4344 this.handle(
4345 IProblem.NotVisibleType,
4346 new String[] {new String(searchedType.leafComponentType().readableName())},
4347 new String[] {new String(searchedType.leafComponentType().shortReadableName())},
4348 nameRef.sourceStart,
4349 (int) nameRef.sourcePositions[index-1]);
4350 return;
4351 case ProblemReasons.NoError : // 0
4352 default :
4353 needImplementation(nameRef); // want to fail to see why we were here...
4354 break;
4355 }
4356 String[] arguments = new String[] {CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1))};
4357 this.handle(
4358 id,
4359 arguments,
4360 arguments,
4361 nameRef.sourceStart,
4362 (int) nameRef.sourcePositions[index]);
4363 }
4364
invalidFileNameForPackageAnnotations(Annotation annotation)4365 public void invalidFileNameForPackageAnnotations(Annotation annotation) {
4366 this.handle(
4367 IProblem.InvalidFileNameForPackageAnnotations,
4368 NoArgument,
4369 NoArgument,
4370 annotation.sourceStart,
4371 annotation.sourceEnd);
4372 }
4373
nonStaticOrAlienTypeReceiver(MessageSend messageSend, MethodBinding method)4374 public void nonStaticOrAlienTypeReceiver(MessageSend messageSend, MethodBinding method) {
4375 this.handle(
4376 IProblem.NonStaticOrAlienTypeReceiver,
4377 new String[] {
4378 new String(method.declaringClass.readableName()),
4379 new String(method.selector),
4380 },
4381 new String[] {
4382 new String(method.declaringClass.shortReadableName()),
4383 new String(method.selector),
4384 },
4385 (int) (messageSend.nameSourcePosition >>> 32),
4386 (int) messageSend.nameSourcePosition);
4387 }
invalidMethod(MessageSend messageSend, MethodBinding method, Scope scope)4388 public void invalidMethod(MessageSend messageSend, MethodBinding method, Scope scope) {
4389 if (isRecoveredName(messageSend.selector)) return;
4390
4391 int id = IProblem.UndefinedMethod; //default...
4392 MethodBinding shownMethod = method;
4393 switch (method.problemId()) {
4394 case ProblemReasons.ErrorAlreadyReported:
4395 return;
4396 case ProblemReasons.NoSuchMethodOnArray :
4397 return; // secondary error.
4398 case ProblemReasons.NotFound :
4399 if ((method.declaringClass.tagBits & TagBits.HasMissingType) != 0) {
4400 this.handle(
4401 IProblem.UndefinedType,
4402 new String[] {new String(method.declaringClass.readableName())},
4403 new String[] {new String(method.declaringClass.shortReadableName())},
4404 messageSend.receiver.sourceStart,
4405 messageSend.receiver.sourceEnd);
4406 return;
4407 }
4408 id = IProblem.UndefinedMethod;
4409 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
4410 if (problemMethod.closestMatch != null) {
4411 shownMethod = problemMethod.closestMatch;
4412 if ((shownMethod.tagBits & TagBits.HasMissingType) != 0) {
4413 missingTypeInMethod(messageSend, shownMethod);
4414 return;
4415 }
4416 String closestParameterTypeNames = typesAsString(shownMethod, false);
4417 String parameterTypeNames = typesAsString(problemMethod.parameters, false);
4418 String closestParameterTypeShortNames = typesAsString(shownMethod, true);
4419 String parameterTypeShortNames = typesAsString(problemMethod.parameters, true);
4420 if (closestParameterTypeNames.equals(parameterTypeNames)) {
4421 // include null annotations, maybe they show the difference:
4422 closestParameterTypeNames = typesAsString(shownMethod, false, true);
4423 parameterTypeNames = typesAsString(problemMethod.parameters, false, true);
4424 closestParameterTypeShortNames = typesAsString(shownMethod, true, true);
4425 parameterTypeShortNames = typesAsString(problemMethod.parameters, true, true);
4426 }
4427 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
4428 closestParameterTypeShortNames = closestParameterTypeNames;
4429 parameterTypeShortNames = parameterTypeNames;
4430 }
4431 this.handle(
4432 IProblem.ParameterMismatch,
4433 new String[] {
4434 new String(shownMethod.declaringClass.readableName()),
4435 new String(shownMethod.selector),
4436 closestParameterTypeNames,
4437 parameterTypeNames
4438 },
4439 new String[] {
4440 new String(shownMethod.declaringClass.shortReadableName()),
4441 new String(shownMethod.selector),
4442 closestParameterTypeShortNames,
4443 parameterTypeShortNames
4444 },
4445 (int) (messageSend.nameSourcePosition >>> 32),
4446 (int) messageSend.nameSourcePosition);
4447 return;
4448 }
4449 break;
4450 case ProblemReasons.NotVisible :
4451 case ProblemReasons.NotAccessible :
4452 id = (method.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleMethod : IProblem.NotAccessibleMethod;
4453 problemMethod = (ProblemMethodBinding) method;
4454 if (problemMethod.closestMatch != null) {
4455 shownMethod = problemMethod.closestMatch.original();
4456 }
4457 break;
4458 case ProblemReasons.Ambiguous :
4459 id = IProblem.AmbiguousMethod;
4460 break;
4461 case ProblemReasons.InheritedNameHidesEnclosingName :
4462 id = IProblem.InheritedMethodHidesEnclosingName;
4463 break;
4464 case ProblemReasons.NonStaticReferenceInConstructorInvocation :
4465 id = IProblem.InstanceMethodDuringConstructorInvocation;
4466 break;
4467 case ProblemReasons.NonStaticReferenceInStaticContext :
4468 id = IProblem.StaticMethodRequested;
4469 break;
4470 case ProblemReasons.NonStaticOrAlienTypeReceiver:
4471 nonStaticOrAlienTypeReceiver(messageSend, method);
4472 return;
4473 case ProblemReasons.InterfaceMethodInvocationNotBelow18:
4474 this.handle(
4475 IProblem.InterfaceStaticMethodInvocationNotBelow18,
4476 new String[] {
4477 new String(method.declaringClass.readableName()),
4478 new String(method.selector),
4479 },
4480 new String[] {
4481 new String(method.declaringClass.shortReadableName()),
4482 new String(method.selector),
4483 },
4484 (int) (messageSend.nameSourcePosition >>> 32),
4485 (int) messageSend.nameSourcePosition);
4486 return;
4487 case ProblemReasons.ReceiverTypeNotVisible :
4488 this.handle(
4489 IProblem.NotVisibleType, // cannot occur in javadoc comments
4490 new String[] {new String(method.declaringClass.readableName())},
4491 new String[] {new String(method.declaringClass.shortReadableName())},
4492 messageSend.receiver.sourceStart,
4493 messageSend.receiver.sourceEnd);
4494 return;
4495 case ProblemReasons.ParameterBoundMismatch :
4496 problemMethod = (ProblemMethodBinding) method;
4497 ParameterizedGenericMethodBinding substitutedMethod = (ParameterizedGenericMethodBinding) problemMethod.closestMatch;
4498 shownMethod = substitutedMethod.original();
4499 int augmentedLength = problemMethod.parameters.length;
4500 TypeBinding inferredTypeArgument = problemMethod.parameters[augmentedLength-2];
4501 TypeVariableBinding typeParameter = (TypeVariableBinding) problemMethod.parameters[augmentedLength-1];
4502 TypeBinding[] invocationArguments = new TypeBinding[augmentedLength-2]; // remove extra info from the end
4503 System.arraycopy(problemMethod.parameters, 0, invocationArguments, 0, augmentedLength-2);
4504 this.handle(
4505 IProblem.GenericMethodTypeArgumentMismatch,
4506 new String[] {
4507 new String(shownMethod.selector),
4508 typesAsString(shownMethod, false),
4509 new String(shownMethod.declaringClass.readableName()),
4510 typesAsString(invocationArguments, false),
4511 new String(inferredTypeArgument.readableName()),
4512 new String(typeParameter.sourceName()),
4513 parameterBoundAsString(typeParameter, false) },
4514 new String[] {
4515 new String(shownMethod.selector),
4516 typesAsString(shownMethod, true),
4517 new String(shownMethod.declaringClass.shortReadableName()),
4518 typesAsString(invocationArguments, true),
4519 new String(inferredTypeArgument.shortReadableName()),
4520 new String(typeParameter.sourceName()),
4521 parameterBoundAsString(typeParameter, true) },
4522 (int) (messageSend.nameSourcePosition >>> 32),
4523 (int) messageSend.nameSourcePosition);
4524 return;
4525 case ProblemReasons.TypeParameterArityMismatch :
4526 problemMethod = (ProblemMethodBinding) method;
4527 shownMethod = problemMethod.closestMatch;
4528 if (shownMethod.typeVariables == Binding.NO_TYPE_VARIABLES) {
4529 this.handle(
4530 IProblem.NonGenericMethod ,
4531 new String[] {
4532 new String(shownMethod.selector),
4533 typesAsString(shownMethod, false),
4534 new String(shownMethod.declaringClass.readableName()),
4535 typesAsString(method, false) },
4536 new String[] {
4537 new String(shownMethod.selector),
4538 typesAsString(shownMethod, true),
4539 new String(shownMethod.declaringClass.shortReadableName()),
4540 typesAsString(method, true) },
4541 (int) (messageSend.nameSourcePosition >>> 32),
4542 (int) messageSend.nameSourcePosition);
4543 } else {
4544 this.handle(
4545 IProblem.IncorrectArityForParameterizedMethod ,
4546 new String[] {
4547 new String(shownMethod.selector),
4548 typesAsString(shownMethod, false),
4549 new String(shownMethod.declaringClass.readableName()),
4550 typesAsString(shownMethod.typeVariables, false),
4551 typesAsString(method, false) },
4552 new String[] {
4553 new String(shownMethod.selector),
4554 typesAsString(shownMethod, true),
4555 new String(shownMethod.declaringClass.shortReadableName()),
4556 typesAsString(shownMethod.typeVariables, true),
4557 typesAsString(method, true) },
4558 (int) (messageSend.nameSourcePosition >>> 32),
4559 (int) messageSend.nameSourcePosition);
4560 }
4561 return;
4562 case ProblemReasons.ParameterizedMethodTypeMismatch :
4563 problemMethod = (ProblemMethodBinding) method;
4564 shownMethod = problemMethod.closestMatch;
4565 this.handle(
4566 IProblem.ParameterizedMethodArgumentTypeMismatch,
4567 new String[] {
4568 new String(shownMethod.selector),
4569 typesAsString(shownMethod, false),
4570 new String(shownMethod.declaringClass.readableName()),
4571 typesAsString(((ParameterizedGenericMethodBinding)shownMethod).typeArguments, false),
4572 typesAsString(method, false) },
4573 new String[] {
4574 new String(shownMethod.selector),
4575 typesAsString(shownMethod, true),
4576 new String(shownMethod.declaringClass.shortReadableName()),
4577 typesAsString(((ParameterizedGenericMethodBinding)shownMethod).typeArguments, true),
4578 typesAsString(method, true) },
4579 (int) (messageSend.nameSourcePosition >>> 32),
4580 (int) messageSend.nameSourcePosition);
4581 return;
4582 case ProblemReasons.TypeArgumentsForRawGenericMethod :
4583 problemMethod = (ProblemMethodBinding) method;
4584 shownMethod = problemMethod.closestMatch;
4585 this.handle(
4586 IProblem.TypeArgumentsForRawGenericMethod ,
4587 new String[] {
4588 new String(shownMethod.selector),
4589 typesAsString(shownMethod, false),
4590 new String(shownMethod.declaringClass.readableName()),
4591 typesAsString(method, false) },
4592 new String[] {
4593 new String(shownMethod.selector),
4594 typesAsString(shownMethod, true),
4595 new String(shownMethod.declaringClass.shortReadableName()),
4596 typesAsString(method, true) },
4597 (int) (messageSend.nameSourcePosition >>> 32),
4598 (int) messageSend.nameSourcePosition);
4599 return;
4600 case ProblemReasons.InferredApplicableMethodInapplicable:
4601 case ProblemReasons.InvocationTypeInferenceFailure:
4602 problemMethod = (ProblemMethodBinding) method;
4603 shownMethod = problemMethod.closestMatch;
4604 if (problemMethod.returnType == shownMethod.returnType) { //$IDENTITY-COMPARISON$
4605 if (messageSend.expressionContext == ExpressionContext.VANILLA_CONTEXT) {
4606 TypeVariableBinding[] typeVariables = method.shallowOriginal().typeVariables;
4607 String typeArguments = typesAsString(typeVariables, false);
4608 this.handle(IProblem.CannotInferInvocationType,
4609 new String[] { typeArguments, String.valueOf(shownMethod.original().readableName()) },
4610 new String[] { typeArguments, String.valueOf(shownMethod.original().shortReadableName()) },
4611 messageSend.sourceStart,
4612 messageSend.sourceEnd);
4613 } else {
4614 // FIXME(stephan): turn into an exception once we are sure about this
4615 this.handle(IProblem.GenericInferenceError,
4616 new String[] { "Unknown error at invocation of "+String.valueOf(shownMethod.readableName())}, //$NON-NLS-1$
4617 new String[] { "Unknown error at invocation of "+String.valueOf(shownMethod.shortReadableName())}, //$NON-NLS-1$
4618 messageSend.sourceStart,
4619 messageSend.sourceEnd);
4620 }
4621 return;
4622 }
4623 TypeBinding shownMethodReturnType = shownMethod.returnType.capture(scope, messageSend.sourceStart, messageSend.sourceEnd);
4624 this.handle(
4625 IProblem.TypeMismatch,
4626 new String[] {
4627 String.valueOf(shownMethodReturnType.readableName()),
4628 (problemMethod.returnType != null ? String.valueOf(problemMethod.returnType.readableName()) : "<unknown>")}, //$NON-NLS-1$
4629 new String[] {
4630 String.valueOf(shownMethodReturnType.shortReadableName()),
4631 (problemMethod.returnType != null ? String.valueOf(problemMethod.returnType.shortReadableName()) : "<unknown>")}, //$NON-NLS-1$
4632 messageSend.sourceStart,
4633 messageSend.sourceEnd);
4634 return;
4635 case ProblemReasons.VarargsElementTypeNotVisible: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346042
4636 problemMethod = (ProblemMethodBinding) method;
4637 if (problemMethod.closestMatch != null) {
4638 shownMethod = problemMethod.closestMatch.original();
4639 }
4640 TypeBinding varargsElementType = shownMethod.parameters[shownMethod.parameters.length - 1].leafComponentType();
4641 this.handle(
4642 IProblem.VarargsElementTypeNotVisible,
4643 new String[] {
4644 new String(shownMethod.selector),
4645 typesAsString(shownMethod, false),
4646 new String(shownMethod.declaringClass.readableName()),
4647 new String(varargsElementType.readableName())
4648 },
4649 new String[] {
4650 new String(shownMethod.selector),
4651 typesAsString(shownMethod, true),
4652 new String(shownMethod.declaringClass.shortReadableName()),
4653 new String(varargsElementType.shortReadableName())
4654 },
4655 (int) (messageSend.nameSourcePosition >>> 32),
4656 (int) messageSend.nameSourcePosition);
4657 return;
4658 case ProblemReasons.ApplicableMethodOverriddenByInapplicable:
4659 problemMethod = (ProblemMethodBinding) method;
4660 if (problemMethod.closestMatch != null) {
4661 shownMethod = problemMethod.closestMatch.original();
4662 }
4663 this.handle(
4664 IProblem.ApplicableMethodOverriddenByInapplicable,
4665 new String[] {
4666 new String(shownMethod.selector),
4667 typesAsString(shownMethod, false),
4668 new String(shownMethod.declaringClass.readableName()),
4669 },
4670 new String[] {
4671 new String(shownMethod.selector),
4672 typesAsString(shownMethod, true),
4673 new String(shownMethod.declaringClass.shortReadableName()),
4674 },
4675 (int) (messageSend.nameSourcePosition >>> 32),
4676 (int) messageSend.nameSourcePosition);
4677 return;
4678 case ProblemReasons.ContradictoryNullAnnotations:
4679 problemMethod = (ProblemMethodBinding) method;
4680 contradictoryNullAnnotationsInferred(problemMethod.closestMatch, messageSend);
4681 return;
4682 case ProblemReasons.NoError : // 0
4683 default :
4684 needImplementation(messageSend); // want to fail to see why we were here...
4685 break;
4686 }
4687 this.handle(
4688 id,
4689 new String[] {
4690 new String(method.declaringClass.readableName()),
4691 new String(shownMethod.selector), typesAsString(shownMethod, false)},
4692 new String[] {
4693 new String(method.declaringClass.shortReadableName()),
4694 new String(shownMethod.selector), typesAsString(shownMethod, true)},
4695 (int) (messageSend.nameSourcePosition >>> 32),
4696 (int) messageSend.nameSourcePosition);
4697 }
invalidNullToSynchronize(Expression expression)4698 public void invalidNullToSynchronize(Expression expression) {
4699 this.handle(
4700 IProblem.InvalidNullToSynchronized,
4701 NoArgument,
4702 NoArgument,
4703 expression.sourceStart,
4704 expression.sourceEnd);
4705 }
invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType)4706 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
4707 String leftName = new String(leftType.readableName());
4708 String rightName = new String(rightType.readableName());
4709 String leftShortName = new String(leftType.shortReadableName());
4710 String rightShortName = new String(rightType.shortReadableName());
4711 if (leftShortName.equals(rightShortName)){
4712 leftShortName = leftName;
4713 rightShortName = rightName;
4714 }
4715 this.handle(
4716 IProblem.InvalidOperator,
4717 new String[] {
4718 expression.operatorToString(),
4719 leftName + ", " + rightName}, //$NON-NLS-1$
4720 new String[] {
4721 expression.operatorToString(),
4722 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
4723 expression.sourceStart,
4724 expression.sourceEnd);
4725 }
invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType)4726 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
4727 String leftName = new String(leftType.readableName());
4728 String rightName = new String(rightType.readableName());
4729 String leftShortName = new String(leftType.shortReadableName());
4730 String rightShortName = new String(rightType.shortReadableName());
4731 if (leftShortName.equals(rightShortName)){
4732 leftShortName = leftName;
4733 rightShortName = rightName;
4734 }
4735 this.handle(
4736 IProblem.InvalidOperator,
4737 new String[] {
4738 assign.operatorToString(),
4739 leftName + ", " + rightName}, //$NON-NLS-1$
4740 new String[] {
4741 assign.operatorToString(),
4742 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
4743 assign.sourceStart,
4744 assign.sourceEnd);
4745 }
invalidOperator(UnaryExpression expression, TypeBinding type)4746 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
4747 this.handle(
4748 IProblem.InvalidOperator,
4749 new String[] {expression.operatorToString(), new String(type.readableName())},
4750 new String[] {expression.operatorToString(), new String(type.shortReadableName())},
4751 expression.sourceStart,
4752 expression.sourceEnd);
4753 }
invalidParameterizedExceptionType(TypeBinding exceptionType, ASTNode location)4754 public void invalidParameterizedExceptionType(TypeBinding exceptionType, ASTNode location) {
4755 this.handle(
4756 IProblem.InvalidParameterizedExceptionType,
4757 new String[] {new String(exceptionType.readableName())},
4758 new String[] {new String(exceptionType.shortReadableName())},
4759 location.sourceStart,
4760 location.sourceEnd);
4761 }
invalidParenthesizedExpression(ASTNode reference)4762 public void invalidParenthesizedExpression(ASTNode reference) {
4763 this.handle(
4764 IProblem.InvalidParenthesizedExpression,
4765 NoArgument,
4766 NoArgument,
4767 reference.sourceStart,
4768 reference.sourceEnd);
4769 }
invalidType(ASTNode location, TypeBinding type)4770 public void invalidType(ASTNode location, TypeBinding type) {
4771 if (type instanceof ReferenceBinding) {
4772 if (isRecoveredName(((ReferenceBinding)type).compoundName)) return;
4773 }
4774 else if (type instanceof ArrayBinding) {
4775 TypeBinding leafType = ((ArrayBinding)type).leafComponentType;
4776 if (leafType instanceof ReferenceBinding) {
4777 if (isRecoveredName(((ReferenceBinding)leafType).compoundName)) return;
4778 }
4779 }
4780
4781 if (type.isParameterizedType()) {
4782 List missingTypes = type.collectMissingTypes(null);
4783 if (missingTypes != null) {
4784 ReferenceContext savedContext = this.referenceContext;
4785 for (Iterator iterator = missingTypes.iterator(); iterator.hasNext(); ) {
4786 try {
4787 invalidType(location, (TypeBinding) iterator.next());
4788 } finally {
4789 this.referenceContext = savedContext;
4790 }
4791 }
4792 return;
4793 }
4794 }
4795 int id = IProblem.UndefinedType; // default
4796 switch (type.problemId()) {
4797 case ProblemReasons.NotFound :
4798 id = IProblem.UndefinedType;
4799 break;
4800 case ProblemReasons.NotVisible :
4801 id = IProblem.NotVisibleType;
4802 break;
4803 case ProblemReasons.NotAccessible :
4804 id = IProblem.NotAccessibleType;
4805 break;
4806 case ProblemReasons.Ambiguous :
4807 id = IProblem.AmbiguousType;
4808 break;
4809 case ProblemReasons.InternalNameProvided :
4810 id = IProblem.InternalTypeNameProvided;
4811 break;
4812 case ProblemReasons.InheritedNameHidesEnclosingName :
4813 id = IProblem.InheritedTypeHidesEnclosingName;
4814 break;
4815 case ProblemReasons.NonStaticReferenceInStaticContext :
4816 id = IProblem.NonStaticTypeFromStaticInvocation;
4817 break;
4818 case ProblemReasons.IllegalSuperTypeVariable :
4819 id = IProblem.IllegalTypeVariableSuperReference;
4820 break;
4821 case ProblemReasons.NoError : // 0
4822 default :
4823 needImplementation(location); // want to fail to see why we were here...
4824 break;
4825 }
4826
4827 int end = location.sourceEnd;
4828 if (location instanceof QualifiedNameReference) {
4829 QualifiedNameReference ref = (QualifiedNameReference) location;
4830 if (isRecoveredName(ref.tokens)) return;
4831 if (ref.indexOfFirstFieldBinding >= 1)
4832 end = (int) ref.sourcePositions[ref.indexOfFirstFieldBinding - 1];
4833 } else if (location instanceof ParameterizedQualifiedTypeReference) {
4834 // must be before instanceof ArrayQualifiedTypeReference
4835 ParameterizedQualifiedTypeReference ref = (ParameterizedQualifiedTypeReference) location;
4836 if (isRecoveredName(ref.tokens)) return;
4837 if (type instanceof ReferenceBinding) {
4838 char[][] name = ((ReferenceBinding) type).compoundName;
4839 end = (int) ref.sourcePositions[name.length - 1];
4840 }
4841 } else if (location instanceof ArrayQualifiedTypeReference) {
4842 ArrayQualifiedTypeReference arrayQualifiedTypeReference = (ArrayQualifiedTypeReference) location;
4843 if (isRecoveredName(arrayQualifiedTypeReference.tokens)) return;
4844 TypeBinding leafType = type.leafComponentType();
4845 if (leafType instanceof ReferenceBinding) {
4846 char[][] name = ((ReferenceBinding) leafType).compoundName; // problem type will tell how much got resolved
4847 end = (int) arrayQualifiedTypeReference.sourcePositions[name.length-1];
4848 } else {
4849 long[] positions = arrayQualifiedTypeReference.sourcePositions;
4850 end = (int) positions[positions.length - 1];
4851 }
4852 } else if (location instanceof QualifiedTypeReference) {
4853 QualifiedTypeReference ref = (QualifiedTypeReference) location;
4854 if (isRecoveredName(ref.tokens)) return;
4855 if (type instanceof ReferenceBinding) {
4856 char[][] name = ((ReferenceBinding) type).compoundName;
4857 if (name.length <= ref.sourcePositions.length)
4858 end = (int) ref.sourcePositions[name.length - 1];
4859 }
4860 } else if (location instanceof ImportReference) {
4861 ImportReference ref = (ImportReference) location;
4862 if (isRecoveredName(ref.tokens)) return;
4863 if (type instanceof ReferenceBinding) {
4864 char[][] name = ((ReferenceBinding) type).compoundName;
4865 end = (int) ref.sourcePositions[name.length - 1];
4866 }
4867 } else if (location instanceof ArrayTypeReference) {
4868 ArrayTypeReference arrayTypeReference = (ArrayTypeReference) location;
4869 if (isRecoveredName(arrayTypeReference.token)) return;
4870 end = arrayTypeReference.originalSourceEnd;
4871 }
4872
4873 int start = location.sourceStart;
4874 if (location instanceof org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) {
4875 org.eclipse.jdt.internal.compiler.ast.SingleTypeReference ref =
4876 (org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) location;
4877 if (ref.annotations != null)
4878 start = end - ref.token.length + 1;
4879 } else if (location instanceof QualifiedTypeReference) {
4880 QualifiedTypeReference ref = (QualifiedTypeReference) location;
4881 if (ref.annotations != null)
4882 start = (int) (ref.sourcePositions[0] & 0x00000000FFFFFFFFL ) - ref.tokens[0].length + 1;
4883 }
4884
4885 this.handle(
4886 id,
4887 new String[] {new String(type.leafComponentType().readableName()) },
4888 new String[] {new String(type.leafComponentType().shortReadableName())},
4889 start,
4890 end);
4891 }
invalidTypeForCollection(Expression expression)4892 public void invalidTypeForCollection(Expression expression) {
4893 this.handle(
4894 IProblem.InvalidTypeForCollection,
4895 NoArgument,
4896 NoArgument,
4897 expression.sourceStart,
4898 expression.sourceEnd);
4899 }
invalidTypeForCollectionTarget14(Expression expression)4900 public void invalidTypeForCollectionTarget14(Expression expression) {
4901 this.handle(
4902 IProblem.InvalidTypeForCollectionTarget14,
4903 NoArgument,
4904 NoArgument,
4905 expression.sourceStart,
4906 expression.sourceEnd);
4907 }
invalidTypeToSynchronize(Expression expression, TypeBinding type)4908 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
4909 this.handle(
4910 IProblem.InvalidTypeToSynchronized,
4911 new String[] {new String(type.readableName())},
4912 new String[] {new String(type.shortReadableName())},
4913 expression.sourceStart,
4914 expression.sourceEnd);
4915 }
invalidTypeVariableAsException(TypeBinding exceptionType, ASTNode location)4916 public void invalidTypeVariableAsException(TypeBinding exceptionType, ASTNode location) {
4917 this.handle(
4918 IProblem.InvalidTypeVariableExceptionType,
4919 new String[] {new String(exceptionType.readableName())},
4920 new String[] {new String(exceptionType.shortReadableName())},
4921 location.sourceStart,
4922 location.sourceEnd);
4923 }
invalidUnaryExpression(Expression expression)4924 public void invalidUnaryExpression(Expression expression) {
4925 this.handle(
4926 IProblem.InvalidUnaryExpression,
4927 NoArgument,
4928 NoArgument,
4929 expression.sourceStart,
4930 expression.sourceEnd);
4931 }
invalidUsageOfAnnotation(Annotation annotation)4932 public void invalidUsageOfAnnotation(Annotation annotation) {
4933 this.handle(
4934 IProblem.InvalidUsageOfAnnotations,
4935 NoArgument,
4936 NoArgument,
4937 annotation.sourceStart,
4938 annotation.sourceEnd);
4939 }
invalidUsageOfAnnotationDeclarations(TypeDeclaration annotationTypeDeclaration)4940 public void invalidUsageOfAnnotationDeclarations(TypeDeclaration annotationTypeDeclaration) {
4941 this.handle(
4942 IProblem.InvalidUsageOfAnnotationDeclarations,
4943 NoArgument,
4944 NoArgument,
4945 annotationTypeDeclaration.sourceStart,
4946 annotationTypeDeclaration.sourceEnd);
4947 }
invalidUsageOfEnumDeclarations(TypeDeclaration enumDeclaration)4948 public void invalidUsageOfEnumDeclarations(TypeDeclaration enumDeclaration) {
4949 this.handle(
4950 IProblem.InvalidUsageOfEnumDeclarations,
4951 NoArgument,
4952 NoArgument,
4953 enumDeclaration.sourceStart,
4954 enumDeclaration.sourceEnd);
4955 }
invalidUsageOfForeachStatements(LocalDeclaration elementVariable, Expression collection)4956 public void invalidUsageOfForeachStatements(LocalDeclaration elementVariable, Expression collection) {
4957 this.handle(
4958 IProblem.InvalidUsageOfForeachStatements,
4959 NoArgument,
4960 NoArgument,
4961 elementVariable.declarationSourceStart,
4962 collection.sourceEnd);
4963 }
invalidUsageOfStaticImports(ImportReference staticImport)4964 public void invalidUsageOfStaticImports(ImportReference staticImport) {
4965 this.handle(
4966 IProblem.InvalidUsageOfStaticImports,
4967 NoArgument,
4968 NoArgument,
4969 staticImport.declarationSourceStart,
4970 staticImport.declarationSourceEnd);
4971 }
invalidUsageOfTypeArguments(TypeReference firstTypeReference, TypeReference lastTypeReference)4972 public void invalidUsageOfTypeArguments(TypeReference firstTypeReference, TypeReference lastTypeReference) {
4973 this.handle(
4974 IProblem.InvalidUsageOfTypeArguments,
4975 NoArgument,
4976 NoArgument,
4977 firstTypeReference.sourceStart,
4978 lastTypeReference.sourceEnd);
4979 }
invalidUsageOfTypeParameters(TypeParameter firstTypeParameter, TypeParameter lastTypeParameter)4980 public void invalidUsageOfTypeParameters(TypeParameter firstTypeParameter, TypeParameter lastTypeParameter) {
4981 this.handle(
4982 IProblem.InvalidUsageOfTypeParameters,
4983 NoArgument,
4984 NoArgument,
4985 firstTypeParameter.declarationSourceStart,
4986 lastTypeParameter.declarationSourceEnd);
4987 }
invalidUsageOfTypeParametersForAnnotationDeclaration(TypeDeclaration annotationTypeDeclaration)4988 public void invalidUsageOfTypeParametersForAnnotationDeclaration(TypeDeclaration annotationTypeDeclaration) {
4989 TypeParameter[] parameters = annotationTypeDeclaration.typeParameters;
4990 int length = parameters.length;
4991 this.handle(
4992 IProblem.InvalidUsageOfTypeParametersForAnnotationDeclaration,
4993 NoArgument,
4994 NoArgument,
4995 parameters[0].declarationSourceStart,
4996 parameters[length - 1].declarationSourceEnd);
4997 }
invalidUsageOfTypeParametersForEnumDeclaration(TypeDeclaration annotationTypeDeclaration)4998 public void invalidUsageOfTypeParametersForEnumDeclaration(TypeDeclaration annotationTypeDeclaration) {
4999 TypeParameter[] parameters = annotationTypeDeclaration.typeParameters;
5000 int length = parameters.length;
5001 this.handle(
5002 IProblem.InvalidUsageOfTypeParametersForEnumDeclaration,
5003 NoArgument,
5004 NoArgument,
5005 parameters[0].declarationSourceStart,
5006 parameters[length - 1].declarationSourceEnd);
5007 }
invalidUsageOfVarargs(AbstractVariableDeclaration aVarDecl)5008 public void invalidUsageOfVarargs(AbstractVariableDeclaration aVarDecl) {
5009 this.handle(
5010 IProblem.InvalidUsageOfVarargs,
5011 NoArgument,
5012 NoArgument,
5013 aVarDecl.type.sourceStart,
5014 aVarDecl.sourceEnd);
5015 }
invalidUsageOfTypeAnnotations(Annotation annotation)5016 public void invalidUsageOfTypeAnnotations(Annotation annotation) {
5017 this.handle(
5018 IProblem.InvalidUsageOfTypeAnnotations,
5019 NoArgument,
5020 NoArgument,
5021 annotation.sourceStart,
5022 annotation.sourceEnd);
5023 }
misplacedTypeAnnotations(Annotation first, Annotation last)5024 public void misplacedTypeAnnotations(Annotation first, Annotation last) {
5025 this.handle(
5026 IProblem.MisplacedTypeAnnotations,
5027 NoArgument,
5028 NoArgument,
5029 first.sourceStart,
5030 last.sourceEnd);
5031 }
illegalUsageOfTypeAnnotations(Annotation annotation)5032 public void illegalUsageOfTypeAnnotations(Annotation annotation) {
5033 this.handle(
5034 IProblem.IllegalUsageOfTypeAnnotations,
5035 NoArgument,
5036 NoArgument,
5037 annotation.sourceStart,
5038 annotation.sourceEnd);
5039 }
illegalTypeAnnotationsInStaticMemberAccess(Annotation first, Annotation last)5040 public void illegalTypeAnnotationsInStaticMemberAccess(Annotation first, Annotation last) {
5041 this.handle(
5042 IProblem.IllegalTypeAnnotationsInStaticMemberAccess,
5043 NoArgument,
5044 NoArgument,
5045 first.sourceStart,
5046 last.sourceEnd);
5047 }
isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, boolean implicitAnnotationUse)5048 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, boolean implicitAnnotationUse) {
5049 // ProblemReporter is not designed to be reentrant. Just in case, we discovered a build path problem while we are already
5050 // in the midst of reporting some other problem, save and restore reference context thereby mimicking a stack.
5051 // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442755.
5052 ReferenceContext savedContext = this.referenceContext;
5053 this.referenceContext = compUnitDecl;
5054 String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)};
5055 int start = 0, end = 0;
5056 if (location != null) {
5057 if (location instanceof InvocationSite) {
5058 InvocationSite site = (InvocationSite) location;
5059 start = site.sourceStart();
5060 end = site.sourceEnd();
5061 } else if (location instanceof ASTNode) {
5062 ASTNode node = (ASTNode) location;
5063 start = node.sourceStart();
5064 end = node.sourceEnd();
5065 }
5066 }
5067 try {
5068 this.handle(
5069 implicitAnnotationUse ? IProblem.MissingNullAnnotationImplicitlyUsed : IProblem.IsClassPathCorrect,
5070 arguments,
5071 arguments,
5072 start,
5073 end);
5074 } finally {
5075 this.referenceContext = savedContext;
5076 }
5077 }
isIdentifier(int token)5078 private boolean isIdentifier(int token) {
5079 return token == TerminalTokens.TokenNameIdentifier;
5080 }
isKeyword(int token)5081 private boolean isKeyword(int token) {
5082 switch(token) {
5083 case TerminalTokens.TokenNameabstract:
5084 case TerminalTokens.TokenNameassert:
5085 case TerminalTokens.TokenNamebyte:
5086 case TerminalTokens.TokenNamebreak:
5087 case TerminalTokens.TokenNameboolean:
5088 case TerminalTokens.TokenNamecase:
5089 case TerminalTokens.TokenNamechar:
5090 case TerminalTokens.TokenNamecatch:
5091 case TerminalTokens.TokenNameclass:
5092 case TerminalTokens.TokenNamecontinue:
5093 case TerminalTokens.TokenNamedo:
5094 case TerminalTokens.TokenNamedouble:
5095 case TerminalTokens.TokenNamedefault:
5096 case TerminalTokens.TokenNameelse:
5097 case TerminalTokens.TokenNameextends:
5098 case TerminalTokens.TokenNamefor:
5099 case TerminalTokens.TokenNamefinal:
5100 case TerminalTokens.TokenNamefloat:
5101 case TerminalTokens.TokenNamefalse:
5102 case TerminalTokens.TokenNamefinally:
5103 case TerminalTokens.TokenNameif:
5104 case TerminalTokens.TokenNameint:
5105 case TerminalTokens.TokenNameimport:
5106 case TerminalTokens.TokenNameinterface:
5107 case TerminalTokens.TokenNameimplements:
5108 case TerminalTokens.TokenNameinstanceof:
5109 case TerminalTokens.TokenNamelong:
5110 case TerminalTokens.TokenNamenew:
5111 case TerminalTokens.TokenNamenull:
5112 case TerminalTokens.TokenNamenative:
5113 case TerminalTokens.TokenNamepublic:
5114 case TerminalTokens.TokenNamepackage:
5115 case TerminalTokens.TokenNameprivate:
5116 case TerminalTokens.TokenNameprotected:
5117 case TerminalTokens.TokenNamereturn:
5118 case TerminalTokens.TokenNameshort:
5119 case TerminalTokens.TokenNamesuper:
5120 case TerminalTokens.TokenNamestatic:
5121 case TerminalTokens.TokenNameswitch:
5122 case TerminalTokens.TokenNamestrictfp:
5123 case TerminalTokens.TokenNamesynchronized:
5124 case TerminalTokens.TokenNametry:
5125 case TerminalTokens.TokenNamethis:
5126 case TerminalTokens.TokenNametrue:
5127 case TerminalTokens.TokenNamethrow:
5128 case TerminalTokens.TokenNamethrows:
5129 case TerminalTokens.TokenNametransient:
5130 case TerminalTokens.TokenNamevoid:
5131 case TerminalTokens.TokenNamevolatile:
5132 case TerminalTokens.TokenNamewhile:
5133 return true;
5134 case TerminalTokens.TokenNameRestrictedIdentifierYield:
5135 case TerminalTokens.TokenNameRestrictedIdentifierrecord:
5136 // making explicit - not a (restricted) keyword but restricted identifier.
5137 //$FALL-THROUGH$
5138 default:
5139 return false;
5140 }
5141 }
isLiteral(int token)5142 private boolean isLiteral(int token) {
5143 return Scanner.isLiteral(token);
5144 }
5145
isRecoveredName(char[] simpleName)5146 private boolean isRecoveredName(char[] simpleName) {
5147 return simpleName == RecoveryScanner.FAKE_IDENTIFIER;
5148 }
5149
isRecoveredName(char[][] qualifiedName)5150 private boolean isRecoveredName(char[][] qualifiedName) {
5151 if(qualifiedName == null) return false;
5152 for (int i = 0; i < qualifiedName.length; i++) {
5153 if(qualifiedName[i] == RecoveryScanner.FAKE_IDENTIFIER) return true;
5154 }
5155 return false;
5156 }
5157
javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers)5158 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers) {
5159 int severity = computeSeverity(IProblem.JavadocAmbiguousMethodReference);
5160 if (severity == ProblemSeverities.Ignore) return;
5161 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5162 String[] arguments = new String[] {new String(fieldBinding.readableName())};
5163 handle(
5164 IProblem.JavadocAmbiguousMethodReference,
5165 arguments,
5166 arguments,
5167 severity,
5168 sourceStart,
5169 sourceEnd);
5170 }
5171 }
5172
javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers)5173 public void javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers) {
5174 int severity = computeSeverity(IProblem.JavadocUsingDeprecatedField);
5175 if (severity == ProblemSeverities.Ignore) return;
5176 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5177 this.handle(
5178 IProblem.JavadocUsingDeprecatedField,
5179 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
5180 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
5181 severity,
5182 nodeSourceStart(field, location),
5183 nodeSourceEnd(field, location));
5184 }
5185 }
5186
javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers)5187 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers) {
5188 boolean isConstructor = method.isConstructor();
5189 int severity = computeSeverity(isConstructor ? IProblem.JavadocUsingDeprecatedConstructor : IProblem.JavadocUsingDeprecatedMethod);
5190 if (severity == ProblemSeverities.Ignore) return;
5191 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5192 if (isConstructor) {
5193 this.handle(
5194 IProblem.JavadocUsingDeprecatedConstructor,
5195 new String[] {new String(method.declaringClass.readableName()), typesAsString(method, false)},
5196 new String[] {new String(method.declaringClass.shortReadableName()), typesAsString(method, true)},
5197 severity,
5198 location.sourceStart,
5199 location.sourceEnd);
5200 } else {
5201 this.handle(
5202 IProblem.JavadocUsingDeprecatedMethod,
5203 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), typesAsString(method, false)},
5204 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), typesAsString(method, true)},
5205 severity,
5206 location.sourceStart,
5207 location.sourceEnd);
5208 }
5209 }
5210 }
javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers)5211 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers) {
5212 javadocDeprecatedType(type, location, modifiers, Integer.MAX_VALUE);
5213 }
javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers, int index)5214 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers, int index) {
5215 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
5216 int severity = computeSeverity(IProblem.JavadocUsingDeprecatedType);
5217 if (severity == ProblemSeverities.Ignore) return;
5218 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5219 if (type.isMemberType() && type instanceof ReferenceBinding && !javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, ((ReferenceBinding)type).modifiers)) {
5220 this.handle(IProblem.JavadocHiddenReference, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
5221 } else {
5222 this.handle(
5223 IProblem.JavadocUsingDeprecatedType,
5224 new String[] {new String(type.readableName())},
5225 new String[] {new String(type.shortReadableName())},
5226 severity,
5227 location.sourceStart,
5228 nodeSourceEnd(null, location, index));
5229 }
5230 }
5231 }
javadocDuplicatedParamTag(char[] token, int sourceStart, int sourceEnd, int modifiers)5232 public void javadocDuplicatedParamTag(char[] token, int sourceStart, int sourceEnd, int modifiers) {
5233 int severity = computeSeverity(IProblem.JavadocDuplicateParamName);
5234 if (severity == ProblemSeverities.Ignore) return;
5235 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5236 String[] arguments = new String[] {String.valueOf(token)};
5237 this.handle(
5238 IProblem.JavadocDuplicateParamName,
5239 arguments,
5240 arguments,
5241 severity,
5242 sourceStart,
5243 sourceEnd);
5244 }
5245 }
javadocDuplicatedProvidesTag(int sourceStart, int sourceEnd)5246 public void javadocDuplicatedProvidesTag(int sourceStart, int sourceEnd){
5247 this.handle(IProblem.JavadocDuplicateProvidesTag, NoArgument, NoArgument, sourceStart, sourceEnd);
5248 }
javadocDuplicatedReturnTag(int sourceStart, int sourceEnd)5249 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd){
5250 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
5251 }
javadocDuplicatedTag(char[] tagName, int sourceStart, int sourceEnd)5252 public void javadocDuplicatedTag(char[] tagName, int sourceStart, int sourceEnd){
5253 String[] arguments = new String[] { new String(tagName) };
5254 this.handle(
5255 IProblem.JavadocDuplicateTag,
5256 arguments,
5257 arguments,
5258 sourceStart,
5259 sourceEnd);
5260 }
javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers)5261 public void javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers) {
5262 int severity = computeSeverity(IProblem.JavadocDuplicateThrowsClassName);
5263 if (severity == ProblemSeverities.Ignore) return;
5264 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5265 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
5266 this.handle(
5267 IProblem.JavadocDuplicateThrowsClassName,
5268 arguments,
5269 arguments,
5270 severity,
5271 typeReference.sourceStart,
5272 typeReference.sourceEnd);
5273 }
5274 }
javadocDuplicatedUsesTag( int sourceStart, int sourceEnd)5275 public void javadocDuplicatedUsesTag(
5276
5277 int sourceStart, int sourceEnd){
5278 this.handle(IProblem.JavadocDuplicateUsesTag, NoArgument, NoArgument, sourceStart, sourceEnd);
5279 }
javadocEmptyReturnTag(int sourceStart, int sourceEnd, int modifiers)5280 public void javadocEmptyReturnTag(int sourceStart, int sourceEnd, int modifiers) {
5281 int severity = computeSeverity(IProblem.JavadocEmptyReturnTag);
5282 if (severity == ProblemSeverities.Ignore) return;
5283 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5284 String[] arguments = new String[] { new String(JavadocTagConstants.TAG_RETURN) };
5285 this.handle(IProblem.JavadocEmptyReturnTag, arguments, arguments, sourceStart, sourceEnd);
5286 }
5287 }
javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers)5288 public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
5289 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
5290 int severity = computeSeverity(id);
5291 if (severity == ProblemSeverities.Ignore) return;
5292 StringBuffer buffer = new StringBuffer();
5293 StringBuffer shortBuffer = new StringBuffer();
5294 for (int i = 0, length = params.length; i < length; i++) {
5295 if (i != 0){
5296 buffer.append(", "); //$NON-NLS-1$
5297 shortBuffer.append(", "); //$NON-NLS-1$
5298 }
5299 buffer.append(new String(params[i].readableName()));
5300 shortBuffer.append(new String(params[i].shortReadableName()));
5301 }
5302 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5303 this.handle(
5304 id,
5305 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
5306 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
5307 severity,
5308 messageSend.sourceStart,
5309 messageSend.sourceEnd);
5310 }
5311 }
javadocHiddenReference(int sourceStart, int sourceEnd, Scope scope, int modifiers)5312 public void javadocHiddenReference(int sourceStart, int sourceEnd, Scope scope, int modifiers) {
5313 Scope currentScope = scope;
5314 while (currentScope.parent.kind != Scope.COMPILATION_UNIT_SCOPE ) {
5315 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, currentScope.getDeclarationModifiers())) {
5316 return;
5317 }
5318 currentScope = currentScope.parent;
5319 }
5320 String[] arguments = new String[] { this.options.getVisibilityString(this.options.reportInvalidJavadocTagsVisibility), this.options.getVisibilityString(modifiers) };
5321 this.handle(IProblem.JavadocHiddenReference, arguments, arguments, sourceStart, sourceEnd);
5322 }
javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers)5323 public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
5324
5325 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) return;
5326 int sourceStart = statement.sourceStart;
5327 int sourceEnd = statement.sourceEnd;
5328 if (statement instanceof AllocationExpression) {
5329 AllocationExpression allocation = (AllocationExpression)statement;
5330 if (allocation.enumConstant != null) {
5331 sourceStart = allocation.enumConstant.sourceStart;
5332 sourceEnd = allocation.enumConstant.sourceEnd;
5333 }
5334 }
5335 int id = IProblem.JavadocUndefinedConstructor; //default...
5336 ProblemMethodBinding problemConstructor = null;
5337 MethodBinding shownConstructor = null;
5338 switch (targetConstructor.problemId()) {
5339 case ProblemReasons.NotFound :
5340 id = IProblem.JavadocUndefinedConstructor;
5341 break;
5342 case ProblemReasons.NotVisible :
5343 id = IProblem.JavadocNotVisibleConstructor;
5344 break;
5345 case ProblemReasons.Ambiguous :
5346 id = IProblem.JavadocAmbiguousConstructor;
5347 break;
5348 case ProblemReasons.ParameterBoundMismatch :
5349 int severity = computeSeverity(IProblem.JavadocGenericConstructorTypeArgumentMismatch);
5350 if (severity == ProblemSeverities.Ignore) return;
5351 problemConstructor = (ProblemMethodBinding) targetConstructor;
5352 ParameterizedGenericMethodBinding substitutedConstructor = (ParameterizedGenericMethodBinding) problemConstructor.closestMatch;
5353 shownConstructor = substitutedConstructor.original();
5354
5355 int augmentedLength = problemConstructor.parameters.length;
5356 TypeBinding inferredTypeArgument = problemConstructor.parameters[augmentedLength-2];
5357 TypeVariableBinding typeParameter = (TypeVariableBinding) problemConstructor.parameters[augmentedLength-1];
5358 TypeBinding[] invocationArguments = new TypeBinding[augmentedLength-2]; // remove extra info from the end
5359 System.arraycopy(problemConstructor.parameters, 0, invocationArguments, 0, augmentedLength-2);
5360
5361 this.handle(
5362 IProblem.JavadocGenericConstructorTypeArgumentMismatch,
5363 new String[] {
5364 new String(shownConstructor.declaringClass.sourceName()),
5365 typesAsString(shownConstructor, false),
5366 new String(shownConstructor.declaringClass.readableName()),
5367 typesAsString(invocationArguments, false),
5368 new String(inferredTypeArgument.readableName()),
5369 new String(typeParameter.sourceName()),
5370 parameterBoundAsString(typeParameter, false) },
5371 new String[] {
5372 new String(shownConstructor.declaringClass.sourceName()),
5373 typesAsString(shownConstructor, true),
5374 new String(shownConstructor.declaringClass.shortReadableName()),
5375 typesAsString(invocationArguments, true),
5376 new String(inferredTypeArgument.shortReadableName()),
5377 new String(typeParameter.sourceName()),
5378 parameterBoundAsString(typeParameter, true) },
5379 severity,
5380 sourceStart,
5381 sourceEnd);
5382 return;
5383
5384 case ProblemReasons.TypeParameterArityMismatch :
5385 problemConstructor = (ProblemMethodBinding) targetConstructor;
5386 shownConstructor = problemConstructor.closestMatch;
5387 boolean noTypeVariables = shownConstructor.typeVariables == Binding.NO_TYPE_VARIABLES;
5388 severity = computeSeverity(noTypeVariables ? IProblem.JavadocNonGenericConstructor : IProblem.JavadocIncorrectArityForParameterizedConstructor);
5389 if (severity == ProblemSeverities.Ignore) return;
5390 if (noTypeVariables) {
5391 this.handle(
5392 IProblem.JavadocNonGenericConstructor,
5393 new String[] {
5394 new String(shownConstructor.declaringClass.sourceName()),
5395 typesAsString(shownConstructor, false),
5396 new String(shownConstructor.declaringClass.readableName()),
5397 typesAsString(targetConstructor, false) },
5398 new String[] {
5399 new String(shownConstructor.declaringClass.sourceName()),
5400 typesAsString(shownConstructor, true),
5401 new String(shownConstructor.declaringClass.shortReadableName()),
5402 typesAsString(targetConstructor, true) },
5403 severity,
5404 sourceStart,
5405 sourceEnd);
5406 } else {
5407 this.handle(
5408 IProblem.JavadocIncorrectArityForParameterizedConstructor,
5409 new String[] {
5410 new String(shownConstructor.declaringClass.sourceName()),
5411 typesAsString(shownConstructor, false),
5412 new String(shownConstructor.declaringClass.readableName()),
5413 typesAsString(shownConstructor.typeVariables, false),
5414 typesAsString(targetConstructor, false) },
5415 new String[] {
5416 new String(shownConstructor.declaringClass.sourceName()),
5417 typesAsString(shownConstructor, true),
5418 new String(shownConstructor.declaringClass.shortReadableName()),
5419 typesAsString(shownConstructor.typeVariables, true),
5420 typesAsString(targetConstructor, true) },
5421 severity,
5422 sourceStart,
5423 sourceEnd);
5424 }
5425 return;
5426 case ProblemReasons.ParameterizedMethodTypeMismatch :
5427 severity = computeSeverity(IProblem.JavadocParameterizedConstructorArgumentTypeMismatch);
5428 if (severity == ProblemSeverities.Ignore) return;
5429 problemConstructor = (ProblemMethodBinding) targetConstructor;
5430 shownConstructor = problemConstructor.closestMatch;
5431 this.handle(
5432 IProblem.JavadocParameterizedConstructorArgumentTypeMismatch,
5433 new String[] {
5434 new String(shownConstructor.declaringClass.sourceName()),
5435 typesAsString(shownConstructor, false),
5436 new String(shownConstructor.declaringClass.readableName()),
5437 typesAsString(((ParameterizedGenericMethodBinding)shownConstructor).typeArguments, false),
5438 typesAsString(targetConstructor, false) },
5439 new String[] {
5440 new String(shownConstructor.declaringClass.sourceName()),
5441 typesAsString(shownConstructor, true),
5442 new String(shownConstructor.declaringClass.shortReadableName()),
5443 typesAsString(((ParameterizedGenericMethodBinding)shownConstructor).typeArguments, true),
5444 typesAsString(targetConstructor, true) },
5445 severity,
5446 sourceStart,
5447 sourceEnd);
5448 return;
5449 case ProblemReasons.TypeArgumentsForRawGenericMethod :
5450 severity = computeSeverity(IProblem.JavadocTypeArgumentsForRawGenericConstructor);
5451 if (severity == ProblemSeverities.Ignore) return;
5452 problemConstructor = (ProblemMethodBinding) targetConstructor;
5453 shownConstructor = problemConstructor.closestMatch;
5454 this.handle(
5455 IProblem.JavadocTypeArgumentsForRawGenericConstructor,
5456 new String[] {
5457 new String(shownConstructor.declaringClass.sourceName()),
5458 typesAsString(shownConstructor, false),
5459 new String(shownConstructor.declaringClass.readableName()),
5460 typesAsString(targetConstructor, false) },
5461 new String[] {
5462 new String(shownConstructor.declaringClass.sourceName()),
5463 typesAsString(shownConstructor, true),
5464 new String(shownConstructor.declaringClass.shortReadableName()),
5465 typesAsString(targetConstructor, true) },
5466 severity,
5467 sourceStart,
5468 sourceEnd);
5469 return;
5470 case ProblemReasons.NoError : // 0
5471 default :
5472 needImplementation(statement); // want to fail to see why we were here...
5473 break;
5474 }
5475 int severity = computeSeverity(id);
5476 if (severity == ProblemSeverities.Ignore) return;
5477 this.handle(
5478 id,
5479 new String[] {new String(targetConstructor.declaringClass.readableName()), typesAsString(targetConstructor, false)},
5480 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), typesAsString(targetConstructor, true)},
5481 severity,
5482 statement.sourceStart,
5483 statement.sourceEnd);
5484 }
5485 /*
5486 * Similar implementation than invalidField(FieldReference...)
5487 * Note that following problem id cannot occur for Javadoc:
5488 * - NonStaticReferenceInStaticContext :
5489 * - NonStaticReferenceInConstructorInvocation :
5490 * - ReceiverTypeNotVisible :
5491 */
javadocInvalidField(FieldReference fieldRef, Binding fieldBinding, TypeBinding searchedType, int modifiers)5492 public void javadocInvalidField(FieldReference fieldRef, Binding fieldBinding, TypeBinding searchedType, int modifiers) {
5493 int id = IProblem.JavadocUndefinedField;
5494 switch (fieldBinding.problemId()) {
5495 case ProblemReasons.NotFound :
5496 id = IProblem.JavadocUndefinedField;
5497 break;
5498 case ProblemReasons.NotVisible :
5499 id = IProblem.JavadocNotVisibleField;
5500 break;
5501 case ProblemReasons.Ambiguous :
5502 id = IProblem.JavadocAmbiguousField;
5503 break;
5504 case ProblemReasons.NoError : // 0
5505 default :
5506 needImplementation(fieldRef); // want to fail to see why we were here...
5507 break;
5508 }
5509 int severity = computeSeverity(id);
5510 if (severity == ProblemSeverities.Ignore) return;
5511 // report issue
5512 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5513 String[] arguments = new String[] {new String(fieldBinding.readableName())};
5514 handle(
5515 id,
5516 arguments,
5517 arguments,
5518 severity,
5519 fieldRef.sourceStart,
5520 fieldRef.sourceEnd);
5521 }
5522 }
javadocInvalidMemberTypeQualification(int sourceStart, int sourceEnd, int modifiers)5523 public void javadocInvalidMemberTypeQualification(int sourceStart, int sourceEnd, int modifiers){
5524 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5525 this.handle(IProblem.JavadocInvalidMemberTypeQualification, NoArgument, NoArgument, sourceStart, sourceEnd);
5526 }
5527 }
5528 /*
5529 * Similar implementation than invalidMethod(MessageSend...)
5530 * Note that following problem id cannot occur for Javadoc:
5531 * - NonStaticReferenceInStaticContext :
5532 * - NonStaticReferenceInConstructorInvocation :
5533 * - ReceiverTypeNotVisible :
5534 */
javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers)5535 public void javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers) {
5536 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) return;
5537 // set problem id
5538 ProblemMethodBinding problemMethod = null;
5539 MethodBinding shownMethod = null;
5540 int id = IProblem.JavadocUndefinedMethod; //default...
5541 switch (method.problemId()) {
5542 case ProblemReasons.NotFound :
5543 id = IProblem.JavadocUndefinedMethod;
5544 problemMethod = (ProblemMethodBinding) method;
5545 if (problemMethod.closestMatch != null) {
5546 int severity = computeSeverity(IProblem.JavadocParameterMismatch);
5547 if (severity == ProblemSeverities.Ignore) return;
5548 String closestParameterTypeNames = typesAsString(problemMethod.closestMatch, false);
5549 String parameterTypeNames = typesAsString(method, false);
5550 String closestParameterTypeShortNames = typesAsString(problemMethod.closestMatch, true);
5551 String parameterTypeShortNames = typesAsString(method, true);
5552 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){
5553 closestParameterTypeShortNames = closestParameterTypeNames;
5554 parameterTypeShortNames = parameterTypeNames;
5555 }
5556 this.handle(
5557 IProblem.JavadocParameterMismatch,
5558 new String[] {
5559 new String(problemMethod.closestMatch.declaringClass.readableName()),
5560 new String(problemMethod.closestMatch.selector),
5561 closestParameterTypeNames,
5562 parameterTypeNames
5563 },
5564 new String[] {
5565 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
5566 new String(problemMethod.closestMatch.selector),
5567 closestParameterTypeShortNames,
5568 parameterTypeShortNames
5569 },
5570 severity,
5571 (int) (messageSend.nameSourcePosition >>> 32),
5572 (int) messageSend.nameSourcePosition);
5573 return;
5574 }
5575 break;
5576 case ProblemReasons.NotVisible :
5577 id = IProblem.JavadocNotVisibleMethod;
5578 break;
5579 case ProblemReasons.Ambiguous :
5580 id = IProblem.JavadocAmbiguousMethod;
5581 break;
5582 case ProblemReasons.ParameterBoundMismatch :
5583 int severity = computeSeverity(IProblem.JavadocGenericMethodTypeArgumentMismatch);
5584 if (severity == ProblemSeverities.Ignore) return;
5585 problemMethod = (ProblemMethodBinding) method;
5586 ParameterizedGenericMethodBinding substitutedMethod = (ParameterizedGenericMethodBinding) problemMethod.closestMatch;
5587 shownMethod = substitutedMethod.original();
5588 int augmentedLength = problemMethod.parameters.length;
5589 TypeBinding inferredTypeArgument = problemMethod.parameters[augmentedLength-2];
5590 TypeVariableBinding typeParameter = (TypeVariableBinding) problemMethod.parameters[augmentedLength-1];
5591 TypeBinding[] invocationArguments = new TypeBinding[augmentedLength-2]; // remove extra info from the end
5592 System.arraycopy(problemMethod.parameters, 0, invocationArguments, 0, augmentedLength-2);
5593 this.handle(
5594 IProblem.JavadocGenericMethodTypeArgumentMismatch,
5595 new String[] {
5596 new String(shownMethod.selector),
5597 typesAsString(shownMethod, false),
5598 new String(shownMethod.declaringClass.readableName()),
5599 typesAsString(invocationArguments, false),
5600 new String(inferredTypeArgument.readableName()),
5601 new String(typeParameter.sourceName()),
5602 parameterBoundAsString(typeParameter, false) },
5603 new String[] {
5604 new String(shownMethod.selector),
5605 typesAsString(shownMethod, true),
5606 new String(shownMethod.declaringClass.shortReadableName()),
5607 typesAsString(invocationArguments, true),
5608 new String(inferredTypeArgument.shortReadableName()),
5609 new String(typeParameter.sourceName()),
5610 parameterBoundAsString(typeParameter, true) },
5611 severity,
5612 (int) (messageSend.nameSourcePosition >>> 32),
5613 (int) messageSend.nameSourcePosition);
5614 return;
5615 case ProblemReasons.TypeParameterArityMismatch :
5616 problemMethod = (ProblemMethodBinding) method;
5617 shownMethod = problemMethod.closestMatch;
5618 boolean noTypeVariables = shownMethod.typeVariables == Binding.NO_TYPE_VARIABLES;
5619 severity = computeSeverity(noTypeVariables ? IProblem.JavadocNonGenericMethod : IProblem.JavadocIncorrectArityForParameterizedMethod);
5620 if (severity == ProblemSeverities.Ignore) return;
5621 if (noTypeVariables) {
5622 this.handle(
5623 IProblem.JavadocNonGenericMethod,
5624 new String[] {
5625 new String(shownMethod.selector),
5626 typesAsString(shownMethod, false),
5627 new String(shownMethod.declaringClass.readableName()),
5628 typesAsString(method, false) },
5629 new String[] {
5630 new String(shownMethod.selector),
5631 typesAsString(shownMethod, true),
5632 new String(shownMethod.declaringClass.shortReadableName()),
5633 typesAsString(method, true) },
5634 severity,
5635 (int) (messageSend.nameSourcePosition >>> 32),
5636 (int) messageSend.nameSourcePosition);
5637 } else {
5638 this.handle(
5639 IProblem.JavadocIncorrectArityForParameterizedMethod,
5640 new String[] {
5641 new String(shownMethod.selector),
5642 typesAsString(shownMethod, false),
5643 new String(shownMethod.declaringClass.readableName()),
5644 typesAsString(shownMethod.typeVariables, false),
5645 typesAsString(method, false) },
5646 new String[] {
5647 new String(shownMethod.selector),
5648 typesAsString(shownMethod, true),
5649 new String(shownMethod.declaringClass.shortReadableName()),
5650 typesAsString(shownMethod.typeVariables, true),
5651 typesAsString(method, true) },
5652 severity,
5653 (int) (messageSend.nameSourcePosition >>> 32),
5654 (int) messageSend.nameSourcePosition);
5655 }
5656 return;
5657 case ProblemReasons.ParameterizedMethodTypeMismatch :
5658 severity = computeSeverity(IProblem.JavadocParameterizedMethodArgumentTypeMismatch);
5659 if (severity == ProblemSeverities.Ignore) return;
5660 problemMethod = (ProblemMethodBinding) method;
5661 shownMethod = problemMethod.closestMatch;
5662 this.handle(
5663 IProblem.JavadocParameterizedMethodArgumentTypeMismatch,
5664 new String[] {
5665 new String(shownMethod.selector),
5666 typesAsString(shownMethod, false),
5667 new String(shownMethod.declaringClass.readableName()),
5668 typesAsString(((ParameterizedGenericMethodBinding)shownMethod).typeArguments, false),
5669 typesAsString(method, false) },
5670 new String[] {
5671 new String(shownMethod.selector),
5672 typesAsString(shownMethod, true),
5673 new String(shownMethod.declaringClass.shortReadableName()),
5674 typesAsString(((ParameterizedGenericMethodBinding)shownMethod).typeArguments, true),
5675 typesAsString(method, true) },
5676 severity,
5677 (int) (messageSend.nameSourcePosition >>> 32),
5678 (int) messageSend.nameSourcePosition);
5679 return;
5680 case ProblemReasons.TypeArgumentsForRawGenericMethod :
5681 severity = computeSeverity(IProblem.JavadocTypeArgumentsForRawGenericMethod);
5682 if (severity == ProblemSeverities.Ignore) return;
5683 problemMethod = (ProblemMethodBinding) method;
5684 shownMethod = problemMethod.closestMatch;
5685 this.handle(
5686 IProblem.JavadocTypeArgumentsForRawGenericMethod,
5687 new String[] {
5688 new String(shownMethod.selector),
5689 typesAsString(shownMethod, false),
5690 new String(shownMethod.declaringClass.readableName()),
5691 typesAsString(method, false) },
5692 new String[] {
5693 new String(shownMethod.selector),
5694 typesAsString(shownMethod, true),
5695 new String(shownMethod.declaringClass.shortReadableName()),
5696 typesAsString(method, true) },
5697 severity,
5698 (int) (messageSend.nameSourcePosition >>> 32),
5699 (int) messageSend.nameSourcePosition);
5700 return;
5701 case ProblemReasons.NoError : // 0
5702 default :
5703 needImplementation(messageSend); // want to fail to see why we were here...
5704 break;
5705 }
5706 int severity = computeSeverity(id);
5707 if (severity == ProblemSeverities.Ignore) return;
5708 // report issue
5709 this.handle(
5710 id,
5711 new String[] {
5712 new String(method.declaringClass.readableName()),
5713 new String(method.selector), typesAsString(method, false)},
5714 new String[] {
5715 new String(method.declaringClass.shortReadableName()),
5716 new String(method.selector), typesAsString(method, true)},
5717 severity,
5718 (int) (messageSend.nameSourcePosition >>> 32),
5719 (int) messageSend.nameSourcePosition);
5720 }
javadocInvalidParamTagName(int sourceStart, int sourceEnd)5721 public void javadocInvalidParamTagName(int sourceStart, int sourceEnd) {
5722 this.handle(IProblem.JavadocInvalidParamTagName, NoArgument, NoArgument, sourceStart, sourceEnd);
5723 }
javadocInvalidParamTypeParameter(int sourceStart, int sourceEnd)5724 public void javadocInvalidParamTypeParameter(int sourceStart, int sourceEnd) {
5725 this.handle(IProblem.JavadocInvalidParamTagTypeParameter, NoArgument, NoArgument, sourceStart, sourceEnd);
5726 }
javadocInvalidProvidesClass(int sourceStart, int sourceEnd)5727 public void javadocInvalidProvidesClass(int sourceStart, int sourceEnd) {
5728 this.handle(IProblem.JavadocInvalidProvidesClass, NoArgument, NoArgument, sourceStart, sourceEnd);
5729 }
5730
javadocInvalidProvidesClassName(TypeReference typeReference, int modifiers)5731 public void javadocInvalidProvidesClassName(TypeReference typeReference, int modifiers) {
5732 int severity = computeSeverity(IProblem.JavadocInvalidProvidesClassName);
5733 if (severity == ProblemSeverities.Ignore) return;
5734 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5735 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
5736 this.handle(
5737 IProblem.JavadocInvalidProvidesClassName,
5738 arguments,
5739 arguments,
5740 severity,
5741 typeReference.sourceStart,
5742 typeReference.sourceEnd);
5743 }
5744 }
javadocInvalidReference(int sourceStart, int sourceEnd)5745 public void javadocInvalidReference(int sourceStart, int sourceEnd) {
5746 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
5747 }
5748 /**
5749 * Report an invalid reference that does not conform to the href syntax.
5750 * Valid syntax example: @see IProblem.JavadocInvalidSeeHref
5751 */
javadocInvalidSeeHref(int sourceStart, int sourceEnd)5752 public void javadocInvalidSeeHref(int sourceStart, int sourceEnd) {
5753 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument, sourceStart, sourceEnd);
5754 }
javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd)5755 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
5756 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument, sourceStart, sourceEnd);
5757 }
5758 /**
5759 * Report a problem on an invalid URL reference.
5760 * Valid syntax example: @see IProblem.JavadocInvalidSeeUrlReference
5761 */
javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd)5762 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
5763 this.handle(IProblem.JavadocInvalidSeeUrlReference, NoArgument, NoArgument, sourceStart, sourceEnd);
5764 }
javadocInvalidTag(int sourceStart, int sourceEnd)5765 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
5766 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument, sourceStart, sourceEnd);
5767 }
javadocInvalidThrowsClass(int sourceStart, int sourceEnd)5768 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
5769 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument, sourceStart, sourceEnd);
5770 }
javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers)5771 public void javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers) {
5772 int severity = computeSeverity(IProblem.JavadocInvalidThrowsClassName);
5773 if (severity == ProblemSeverities.Ignore) return;
5774 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5775 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
5776 this.handle(
5777 IProblem.JavadocInvalidThrowsClassName,
5778 arguments,
5779 arguments,
5780 severity,
5781 typeReference.sourceStart,
5782 typeReference.sourceEnd);
5783 }
5784 }
javadocInvalidType(ASTNode location, TypeBinding type, int modifiers)5785 public void javadocInvalidType(ASTNode location, TypeBinding type, int modifiers) {
5786 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5787 int id = IProblem.JavadocUndefinedType; // default
5788 switch (type.problemId()) {
5789 case ProblemReasons.NotFound :
5790 id = IProblem.JavadocUndefinedType;
5791 break;
5792 case ProblemReasons.NotVisible :
5793 id = IProblem.JavadocNotVisibleType;
5794 break;
5795 case ProblemReasons.NotAccessible:
5796 id = IProblem.JavadocNotAccessibleType;
5797 break;
5798 case ProblemReasons.Ambiguous :
5799 id = IProblem.JavadocAmbiguousType;
5800 break;
5801 case ProblemReasons.InternalNameProvided :
5802 id = IProblem.JavadocInternalTypeNameProvided;
5803 break;
5804 case ProblemReasons.InheritedNameHidesEnclosingName :
5805 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
5806 break;
5807 case ProblemReasons.NonStaticReferenceInStaticContext :
5808 id = IProblem.JavadocNonStaticTypeFromStaticInvocation;
5809 break;
5810 case ProblemReasons.NoError : // 0
5811 default :
5812 needImplementation(location); // want to fail to see why we were here...
5813 break;
5814 }
5815 int severity = computeSeverity(id);
5816 if (severity == ProblemSeverities.Ignore) return;
5817 this.handle(
5818 id,
5819 new String[] {new String(type.readableName())},
5820 new String[] {new String(type.shortReadableName())},
5821 severity,
5822 location.sourceStart,
5823 location.sourceEnd);
5824 }
5825 }
javadocInvalidUsesClass(int sourceStart, int sourceEnd)5826 public void javadocInvalidUsesClass(int sourceStart, int sourceEnd) {
5827 this.handle(IProblem.JavadocInvalidUsesClass, NoArgument, NoArgument, sourceStart, sourceEnd);
5828 }
5829
javadocInvalidUsesClassName(TypeReference typeReference, int modifiers)5830 public void javadocInvalidUsesClassName(TypeReference typeReference, int modifiers) {
5831 int severity = computeSeverity(IProblem.JavadocInvalidUsesClassName);
5832 if (severity == ProblemSeverities.Ignore) return;
5833 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5834 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
5835 this.handle(
5836 IProblem.JavadocInvalidUsesClassName,
5837 arguments,
5838 arguments,
5839 severity,
5840 typeReference.sourceStart,
5841 typeReference.sourceEnd);
5842 }
5843 }
javadocInvalidValueReference(int sourceStart, int sourceEnd, int modifiers)5844 public void javadocInvalidValueReference(int sourceStart, int sourceEnd, int modifiers) {
5845 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers))
5846 this.handle(IProblem.JavadocInvalidValueReference, NoArgument, NoArgument, sourceStart, sourceEnd);
5847 }
javadocMalformedSeeReference(int sourceStart, int sourceEnd)5848 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
5849 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
5850 }
javadocMissing(int sourceStart, int sourceEnd, int modifiers)5851 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers){
5852 int severity = computeSeverity(IProblem.JavadocMissing);
5853 this.javadocMissing(sourceStart, sourceEnd, severity, modifiers);
5854 }
javadocMissing(int sourceStart, int sourceEnd, int severity, int modifiers)5855 public void javadocMissing(int sourceStart, int sourceEnd, int severity, int modifiers){
5856 if (severity == ProblemSeverities.Ignore) return;
5857 boolean overriding = (modifiers & (ExtraCompilerModifiers.AccImplementing|ExtraCompilerModifiers.AccOverriding)) != 0;
5858 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
5859 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
5860 if (report) {
5861 String arg = javadocVisibilityArgument(this.options.reportMissingJavadocCommentsVisibility, modifiers);
5862 if (arg != null) {
5863 String[] arguments = new String[] { arg };
5864 this.handle(
5865 IProblem.JavadocMissing,
5866 arguments,
5867 arguments,
5868 severity,
5869 sourceStart,
5870 sourceEnd);
5871 }
5872 }
5873 }
javadocModuleMissing(int sourceStart, int sourceEnd, int severity)5874 public void javadocModuleMissing(int sourceStart, int sourceEnd, int severity){
5875 if (severity == ProblemSeverities.Ignore) return;
5876 boolean report = this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore;
5877 if (report) {
5878 String[] arguments = new String[] { "module" }; //$NON-NLS-1$
5879 this.handle(
5880 IProblem.JavadocMissing,
5881 arguments,
5882 arguments,
5883 severity,
5884 sourceStart,
5885 sourceEnd);
5886 }
5887 }
javadocMissingHashCharacter(int sourceStart, int sourceEnd, String ref)5888 public void javadocMissingHashCharacter(int sourceStart, int sourceEnd, String ref){
5889 int severity = computeSeverity(IProblem.JavadocMissingHashCharacter);
5890 if (severity == ProblemSeverities.Ignore) return;
5891 String[] arguments = new String[] { ref };
5892 this.handle(
5893 IProblem.JavadocMissingHashCharacter,
5894 arguments,
5895 arguments,
5896 severity,
5897 sourceStart,
5898 sourceEnd);
5899 }
javadocMissingIdentifier(int sourceStart, int sourceEnd, int modifiers)5900 public void javadocMissingIdentifier(int sourceStart, int sourceEnd, int modifiers){
5901 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers))
5902 this.handle(IProblem.JavadocMissingIdentifier, NoArgument, NoArgument, sourceStart, sourceEnd);
5903 }
javadocMissingParamName(int sourceStart, int sourceEnd, int modifiers)5904 public void javadocMissingParamName(int sourceStart, int sourceEnd, int modifiers){
5905 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers))
5906 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument, sourceStart, sourceEnd);
5907 }
javadocMissingParamTag(char[] name, int sourceStart, int sourceEnd, int modifiers)5908 public void javadocMissingParamTag(char[] name, int sourceStart, int sourceEnd, int modifiers) {
5909 int severity = computeSeverity(IProblem.JavadocMissingParamTag);
5910 if (severity == ProblemSeverities.Ignore) return;
5911 boolean overriding = (modifiers & (ExtraCompilerModifiers.AccImplementing|ExtraCompilerModifiers.AccOverriding)) != 0;
5912 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
5913 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
5914 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
5915 String[] arguments = new String[] { String.valueOf(name) };
5916 this.handle(
5917 IProblem.JavadocMissingParamTag,
5918 arguments,
5919 arguments,
5920 severity,
5921 sourceStart,
5922 sourceEnd);
5923 }
5924 }
javadocMissingProvidesClassName(int sourceStart, int sourceEnd, int modifiers)5925 public void javadocMissingProvidesClassName(int sourceStart, int sourceEnd, int modifiers){
5926 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5927 this.handle(IProblem.JavadocMissingProvidesClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
5928 }
5929 }
javadocMissingProvidesTag(TypeReference typeRef, int sourceStart, int sourceEnd, int modifiers)5930 public void javadocMissingProvidesTag(TypeReference typeRef, int sourceStart, int sourceEnd, int modifiers){
5931 int severity = computeSeverity(IProblem.JavadocMissingProvidesTag);
5932 if (severity == ProblemSeverities.Ignore) return;
5933 boolean report = this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore;
5934 if (report) {
5935 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
5936 this.handle(
5937 IProblem.JavadocMissingProvidesTag,
5938 arguments,
5939 arguments,
5940 severity,
5941 sourceStart,
5942 sourceEnd);
5943 }
5944 }
javadocMissingReference(int sourceStart, int sourceEnd, int modifiers)5945 public void javadocMissingReference(int sourceStart, int sourceEnd, int modifiers){
5946 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers))
5947 this.handle(IProblem.JavadocMissingSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
5948 }
javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers)5949 public void javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers){
5950 boolean overriding = (modifiers & (ExtraCompilerModifiers.AccImplementing|ExtraCompilerModifiers.AccOverriding)) != 0;
5951 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
5952 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
5953 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
5954 this.handle(IProblem.JavadocMissingReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
5955 }
5956 }
javadocMissingTagDescription(char[] tokenName, int sourceStart, int sourceEnd, int modifiers)5957 public void javadocMissingTagDescription(char[] tokenName, int sourceStart, int sourceEnd, int modifiers) {
5958 int severity = computeSeverity(IProblem.JavadocMissingTagDescription);
5959 if (severity == ProblemSeverities.Ignore) return;
5960 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5961 String[] arguments = new String[] { new String(tokenName) };
5962 // use IProblem.JavadocEmptyReturnTag for all identified tags
5963 this.handle(IProblem.JavadocEmptyReturnTag, arguments, arguments, sourceStart, sourceEnd);
5964 }
5965 }
javadocMissingTagDescriptionAfterReference(int sourceStart, int sourceEnd, int modifiers)5966 public void javadocMissingTagDescriptionAfterReference(int sourceStart, int sourceEnd, int modifiers){
5967 int severity = computeSeverity(IProblem.JavadocMissingTagDescription);
5968 if (severity == ProblemSeverities.Ignore) return;
5969 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5970 this.handle(IProblem.JavadocMissingTagDescription, NoArgument, NoArgument, severity, sourceStart, sourceEnd);
5971 }
5972 }
javadocMissingThrowsClassName(int sourceStart, int sourceEnd, int modifiers)5973 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd, int modifiers){
5974 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5975 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
5976 }
5977 }
javadocMissingThrowsTag(TypeReference typeRef, int modifiers)5978 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers){
5979 int severity = computeSeverity(IProblem.JavadocMissingThrowsTag);
5980 if (severity == ProblemSeverities.Ignore) return;
5981 boolean overriding = (modifiers & (ExtraCompilerModifiers.AccImplementing|ExtraCompilerModifiers.AccOverriding)) != 0;
5982 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
5983 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
5984 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
5985 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
5986 this.handle(
5987 IProblem.JavadocMissingThrowsTag,
5988 arguments,
5989 arguments,
5990 severity,
5991 typeRef.sourceStart,
5992 typeRef.sourceEnd);
5993 }
5994 }
javadocMissingUsesClassName(int sourceStart, int sourceEnd, int modifiers)5995 public void javadocMissingUsesClassName(int sourceStart, int sourceEnd, int modifiers){
5996 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
5997 this.handle(IProblem.JavadocMissingUsesClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
5998 }
5999 }
6000
javadocMissingUsesTag(TypeReference typeRef, int sourceStart, int sourceEnd, int modifiers)6001 public void javadocMissingUsesTag(TypeReference typeRef, int sourceStart, int sourceEnd, int modifiers){
6002 int severity = computeSeverity(IProblem.JavadocMissingUsesTag);
6003 if (severity == ProblemSeverities.Ignore) return;
6004 boolean report = this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore;
6005 if (report) {
6006 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
6007 this.handle(
6008 IProblem.JavadocMissingUsesTag,
6009 arguments,
6010 arguments,
6011 severity,
6012 sourceStart,
6013 sourceEnd);
6014 }
6015 }
javadocUndeclaredParamTagName(char[] token, int sourceStart, int sourceEnd, int modifiers)6016 public void javadocUndeclaredParamTagName(char[] token, int sourceStart, int sourceEnd, int modifiers) {
6017 int severity = computeSeverity(IProblem.JavadocInvalidParamName);
6018 if (severity == ProblemSeverities.Ignore) return;
6019 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
6020 String[] arguments = new String[] {String.valueOf(token)};
6021 this.handle(
6022 IProblem.JavadocInvalidParamName,
6023 arguments,
6024 arguments,
6025 severity,
6026 sourceStart,
6027 sourceEnd);
6028 }
6029 }
6030
javadocUnexpectedTag(int sourceStart, int sourceEnd)6031 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
6032 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument, sourceStart, sourceEnd);
6033 }
6034
javadocUnexpectedText(int sourceStart, int sourceEnd)6035 public void javadocUnexpectedText(int sourceStart, int sourceEnd) {
6036 this.handle(IProblem.JavadocUnexpectedText, NoArgument, NoArgument, sourceStart, sourceEnd);
6037 }
6038
javadocUnterminatedInlineTag(int sourceStart, int sourceEnd)6039 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
6040 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument, NoArgument, sourceStart, sourceEnd);
6041 }
6042
javadocVisibility(int visibility, int modifiers)6043 private boolean javadocVisibility(int visibility, int modifiers) {
6044 if (modifiers < 0) return true;
6045 switch (modifiers & ExtraCompilerModifiers.AccVisibilityMASK) {
6046 case ClassFileConstants.AccPublic :
6047 return true;
6048 case ClassFileConstants.AccProtected:
6049 return (visibility != ClassFileConstants.AccPublic);
6050 case ClassFileConstants.AccDefault:
6051 return (visibility == ClassFileConstants.AccDefault || visibility == ClassFileConstants.AccPrivate);
6052 case ClassFileConstants.AccPrivate:
6053 return (visibility == ClassFileConstants.AccPrivate);
6054 }
6055 return true;
6056 }
6057
javadocVisibilityArgument(int visibility, int modifiers)6058 private String javadocVisibilityArgument(int visibility, int modifiers) {
6059 String argument = null;
6060 switch (modifiers & ExtraCompilerModifiers.AccVisibilityMASK) {
6061 case ClassFileConstants.AccPublic :
6062 argument = CompilerOptions.PUBLIC;
6063 break;
6064 case ClassFileConstants.AccProtected:
6065 if (visibility != ClassFileConstants.AccPublic) {
6066 argument = CompilerOptions.PROTECTED;
6067 }
6068 break;
6069 case ClassFileConstants.AccDefault:
6070 if (visibility == ClassFileConstants.AccDefault || visibility == ClassFileConstants.AccPrivate) {
6071 argument = CompilerOptions.DEFAULT;
6072 }
6073 break;
6074 case ClassFileConstants.AccPrivate:
6075 if (visibility == ClassFileConstants.AccPrivate) {
6076 argument = CompilerOptions.PRIVATE;
6077 }
6078 break;
6079 }
6080 return argument;
6081 }
6082
localVariableHiding(LocalDeclaration local, Binding hiddenVariable, boolean isSpecialArgHidingField)6083 public void localVariableHiding(LocalDeclaration local, Binding hiddenVariable, boolean isSpecialArgHidingField) {
6084 if (hiddenVariable instanceof LocalVariableBinding) {
6085 int id = (local instanceof Argument)
6086 ? IProblem.ArgumentHidingLocalVariable
6087 : IProblem.LocalVariableHidingLocalVariable;
6088 int severity = computeSeverity(id);
6089 if (severity == ProblemSeverities.Ignore) return;
6090 String[] arguments = new String[] {new String(local.name) };
6091 this.handle(
6092 id,
6093 arguments,
6094 arguments,
6095 severity,
6096 nodeSourceStart(hiddenVariable, local),
6097 nodeSourceEnd(hiddenVariable, local));
6098 } else if (hiddenVariable instanceof FieldBinding) {
6099 if (isSpecialArgHidingField && !this.options.reportSpecialParameterHidingField){
6100 return;
6101 }
6102 int id = (local instanceof Argument)
6103 ? IProblem.ArgumentHidingField
6104 : IProblem.LocalVariableHidingField;
6105 int severity = computeSeverity(id);
6106 if (severity == ProblemSeverities.Ignore) return;
6107 FieldBinding field = (FieldBinding) hiddenVariable;
6108 this.handle(
6109 id,
6110 new String[] {new String(local.name) , new String(field.declaringClass.readableName()) },
6111 new String[] {new String(local.name), new String(field.declaringClass.shortReadableName()) },
6112 severity,
6113 local.sourceStart,
6114 local.sourceEnd);
6115 }
6116 }
6117
localVariableNonNullComparedToNull(LocalVariableBinding local, ASTNode location)6118 public void localVariableNonNullComparedToNull(LocalVariableBinding local, ASTNode location) {
6119 int severity = computeSeverity(IProblem.NonNullLocalVariableComparisonYieldsFalse);
6120 if (severity == ProblemSeverities.Ignore) return;
6121 String[] arguments;
6122 int problemId;
6123 if (local.isNonNull()) {
6124 char[][] annotationName = this.options.nonNullAnnotationName; // cannot be null if local is declared @NonNull
6125 arguments = new String[] {new String(local.name), new String(annotationName[annotationName.length-1]) };
6126 problemId = IProblem.SpecdNonNullLocalVariableComparisonYieldsFalse;
6127 } else {
6128 arguments = new String[] {new String(local.name) };
6129 problemId = IProblem.NonNullLocalVariableComparisonYieldsFalse;
6130 }
6131 this.handle(
6132 problemId,
6133 arguments,
6134 arguments,
6135 severity,
6136 nodeSourceStart(local, location),
6137 nodeSourceEnd(local, location));
6138 }
6139
localVariableNullComparedToNonNull(LocalVariableBinding local, ASTNode location)6140 public void localVariableNullComparedToNonNull(LocalVariableBinding local, ASTNode location) {
6141 int severity = computeSeverity(IProblem.NullLocalVariableComparisonYieldsFalse);
6142 if (severity == ProblemSeverities.Ignore) return;
6143 String[] arguments = new String[] {new String(local.name) };
6144 this.handle(
6145 IProblem.NullLocalVariableComparisonYieldsFalse,
6146 arguments,
6147 arguments,
6148 severity,
6149 nodeSourceStart(local, location),
6150 nodeSourceEnd(local, location));
6151 }
6152
6153 /**
6154 * @param expr expression being compared for null or nonnull
6155 * @param checkForNull true if checking for null, false if checking for nonnull
6156 */
expressionNonNullComparison(Expression expr, boolean checkForNull)6157 public boolean expressionNonNullComparison(Expression expr, boolean checkForNull) {
6158 int problemId = 0;
6159 Binding binding = null;
6160 String[] arguments = null;
6161 int start = 0, end = 0;
6162 Expression location = expr;
6163
6164 if (expr.resolvedType != null) {
6165 long tagBits = expr.resolvedType.tagBits & TagBits.AnnotationNullMASK;
6166 if (tagBits == TagBits.AnnotationNonNull) {
6167 problemId = IProblem.RedundantNullCheckAgainstNonNullType;
6168 arguments = new String[] { String.valueOf(expr.resolvedType.nullAnnotatedReadableName(this.options, true)) };
6169 start = nodeSourceStart(location);
6170 end = nodeSourceEnd(location);
6171 handle(problemId, arguments, arguments, start, end);
6172 return true;
6173 }
6174 }
6175 // unwrap uninteresting nodes:
6176 while (true) {
6177 if (expr instanceof Assignment)
6178 return false; // don't report against the assignment, but the variable
6179 else if (expr instanceof CastExpression)
6180 expr = ((CastExpression) expr).expression;
6181 else
6182 break;
6183 }
6184 // check all those kinds of expressions that can possible answer NON_NULL from nullStatus():
6185 if (expr instanceof MessageSend) {
6186 problemId = checkForNull
6187 ? IProblem.NonNullMessageSendComparisonYieldsFalse
6188 : IProblem.RedundantNullCheckOnNonNullMessageSend;
6189 MethodBinding method = ((MessageSend)expr).binding;
6190 binding = method;
6191 arguments = new String[] { new String(method.shortReadableName()) };
6192 start = location.sourceStart;
6193 end = location.sourceEnd;
6194 } else if (expr instanceof Reference && !(expr instanceof ThisReference) && !(expr instanceof ArrayReference)) {
6195 FieldBinding field = ((Reference)expr).lastFieldBinding();
6196 if (field == null) {
6197 return false;
6198 }
6199 if (field.isNonNull()) {
6200 problemId = checkForNull
6201 ? IProblem.NonNullSpecdFieldComparisonYieldsFalse
6202 : IProblem.RedundantNullCheckOnNonNullSpecdField;
6203 char[][] nonNullName = this.options.nonNullAnnotationName;
6204 arguments = new String[] { new String(field.name),
6205 new String(nonNullName[nonNullName.length-1]) };
6206 } else if (field.constant() != Constant.NotAConstant) {
6207 problemId = checkForNull ? IProblem.ConstNonNullFieldComparisonYieldsFalse : IProblem.RedundantNullCheckOnConstNonNullField;
6208 char[][] nonNullName = this.options.nonNullAnnotationName;
6209 arguments = new String[] { new String(field.name),
6210 new String(nonNullName[nonNullName.length-1]) };
6211 } else {
6212 // signaling redundancy based on syntactic analysis:
6213 problemId = checkForNull
6214 ? IProblem.FieldComparisonYieldsFalse
6215 : IProblem.RedundantNullCheckOnField;
6216 arguments = new String[] { String.valueOf(field.name)};
6217 }
6218 binding = field;
6219 start = nodeSourceStart(binding, location);
6220 end = nodeSourceEnd(binding, location);
6221 } else if (expr instanceof AllocationExpression
6222 || expr instanceof ArrayAllocationExpression
6223 || expr instanceof ArrayInitializer
6224 || expr instanceof ClassLiteralAccess
6225 || expr instanceof ThisReference) {
6226 // fall through to bottom
6227 } else if (expr instanceof Literal
6228 || expr instanceof ConditionalExpression
6229 || expr instanceof SwitchExpression) {
6230 if (expr instanceof NullLiteral) {
6231 needImplementation(location); // reported as nonnull??
6232 return false;
6233 }
6234 if (expr.resolvedType != null && expr.resolvedType.isBaseType()) {
6235 // false alarm, auto(un)boxing is involved
6236 return false;
6237 }
6238 // fall through to bottom
6239 } else if (expr instanceof BinaryExpression) {
6240 if ((expr.bits & ASTNode.ReturnTypeIDMASK) != TypeIds.T_JavaLangString) {
6241 // false alarm, primitive types involved, must be auto(un)boxing?
6242 return false;
6243 }
6244 // fall through to bottom
6245 } else {
6246 needImplementation(expr); // want to see if we get here
6247 return false;
6248 }
6249 if (problemId == 0) {
6250 // standard case, fill in details now
6251 problemId = checkForNull
6252 ? IProblem.NonNullExpressionComparisonYieldsFalse
6253 : IProblem.RedundantNullCheckOnNonNullExpression;
6254 start = location.sourceStart;
6255 end = location.sourceEnd;
6256 arguments = NoArgument;
6257 }
6258 this.handle(problemId, arguments, arguments, start, end);
6259 return true;
6260 }
nullAnnotationUnsupportedLocation(Annotation annotation)6261 public void nullAnnotationUnsupportedLocation(Annotation annotation) {
6262 String[] arguments = new String[] {
6263 String.valueOf(annotation.resolvedType.readableName())
6264 };
6265 String[] shortArguments = new String[] {
6266 String.valueOf(annotation.resolvedType.shortReadableName())
6267 };
6268 int severity = ProblemSeverities.Error | ProblemSeverities.Fatal;
6269 if (annotation.recipient instanceof ReferenceBinding) {
6270 if (((ReferenceBinding) annotation.recipient).isAnnotationType())
6271 severity = ProblemSeverities.Warning; // special case for https://bugs.eclipse.org/461878
6272 }
6273 handle(IProblem.NullAnnotationUnsupportedLocation,
6274 arguments, shortArguments,
6275 severity,
6276 annotation.sourceStart, annotation.sourceEnd);
6277 }
nullAnnotationAtQualifyingType(Annotation annotation)6278 public void nullAnnotationAtQualifyingType(Annotation annotation) {
6279 String[] arguments = new String[] {
6280 String.valueOf(annotation.resolvedType.readableName())
6281 };
6282 String[] shortArguments = new String[] {
6283 String.valueOf(annotation.resolvedType.shortReadableName())
6284 };
6285 int severity = ProblemSeverities.Error | ProblemSeverities.Fatal;
6286 handle(IProblem.NullAnnotationAtQualifyingType,
6287 arguments, shortArguments,
6288 severity,
6289 annotation.sourceStart, annotation.sourceEnd);
6290 }
nullAnnotationUnsupportedLocation(TypeReference type)6291 public void nullAnnotationUnsupportedLocation(TypeReference type) {
6292 int sourceEnd = type.sourceEnd;
6293 if (type instanceof ParameterizedSingleTypeReference) {
6294 ParameterizedSingleTypeReference typeReference = (ParameterizedSingleTypeReference) type;
6295 TypeReference[] typeArguments = typeReference.typeArguments;
6296 if (typeArguments[typeArguments.length - 1].sourceEnd > typeReference.sourceEnd) {
6297 sourceEnd = retrieveClosingAngleBracketPosition(typeReference.sourceEnd);
6298 } else {
6299 sourceEnd = type.sourceEnd;
6300 }
6301 } else if (type instanceof ParameterizedQualifiedTypeReference) {
6302 ParameterizedQualifiedTypeReference typeReference = (ParameterizedQualifiedTypeReference) type;
6303 sourceEnd = retrieveClosingAngleBracketPosition(typeReference.sourceEnd);
6304 } else {
6305 sourceEnd = type.sourceEnd;
6306 }
6307
6308 handle(IProblem.NullAnnotationUnsupportedLocationAtType,
6309 NoArgument, NoArgument, type.sourceStart, sourceEnd);
6310 }
localVariableNullInstanceof(LocalVariableBinding local, ASTNode location)6311 public void localVariableNullInstanceof(LocalVariableBinding local, ASTNode location) {
6312 int severity = computeSeverity(IProblem.NullLocalVariableInstanceofYieldsFalse);
6313 if (severity == ProblemSeverities.Ignore) return;
6314 String[] arguments = new String[] {new String(local.name) };
6315 this.handle(
6316 IProblem.NullLocalVariableInstanceofYieldsFalse,
6317 arguments,
6318 arguments,
6319 severity,
6320 nodeSourceStart(local, location),
6321 nodeSourceEnd(local, location));
6322 }
6323
localVariableNullReference(LocalVariableBinding local, ASTNode location)6324 public void localVariableNullReference(LocalVariableBinding local, ASTNode location) {
6325 if (location instanceof Expression && ((Expression) location).isTrulyExpression() &&
6326 (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
6327 nullUnboxing(location, local.type);
6328 return;
6329 }
6330 int severity = computeSeverity(IProblem.NullLocalVariableReference);
6331 if (severity == ProblemSeverities.Ignore) return;
6332 String[] arguments = new String[] {new String(local.name) };
6333 this.handle(
6334 IProblem.NullLocalVariableReference,
6335 arguments,
6336 arguments,
6337 severity,
6338 nodeSourceStart(local, location),
6339 nodeSourceEnd(local, location));
6340 }
6341
fieldFreeTypeVariableReference(FieldBinding variable, long position)6342 public void fieldFreeTypeVariableReference(FieldBinding variable, long position) {
6343 char[][] nullableName = this.options.nullableAnnotationName;
6344 String[] arguments = new String[] {new String(variable.type.readableName()),
6345 new String(nullableName[nullableName.length-1])};
6346 this.handle(
6347 IProblem.UncheckedAccessOfValueOfFreeTypeVariable,
6348 arguments,
6349 arguments,
6350 (int)(position >>> 32),
6351 (int)position);
6352 }
6353
6354
localVariableFreeTypeVariableReference(LocalVariableBinding local, ASTNode location)6355 public void localVariableFreeTypeVariableReference(LocalVariableBinding local, ASTNode location) {
6356 int severity = computeSeverity(IProblem.UncheckedAccessOfValueOfFreeTypeVariable);
6357 if (severity == ProblemSeverities.Ignore) return;
6358 char[][] nullableName = this.options.nullableAnnotationName;
6359 String[] arguments = new String[] {new String(local.type.readableName()),
6360 new String(nullableName[nullableName.length-1])};
6361 this.handle(
6362 IProblem.UncheckedAccessOfValueOfFreeTypeVariable,
6363 arguments,
6364 arguments,
6365 severity,
6366 nodeSourceStart(local, location),
6367 nodeSourceEnd(local, location));
6368 }
6369
methodReturnTypeFreeTypeVariableReference(MethodBinding method, ASTNode location)6370 public void methodReturnTypeFreeTypeVariableReference(MethodBinding method, ASTNode location) {
6371 int severity = computeSeverity(IProblem.UncheckedAccessOfValueOfFreeTypeVariable);
6372 if (severity == ProblemSeverities.Ignore) return;
6373 char[][] nullableName = this.options.nullableAnnotationName;
6374 String[] arguments = new String[] {new String(method.returnType.readableName()),
6375 new String(nullableName[nullableName.length-1])};
6376 this.handle(
6377 IProblem.UncheckedAccessOfValueOfFreeTypeVariable,
6378 arguments,
6379 arguments,
6380 location.sourceStart,
6381 location.sourceEnd);
6382 }
6383
6384
localVariablePotentialNullReference(LocalVariableBinding local, ASTNode location)6385 public void localVariablePotentialNullReference(LocalVariableBinding local, ASTNode location) {
6386 if(local.type.isFreeTypeVariable()) {
6387 localVariableFreeTypeVariableReference(local, location);
6388 return;
6389 }
6390 if (location instanceof Expression && ((Expression) location).isTrulyExpression()
6391 && (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
6392 potentialNullUnboxing(location, local.type);
6393 return;
6394 }
6395 if ((local.type.tagBits & TagBits.AnnotationNullable) != 0 && location instanceof Expression
6396 && ((Expression) location).isTrulyExpression()) {
6397 dereferencingNullableExpression((Expression) location);
6398 return;
6399 }
6400 int severity = computeSeverity(IProblem.PotentialNullLocalVariableReference);
6401 if (severity == ProblemSeverities.Ignore) return;
6402 String[] arguments = new String[] {new String(local.name)};
6403 this.handle(
6404 IProblem.PotentialNullLocalVariableReference,
6405 arguments,
6406 arguments,
6407 severity,
6408 nodeSourceStart(local, location),
6409 nodeSourceEnd(local, location));
6410 }
potentialNullUnboxing(ASTNode expression, TypeBinding boxType)6411