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