1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
16 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
17 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
18 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
19 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
20 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
21 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
32 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
33 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
34 import net.sourceforge.phpdt.internal.compiler.util.Util;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
76 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
77 public ReferenceContext referenceContext;
78 public ProblemReporter(IErrorHandlingPolicy policy,
79 CompilerOptions options,
80 IProblemFactory problemFactory) {
82 // IProblemFactory problemFactory) {
83 super(policy, options, problemFactory); //), problemFactory);
85 public void abortDueToInternalError(String errorMessage) {
86 String[] arguments = new String[]{errorMessage};
87 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0,
90 public void abortDueToInternalError(String errorMessage, AstNode location) {
91 String[] arguments = new String[]{errorMessage};
92 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
93 location.sourceStart, location.sourceEnd);
95 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
96 MethodBinding concreteMethod) {
99 // %1 must be abstract since it cannot override the inherited
100 // package-private abstract method %2
101 IProblem.AbstractMethodCannotBeOverridden, new String[]{
102 new String(type.sourceName()),
103 new String(CharOperation.concat(concreteMethod.declaringClass
104 .readableName(), concreteMethod.readableName(), '.'))},
106 new String(type.sourceName()),
107 new String(CharOperation.concat(concreteMethod.declaringClass
108 .shortReadableName(), concreteMethod.shortReadableName(),
109 '.'))}, type.sourceStart(), type.sourceEnd());
111 public void abstractMethodInAbstractClass(SourceTypeBinding type,
112 AbstractMethodDeclaration methodDecl) {
113 String[] arguments = new String[]{new String(type.sourceName()),
114 new String(methodDecl.selector)};
115 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments,
116 methodDecl.sourceStart, methodDecl.sourceEnd);
118 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
119 MethodBinding abstractMethod) {
121 // Must implement the inherited abstract method %1
122 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
123 // must provide a concrete implementation of all of A's
125 IProblem.AbstractMethodMustBeImplemented, new String[]{new String(
126 CharOperation.concat(abstractMethod.declaringClass.readableName(),
127 abstractMethod.readableName(), '.'))},
128 new String[]{new String(CharOperation.concat(
129 abstractMethod.declaringClass.shortReadableName(), abstractMethod
130 .shortReadableName(), '.'))}, type.sourceStart(), type
133 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
134 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
135 method.sourceStart, method.sourceEnd, method, method
136 .compilationResult());
138 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
139 String[] arguments = new String[]{new String(labelName)};
140 this.handle(IProblem.DuplicateLabel, arguments, arguments,
141 location.sourceStart, location.sourceEnd);
143 public void anonymousClassCannotExtendFinalClass(Expression expression,
145 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
146 new String[]{new String(type.readableName())}, new String[]{new String(
147 type.shortReadableName())}, expression.sourceStart,
148 expression.sourceEnd);
150 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
151 AbstractMethodDeclaration methodDecl, Argument arg) {
152 String[] arguments = new String[]{new String(methodDecl.selector),
153 new String(arg.name)};
154 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
155 methodDecl.sourceStart, methodDecl.sourceEnd);
157 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
158 AbstractMethodDeclaration methodDecl, Argument arg) {
159 String[] arguments = new String[]{new String(methodDecl.selector),
160 new String(arg.name)};
161 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments,
162 methodDecl.sourceStart, methodDecl.sourceEnd);
164 public void argumentTypeProblem(SourceTypeBinding type,
165 AbstractMethodDeclaration methodDecl, Argument arg,
166 TypeBinding expectedType) {
167 int problemId = expectedType.problemId();
172 id = IProblem.ArgumentTypeNotFound;
176 id = IProblem.ArgumentTypeNotVisible;
180 id = IProblem.ArgumentTypeAmbiguous;
182 case InternalNameProvided :
184 id = IProblem.ArgumentTypeInternalNameProvided;
186 case InheritedNameHidesEnclosingName :
188 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
193 needImplementation(); // want to fail to see why we were
197 this.handle(id, new String[]{new String(methodDecl.selector), arg.name(),
198 new String(expectedType.readableName())}, new String[]{
199 new String(methodDecl.selector), arg.name(),
200 new String(expectedType.shortReadableName())}, arg.type.sourceStart,
203 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
205 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
206 NoArgument, sourceStart, sourceEnd);
208 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
209 String[] arguments = new String[]{new String(name)};
210 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
211 assignment.sourceStart, assignment.sourceEnd);
213 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement,
214 TypeBinding expectedType) {
215 this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String(
216 expectedType.readableName())}, new String[]{new String(expectedType
217 .shortReadableName())}, returnStatement.sourceStart,
218 returnStatement.sourceEnd);
220 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
221 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
222 returnStatement.sourceStart, returnStatement.sourceEnd);
224 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
226 // String[] arguments = new String[] {new String(location.selector),
227 // parametersAsString(location.binding)};
228 // if (location.isConstructor()) {
230 // IProblem.BytecodeExceeds64KLimitForConstructor,
234 // location.sourceStart,
235 // location.sourceEnd);
238 // IProblem.BytecodeExceeds64KLimit,
242 // location.sourceStart,
243 // location.sourceEnd);
246 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
247 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
248 NoArgument, Error | Abort, location.sourceStart, location.sourceEnd);
250 public void cannotAllocateVoidArray(Expression expression) {
251 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
252 expression.sourceStart, expression.sourceEnd);
254 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
255 this.handle(IProblem.FinalFieldAssignment, new String[]{
256 (field.declaringClass == null ? "array" : new String(
257 field.declaringClass.readableName())), //$NON-NLS-1$
258 new String(field.readableName())}, new String[]{
259 (field.declaringClass == null ? "array" : new String(
260 field.declaringClass.shortReadableName())), //$NON-NLS-1$
261 new String(field.shortReadableName())}, location.sourceStart,
264 public void cannotAssignToFinalLocal(LocalVariableBinding local,
266 String[] arguments = new String[]{new String(local.readableName())};
267 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments,
268 location.sourceStart, location.sourceEnd);
270 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
272 String[] arguments = new String[]{new String(local.readableName())};
273 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
274 location.sourceStart, location.sourceEnd);
276 public void cannotDeclareLocalInterface(char[] interfaceName,
277 int sourceStart, int sourceEnd) {
278 String[] arguments = new String[]{new String(interfaceName)};
279 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
280 arguments, sourceStart, sourceEnd);
282 public void cannotDefineDimensionsAndInitializer(
283 ArrayAllocationExpression expresssion) {
284 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument,
285 NoArgument, expresssion.sourceStart, expresssion.sourceEnd);
287 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
288 MethodBinding method) {
289 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{
290 new String(method.declaringClass.readableName()),
291 new String(method.selector), parametersAsString(method)}, new String[]{
292 new String(method.declaringClass.shortReadableName()),
293 new String(method.selector), parametersAsShortString(method)},
294 messageSend.sourceStart, messageSend.sourceEnd);
296 // public void cannotImportPackage(ImportReference importRef) {
297 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
298 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
299 // importRef.sourceStart, importRef.sourceEnd);
301 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
302 this.handle(IProblem.InvalidClassInstantiation, new String[]{new String(
303 type.readableName())},
304 new String[]{new String(type.shortReadableName())},
305 typeRef.sourceStart, typeRef.sourceEnd);
307 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
309 String[] arguments = new String[]{new String(local.readableName())};
310 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
311 location.sourceStart, location.sourceEnd);
313 public void cannotReturnInInitializer(AstNode location) {
314 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
315 location.sourceStart, location.sourceEnd);
317 public void cannotThrowNull(ThrowStatement statement) {
318 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
319 statement.sourceStart, statement.sourceEnd);
321 public void cannotThrowType(SourceTypeBinding type,
322 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
323 TypeBinding expectedType) {
324 this.handle(IProblem.CannotThrowType, new String[]{new String(expectedType
325 .readableName())}, new String[]{new String(expectedType
326 .shortReadableName())}, exceptionType.sourceStart,
327 exceptionType.sourceEnd);
329 public void cannotUseSuperInJavaLangObject(AstNode reference) {
330 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
331 reference.sourceStart, reference.sourceEnd);
333 public void cannotUseSuperInCodeSnippet(int start, int end) {
334 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument,
335 Error | Abort, start, end);
337 public void caseExpressionMustBeConstant(Expression expression) {
338 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
339 expression.sourceStart, expression.sourceEnd);
341 public void classExtendFinalClass(SourceTypeBinding type,
342 TypeReference superclass, TypeBinding expectedType) {
343 String name = new String(type.sourceName());
344 String expectedFullName = new String(expectedType.readableName());
345 String expectedShortName = new String(expectedType.shortReadableName());
346 if (expectedShortName.equals(name))
347 expectedShortName = expectedFullName;
348 this.handle(IProblem.ClassExtendFinalClass, new String[]{expectedFullName,
349 name}, new String[]{expectedShortName, name}, superclass.sourceStart,
350 superclass.sourceEnd);
352 public void codeSnippetMissingClass(String missing, int start, int end) {
353 String[] arguments = new String[]{missing};
354 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error
355 | Abort, start, end);
357 public void codeSnippetMissingMethod(String className, String missingMethod,
358 String argumentTypes, int start, int end) {
359 String[] arguments = new String[]{className, missingMethod, argumentTypes};
360 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error
361 | Abort, start, end);
364 * Given the current configuration, answers which category the problem
366 * Error | Warning | Ignore
368 public int computeSeverity(int problemId){
370 // severity can have been preset on the problem
371 // if ((problem.severity & Fatal) != 0){
375 // if not then check whether it is a configurable problem
377 case IProblem.PHPVarDeprecatedWarning :
378 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
380 case IProblem.MaskedCatch :
381 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
383 case IProblem.UnusedImport :
384 return this.options.getSeverity(CompilerOptions.UnusedImport);
386 case IProblem.MethodButWithConstructorName :
387 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
389 case IProblem.OverridingNonVisibleMethod :
390 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
392 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
393 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod :
394 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
396 case IProblem.OverridingDeprecatedMethod :
397 case IProblem.UsingDeprecatedType :
398 case IProblem.UsingDeprecatedMethod :
399 case IProblem.UsingDeprecatedConstructor :
400 case IProblem.UsingDeprecatedField :
401 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
403 case IProblem.LocalVariableIsNeverUsed :
404 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
406 case IProblem.ArgumentIsNeverUsed :
407 return this.options.getSeverity(CompilerOptions.UnusedArgument);
409 case IProblem.NoImplicitStringConversionForCharArrayExpression :
410 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
412 case IProblem.NeedToEmulateFieldReadAccess :
413 case IProblem.NeedToEmulateFieldWriteAccess :
414 case IProblem.NeedToEmulateMethodAccess :
415 case IProblem.NeedToEmulateConstructorAccess :
416 return this.options.getSeverity(CompilerOptions.AccessEmulation);
418 case IProblem.NonExternalizedStringLiteral :
419 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
421 case IProblem.UseAssertAsAnIdentifier :
422 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
424 case IProblem.NonStaticAccessToStaticMethod :
425 case IProblem.NonStaticAccessToStaticField :
426 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
428 // case IProblem.IndirectAccessToStaticMethod :
429 // case IProblem.IndirectAccessToStaticField :
430 // case IProblem.IndirectAccessToStaticType :
431 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
433 case IProblem.AssignmentHasNoEffect:
434 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
436 case IProblem.UnusedPrivateConstructor:
437 case IProblem.UnusedPrivateMethod:
438 case IProblem.UnusedPrivateField:
439 case IProblem.UnusedPrivateType:
440 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
445 // case IProblem.LocalVariableHidingLocalVariable:
446 // case IProblem.LocalVariableHidingField:
447 // case IProblem.ArgumentHidingLocalVariable:
448 // case IProblem.ArgumentHidingField:
449 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
451 // case IProblem.FieldHidingLocalVariable:
452 // case IProblem.FieldHidingField:
453 // return this.options.getSeverity(CompilerOptions.FieldHiding);
455 // case IProblem.PossibleAccidentalBooleanAssignment:
456 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
458 // case IProblem.SuperfluousSemicolon:
459 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
461 // case IProblem.UndocumentedEmptyBlock:
462 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
464 // case IProblem.UnnecessaryCast:
465 // case IProblem.UnnecessaryArgumentCast:
466 // case IProblem.UnnecessaryInstanceof:
467 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
469 // case IProblem.FinallyMustCompleteNormally:
470 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
472 // case IProblem.UnusedMethodDeclaredThrownException:
473 // case IProblem.UnusedConstructorDeclaredThrownException:
474 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
476 // case IProblem.UnqualifiedFieldAccess:
477 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
480 * Javadoc syntax errors
482 // Javadoc explicit IDs
483 // case IProblem.JavadocUnexpectedTag:
484 // case IProblem.JavadocDuplicateReturnTag:
485 // case IProblem.JavadocInvalidThrowsClass:
486 // case IProblem.JavadocInvalidSeeReference:
487 // case IProblem.JavadocInvalidSeeHref:
488 // case IProblem.JavadocInvalidSeeArgs:
489 // case IProblem.JavadocInvalidTag:
490 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
493 * Javadoc tags resolved references errors
495 // case IProblem.JavadocInvalidParamName:
496 // case IProblem.JavadocDuplicateParamName:
497 // case IProblem.JavadocMissingParamName:
498 // case IProblem.JavadocInvalidThrowsClassName:
499 // case IProblem.JavadocDuplicateThrowsClassName:
500 // case IProblem.JavadocMissingThrowsClassName:
501 // case IProblem.JavadocMissingSeeReference:
502 // case IProblem.JavadocUsingDeprecatedField:
503 // case IProblem.JavadocUsingDeprecatedConstructor:
504 // case IProblem.JavadocUsingDeprecatedMethod:
505 // case IProblem.JavadocUsingDeprecatedType:
506 // case IProblem.JavadocUndefinedField:
507 // case IProblem.JavadocNotVisibleField:
508 // case IProblem.JavadocAmbiguousField:
509 // case IProblem.JavadocUndefinedConstructor:
510 // case IProblem.JavadocNotVisibleConstructor:
511 // case IProblem.JavadocAmbiguousConstructor:
512 // case IProblem.JavadocUndefinedMethod:
513 // case IProblem.JavadocNotVisibleMethod:
514 // case IProblem.JavadocAmbiguousMethod:
515 // case IProblem.JavadocParameterMismatch:
516 // case IProblem.JavadocUndefinedType:
517 // case IProblem.JavadocNotVisibleType:
518 // case IProblem.JavadocAmbiguousType:
519 // case IProblem.JavadocInternalTypeNameProvided:
520 // case IProblem.JavadocNoMessageSendOnArrayType:
521 // case IProblem.JavadocNoMessageSendOnBaseType:
522 // if (!this.options.reportInvalidJavadocTags)
523 // return ProblemSeverities.Ignore;
525 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
528 * Javadoc missing tags errors
530 // case IProblem.JavadocMissingParamTag:
531 // case IProblem.JavadocMissingReturnTag:
532 // case IProblem.JavadocMissingThrowsTag:
533 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
536 * Missing Javadoc errors
538 // case IProblem.JavadocMissing:
539 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
541 // by default problems are errors.
546 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
547 // expression, TypeBinding trueType, TypeBinding falseType) {
549 // IProblem.IncompatibleTypesInConditionalOperator,
550 // new String[] {new String(trueType.readableName()), new
551 // String(falseType.readableName())},
552 // new String[] {new String(trueType.sourceName()), new
553 // String(falseType.sourceName())},
554 // expression.sourceStart,
555 // expression.sourceEnd);
557 // public void conflictingImport(ImportReference importRef) {
558 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
559 // this.handle(IProblem.ConflictingImport, arguments, arguments,
560 // importRef.sourceStart, importRef.sourceEnd);
562 public void constantOutOfFormat(NumberLiteral lit) {
563 // the literal is not in a correct format
564 // this code is called on IntLiteral and LongLiteral
565 // example 000811 ...the 8 is uncorrect.
566 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
567 char[] source = lit.source();
571 if ((source[1] == 'x') || (source[1] == 'X')) {
573 Radix = "Hexa"; //$NON-NLS-1$
576 Radix = "Octal"; //$NON-NLS-1$
578 //look for the first digit that is incorrect
580 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
581 if (Character.digit(source[i], radix) == -1) {
586 String[] arguments = new String[]{Radix + " " + new String(source)
587 + " (digit " + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
588 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
589 lit.sourceStart, lit.sourceEnd);
591 } catch (IndexOutOfBoundsException ex) {
593 // just in case .... use a predefined error..
594 // we should never come here...(except if the code changes !)
595 this.constantOutOfRange(lit);
598 public void constantOutOfRange(Literal lit) {
599 // lit is some how out of range of it declared type
601 // 9999999999999999999999999999999999999999999999999999999999999999999
602 String[] arguments = new String[]{new String(lit.source())};
603 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
604 lit.sourceStart, lit.sourceEnd);
606 public void deprecatedField(FieldBinding field, AstNode location) {
607 this.handle(IProblem.UsingDeprecatedField,
608 new String[]{new String(field.declaringClass.readableName()),
609 new String(field.name)}, new String[]{
610 new String(field.declaringClass.shortReadableName()),
611 new String(field.name)}, location.sourceStart, location.sourceEnd);
613 public void deprecatedMethod(MethodBinding method, AstNode location) {
614 if (method.isConstructor())
615 this.handle(IProblem.UsingDeprecatedConstructor, new String[]{
616 new String(method.declaringClass.readableName()),
617 parametersAsString(method)}, new String[]{
618 new String(method.declaringClass.shortReadableName()),
619 parametersAsShortString(method)}, location.sourceStart,
622 this.handle(IProblem.UsingDeprecatedMethod, new String[]{
623 new String(method.declaringClass.readableName()),
624 new String(method.selector), parametersAsString(method)},
625 new String[]{new String(method.declaringClass.shortReadableName()),
626 new String(method.selector), parametersAsShortString(method)},
627 location.sourceStart, location.sourceEnd);
629 public void deprecatedType(TypeBinding type, AstNode location) {
630 if (location == null)
631 return; // 1G828DN - no type ref for synthetic arguments
632 this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type
633 .readableName())}, new String[]{new String(type.shortReadableName())},
634 location.sourceStart, location.sourceEnd);
636 public void duplicateCase(Case statement, Constant constant) {
637 String[] arguments = new String[]{String.valueOf(constant.intValue())};
638 this.handle(IProblem.DuplicateCase, arguments, arguments,
639 statement.sourceStart, statement.sourceEnd);
641 public void duplicateDefaultCase(DefaultCase statement) {
642 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
643 statement.sourceStart, statement.sourceEnd);
645 public void duplicateFieldInType(SourceTypeBinding type,
646 FieldDeclaration fieldDecl) {
647 this.handle(IProblem.DuplicateField, new String[]{
648 new String(type.sourceName()), fieldDecl.name()}, new String[]{
649 new String(type.shortReadableName()), fieldDecl.name()},
650 fieldDecl.sourceStart, fieldDecl.sourceEnd);
652 // public void duplicateImport(ImportReference importRef) {
653 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
654 // this.handle(IProblem.DuplicateImport, arguments, arguments,
655 // importRef.sourceStart, importRef.sourceEnd);
657 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
658 Reference reference) {
659 String[] arguments = new String[]{new String(field.readableName())};
660 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
661 arguments, reference.sourceStart, reference.sourceEnd);
663 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
665 String[] arguments = new String[]{new String(local.readableName())};
666 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
667 arguments, location.sourceStart, location.sourceEnd);
669 public void duplicateMethodInType(SourceTypeBinding type,
670 AbstractMethodDeclaration methodDecl) {
671 String[] arguments = new String[]{new String(methodDecl.selector),
672 new String(type.sourceName())};
673 this.handle(IProblem.DuplicateMethod, arguments, arguments,
674 methodDecl.sourceStart, methodDecl.sourceEnd);
676 public void duplicateModifierForField(ReferenceBinding type,
677 FieldDeclaration fieldDecl) {
679 * to highlight modifiers use: this.handle( new Problem(
680 * DuplicateModifierForField, new String[] {fieldDecl.name()},
681 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
683 String[] arguments = new String[]{fieldDecl.name()};
684 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
685 fieldDecl.sourceStart, fieldDecl.sourceEnd);
687 public void duplicateModifierForMethod(ReferenceBinding type,
688 AbstractMethodDeclaration methodDecl) {
689 this.handle(IProblem.DuplicateModifierForMethod, new String[]{
690 new String(type.sourceName()), new String(methodDecl.selector)},
691 new String[]{new String(type.shortReadableName()),
692 new String(methodDecl.selector)}, methodDecl.sourceStart,
693 methodDecl.sourceEnd);
695 public void duplicateModifierForType(SourceTypeBinding type) {
696 String[] arguments = new String[]{new String(type.sourceName())};
697 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type
698 .sourceStart(), type.sourceEnd());
700 public void duplicateModifierForVariable(LocalDeclaration localDecl,
701 boolean complainForArgument) {
702 String[] arguments = new String[]{localDecl.name()};
703 this.handle(complainForArgument
704 ? IProblem.DuplicateModifierForArgument
705 : IProblem.DuplicateModifierForVariable, arguments, arguments,
706 localDecl.sourceStart, localDecl.sourceEnd);
708 public void duplicateNestedType(TypeDeclaration typeDecl) {
709 String[] arguments = new String[]{new String(typeDecl.name)};
710 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
711 typeDecl.sourceStart, typeDecl.sourceEnd);
713 public void duplicateSuperinterface(SourceTypeBinding type,
714 TypeDeclaration typeDecl, ReferenceBinding superType) {
715 this.handle(IProblem.DuplicateSuperInterface, new String[]{
716 new String(superType.readableName()), new String(type.sourceName())},
717 new String[]{new String(superType.shortReadableName()),
718 new String(type.sourceName())}, typeDecl.sourceStart,
721 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
722 TypeDeclaration typeDecl) {
723 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
724 new String(typeDecl.name)};
725 this.referenceContext = typeDecl; // report the problem against the
726 // type not the entire compilation
728 this.handle(IProblem.DuplicateTypes, arguments, arguments,
729 typeDecl.sourceStart, typeDecl.sourceEnd,
730 compUnitDecl.compilationResult);
732 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
733 TypeBinding[] params) {
734 StringBuffer buffer = new StringBuffer();
735 StringBuffer shortBuffer = new StringBuffer();
736 for (int i = 0, length = params.length; i < length; i++) {
738 buffer.append(", "); //$NON-NLS-1$
739 shortBuffer.append(", "); //$NON-NLS-1$
741 buffer.append(new String(params[i].readableName()));
742 shortBuffer.append(new String(params[i].shortReadableName()));
744 this.handle(recType.isArrayType()
745 ? IProblem.NoMessageSendOnArrayType
746 : IProblem.NoMessageSendOnBaseType, new String[]{
747 new String(recType.readableName()), new String(messageSend.selector),
748 buffer.toString()}, new String[]{
749 new String(recType.shortReadableName()),
750 new String(messageSend.selector), shortBuffer.toString()},
751 messageSend.sourceStart, messageSend.sourceEnd);
753 public void errorThisSuperInStatic(AstNode reference) {
754 String[] arguments = new String[]{reference.isSuper() ? "super" : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
755 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
756 reference.sourceStart, reference.sourceEnd);
758 public void exceptionTypeProblem(SourceTypeBinding type,
759 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
760 TypeBinding expectedType) {
761 int problemId = expectedType.problemId();
766 id = IProblem.ExceptionTypeNotFound;
770 id = IProblem.ExceptionTypeNotVisible;
774 id = IProblem.ExceptionTypeAmbiguous;
776 case InternalNameProvided :
778 id = IProblem.ExceptionTypeInternalNameProvided;
780 case InheritedNameHidesEnclosingName :
782 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
787 needImplementation(); // want to fail to see why we were
791 this.handle(id, new String[]{new String(methodDecl.selector),
792 new String(expectedType.readableName())}, new String[]{
793 new String(methodDecl.selector),
794 new String(expectedType.shortReadableName())},
795 exceptionType.sourceStart, exceptionType.sourceEnd);
797 public void expressionShouldBeAVariable(Expression expression) {
798 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument,
799 expression.sourceStart, expression.sourceEnd);
801 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
802 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
803 NoArgument, reference.sourceStart, reference.sourceEnd);
805 public void fieldTypeProblem(SourceTypeBinding type,
806 FieldDeclaration fieldDecl, TypeBinding expectedType) {
807 int problemId = expectedType.problemId();
812 id = IProblem.FieldTypeNotFound;
816 id = IProblem.FieldTypeNotVisible;
820 id = IProblem.FieldTypeAmbiguous;
822 case InternalNameProvided :
824 id = IProblem.FieldTypeInternalNameProvided;
826 case InheritedNameHidesEnclosingName :
828 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
833 needImplementation(); // want to fail to see why we were
838 new String[]{fieldDecl.name(), new String(type.sourceName()),
839 new String(expectedType.readableName())}, new String[]{
840 fieldDecl.name(), new String(type.sourceName()),
841 new String(expectedType.shortReadableName())},
842 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
844 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
845 MethodBinding inheritedMethod) {
847 // Cannot override the final method from %1
848 // 8.4.3.3 - Final methods cannot be overridden or hidden.
849 IProblem.FinalMethodCannotBeOverridden, new String[]{new String(
850 inheritedMethod.declaringClass.readableName())},
851 new String[]{new String(inheritedMethod.declaringClass
852 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
855 public void forwardReference(Reference reference, int indexInQualification,
857 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
858 reference.sourceStart, reference.sourceEnd);
860 // use this private API when the compilation unit result can be found
862 // reference context. Otherwise, use the other API taking a problem and a
863 // compilation result
865 private void handle(int problemId, String[] problemArguments,
866 String[] messageArguments, int problemStartPosition,
867 int problemEndPosition) {
868 this.handle(problemId, problemArguments, messageArguments,
869 problemStartPosition, problemEndPosition, referenceContext,
870 referenceContext == null ? null : referenceContext.compilationResult());
871 referenceContext = null;
873 // use this private API when the compilation unit result can be found
875 // reference context. Otherwise, use the other API taking a problem and a
876 // compilation result
878 private void handle(int problemId, String[] problemArguments,
879 String[] messageArguments, int severity, int problemStartPosition,
880 int problemEndPosition) {
881 this.handle(problemId, problemArguments, messageArguments, severity,
882 problemStartPosition, problemEndPosition, referenceContext,
883 referenceContext == null ? null : referenceContext.compilationResult());
884 referenceContext = null;
886 // use this private API when the compilation unit result cannot be found
888 // reference context.
889 private void handle(int problemId, String[] problemArguments,
890 String[] messageArguments, int problemStartPosition,
891 int problemEndPosition, CompilationResult unitResult) {
892 this.handle(problemId, problemArguments, messageArguments,
893 problemStartPosition, problemEndPosition, referenceContext, unitResult);
894 referenceContext = null;
896 public void hidingEnclosingType(TypeDeclaration typeDecl) {
897 String[] arguments = new String[]{new String(typeDecl.name)};
898 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
899 typeDecl.sourceStart, typeDecl.sourceEnd);
901 public void hierarchyCircularity(SourceTypeBinding sourceType,
902 ReferenceBinding superType, TypeReference reference) {
905 String typeName = ""; //$NON-NLS-1$
906 String shortTypeName = ""; //$NON-NLS-1$
907 if (reference == null) { // can only happen when java.lang.Object is
909 start = sourceType.sourceStart();
910 end = sourceType.sourceEnd();
911 typeName = new String(superType.readableName());
912 shortTypeName = new String(superType.sourceName());
914 start = reference.sourceStart;
915 end = reference.sourceEnd;
916 char[][] qName = reference.getTypeName();
917 typeName = CharOperation.toString(qName);
918 shortTypeName = new String(qName[qName.length - 1]);
920 if (sourceType == superType)
921 this.handle(IProblem.HierarchyCircularitySelfReference, new String[]{
922 new String(sourceType.sourceName()), typeName}, new String[]{
923 new String(sourceType.sourceName()), shortTypeName}, start, end);
925 this.handle(IProblem.HierarchyCircularity, new String[]{
926 new String(sourceType.sourceName()), typeName}, new String[]{
927 new String(sourceType.sourceName()), shortTypeName}, start, end);
929 public void hierarchyHasProblems(SourceTypeBinding type) {
930 String[] arguments = new String[]{new String(type.sourceName())};
931 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
932 .sourceStart(), type.sourceEnd());
934 public void illegalAbstractModifierCombinationForMethod(
935 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
936 String[] arguments = new String[]{new String(type.sourceName()),
937 new String(methodDecl.selector)};
938 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
939 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
941 public void illegalModifierCombinationFinalAbstractForClass(
942 SourceTypeBinding type) {
943 String[] arguments = new String[]{new String(type.sourceName())};
944 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
945 arguments, arguments, type.sourceStart(), type.sourceEnd());
947 public void illegalModifierCombinationFinalVolatileForField(
948 ReferenceBinding type, FieldDeclaration fieldDecl) {
949 String[] arguments = new String[]{fieldDecl.name()};
950 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
951 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
953 public void illegalModifierForClass(SourceTypeBinding type) {
954 String[] arguments = new String[]{new String(type.sourceName())};
955 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type
956 .sourceStart(), type.sourceEnd());
958 public void illegalModifierForField(ReferenceBinding type,
959 FieldDeclaration fieldDecl) {
960 String[] arguments = new String[]{fieldDecl.name()};
961 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
962 fieldDecl.sourceStart, fieldDecl.sourceEnd);
964 public void illegalModifierForInterface(SourceTypeBinding type) {
965 String[] arguments = new String[]{new String(type.sourceName())};
966 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
967 type.sourceStart(), type.sourceEnd());
969 public void illegalModifierForInterfaceField(ReferenceBinding type,
970 FieldDeclaration fieldDecl) {
971 String[] arguments = new String[]{fieldDecl.name()};
972 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
973 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
975 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
976 AbstractMethodDeclaration methodDecl) {
977 String[] arguments = new String[]{new String(type.sourceName()),
978 new String(methodDecl.selector)};
979 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
980 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
982 public void illegalModifierForLocalClass(SourceTypeBinding type) {
983 String[] arguments = new String[]{new String(type.sourceName())};
984 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments,
985 type.sourceStart(), type.sourceEnd());
987 public void illegalModifierForMemberClass(SourceTypeBinding type) {
988 String[] arguments = new String[]{new String(type.sourceName())};
989 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments,
990 type.sourceStart(), type.sourceEnd());
992 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
993 String[] arguments = new String[]{new String(type.sourceName())};
994 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
995 arguments, type.sourceStart(), type.sourceEnd());
997 public void illegalModifierForMethod(ReferenceBinding type,
998 AbstractMethodDeclaration methodDecl) {
999 String[] arguments = new String[]{new String(type.sourceName()),
1000 new String(methodDecl.selector)};
1001 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1002 methodDecl.sourceStart, methodDecl.sourceEnd);
1004 public void illegalModifierForVariable(LocalDeclaration localDecl,
1005 boolean complainAsArgument) {
1006 String[] arguments = new String[]{localDecl.name()};
1007 this.handle(complainAsArgument
1008 ? IProblem.IllegalModifierForArgument
1009 : IProblem.IllegalModifierForVariable, arguments, arguments,
1010 localDecl.sourceStart, localDecl.sourceEnd);
1012 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1013 TypeBinding enclosingType, AstNode location) {
1014 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1015 new String[]{new String(enclosingType.readableName())},
1016 new String[]{new String(enclosingType.shortReadableName())},
1017 location.sourceStart, location.sourceEnd);
1019 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1020 String[] arguments = new String[]{new String(type.sourceName())};
1021 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1022 arguments, type.sourceStart(), type.sourceEnd());
1024 public void illegalVisibilityModifierCombinationForField(
1025 ReferenceBinding type, FieldDeclaration fieldDecl) {
1026 String[] arguments = new String[]{new String(fieldDecl.name())};
1027 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1028 arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1030 public void illegalVisibilityModifierCombinationForMemberType(
1031 SourceTypeBinding type) {
1032 String[] arguments = new String[]{new String(type.sourceName())};
1033 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1034 arguments, arguments, type.sourceStart(), type.sourceEnd());
1036 public void illegalVisibilityModifierCombinationForMethod(
1037 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1038 String[] arguments = new String[]{new String(type.sourceName()),
1039 new String(methodDecl.selector)};
1040 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1041 arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1043 public void illegalVisibilityModifierForInterfaceMemberType(
1044 SourceTypeBinding type) {
1045 String[] arguments = new String[]{new String(type.sourceName())};
1046 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1047 arguments, arguments, type.sourceStart(), type.sourceEnd());
1049 public void illegalVoidExpression(AstNode location) {
1050 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1051 location.sourceStart, location.sourceEnd);
1053 // public void importProblem(ImportReference importRef, Binding expectedImport) {
1054 // int problemId = expectedImport.problemId();
1056 // switch (problemId) {
1059 // id = IProblem.ImportNotFound;
1061 // case NotVisible :
1063 // id = IProblem.ImportNotVisible;
1067 // id = IProblem.ImportAmbiguous;
1069 // case InternalNameProvided :
1071 // id = IProblem.ImportInternalNameProvided;
1073 // case InheritedNameHidesEnclosingName :
1075 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1080 // needImplementation(); // want to fail to see why we were
1085 // if (expectedImport instanceof ProblemReferenceBinding) {
1086 // argument = CharOperation
1087 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1089 // argument = CharOperation.toString(importRef.tokens);
1091 // String[] arguments = new String[]{argument};
1092 // this.handle(id, arguments, arguments, importRef.sourceStart,
1093 // importRef.sourceEnd);
1095 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1096 MethodBinding currentMethod, MethodBinding inheritedMethod,
1097 ReferenceBinding exceptionType) {
1098 if (type == currentMethod.declaringClass) {
1100 if (currentMethod.declaringClass.isInterface()
1101 && !inheritedMethod.isPublic()) { // interface inheriting
1104 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1106 id = IProblem.IncompatibleExceptionInThrowsClause;
1109 // Exception %1 is not compatible with throws
1111 // 9.4.4 - The type of exception in the throws
1112 // clause is incompatible.
1114 new String(exceptionType.sourceName()),
1115 new String(CharOperation.concat(inheritedMethod.declaringClass
1116 .readableName(), inheritedMethod.readableName(), '.'))},
1118 new String(exceptionType.sourceName()),
1119 new String(CharOperation.concat(inheritedMethod.declaringClass
1120 .shortReadableName(), inheritedMethod.shortReadableName(),
1121 '.'))}, currentMethod.sourceStart(), currentMethod
1125 // Exception %1 in throws clause of %2 is not
1126 // compatible with %3
1127 // 9.4.4 - The type of exception in the throws
1128 // clause is incompatible.
1129 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1131 new String(exceptionType.sourceName()),
1132 new String(CharOperation.concat(currentMethod.declaringClass
1133 .sourceName(), currentMethod.readableName(), '.')),
1134 new String(CharOperation.concat(inheritedMethod.declaringClass
1135 .readableName(), inheritedMethod.readableName(), '.'))},
1137 new String(exceptionType.sourceName()),
1138 new String(CharOperation.concat(currentMethod.declaringClass
1139 .sourceName(), currentMethod.shortReadableName(), '.')),
1140 new String(CharOperation.concat(inheritedMethod.declaringClass
1141 .shortReadableName(), inheritedMethod.shortReadableName(),
1142 '.'))}, type.sourceStart(), type.sourceEnd());
1144 public void incompatibleReturnType(MethodBinding currentMethod,
1145 MethodBinding inheritedMethod) {
1146 StringBuffer methodSignature = new StringBuffer();
1147 methodSignature.append(inheritedMethod.declaringClass.readableName())
1148 .append('.').append(inheritedMethod.readableName());
1149 StringBuffer shortSignature = new StringBuffer();
1150 shortSignature.append(inheritedMethod.declaringClass.shortReadableName())
1151 .append('.').append(inheritedMethod.shortReadableName());
1153 if (currentMethod.declaringClass.isInterface()
1154 && !inheritedMethod.isPublic()) { // interface inheriting
1155 // Object protected method
1156 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1158 id = IProblem.IncompatibleReturnType;
1160 this.handle(id, new String[]{methodSignature.toString()},
1161 new String[]{shortSignature.toString()}, currentMethod.sourceStart(),
1162 currentMethod.sourceEnd());
1164 public void incorrectLocationForEmptyDimension(
1165 ArrayAllocationExpression expression, int index) {
1166 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1167 expression.dimensions[index + 1].sourceStart,
1168 expression.dimensions[index + 1].sourceEnd);
1170 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1171 this.handle(IProblem.IncorrectSwitchType, new String[]{new String(testType
1173 new String[]{new String(testType.shortReadableName())},
1174 expression.sourceStart, expression.sourceEnd);
1176 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1177 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1178 StringBuffer concreteSignature = new StringBuffer();
1179 concreteSignature.append(concreteMethod.declaringClass.readableName())
1180 .append('.').append(concreteMethod.readableName());
1181 StringBuffer shortSignature = new StringBuffer();
1182 shortSignature.append(concreteMethod.declaringClass.shortReadableName())
1183 .append('.').append(concreteMethod.shortReadableName());
1185 // The inherited method %1 cannot hide the public abstract method in %2
1186 IProblem.InheritedMethodReducesVisibility, new String[]{
1187 new String(concreteSignature.toString()),
1188 new String(abstractMethods[0].declaringClass.readableName())},
1189 new String[]{new String(shortSignature.toString()),
1190 new String(abstractMethods[0].declaringClass.shortReadableName())},
1191 type.sourceStart(), type.sourceEnd());
1193 public void inheritedMethodsHaveIncompatibleReturnTypes(
1194 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1195 StringBuffer methodSignatures = new StringBuffer();
1196 StringBuffer shortSignatures = new StringBuffer();
1197 for (int i = length; --i >= 0;) {
1199 .append(inheritedMethods[i].declaringClass.readableName())
1200 .append('.').append(inheritedMethods[i].readableName());
1201 shortSignatures.append(
1202 inheritedMethods[i].declaringClass.shortReadableName()).append('.')
1203 .append(inheritedMethods[i].shortReadableName());
1205 methodSignatures.append(", "); //$NON-NLS-1$
1206 shortSignatures.append(", "); //$NON-NLS-1$
1210 // Return type is incompatible with %1
1211 // 9.4.2 - The return type from the method is incompatible with
1213 IProblem.IncompatibleReturnType, new String[]{methodSignatures
1214 .toString()}, new String[]{shortSignatures.toString()}, type
1215 .sourceStart(), type.sourceEnd());
1217 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1218 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1219 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1221 public void innerTypesCannotDeclareStaticInitializers(
1222 ReferenceBinding innerType, AstNode location) {
1223 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1224 new String[]{new String(innerType.readableName())},
1225 new String[]{new String(innerType.shortReadableName())},
1226 location.sourceStart, location.sourceEnd);
1228 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1229 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1230 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1231 constructor, constructor.compilationResult());
1233 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1234 FieldDeclaration fieldDecl) {
1235 String[] arguments = new String[]{new String(type.sourceName())};
1236 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments,
1237 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1239 public void invalidBreak(AstNode location) {
1240 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1241 location.sourceStart, location.sourceEnd);
1243 public void invalidConstructor(Statement statement,
1244 MethodBinding targetConstructor) {
1245 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1246 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1247 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1248 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1249 int flag = IProblem.UndefinedConstructor; //default...
1250 switch (targetConstructor.problemId()) {
1252 if (insideDefaultConstructor) {
1253 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1254 } else if (insideImplicitConstructorCall) {
1255 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1257 flag = IProblem.UndefinedConstructor;
1261 if (insideDefaultConstructor) {
1262 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1263 } else if (insideImplicitConstructorCall) {
1264 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1266 flag = IProblem.NotVisibleConstructor;
1270 if (insideDefaultConstructor) {
1271 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1272 } else if (insideImplicitConstructorCall) {
1273 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1275 flag = IProblem.AmbiguousConstructor;
1281 needImplementation(); // want to fail to see why we were
1285 this.handle(flag, new String[]{
1286 new String(targetConstructor.declaringClass.readableName()),
1287 parametersAsString(targetConstructor)}, new String[]{
1288 new String(targetConstructor.declaringClass.shortReadableName()),
1289 parametersAsShortString(targetConstructor)}, statement.sourceStart,
1290 statement.sourceEnd);
1292 public void invalidContinue(AstNode location) {
1293 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1294 location.sourceStart, location.sourceEnd);
1296 public void invalidEnclosingType(Expression expression, TypeBinding type,
1297 ReferenceBinding enclosingType) {
1298 if (enclosingType.isAnonymousType())
1299 enclosingType = enclosingType.superclass();
1300 int flag = IProblem.UndefinedType; // default
1301 switch (type.problemId()) {
1304 flag = IProblem.UndefinedType;
1308 flag = IProblem.NotVisibleType;
1312 flag = IProblem.AmbiguousType;
1314 case InternalNameProvided :
1315 flag = IProblem.InternalTypeNameProvided;
1320 needImplementation(); // want to fail to see why we were
1324 this.handle(flag, new String[]{new String(enclosingType.readableName())
1325 + "." + new String(type.readableName())}, //$NON-NLS-1$
1326 new String[]{new String(enclosingType.shortReadableName()) + "."
1327 + new String(type.shortReadableName())}, //$NON-NLS-1$
1328 expression.sourceStart, expression.sourceEnd);
1330 public void invalidExpressionAsStatement(Expression expression) {
1331 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument,
1332 expression.sourceStart, expression.sourceEnd);
1334 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1335 int severity = Error;
1336 int flag = IProblem.UndefinedField;
1337 FieldBinding field = fieldRef.binding;
1338 switch (field.problemId()) {
1340 flag = IProblem.UndefinedField;
1342 * also need to check that the searchedType is the receiver type if
1343 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1347 flag = IProblem.NotVisibleField;
1350 flag = IProblem.AmbiguousField;
1352 case NonStaticReferenceInStaticContext :
1353 flag = IProblem.NonStaticFieldFromStaticInvocation;
1355 case NonStaticReferenceInConstructorInvocation :
1356 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1358 case InheritedNameHidesEnclosingName :
1359 flag = IProblem.InheritedFieldHidesEnclosingName;
1361 case ReceiverTypeNotVisible :
1362 this.handle(IProblem.NotVisibleType, new String[]{new String(
1363 searchedType.leafComponentType().readableName())},
1364 new String[]{new String(searchedType.leafComponentType()
1365 .shortReadableName())}, fieldRef.receiver.sourceStart,
1366 fieldRef.receiver.sourceEnd);
1371 needImplementation(); // want to fail to see why we were
1375 String[] arguments = new String[]{new String(field.readableName())};
1376 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1377 fieldRef.sourceEnd);
1379 public void invalidField(NameReference nameRef, FieldBinding field) {
1380 int flag = IProblem.UndefinedField;
1381 switch (field.problemId()) {
1383 flag = IProblem.UndefinedField;
1386 flag = IProblem.NotVisibleField;
1389 flag = IProblem.AmbiguousField;
1391 case NonStaticReferenceInStaticContext :
1392 flag = IProblem.NonStaticFieldFromStaticInvocation;
1394 case NonStaticReferenceInConstructorInvocation :
1395 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1397 case InheritedNameHidesEnclosingName :
1398 flag = IProblem.InheritedFieldHidesEnclosingName;
1400 case ReceiverTypeNotVisible :
1401 this.handle(IProblem.NotVisibleType, new String[]{new String(
1402 field.declaringClass.leafComponentType().readableName())},
1403 new String[]{new String(field.declaringClass.leafComponentType()
1404 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1409 needImplementation(); // want to fail to see why we were
1413 String[] arguments = new String[]{new String(field.readableName())};
1414 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1417 public void invalidField(QualifiedNameReference nameRef, FieldBinding field,
1418 int index, TypeBinding searchedType) {
1419 //the resolution of the index-th field of qname failed
1420 //qname.otherBindings[index] is the binding that has produced the
1422 //The different targetted errors should be :
1426 if (searchedType.isBaseType()) {
1427 this.handle(IProblem.NoFieldOnBaseType, new String[]{
1428 new String(searchedType.readableName()),
1429 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1430 index)), new String(nameRef.tokens[index])}, new String[]{
1431 new String(searchedType.sourceName()),
1432 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0,
1433 index)), new String(nameRef.tokens[index])}, nameRef.sourceStart,
1437 int flag = IProblem.UndefinedField;
1438 switch (field.problemId()) {
1440 flag = IProblem.UndefinedField;
1442 * also need to check that the searchedType is the receiver type if
1443 * (searchedType.isHierarchyInconsistent()) severity = SecondaryError;
1447 flag = IProblem.NotVisibleField;
1450 flag = IProblem.AmbiguousField;
1452 case NonStaticReferenceInStaticContext :
1453 flag = IProblem.NonStaticFieldFromStaticInvocation;
1455 case NonStaticReferenceInConstructorInvocation :
1456 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1458 case InheritedNameHidesEnclosingName :
1459 flag = IProblem.InheritedFieldHidesEnclosingName;
1461 case ReceiverTypeNotVisible :
1462 this.handle(IProblem.NotVisibleType, new String[]{new String(
1463 searchedType.leafComponentType().readableName())},
1464 new String[]{new String(searchedType.leafComponentType()
1465 .shortReadableName())}, nameRef.sourceStart, nameRef.sourceEnd);
1470 needImplementation(); // want to fail to see why we were
1474 String[] arguments = new String[]{CharOperation.toString(CharOperation
1475 .subarray(nameRef.tokens, 0, index + 1))};
1476 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1479 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1480 // CODE should be UPDATED according to error coding in the different
1481 // method binding errors
1482 // The different targetted errors should be :
1486 // InheritedNameHidesEnclosingName
1487 // InstanceMethodDuringConstructorInvocation
1488 // StaticMethodRequested
1489 int flag = IProblem.UndefinedMethod; //default...
1490 switch (method.problemId()) {
1492 flag = IProblem.UndefinedMethod;
1495 flag = IProblem.NotVisibleMethod;
1498 flag = IProblem.AmbiguousMethod;
1500 case InheritedNameHidesEnclosingName :
1501 flag = IProblem.InheritedMethodHidesEnclosingName;
1503 case NonStaticReferenceInConstructorInvocation :
1504 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1506 case NonStaticReferenceInStaticContext :
1507 flag = IProblem.StaticMethodRequested;
1509 case ReceiverTypeNotVisible :
1510 this.handle(IProblem.NotVisibleType, new String[]{new String(
1511 method.declaringClass.leafComponentType().readableName())},
1512 new String[]{new String(method.declaringClass.leafComponentType()
1513 .shortReadableName())}, messageSend.receiver.sourceStart,
1514 messageSend.receiver.sourceEnd);
1519 needImplementation(); // want to fail to see why we were
1523 if (flag == IProblem.UndefinedMethod) {
1524 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1525 if (problemMethod.closestMatch != null) {
1526 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1527 String parameterTypeNames = parametersAsString(method);
1528 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1529 String parameterTypeShortNames = parametersAsShortString(method);
1530 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1531 closestParameterTypeShortNames = closestParameterTypeNames;
1532 parameterTypeShortNames = parameterTypeNames;
1534 this.handle(IProblem.ParameterMismatch,
1536 new String(problemMethod.closestMatch.declaringClass
1538 new String(problemMethod.closestMatch.selector),
1539 closestParameterTypeNames, parameterTypeNames}, new String[]{
1540 new String(problemMethod.closestMatch.declaringClass
1541 .shortReadableName()),
1542 new String(problemMethod.closestMatch.selector),
1543 closestParameterTypeShortNames, parameterTypeShortNames},
1544 (int) (messageSend.nameSourcePosition >>> 32),
1545 (int) messageSend.nameSourcePosition);
1549 this.handle(flag, new String[]{
1550 new String(method.declaringClass.readableName()),
1551 new String(method.selector), parametersAsString(method)}, new String[]{
1552 new String(method.declaringClass.shortReadableName()),
1553 new String(method.selector), parametersAsShortString(method)},
1554 (int) (messageSend.nameSourcePosition >>> 32),
1555 (int) messageSend.nameSourcePosition);
1557 public void invalidNullToSynchronize(Expression expression) {
1558 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1559 expression.sourceStart, expression.sourceEnd);
1561 public void invalidOperator(BinaryExpression expression,
1562 TypeBinding leftType, TypeBinding rightType) {
1563 String leftName = new String(leftType.readableName());
1564 String rightName = new String(rightType.readableName());
1565 String leftShortName = new String(leftType.shortReadableName());
1566 String rightShortName = new String(rightType.shortReadableName());
1567 if (leftShortName.equals(rightShortName)) {
1568 leftShortName = leftName;
1569 rightShortName = rightName;
1571 this.handle(IProblem.InvalidOperator, new String[]{
1572 expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1573 new String[]{expression.operatorToString(),
1574 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1575 expression.sourceStart, expression.sourceEnd);
1577 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType,
1578 TypeBinding rightType) {
1579 String leftName = new String(leftType.readableName());
1580 String rightName = new String(rightType.readableName());
1581 String leftShortName = new String(leftType.shortReadableName());
1582 String rightShortName = new String(rightType.shortReadableName());
1583 if (leftShortName.equals(rightShortName)) {
1584 leftShortName = leftName;
1585 rightShortName = rightName;
1587 this.handle(IProblem.InvalidOperator, new String[]{
1588 assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1589 new String[]{assign.operatorToString(),
1590 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1591 assign.sourceStart, assign.sourceEnd);
1593 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1594 this.handle(IProblem.InvalidOperator, new String[]{
1595 expression.operatorToString(), new String(type.readableName())},
1596 new String[]{expression.operatorToString(),
1597 new String(type.shortReadableName())}, expression.sourceStart,
1598 expression.sourceEnd);
1600 public void invalidParenthesizedExpression(AstNode reference) {
1601 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1602 NoArgument, reference.sourceStart, reference.sourceEnd);
1604 public void invalidSuperclass(SourceTypeBinding type,
1605 TypeReference superclassRef, ReferenceBinding expectedType) {
1606 int problemId = expectedType.problemId();
1608 switch (problemId) {
1611 id = IProblem.SuperclassNotFound;
1615 id = IProblem.SuperclassNotVisible;
1619 id = IProblem.SuperclassAmbiguous;
1621 case InternalNameProvided :
1623 id = IProblem.SuperclassInternalNameProvided;
1625 case InheritedNameHidesEnclosingName :
1627 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1632 needImplementation(); // want to fail to see why we were
1636 this.handle(id, new String[]{new String(expectedType.readableName()),
1637 new String(type.sourceName())}, new String[]{
1638 new String(expectedType.shortReadableName()),
1639 new String(type.sourceName())}, superclassRef.sourceStart,
1640 superclassRef.sourceEnd);
1642 public void invalidSuperinterface(SourceTypeBinding type,
1643 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1644 int problemId = expectedType.problemId();
1646 switch (problemId) {
1649 id = IProblem.InterfaceNotFound;
1653 id = IProblem.InterfaceNotVisible;
1657 id = IProblem.InterfaceAmbiguous;
1659 case InternalNameProvided :
1661 id = IProblem.InterfaceInternalNameProvided;
1663 case InheritedNameHidesEnclosingName :
1665 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1670 needImplementation(); // want to fail to see why we were
1674 this.handle(id, new String[]{new String(expectedType.readableName()),
1675 new String(type.sourceName())}, new String[]{
1676 new String(expectedType.shortReadableName()),
1677 new String(type.sourceName())}, superinterfaceRef.sourceStart,
1678 superinterfaceRef.sourceEnd);
1680 public void invalidType(AstNode location, TypeBinding type) {
1681 int flag = IProblem.UndefinedType; // default
1682 switch (type.problemId()) {
1684 flag = IProblem.UndefinedType;
1687 flag = IProblem.NotVisibleType;
1690 flag = IProblem.AmbiguousType;
1692 case InternalNameProvided :
1693 flag = IProblem.InternalTypeNameProvided;
1695 case InheritedNameHidesEnclosingName :
1696 flag = IProblem.InheritedTypeHidesEnclosingName;
1701 needImplementation(); // want to fail to see why we were
1705 this.handle(flag, new String[]{new String(type.readableName())},
1706 new String[]{new String(type.shortReadableName())},
1707 location.sourceStart, location.sourceEnd);
1709 public void invalidTypeReference(Expression expression) {
1710 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1711 expression.sourceStart, expression.sourceEnd);
1713 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1714 this.handle(IProblem.InvalidTypeToSynchronized, new String[]{new String(
1715 type.readableName())},
1716 new String[]{new String(type.shortReadableName())},
1717 expression.sourceStart, expression.sourceEnd);
1719 public void invalidUnaryExpression(Expression expression) {
1720 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1721 expression.sourceStart, expression.sourceEnd);
1723 public void isClassPathCorrect(char[][] wellKnownTypeName,
1724 CompilationUnitDeclaration compUnitDecl) {
1725 referenceContext = compUnitDecl;
1726 String[] arguments = new String[]{CharOperation.toString(wellKnownTypeName)};
1727 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1728 AbortCompilation | Error, compUnitDecl == null
1730 : compUnitDecl.sourceStart, compUnitDecl == null
1732 : compUnitDecl.sourceEnd);
1734 public void maskedExceptionHandler(ReferenceBinding exceptionType,
1736 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument,
1737 location.sourceStart, location.sourceEnd);
1739 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1740 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
1741 methodDecl.sourceStart, methodDecl.sourceEnd);
1743 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1745 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1746 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1747 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
1748 methodDecl.sourceStart, methodDecl.sourceEnd);
1750 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1751 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument,
1752 methodDecl.sourceStart, methodDecl.sourceEnd);
1754 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1755 // enclosingType, AstNode location) {
1756 // boolean insideConstructorCall =
1757 // (location instanceof ExplicitConstructorCall)
1758 // && (((ExplicitConstructorCall) location).accessMode ==
1759 // ExplicitConstructorCall.ImplicitSuper);
1762 // insideConstructorCall
1763 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1764 // : IProblem.MissingEnclosingInstance,
1765 // new String[] {new String(enclosingType.readableName())},
1766 // new String[] {new String(enclosingType.shortReadableName())},
1767 // location.sourceStart,
1768 // location.sourceEnd);
1770 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1771 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
1772 methodDecl.sourceStart, methodDecl.sourceEnd);
1774 public void missingSemiColon(Expression expression) {
1775 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
1776 expression.sourceStart, expression.sourceEnd);
1778 public void mustDefineDimensionsOrInitializer(
1779 ArrayAllocationExpression expression) {
1780 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1781 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1783 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1784 String[] arguments = new String[]{new String(compUnitDecl.getFileName())};
1785 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
1786 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1788 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1789 this.handle(IProblem.StaticMethodRequested, new String[]{
1790 new String(method.declaringClass.readableName()),
1791 new String(method.selector), parametersAsString(method)}, new String[]{
1792 new String(method.declaringClass.shortReadableName()),
1793 new String(method.selector), parametersAsShortString(method)},
1794 messageSend.sourceStart, messageSend.sourceEnd);
1796 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
1797 AbstractMethodDeclaration methodDecl) {
1798 String[] arguments = new String[]{new String(type.sourceName()),
1799 new String(methodDecl.selector)};
1800 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments,
1801 methodDecl.sourceStart, methodDecl.sourceEnd);
1803 public void needImplementation() {
1804 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1806 public void needToEmulateFieldReadAccess(FieldBinding field, AstNode location) {
1807 this.handle(IProblem.NeedToEmulateFieldReadAccess,
1808 new String[]{new String(field.declaringClass.readableName()),
1809 new String(field.name)}, new String[]{
1810 new String(field.declaringClass.shortReadableName()),
1811 new String(field.name)}, location.sourceStart, location.sourceEnd);
1813 public void needToEmulateFieldWriteAccess(FieldBinding field, AstNode location) {
1814 this.handle(IProblem.NeedToEmulateFieldWriteAccess,
1815 new String[]{new String(field.declaringClass.readableName()),
1816 new String(field.name)}, new String[]{
1817 new String(field.declaringClass.shortReadableName()),
1818 new String(field.name)}, location.sourceStart, location.sourceEnd);
1820 public void needToEmulateMethodAccess(MethodBinding method, AstNode location) {
1821 if (method.isConstructor())
1822 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{
1823 new String(method.declaringClass.readableName()),
1824 parametersAsString(method)}, new String[]{
1825 new String(method.declaringClass.shortReadableName()),
1826 parametersAsShortString(method)}, location.sourceStart,
1827 location.sourceEnd);
1829 this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{
1830 new String(method.declaringClass.readableName()),
1831 new String(method.selector), parametersAsString(method)},
1832 new String[]{new String(method.declaringClass.shortReadableName()),
1833 new String(method.selector), parametersAsShortString(method)},
1834 location.sourceStart, location.sourceEnd);
1836 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1837 String[] arguments = new String[]{new String(typeDecl.name)};
1838 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
1839 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1841 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
1843 String[] arguments = new String[]{new String(local.name)};
1844 this.handle(local instanceof SyntheticArgumentBinding
1845 ? IProblem.TooManySyntheticArgumentSlots
1846 : IProblem.TooManyArgumentSlots, arguments, arguments, Abort | Error,
1847 location.sourceStart, location.sourceEnd);
1849 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
1851 String[] arguments = new String[]{new String(local.name)};
1852 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort
1853 | Error, location.sourceStart, location.sourceEnd);
1855 public void noSuchEnclosingInstance(TypeBinding targetType, AstNode location,
1856 boolean isConstructorCall) {
1858 if (isConstructorCall) {
1859 //28 = No enclosing instance of type {0} is available due to some
1860 // intermediate constructor invocation
1861 id = IProblem.EnclosingInstanceInConstructorCall;
1862 } else if ((location instanceof ExplicitConstructorCall)
1863 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
1864 //20 = No enclosing instance of type {0} is accessible to invoke
1865 // the super constructor. Must define a constructor and explicitly
1866 // qualify its super constructor invocation with an instance of {0}
1867 // (e.g. x.super() where x is an instance of {0}).
1868 id = IProblem.MissingEnclosingInstanceForConstructorCall;
1869 } else if (location instanceof AllocationExpression
1870 && (((AllocationExpression) location).binding.declaringClass
1871 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
1872 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
1873 .superclass().isMemberType()))) {
1874 //21 = No enclosing instance of type {0} is accessible. Must
1875 // qualify the allocation with an enclosing instance of type {0}
1876 // (e.g. x.new A() where x is an instance of {0}).
1877 id = IProblem.MissingEnclosingInstance;
1879 //22 = No enclosing instance of the type {0} is accessible in
1881 id = IProblem.IncorrectEnclosingInstanceReference;
1883 this.handle(id, new String[]{new String(targetType.readableName())},
1884 new String[]{new String(targetType.shortReadableName())},
1885 location.sourceStart, location.sourceEnd);
1887 public void notCompatibleTypesError(EqualExpression expression,
1888 TypeBinding leftType, TypeBinding rightType) {
1889 String leftName = new String(leftType.readableName());
1890 String rightName = new String(rightType.readableName());
1891 String leftShortName = new String(leftType.shortReadableName());
1892 String rightShortName = new String(rightType.shortReadableName());
1893 if (leftShortName.equals(rightShortName)) {
1894 leftShortName = leftName;
1895 rightShortName = rightName;
1897 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{
1898 leftName, rightName}, new String[]{leftShortName, rightShortName},
1899 expression.sourceStart, expression.sourceEnd);
1901 public void notCompatibleTypesError(InstanceOfExpression expression,
1902 TypeBinding leftType, TypeBinding rightType) {
1903 String leftName = new String(leftType.readableName());
1904 String rightName = new String(rightType.readableName());
1905 String leftShortName = new String(leftType.shortReadableName());
1906 String rightShortName = new String(rightType.shortReadableName());
1907 if (leftShortName.equals(rightShortName)) {
1908 leftShortName = leftName;
1909 rightShortName = rightName;
1911 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[]{
1912 leftName, rightName}, new String[]{leftShortName, rightShortName},
1913 expression.sourceStart, expression.sourceEnd);
1915 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
1916 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument,
1917 type.sourceStart(), type.sourceEnd());
1919 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
1920 TypeBinding leftType, TypeBinding rightType) {
1921 String leftName = new String(leftType.readableName());
1922 String rightName = new String(rightType.readableName());
1923 String leftShortName = new String(leftType.shortReadableName());
1924 String rightShortName = new String(rightType.shortReadableName());
1925 if (leftShortName.equals(rightShortName)) {
1926 leftShortName = leftName;
1927 rightShortName = rightName;
1929 this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName},
1930 new String[]{leftShortName, rightShortName}, assignment.sourceStart,
1931 assignment.sourceEnd);
1933 public void overridesDeprecatedMethod(MethodBinding localMethod,
1934 MethodBinding inheritedMethod) {
1935 this.handle(IProblem.OverridingDeprecatedMethod, new String[]{
1936 new String(CharOperation.concat(localMethod.declaringClass
1937 .readableName(), localMethod.readableName(), '.')),
1938 new String(inheritedMethod.declaringClass.readableName())},
1940 new String(CharOperation.concat(localMethod.declaringClass
1941 .shortReadableName(), localMethod.shortReadableName(), '.')),
1942 new String(inheritedMethod.declaringClass.shortReadableName())},
1943 localMethod.sourceStart(), localMethod.sourceEnd());
1945 public void overridesPackageDefaultMethod(MethodBinding localMethod,
1946 MethodBinding inheritedMethod) {
1947 this.handle(IProblem.OverridingNonVisibleMethod, new String[]{
1948 new String(CharOperation.concat(localMethod.declaringClass
1949 .readableName(), localMethod.readableName(), '.')),
1950 new String(inheritedMethod.declaringClass.readableName())},
1952 new String(CharOperation.concat(localMethod.declaringClass
1953 .shortReadableName(), localMethod.shortReadableName(), '.')),
1954 new String(inheritedMethod.declaringClass.shortReadableName())},
1955 localMethod.sourceStart(), localMethod.sourceEnd());
1957 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1958 // String[] arguments = new String[]{CharOperation
1959 // .toString(compUnitDecl.currentPackage.tokens)};
1960 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
1961 // compUnitDecl.currentPackage.sourceStart,
1962 // compUnitDecl.currentPackage.sourceEnd);
1964 public void packageIsNotExpectedPackage(
1965 CompilationUnitDeclaration compUnitDecl) {
1966 String[] arguments = new String[]{CharOperation
1967 .toString(compUnitDecl.compilationResult.compilationUnit
1968 .getPackageName())};
1969 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
1970 compUnitDecl.currentPackage == null
1972 : compUnitDecl.currentPackage.sourceStart,
1973 compUnitDecl.currentPackage == null
1975 : compUnitDecl.currentPackage.sourceEnd);
1977 private String parametersAsString(MethodBinding method) {
1978 TypeBinding[] params = method.parameters;
1979 StringBuffer buffer = new StringBuffer();
1980 for (int i = 0, length = params.length; i < length; i++) {
1982 buffer.append(", "); //$NON-NLS-1$
1983 buffer.append(new String(params[i].readableName()));
1985 return buffer.toString();
1987 private String parametersAsShortString(MethodBinding method) {
1988 TypeBinding[] params = method.parameters;
1989 StringBuffer buffer = new StringBuffer();
1990 for (int i = 0, length = params.length; i < length; i++) {
1992 buffer.append(", "); //$NON-NLS-1$
1993 buffer.append(new String(params[i].shortReadableName()));
1995 return buffer.toString();
1997 public void parseError(int startPosition, int endPosition,
1998 char[] currentTokenSource, String errorTokenName, String[] possibleTokens) {
1999 if (possibleTokens.length == 0) { //no suggestion available
2000 if (isKeyword(currentTokenSource)) {
2001 String[] arguments = new String[]{new String(currentTokenSource)};
2002 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments,
2004 // this is the current -invalid- token position
2005 startPosition, endPosition);
2008 String[] arguments = new String[]{errorTokenName};
2009 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2010 // this is the current -invalid- token position
2011 startPosition, endPosition);
2015 //build a list of probable right tokens
2016 StringBuffer list = new StringBuffer(20);
2017 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2019 list.append(", "); //$NON-NLS-1$
2021 list.append(possibleTokens[i]);
2024 if (isKeyword(currentTokenSource)) {
2025 String[] arguments = new String[]{new String(currentTokenSource),
2027 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2028 // this is the current -invalid- token position
2029 startPosition, endPosition);
2032 //extract the literal when it's a literal
2033 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2034 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2035 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2036 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2037 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2038 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2039 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2040 errorTokenName = new String(currentTokenSource);
2042 String[] arguments = new String[]{errorTokenName, list.toString()};
2043 this.handle(IProblem.ParsingError, arguments, arguments,
2044 // this is the current -invalid- token position
2045 startPosition, endPosition);
2047 public void publicClassMustMatchFileName(
2048 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2049 this.referenceContext = typeDecl; // report the problem against the
2050 // type not the entire compilation
2052 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2053 new String(typeDecl.name)};
2054 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments,
2055 typeDecl.sourceStart, typeDecl.sourceEnd,
2056 compUnitDecl.compilationResult);
2058 public void recursiveConstructorInvocation(
2059 ExplicitConstructorCall constructorCall) {
2060 this.handle(IProblem.RecursiveConstructorInvocation, new String[]{
2061 new String(constructorCall.binding.declaringClass.readableName()),
2062 parametersAsString(constructorCall.binding)}, new String[]{
2063 new String(constructorCall.binding.declaringClass.shortReadableName()),
2064 parametersAsShortString(constructorCall.binding)},
2065 constructorCall.sourceStart, constructorCall.sourceEnd);
2067 public void redefineArgument(Argument arg) {
2068 String[] arguments = new String[]{new String(arg.name)};
2069 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2070 arg.sourceStart, arg.sourceEnd);
2072 public void redefineLocal(LocalDeclaration localDecl) {
2073 String[] arguments = new String[]{new String(localDecl.name)};
2074 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2075 localDecl.sourceStart, localDecl.sourceEnd);
2077 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2078 ArrayReference arrayRef) {
2079 this.handle(IProblem.ArrayReferenceRequired, new String[]{new String(
2080 arrayType.readableName())}, new String[]{new String(arrayType
2081 .shortReadableName())}, arrayRef.sourceStart, arrayRef.sourceEnd);
2083 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2084 MethodDeclaration methodDecl) {
2085 String[] arguments = new String[]{new String(methodDecl.selector)};
2086 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2087 methodDecl.sourceStart, methodDecl.sourceEnd);
2089 public void returnTypeProblem(SourceTypeBinding type,
2090 MethodDeclaration methodDecl, TypeBinding expectedType) {
2091 int problemId = expectedType.problemId();
2093 switch (problemId) {
2096 id = IProblem.ReturnTypeNotFound;
2100 id = IProblem.ReturnTypeNotVisible;
2104 id = IProblem.ReturnTypeAmbiguous;
2106 case InternalNameProvided :
2108 id = IProblem.ReturnTypeInternalNameProvided;
2110 case InheritedNameHidesEnclosingName :
2112 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2117 needImplementation(); // want to fail to see why we were
2121 this.handle(id, new String[]{new String(methodDecl.selector),
2122 new String(expectedType.readableName())}, new String[]{
2123 new String(methodDecl.selector),
2124 new String(expectedType.shortReadableName())},
2125 methodDecl.returnType.sourceStart, methodDecl.returnType.sourceEnd);
2127 public void scannerError(Parser parser, String errorTokenName) {
2128 Scanner scanner = parser.scanner;
2129 int flag = IProblem.ParsingErrorNoSuggestion;
2130 int startPos = scanner.startPosition;
2131 //special treatment for recognized errors....
2132 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2133 flag = IProblem.EndOfSource;
2134 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2135 flag = IProblem.InvalidHexa;
2136 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2137 flag = IProblem.InvalidOctal;
2138 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2139 flag = IProblem.InvalidCharacterConstant;
2140 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2141 flag = IProblem.InvalidEscape;
2142 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2143 flag = IProblem.InvalidUnicodeEscape;
2144 // better locate the error message
2145 char[] source = scanner.source;
2146 int checkPos = scanner.currentPosition - 1;
2147 if (checkPos >= source.length)
2148 checkPos = source.length - 1;
2149 while (checkPos >= startPos) {
2150 if (source[checkPos] == '\\')
2154 startPos = checkPos;
2155 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2156 flag = IProblem.InvalidFloat;
2157 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2158 flag = IProblem.UnterminatedString;
2159 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2160 flag = IProblem.UnterminatedComment;
2161 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2162 flag = IProblem.UnterminatedString;
2163 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2164 ? new String[]{errorTokenName}
2166 this.handle(flag, arguments, arguments,
2167 // this is the current -invalid- token position
2168 startPos, scanner.currentPosition - 1,
2169 parser.compilationUnit.compilationResult);
2171 public void shouldReturn(TypeBinding returnType, AstNode location) {
2172 this.handle(IProblem.ShouldReturnValue, new String[]{new String(returnType
2173 .readableName())}, new String[]{new String(returnType
2174 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2176 public void signalNoImplicitStringConversionForCharArrayExpression(
2177 Expression expression) {
2178 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
2179 NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2181 public void staticAndInstanceConflict(MethodBinding currentMethod,
2182 MethodBinding inheritedMethod) {
2183 if (currentMethod.isStatic())
2186 // This static method cannot hide the instance method from %1
2187 // 8.4.6.4 - If a class inherits more than one method with
2188 // the same signature a static (non-abstract) method cannot
2189 // hide an instance method.
2190 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2191 new String[]{new String(inheritedMethod.declaringClass
2192 .readableName())}, new String[]{new String(
2193 inheritedMethod.declaringClass.shortReadableName())},
2194 currentMethod.sourceStart(), currentMethod.sourceEnd());
2198 // This instance method cannot override the static method from %1
2199 // 8.4.6.4 - If a class inherits more than one method with
2200 // the same signature an instance (non-abstract) method
2201 // cannot override a static method.
2202 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2203 new String[]{new String(inheritedMethod.declaringClass
2204 .readableName())}, new String[]{new String(
2205 inheritedMethod.declaringClass.shortReadableName())},
2206 currentMethod.sourceStart(), currentMethod.sourceEnd());
2208 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
2209 FieldBinding field) {
2210 String[] arguments = new String[]{new String(field.readableName())};
2211 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2212 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2214 public void staticFieldAccessToNonStaticVariable(
2215 QualifiedNameReference nameRef, FieldBinding field) {
2216 String[] arguments = new String[]{new String(field.readableName())};
2217 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2218 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2220 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef,
2221 FieldBinding field) {
2222 String[] arguments = new String[]{new String(field.readableName())};
2223 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2224 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2226 public void staticInheritedMethodConflicts(SourceTypeBinding type,
2227 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2229 // The static method %1 conflicts with the abstract method in %2
2230 // 8.4.6.4 - If a class inherits more than one method with the
2231 // same signature it is an error for one to be static
2232 // (non-abstract) and the other abstract.
2233 IProblem.StaticInheritedMethodConflicts, new String[]{
2234 new String(concreteMethod.readableName()),
2235 new String(abstractMethods[0].declaringClass.readableName())},
2236 new String[]{new String(concreteMethod.readableName()),
2237 new String(abstractMethods[0].declaringClass.shortReadableName())},
2238 type.sourceStart(), type.sourceEnd());
2240 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2241 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
2242 NoArgument, location.sourceStart, location.sourceEnd);
2244 public void superclassMustBeAClass(SourceTypeBinding type,
2245 TypeReference superclassRef, ReferenceBinding superType) {
2246 this.handle(IProblem.SuperclassMustBeAClass, new String[]{
2247 new String(superType.readableName()), new String(type.sourceName())},
2248 new String[]{new String(superType.shortReadableName()),
2249 new String(type.sourceName())}, superclassRef.sourceStart,
2250 superclassRef.sourceEnd);
2252 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
2253 TypeDeclaration typeDecl, ReferenceBinding superType) {
2254 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{
2255 new String(superType.readableName()), new String(type.sourceName())},
2256 new String[]{new String(superType.shortReadableName()),
2257 new String(type.sourceName())}, typeDecl.sourceStart,
2258 typeDecl.sourceEnd);
2260 public void task(String tag, String message, String priority, int start,
2262 this.handle(IProblem.Task, new String[]{tag, message, priority/*
2270 */}, new String[]{tag, message, priority/*
2271 * secret argument that is not
2272 * surfaced in getMessage()
2275 public void tooManyDimensions(AstNode expression) {
2276 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
2277 expression.sourceStart, expression.sourceEnd);
2279 public void tooManyFields(TypeDeclaration typeDeclaration) {
2280 this.handle(IProblem.TooManyFields, new String[]{new String(
2281 typeDeclaration.binding.readableName())}, new String[]{new String(
2282 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2283 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2285 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2286 this.handle(IProblem.TooManyMethods, new String[]{new String(
2287 typeDeclaration.binding.readableName())}, new String[]{new String(
2288 typeDeclaration.binding.shortReadableName())}, Abort | Error,
2289 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2291 public void typeCastError(CastExpression expression, TypeBinding leftType,
2292 TypeBinding rightType) {
2293 String leftName = new String(leftType.readableName());
2294 String rightName = new String(rightType.readableName());
2295 String leftShortName = new String(leftType.shortReadableName());
2296 String rightShortName = new String(rightType.shortReadableName());
2297 if (leftShortName.equals(rightShortName)) {
2298 leftShortName = leftName;
2299 rightShortName = rightName;
2301 this.handle(IProblem.IllegalCast, new String[]{rightName, leftName},
2302 new String[]{rightShortName, leftShortName}, expression.sourceStart,
2303 expression.sourceEnd);
2305 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl,
2306 TypeDeclaration typeDecl) {
2307 this.referenceContext = typeDecl; // report the problem against the
2308 // type not the entire compilation
2310 String[] arguments = new String[]{new String(compUnitDecl.getFileName()),
2311 new String(typeDecl.name)};
2312 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
2313 typeDecl.sourceStart, typeDecl.sourceEnd,
2314 compUnitDecl.compilationResult);
2316 public void typeMismatchError(TypeBinding resultType,
2317 TypeBinding expectedType, AstNode location) {
2318 String resultTypeName = new String(resultType.readableName());
2319 String expectedTypeName = new String(expectedType.readableName());
2320 String resultTypeShortName = new String(resultType.shortReadableName());
2321 String expectedTypeShortName = new String(expectedType.shortReadableName());
2322 if (resultTypeShortName.equals(expectedTypeShortName)) {
2323 resultTypeShortName = resultTypeName;
2324 expectedTypeShortName = expectedTypeName;
2326 this.handle(IProblem.TypeMismatch, new String[]{resultTypeName,
2327 expectedTypeName}, new String[]{resultTypeShortName,
2328 expectedTypeShortName}, location.sourceStart, location.sourceEnd);
2330 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
2331 TypeBinding constantType, TypeBinding expectedType) {
2332 String constantTypeName = new String(constantType.readableName());
2333 String expectedTypeName = new String(expectedType.readableName());
2334 String constantTypeShortName = new String(constantType.shortReadableName());
2335 String expectedTypeShortName = new String(expectedType.shortReadableName());
2336 if (constantTypeShortName.equals(expectedTypeShortName)) {
2337 constantTypeShortName = constantTypeName;
2338 expectedTypeShortName = expectedTypeName;
2340 this.handle(IProblem.TypeMismatch, new String[]{constantTypeName,
2341 expectedTypeName}, new String[]{constantTypeShortName,
2342 expectedTypeShortName}, expression.sourceStart, expression.sourceEnd);
2344 public void undefinedLabel(BranchStatement statement) {
2345 String[] arguments = new String[]{new String(statement.label)};
2346 this.handle(IProblem.UndefinedLabel, arguments, arguments,
2347 statement.sourceStart, statement.sourceEnd);
2349 public void unexpectedStaticModifierForField(SourceTypeBinding type,
2350 FieldDeclaration fieldDecl) {
2351 String[] arguments = new String[]{fieldDecl.name()};
2352 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
2353 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2355 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
2356 AbstractMethodDeclaration methodDecl) {
2357 String[] arguments = new String[]{new String(type.sourceName()),
2358 new String(methodDecl.selector)};
2359 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
2360 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2362 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2363 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2364 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2365 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2366 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2367 this.handle(insideDefaultConstructor
2368 ? IProblem.UnhandledExceptionInDefaultConstructor
2369 : (insideImplicitConstructorCall
2370 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2371 : IProblem.UnhandledException), new String[]{new String(
2372 exceptionType.readableName())}, new String[]{new String(exceptionType
2373 .shortReadableName())}, location.sourceStart, location.sourceEnd);
2375 public void uninitializedBlankFinalField(FieldBinding binding,
2377 String[] arguments = new String[]{new String(binding.readableName())};
2378 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments,
2379 location.sourceStart, location.sourceEnd);
2381 public void uninitializedLocalVariable(LocalVariableBinding binding,
2383 String[] arguments = new String[]{new String(binding.readableName())};
2384 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
2385 location.sourceStart, location.sourceEnd);
2387 public void unmatchedBracket(int position, ReferenceContext context,
2388 CompilationResult compilationResult) {
2389 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position,
2390 position, context, compilationResult);
2392 public void unnecessaryEnclosingInstanceSpecification(Expression expression,
2393 ReferenceBinding targetType) {
2394 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
2395 new String[]{new String(targetType.readableName())},
2396 new String[]{new String(targetType.shortReadableName())},
2397 expression.sourceStart, expression.sourceEnd);
2399 public void unnecessaryReceiverForStaticMethod(AstNode location,
2400 MethodBinding method) {
2401 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{
2402 new String(method.declaringClass.readableName()),
2403 new String(method.selector), parametersAsString(method)}, new String[]{
2404 new String(method.declaringClass.shortReadableName()),
2405 new String(method.selector), parametersAsShortString(method)},
2406 location.sourceStart, location.sourceEnd);
2408 public void unnecessaryReceiverForStaticField(AstNode location,
2409 FieldBinding field) {
2410 this.handle(IProblem.NonStaticAccessToStaticField,
2411 new String[]{new String(field.declaringClass.readableName()),
2412 new String(field.name)}, new String[]{
2413 new String(field.declaringClass.shortReadableName()),
2414 new String(field.name)}, location.sourceStart, location.sourceEnd);
2416 public void unreachableCode(Statement statement) {
2417 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument,
2418 statement.sourceStart, statement.sourceEnd);
2420 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
2422 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2423 location.sourceStart, location.sourceEnd);
2425 public void unresolvableReference(NameReference nameRef, Binding binding) {
2426 int severity = Error;
2428 * also need to check that the searchedType is the receiver type if
2429 * (binding instanceof ProblemBinding) { ProblemBinding problem =
2430 * (ProblemBinding) binding; if (problem.searchType != null &&
2431 * problem.searchType.isHierarchyInconsistent()) severity = SecondaryError; }
2433 String[] arguments = new String[]{new String(binding.readableName())};
2434 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
2435 nameRef.sourceStart, nameRef.sourceEnd);
2437 public void unusedArgument(LocalDeclaration localDecl) {
2438 String[] arguments = new String[]{localDecl.name()};
2439 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
2440 localDecl.sourceStart, localDecl.sourceEnd);
2442 // public void unusedImport(ImportReference importRef) {
2443 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2444 // this.handle(IProblem.UnusedImport, arguments, arguments,
2445 // importRef.sourceStart, importRef.sourceEnd);
2447 public void unusedLocalVariable(LocalDeclaration localDecl) {
2448 String[] arguments = new String[]{localDecl.name()};
2449 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
2450 localDecl.sourceStart, localDecl.sourceEnd);
2452 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2453 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2455 // no complaint for no-arg constructors (or default ones) - known
2456 // pattern to block instantiation
2457 if (constructorDecl.arguments == null
2458 || constructorDecl.arguments.length == 0)
2460 MethodBinding constructor = constructorDecl.binding;
2461 this.handle(IProblem.UnusedPrivateConstructor, new String[]{
2462 new String(constructor.declaringClass.readableName()),
2463 parametersAsString(constructor)}, new String[]{
2464 new String(constructor.declaringClass.shortReadableName()),
2465 parametersAsShortString(constructor)}, constructorDecl.sourceStart,
2466 constructorDecl.sourceEnd);
2468 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2469 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2471 FieldBinding field = fieldDecl.binding;
2472 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2473 && field.isStatic() && field.isFinal()
2474 && TypeBinding.LongBinding == field.type) {
2475 return; // do not report unused serialVersionUID field
2477 this.handle(IProblem.UnusedPrivateField, new String[]{
2478 new String(field.declaringClass.readableName()),
2479 new String(field.name),}, new String[]{
2480 new String(field.declaringClass.shortReadableName()),
2481 new String(field.name),}, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2483 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2484 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2486 MethodBinding method = methodDecl.binding;
2487 // no report for serialization support 'void
2488 // readObject(ObjectInputStream)'
2489 if (!method.isStatic()
2490 && TypeBinding.VoidBinding == method.returnType
2491 && method.parameters.length == 1
2492 && method.parameters[0].dimensions() == 0
2493 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2494 && CharOperation.equals(
2495 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
2496 method.parameters[0].readableName())) {
2499 // no report for serialization support 'void
2500 // writeObject(ObjectOutputStream)'
2501 if (!method.isStatic()
2502 && TypeBinding.VoidBinding == method.returnType
2503 && method.parameters.length == 1
2504 && method.parameters[0].dimensions() == 0
2505 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2506 && CharOperation.equals(
2507 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
2508 method.parameters[0].readableName())) {
2511 // no report for serialization support 'Object readResolve()'
2512 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2513 && method.parameters.length == 0
2514 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2517 // no report for serialization support 'Object writeReplace()'
2518 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id
2519 && method.parameters.length == 0
2520 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2523 this.handle(IProblem.UnusedPrivateMethod, new String[]{
2524 new String(method.declaringClass.readableName()),
2525 new String(method.selector), parametersAsString(method)}, new String[]{
2526 new String(method.declaringClass.shortReadableName()),
2527 new String(method.selector), parametersAsShortString(method)},
2528 methodDecl.sourceStart, methodDecl.sourceEnd);
2530 public void unusedPrivateType(TypeDeclaration typeDecl) {
2531 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2533 ReferenceBinding type = typeDecl.binding;
2534 this.handle(IProblem.UnusedPrivateType, new String[]{new String(type
2536 new String[]{new String(type.shortReadableName()),},
2537 typeDecl.sourceStart, typeDecl.sourceEnd);
2539 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2540 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
2541 sourceStart, sourceEnd);
2543 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2544 String[] arguments = new String[]{new String(varDecl.name)};
2545 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
2546 varDecl.sourceStart, varDecl.sourceEnd);
2548 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2549 String[] arguments = new String[]{new String(varDecl.name)};
2550 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments,
2551 varDecl.sourceStart, varDecl.sourceEnd);
2553 public void visibilityConflict(MethodBinding currentMethod,
2554 MethodBinding inheritedMethod) {
2556 // Cannot reduce the visibility of the inherited method from %1
2557 // 8.4.6.3 - The access modifier of an hiding method must
2558 // provide at least as much access as the hidden method.
2559 // 8.4.6.3 - The access modifier of an overiding method must
2560 // provide at least as much access as the overriden method.
2561 IProblem.MethodReducesVisibility, new String[]{new String(
2562 inheritedMethod.declaringClass.readableName())},
2563 new String[]{new String(inheritedMethod.declaringClass
2564 .shortReadableName())}, currentMethod.sourceStart(), currentMethod
2567 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
2568 int under, int upper) {
2569 //the two catch block under and upper are in an incorrect order.
2570 //under should be define BEFORE upper in the source
2571 TypeReference typeRef = statement.catchArguments[under].type;
2572 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2573 typeRef.sourceStart, typeRef.sourceEnd);
2575 public void nonExternalizedStringLiteral(AstNode location) {
2576 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument,
2577 location.sourceStart, location.sourceEnd);
2579 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2580 this.handle(IProblem.TooManyBytesForStringConstant,
2581 new String[]{new String(typeDeclaration.binding.readableName())},
2582 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2583 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2585 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2586 this.handle(IProblem.TooManyConstantsInConstantPool,
2587 new String[]{new String(typeDeclaration.binding.readableName())},
2588 new String[]{new String(typeDeclaration.binding.shortReadableName())},
2589 Abort | Error, typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2591 private boolean isKeyword(char[] tokenSource) {
2593 * This code is heavily grammar dependant
2595 if (tokenSource == null) {
2599 Scanner scanner = new Scanner();
2600 scanner.setSource(tokenSource);
2601 int token = scanner.getNextToken();
2602 char[] currentKeyword;
2604 currentKeyword = scanner.getCurrentIdentifierSource();
2605 } catch (ArrayIndexOutOfBoundsException e) {
2608 int nextToken = scanner.getNextToken();
2609 if (nextToken == Scanner.TokenNameEOF
2610 && scanner.startPosition == scanner.source.length) { // to
2617 // ArrayIndexOutOfBoundsException
2618 // while reading the last token
2620 case Scanner.TokenNameERROR :
2621 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2622 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2627 case Scanner.TokenNameabstract :
2628 // case Scanner.TokenNameassert:
2629 // case Scanner.TokenNamebyte:
2630 case Scanner.TokenNamebreak :
2631 // case Scanner.TokenNameboolean:
2632 case Scanner.TokenNamecase :
2633 // case Scanner.TokenNamechar:
2634 case Scanner.TokenNamecatch :
2635 case Scanner.TokenNameclass :
2636 case Scanner.TokenNamecontinue :
2637 case Scanner.TokenNamedo :
2638 // case Scanner.TokenNamedouble:
2639 case Scanner.TokenNamedefault :
2640 case Scanner.TokenNameelse :
2641 case Scanner.TokenNameextends :
2642 case Scanner.TokenNamefor :
2643 // case Scanner.TokenNamefinal:
2644 // case Scanner.TokenNamefloat:
2645 // case Scanner.TokenNamefalse :
2646 case Scanner.TokenNamefinally :
2647 case Scanner.TokenNameif :
2648 // case Scanner.TokenNameint:
2649 // case Scanner.TokenNameimport:
2650 case Scanner.TokenNameinterface :
2651 case Scanner.TokenNameimplements :
2652 case Scanner.TokenNameinstanceof :
2653 // case Scanner.TokenNamelong:
2654 case Scanner.TokenNamenew :
2655 // case Scanner.TokenNamenull :
2656 // case Scanner.TokenNamenative:
2657 case Scanner.TokenNamepublic :
2658 // case Scanner.TokenNamepackage:
2659 case Scanner.TokenNameprivate :
2660 case Scanner.TokenNameprotected :
2661 case Scanner.TokenNamereturn :
2662 // case Scanner.TokenNameshort:
2663 case Scanner.TokenNamesuper :
2664 case Scanner.TokenNamestatic :
2665 case Scanner.TokenNameswitch :
2666 // case Scanner.TokenNamestrictfp:
2667 // case Scanner.TokenNamesynchronized:
2668 case Scanner.TokenNametry :
2669 // case Scanner.TokenNamethis :
2670 // case Scanner.TokenNametrue :
2671 case Scanner.TokenNamethrow :
2672 // case Scanner.TokenNamethrows:
2673 // case Scanner.TokenNametransient:
2674 // case Scanner.TokenNamevoid:
2675 // case Scanner.TokenNamevolatile:
2676 case Scanner.TokenNamewhile :
2684 } catch (InvalidInputException e) {
2689 public void phpParsingError(String[] messageArguments,
2690 int problemStartPosition, int problemEndPosition,
2691 ReferenceContext context, CompilationResult compilationResult) {
2692 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
2693 problemStartPosition, problemEndPosition, context, compilationResult);
2695 public void phpParsingWarning(String[] messageArguments,
2696 int problemStartPosition, int problemEndPosition,
2697 ReferenceContext context, CompilationResult compilationResult) {
2698 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
2699 problemStartPosition, problemEndPosition, context, compilationResult);
2701 public void phpVarDeprecatedWarning(
2702 int problemStartPosition, int problemEndPosition,
2703 ReferenceContext context, CompilationResult compilationResult) {
2704 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2706 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[]{},
2707 problemStartPosition, problemEndPosition, context, compilationResult);