1 /**********************************************************************
2 Copyright (c) 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v0.5
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v05.html
9 IBM Corporation - initial API and implementation
10 **********************************************************************/
12 package net.sourceforge.phpdt.core.compiler;
14 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
17 * Description of a Java problem, as detected by the compiler or some of the underlying
18 * technology reusing the compiler.
19 * A problem provides access to:
21 * <li> its location (originating source file name, source position, line number), </li>
22 * <li> its message description and a predicate to check its severity (warning or error). </li>
23 * <li> its ID : an number identifying the very nature of this problem. All possible IDs are listed
24 * as constants on this interface. </li>
27 * Note: the compiler produces IProblems internally, which are turned into markers by the JavaBuilder
28 * so as to persist problem descriptions. This explains why there is no API allowing to reach IProblem detected
29 * when compiling. However, the Java problem markers carry equivalent information to IProblem, in particular
30 * their ID (attribute "id") is set to one of the IDs defined on this interface.
34 public interface IProblem {
37 * Answer back the original arguments recorded into the problem.
38 * @return the original arguments recorded into the problem
40 String[] getArguments();
43 * Returns the problem id
45 * @return the problem id
50 * Answer a localized, human-readable message string which describes the problem.
52 * @return a localized, human-readable message string which describes the problem
57 * Answer the file name in which the problem was found.
59 * @return the file name in which the problem was found
61 char[] getOriginatingFileName();
64 * Answer the end position of the problem (inclusive), or -1 if unknown.
66 * @return the end position of the problem (inclusive), or -1 if unknown
71 * Answer the line number in source where the problem begins.
73 * @return the line number in source where the problem begins
75 int getSourceLineNumber();
78 * Answer the start position of the problem (inclusive), or -1 if unknown.
80 * @return the start position of the problem (inclusive), or -1 if unknown
85 * Checks the severity to see if the Error bit is set.
87 * @return true if the Error bit is set for the severity, false otherwise
92 * Checks the severity to see if the Error bit is not set.
94 * @return true if the Error bit is not set for the severity, false otherwise
99 * Set the end position of the problem (inclusive), or -1 if unknown.
100 * Used for shifting problem positions.
102 * @param sourceEnd the given end position
104 void setSourceEnd(int sourceEnd);
107 * Set the line number in source where the problem begins.
109 * @param lineNumber the given line number
111 void setSourceLineNumber(int lineNumber);
114 * Set the start position of the problem (inclusive), or -1 if unknown.
115 * Used for shifting problem positions.
117 * @param the given start position
119 void setSourceStart(int sourceStart);
123 * The high bits of a problem ID contains information about the category of a problem.
124 * e.g. (problemID & TypeRelated) != 0, indicates that this problem is type related.
126 * A problem category can help to implement custom problem filters. Indeed, when numerous problems
127 * are listed, focusing on import related problems first might be relevant.
129 * When a problem is tagged as Internal, it means that no change other than a local source code change
130 * can fix the corresponding problem.
132 int TypeRelated = 0x01000000;
133 int FieldRelated = 0x02000000;
134 int MethodRelated = 0x04000000;
135 int ConstructorRelated = 0x08000000;
136 int ImportRelated = 0x10000000;
137 int Internal = 0x20000000;
138 int Syntax = 0x40000000;
141 * Mask to use in order to filter out the category portion of the problem ID.
143 int IgnoreCategoriesMask = 0xFFFFFF;
146 * Below are listed all available problem IDs. Note that this list could be augmented in the future,
147 * as new features are added to the Java core implementation.
151 * ID reserved for referencing an internal error inside the JavaCore implementation which
152 * may be surfaced as a problem associated with the compilation unit which caused it to occur.
154 int Unclassified = 0;
157 * Generic type related problems
159 int ObjectHasNoSuperclass = TypeRelated + 1;
160 int UndefinedType = TypeRelated + 2;
161 int NotVisibleType = TypeRelated + 3;
162 int AmbiguousType = TypeRelated + 4;
163 int UsingDeprecatedType = TypeRelated + 5;
164 int InternalTypeNameProvided = TypeRelated + 6;
166 int IncompatibleTypesInEqualityOperator = TypeRelated + 15;
167 int IncompatibleTypesInConditionalOperator = TypeRelated + 16;
168 int TypeMismatch = TypeRelated + 17;
171 * Inner types related problems
173 int MissingEnclosingInstanceForConstructorCall = TypeRelated + 20;
174 int MissingEnclosingInstance = TypeRelated + 21;
175 int IncorrectEnclosingInstanceReference = TypeRelated + 22;
176 int IllegalEnclosingInstanceSpecification = TypeRelated + 23;
177 int CannotDefineStaticInitializerInLocalType = Internal + 24;
178 int OuterLocalMustBeFinal = Internal + 25;
179 int CannotDefineInterfaceInLocalType = Internal + 26;
180 int IllegalPrimitiveOrArrayTypeForEnclosingInstance = TypeRelated + 27;
181 int AnonymousClassCannotExtendFinalClass = TypeRelated + 29;
184 int UndefinedName = 50;
185 int UninitializedLocalVariable = Internal + 51;
186 int VariableTypeCannotBeVoid = Internal + 52;
187 int VariableTypeCannotBeVoidArray = Internal + 53;
188 int CannotAllocateVoidArray = Internal + 54;
190 int RedefinedLocal = Internal + 55;
191 int RedefinedArgument = Internal + 56;
192 int DuplicateFinalLocalInitialization = Internal + 57;
193 // final local variables
194 int FinalOuterLocalAssignment = Internal + 60;
195 int LocalVariableIsNeverUsed = Internal + 61;
196 int ArgumentIsNeverUsed = Internal + 62;
197 int BytecodeExceeds64KLimit = Internal + 63;
198 int BytecodeExceeds64KLimitForClinit = Internal + 64;
199 int TooManyArgumentSlots = Internal + 65;
200 int TooManyLocalVariableSlots = Internal + 66;
203 int UndefinedField = FieldRelated + 70;
204 int NotVisibleField = FieldRelated + 71;
205 int AmbiguousField = FieldRelated + 72;
206 int UsingDeprecatedField = FieldRelated + 73;
207 int NonStaticFieldFromStaticInvocation = FieldRelated + 74;
208 int ReferenceToForwardField = FieldRelated + Internal + 75;
210 // blank final fields
211 int FinalFieldAssignment = FieldRelated + 80;
212 int UninitializedBlankFinalField = FieldRelated + 81;
213 int DuplicateBlankFinalFieldInitialization = FieldRelated + 82;
216 int UndefinedMethod = MethodRelated + 100;
217 int NotVisibleMethod = MethodRelated + 101;
218 int AmbiguousMethod = MethodRelated + 102;
219 int UsingDeprecatedMethod = MethodRelated + 103;
220 int DirectInvocationOfAbstractMethod = MethodRelated + 104;
221 int VoidMethodReturnsValue = MethodRelated + 105;
222 int MethodReturnsVoid = MethodRelated + 106;
223 int MethodRequiresBody = Internal + MethodRelated + 107;
224 int ShouldReturnValue = Internal + MethodRelated + 108;
225 int MethodButWithConstructorName = MethodRelated + 110;
226 int MissingReturnType = TypeRelated + 111;
227 int BodyForNativeMethod = Internal + MethodRelated + 112;
228 int BodyForAbstractMethod = Internal + MethodRelated + 113;
229 int NoMessageSendOnBaseType = MethodRelated + 114;
230 int ParameterMismatch = MethodRelated + 115;
231 int NoMessageSendOnArrayType = MethodRelated + 116;
234 int UndefinedConstructor = ConstructorRelated + 130;
235 int NotVisibleConstructor = ConstructorRelated + 131;
236 int AmbiguousConstructor = ConstructorRelated + 132;
237 int UsingDeprecatedConstructor = ConstructorRelated + 133;
238 // explicit constructor calls
239 int InstanceFieldDuringConstructorInvocation = ConstructorRelated + 135;
240 int InstanceMethodDuringConstructorInvocation = ConstructorRelated + 136;
241 int RecursiveConstructorInvocation = ConstructorRelated + 137;
242 int ThisSuperDuringConstructorInvocation = ConstructorRelated + 138;
243 // implicit constructor calls
244 int UndefinedConstructorInDefaultConstructor = ConstructorRelated + 140;
245 int NotVisibleConstructorInDefaultConstructor = ConstructorRelated + 141;
246 int AmbiguousConstructorInDefaultConstructor = ConstructorRelated + 142;
247 int UndefinedConstructorInImplicitConstructorCall = ConstructorRelated + 143;
248 int NotVisibleConstructorInImplicitConstructorCall = ConstructorRelated + 144;
249 int AmbiguousConstructorInImplicitConstructorCall = ConstructorRelated + 145;
250 int UnhandledExceptionInDefaultConstructor = TypeRelated + 146;
251 int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147;
254 int ArrayReferenceRequired = Internal + 150;
255 int NoImplicitStringConversionForCharArrayExpression = Internal + 151;
256 // constant expressions
257 int StringConstantIsExceedingUtf8Limit = Internal + 152;
258 int NonConstantExpression = 153;
259 int NumericValueOutOfRange = Internal + 154;
261 int IllegalCast = TypeRelated + 156;
263 int InvalidClassInstantiation = TypeRelated + 157;
264 int CannotDefineDimensionExpressionsWithInit = Internal + 158;
265 int MustDefineEitherDimensionExpressionsOrInitializer = Internal + 159;
267 int InvalidOperator = Internal + 160;
269 int CodeCannotBeReached = Internal + 161;
270 int CannotReturnInInitializer = Internal + 162;
271 int InitializerMustCompleteNormally = Internal + 163;
274 int InvalidVoidExpression = Internal + 164;
276 int MaskedCatch = TypeRelated + 165;
277 int DuplicateDefaultCase = 166;
278 int UnreachableCatch = TypeRelated + MethodRelated + 167;
279 int UnhandledException = TypeRelated + 168;
281 int IncorrectSwitchType = TypeRelated + 169;
282 int DuplicateCase = FieldRelated + 170;
284 int DuplicateLabel = Internal + 171;
285 int InvalidBreak = Internal + 172;
286 int InvalidContinue = Internal + 173;
287 int UndefinedLabel = Internal + 174;
289 int InvalidTypeToSynchronized = Internal + 175;
290 int InvalidNullToSynchronized = Internal + 176;
292 int CannotThrowNull = Internal + 177;
295 int NeedToEmulateFieldReadAccess = FieldRelated + 190;
296 int NeedToEmulateFieldWriteAccess = FieldRelated + 191;
297 int NeedToEmulateMethodAccess = MethodRelated + 192;
298 int NeedToEmulateConstructorAccess = MethodRelated + 193;
300 //inherited name hides enclosing name (sort of ambiguous)
301 int InheritedMethodHidesEnclosingName = MethodRelated + 195;
302 int InheritedFieldHidesEnclosingName = FieldRelated + 196;
303 int InheritedTypeHidesEnclosingName = TypeRelated + 197;
306 int ThisInStaticContext = Internal + 200;
307 int StaticMethodRequested = Internal + MethodRelated + 201;
308 int IllegalDimension = Internal + 202;
309 int InvalidTypeExpression = Internal + 203;
310 int ParsingError = Syntax + Internal + 204;
311 int ParsingErrorNoSuggestion = Syntax + Internal + 205;
312 int InvalidUnaryExpression = Syntax + Internal + 206;
315 int InterfaceCannotHaveConstructors = Syntax + Internal + 207;
316 int ArrayConstantsOnlyInArrayInitializers = Syntax + Internal + 208;
317 int ParsingErrorOnKeyword = Syntax + Internal + 209;
318 int ParsingErrorOnKeywordNoSuggestion = Syntax + Internal + 210;
320 int UnmatchedBracket = Syntax + Internal + 220;
321 int NoFieldOnBaseType = FieldRelated + 221;
322 int InvalidExpressionAsStatement = Syntax + Internal + 222;
325 int EndOfSource = Syntax + Internal + 250;
326 int InvalidHexa = Syntax + Internal + 251;
327 int InvalidOctal = Syntax + Internal + 252;
328 int InvalidCharacterConstant = Syntax + Internal + 253;
329 int InvalidEscape = Syntax + Internal + 254;
330 int InvalidInput = Syntax + Internal + 255;
331 int InvalidUnicodeEscape = Syntax + Internal + 256;
332 int InvalidFloat = Syntax + Internal + 257;
333 int NullSourceString = Syntax + Internal + 258;
334 int UnterminatedString = Syntax + Internal + 259;
335 int UnterminatedComment = Syntax + Internal + 260;
337 // type related problems
338 int InterfaceCannotHaveInitializers = TypeRelated + 300;
339 int DuplicateModifierForType = TypeRelated + 301;
340 int IllegalModifierForClass = TypeRelated + 302;
341 int IllegalModifierForInterface = TypeRelated + 303;
342 int IllegalModifierForMemberClass = TypeRelated + 304;
343 int IllegalModifierForMemberInterface = TypeRelated + 305;
344 int IllegalModifierForLocalClass = TypeRelated + 306;
346 int IllegalModifierCombinationFinalAbstractForClass = TypeRelated + 308;
347 int IllegalVisibilityModifierForInterfaceMemberType = TypeRelated + 309;
348 int IllegalVisibilityModifierCombinationForMemberType = TypeRelated + 310;
349 int IllegalStaticModifierForMemberType = TypeRelated + 311;
350 int SuperclassMustBeAClass = TypeRelated + 312;
351 int ClassExtendFinalClass = TypeRelated + 313;
352 int DuplicateSuperInterface = TypeRelated + 314;
353 int SuperInterfaceMustBeAnInterface = TypeRelated + 315;
354 int HierarchyCircularitySelfReference = TypeRelated + 316;
355 int HierarchyCircularity = TypeRelated + 317;
356 int HidingEnclosingType = TypeRelated + 318;
357 int DuplicateNestedType = TypeRelated + 319;
358 int CannotThrowType = TypeRelated + 320;
359 int PackageCollidesWithType = TypeRelated + 321;
360 int TypeCollidesWithPackage = TypeRelated + 322;
361 int DuplicateTypes = TypeRelated + 323;
362 int IsClassPathCorrect = TypeRelated + 324;
363 int PublicClassMustMatchFileName = TypeRelated + 325;
364 int MustSpecifyPackage = 326;
365 int HierarchyHasProblems = TypeRelated + 327;
366 int PackageIsNotExpectedPackage = 328;
368 // int InvalidSuperclassBase = TypeRelated + 329; // reserved to 334 included
369 int SuperclassNotFound = TypeRelated + 329 + ProblemReasons.NotFound; // TypeRelated + 330
370 int SuperclassNotVisible = TypeRelated + 329 + ProblemReasons.NotVisible; // TypeRelated + 331
371 int SuperclassAmbiguous = TypeRelated + 329 + ProblemReasons.Ambiguous; // TypeRelated + 332
372 int SuperclassInternalNameProvided = TypeRelated + 329 + ProblemReasons.InternalNameProvided; // TypeRelated + 333
373 int SuperclassInheritedNameHidesEnclosingName = TypeRelated + 329 + ProblemReasons.InheritedNameHidesEnclosingName; // TypeRelated + 334
375 // int InvalidInterfaceBase = TypeRelated + 334; // reserved to 339 included
376 int InterfaceNotFound = TypeRelated + 334 + ProblemReasons.NotFound; // TypeRelated + 335
377 int InterfaceNotVisible = TypeRelated + 334 + ProblemReasons.NotVisible; // TypeRelated + 336
378 int InterfaceAmbiguous = TypeRelated + 334 + ProblemReasons.Ambiguous; // TypeRelated + 337
379 int InterfaceInternalNameProvided = TypeRelated + 334 + ProblemReasons.InternalNameProvided; // TypeRelated + 338
380 int InterfaceInheritedNameHidesEnclosingName = TypeRelated + 334 + ProblemReasons.InheritedNameHidesEnclosingName; // TypeRelated + 339
382 // field related problems
383 int DuplicateField = FieldRelated + 340;
384 int DuplicateModifierForField = FieldRelated + 341;
385 int IllegalModifierForField = FieldRelated + 342;
386 int IllegalModifierForInterfaceField = FieldRelated + 343;
387 int IllegalVisibilityModifierCombinationForField = FieldRelated + 344;
388 int IllegalModifierCombinationFinalVolatileForField = FieldRelated + 345;
389 int UnexpectedStaticModifierForField = FieldRelated + 346;
391 // int FieldTypeProblemBase = FieldRelated + 349; //reserved to 354
392 int FieldTypeNotFound = FieldRelated + 349 + ProblemReasons.NotFound; // FieldRelated + 350
393 int FieldTypeNotVisible = FieldRelated + 349 + ProblemReasons.NotVisible; // FieldRelated + 351
394 int FieldTypeAmbiguous = FieldRelated + 349 + ProblemReasons.Ambiguous; // FieldRelated + 352
395 int FieldTypeInternalNameProvided = FieldRelated + 349 + ProblemReasons.InternalNameProvided; // FieldRelated + 353
396 int FieldTypeInheritedNameHidesEnclosingName = FieldRelated + 349 + ProblemReasons.InheritedNameHidesEnclosingName; // FieldRelated + 354
398 // method related problems
399 int DuplicateMethod = MethodRelated + 355;
400 int IllegalModifierForArgument = MethodRelated + 356;
401 int DuplicateModifierForMethod = MethodRelated + 357;
402 int IllegalModifierForMethod = MethodRelated + 358;
403 int IllegalModifierForInterfaceMethod = MethodRelated + 359;
404 int IllegalVisibilityModifierCombinationForMethod = MethodRelated + 360;
405 int UnexpectedStaticModifierForMethod = MethodRelated + 361;
406 int IllegalAbstractModifierCombinationForMethod = MethodRelated + 362;
407 int AbstractMethodInAbstractClass = MethodRelated + 363;
408 int ArgumentTypeCannotBeVoid = MethodRelated + 364;
409 int ArgumentTypeCannotBeVoidArray = MethodRelated + 365;
410 int ReturnTypeCannotBeVoidArray = MethodRelated + 366;
411 int NativeMethodsCannotBeStrictfp = MethodRelated + 367;
412 int DuplicateModifierForArgument = MethodRelated + 368;
414 // int ArgumentProblemBase = MethodRelated + 369; // reserved to 374 included.
415 int ArgumentTypeNotFound = MethodRelated + 369 + ProblemReasons.NotFound; // MethodRelated + 370
416 int ArgumentTypeNotVisible = MethodRelated + 369 + ProblemReasons.NotVisible; // MethodRelated + 371
417 int ArgumentTypeAmbiguous = MethodRelated + 369 + ProblemReasons.Ambiguous; // MethodRelated + 372
418 int ArgumentTypeInternalNameProvided = MethodRelated + 369 + ProblemReasons.InternalNameProvided; // MethodRelated + 373
419 int ArgumentTypeInheritedNameHidesEnclosingName = MethodRelated + 369 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 374
421 // int ExceptionTypeProblemBase = MethodRelated + 374; // reserved to 379 included.
422 int ExceptionTypeNotFound = MethodRelated + 374 + ProblemReasons.NotFound; // MethodRelated + 375
423 int ExceptionTypeNotVisible = MethodRelated + 374 + ProblemReasons.NotVisible; // MethodRelated + 376
424 int ExceptionTypeAmbiguous = MethodRelated + 374 + ProblemReasons.Ambiguous; // MethodRelated + 377
425 int ExceptionTypeInternalNameProvided = MethodRelated + 374 + ProblemReasons.InternalNameProvided; // MethodRelated + 378
426 int ExceptionTypeInheritedNameHidesEnclosingName = MethodRelated + 374 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 379
428 // int ReturnTypeProblemBase = MethodRelated + 379;
429 int ReturnTypeNotFound = MethodRelated + 379 + ProblemReasons.NotFound; // MethodRelated + 380
430 int ReturnTypeNotVisible = MethodRelated + 379 + ProblemReasons.NotVisible; // MethodRelated + 381
431 int ReturnTypeAmbiguous = MethodRelated + 379 + ProblemReasons.Ambiguous; // MethodRelated + 382
432 int ReturnTypeInternalNameProvided = MethodRelated + 379 + ProblemReasons.InternalNameProvided; // MethodRelated + 383
433 int ReturnTypeInheritedNameHidesEnclosingName = MethodRelated + 379 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 384
435 // import related problems
436 int ConflictingImport = ImportRelated + 385;
437 int DuplicateImport = ImportRelated + 386;
438 int CannotImportPackage = ImportRelated + 387;
439 int UnusedImport = ImportRelated + 388;
441 // int ImportProblemBase = ImportRelated + 389;
442 int ImportNotFound = ImportRelated + 389 + ProblemReasons.NotFound; // ImportRelated + 390
443 int ImportNotVisible = ImportRelated + 389 + ProblemReasons.NotVisible; // ImportRelated + 391
444 int ImportAmbiguous = ImportRelated + 389 + ProblemReasons.Ambiguous; // ImportRelated + 392
445 int ImportInternalNameProvided = ImportRelated + 389 + ProblemReasons.InternalNameProvided; // ImportRelated + 393
446 int ImportInheritedNameHidesEnclosingName = ImportRelated + 389 + ProblemReasons.InheritedNameHidesEnclosingName; // ImportRelated + 394
449 // local variable related problems
450 int DuplicateModifierForVariable = MethodRelated + 395;
451 int IllegalModifierForVariable = MethodRelated + 396;
453 // method verifier problems
454 int AbstractMethodMustBeImplemented = MethodRelated + 400;
455 int FinalMethodCannotBeOverridden = MethodRelated + 401;
456 int IncompatibleExceptionInThrowsClause = MethodRelated + 402;
457 int IncompatibleExceptionInInheritedMethodThrowsClause = MethodRelated + 403;
458 int IncompatibleReturnType = MethodRelated + 404;
459 int InheritedMethodReducesVisibility = MethodRelated + 405;
460 int CannotOverrideAStaticMethodWithAnInstanceMethod = MethodRelated + 406;
461 int CannotHideAnInstanceMethodWithAStaticMethod = MethodRelated + 407;
462 int StaticInheritedMethodConflicts = MethodRelated + 408;
463 int MethodReducesVisibility = MethodRelated + 409;
464 int OverridingNonVisibleMethod = MethodRelated + 410;
465 int AbstractMethodCannotBeOverridden = MethodRelated + 411;
466 int OverridingDeprecatedMethod = MethodRelated + 412;
468 // code snippet support
469 int CodeSnippetMissingClass = Internal + 420;
470 int CodeSnippetMissingMethod = Internal + 421;
471 int NonExternalizedStringLiteral = Internal + 261;
472 int CannotUseSuperInCodeSnippet = Internal + 422;
475 int TooManyConstantsInConstantPool = Internal + 430;
479 int UseAssertAsAnIdentifier = Internal + 440;