1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.problem;
10 import net.sourceforge.phpdt.core.compiler.CharOperation;
11 import net.sourceforge.phpdt.core.compiler.IProblem;
12 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
13 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
14 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
15 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
16 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
17 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
19 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
20 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
22 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
27 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
30 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
31 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
32 import net.sourceforge.phpdt.internal.compiler.util.Util;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
75 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
76 public ReferenceContext referenceContext;
78 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
80 // IProblemFactory problemFactory) {
81 super(policy, options, problemFactory); //), problemFactory);
84 public void abortDueToInternalError(String errorMessage) {
85 String[] arguments = new String[] { errorMessage };
86 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0, 0);
89 public void abortDueToInternalError(String errorMessage, ASTNode location) {
90 String[] arguments = new String[] { errorMessage };
91 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, location.sourceStart, location.sourceEnd);
94 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
96 // %1 must be abstract since it cannot override the inherited
97 // package-private abstract method %2
98 IProblem.AbstractMethodCannotBeOverridden, new String[] { new String(type.sourceName()),
99 new String(CharOperation.concat(concreteMethod.declaringClass.readableName(), concreteMethod.readableName(), '.')) },
101 new String(type.sourceName()),
102 new String(CharOperation.concat(concreteMethod.declaringClass.shortReadableName(), concreteMethod.shortReadableName(),
103 '.')) }, type.sourceStart(), type.sourceEnd());
106 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
107 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
108 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
111 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
113 // Must implement the inherited abstract method %1
114 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
115 // must provide a concrete implementation of all of A's
117 IProblem.AbstractMethodMustBeImplemented, new String[] { new String(CharOperation.concat(abstractMethod.declaringClass
118 .readableName(), abstractMethod.readableName(), '.')) }, new String[] { new String(CharOperation.concat(
119 abstractMethod.declaringClass.shortReadableName(), abstractMethod.shortReadableName(), '.')) }, type.sourceStart(),
123 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
124 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, method.sourceStart, method.sourceEnd, method, method
125 .compilationResult());
128 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
129 String[] arguments = new String[] { new String(labelName) };
130 this.handle(IProblem.DuplicateLabel, arguments, arguments, location.sourceStart, location.sourceEnd);
133 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
134 this.handle(IProblem.AnonymousClassCannotExtendFinalClass, new String[] { new String(type.readableName()) },
135 new String[] { new String(type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
138 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
139 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
140 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
143 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
144 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
145 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
148 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg,
149 TypeBinding expectedType) {
150 int problemId = expectedType.problemId();
155 id = IProblem.ArgumentTypeNotFound;
159 id = IProblem.ArgumentTypeNotVisible;
163 id = IProblem.ArgumentTypeAmbiguous;
165 case InternalNameProvided:
167 id = IProblem.ArgumentTypeInternalNameProvided;
169 case InheritedNameHidesEnclosingName:
171 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
176 needImplementation(); // want to fail to see why we were
180 this.handle(id, new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.readableName()) },
181 new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName()) },
182 arg.type.sourceStart, arg.type.sourceEnd);
185 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
186 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, NoArgument, sourceStart, sourceEnd);
189 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
190 String[] arguments = new String[] { new String(name) };
191 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, assignment.sourceStart, assignment.sourceEnd);
194 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
195 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(expectedType.readableName()) },
196 new String[] { new String(expectedType.shortReadableName()) }, returnStatement.sourceStart, returnStatement.sourceEnd);
199 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
200 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, returnStatement.sourceStart, returnStatement.sourceEnd);
203 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
205 // String[] arguments = new String[] {new String(location.selector),
206 // parametersAsString(location.binding)};
207 // if (location.isConstructor()) {
209 // IProblem.BytecodeExceeds64KLimitForConstructor,
213 // location.sourceStart,
214 // location.sourceEnd);
217 // IProblem.BytecodeExceeds64KLimit,
221 // location.sourceStart,
222 // location.sourceEnd);
225 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
226 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, NoArgument, Error | Abort, location.sourceStart,
230 public void cannotAllocateVoidArray(Expression expression) {
231 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
234 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
235 this.handle(IProblem.FinalFieldAssignment, new String[] {
236 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
237 new String(field.readableName()) }, new String[] {
238 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
239 new String(field.shortReadableName()) }, location.sourceStart, location.sourceEnd);
242 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
243 String[] arguments = new String[] { new String(local.readableName()) };
244 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
247 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
248 String[] arguments = new String[] { new String(local.readableName()) };
249 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
252 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
253 String[] arguments = new String[] { new String(interfaceName) };
254 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, sourceStart, sourceEnd);
257 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
258 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, NoArgument, expresssion.sourceStart,
259 expresssion.sourceEnd);
262 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
263 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] { new String(method.declaringClass.readableName()),
264 new String(method.selector), parametersAsString(method) }, new String[] {
265 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
266 messageSend.sourceStart, messageSend.sourceEnd);
269 // public void cannotImportPackage(ImportReference importRef) {
270 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
271 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
272 // importRef.sourceStart, importRef.sourceEnd);
274 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
275 this.handle(IProblem.InvalidClassInstantiation, new String[] { new String(type.readableName()) }, new String[] { new String(
276 type.shortReadableName()) }, typeRef.sourceStart, typeRef.sourceEnd);
279 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
280 String[] arguments = new String[] { new String(local.readableName()) };
281 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, location.sourceStart, location.sourceEnd);
284 public void cannotReturnInInitializer(ASTNode location) {
285 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
288 public void cannotThrowNull(ThrowStatement statement) {
289 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
292 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
293 TypeBinding expectedType) {
294 this.handle(IProblem.CannotThrowType, new String[] { new String(expectedType.readableName()) }, new String[] { new String(
295 expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
298 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
299 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
302 public void cannotUseSuperInCodeSnippet(int start, int end) {
303 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument, Error | Abort, start, end);
306 public void caseExpressionMustBeConstant(Expression expression) {
307 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
310 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
311 String name = new String(type.sourceName());
312 String expectedFullName = new String(expectedType.readableName());
313 String expectedShortName = new String(expectedType.shortReadableName());
314 if (expectedShortName.equals(name))
315 expectedShortName = expectedFullName;
316 this.handle(IProblem.ClassExtendFinalClass, new String[] { expectedFullName, name }, new String[] { expectedShortName, name },
317 superclass.sourceStart, superclass.sourceEnd);
320 public void codeSnippetMissingClass(String missing, int start, int end) {
321 String[] arguments = new String[] { missing };
322 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error | Abort, start, end);
325 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
326 String[] arguments = new String[] { className, missingMethod, argumentTypes };
327 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error | Abort, start, end);
331 * Given the current configuration, answers which category the problem falls into: Error | Warning | Ignore
333 public int computeSeverity(int problemId) {
335 // severity can have been preset on the problem
336 // if ((problem.severity & Fatal) != 0){
340 // if not then check whether it is a configurable problem
342 case IProblem.PHPIncludeNotExistWarning:
343 return this.options.getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
344 case IProblem.PHPVarDeprecatedWarning:
345 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
346 case IProblem.PHPBadStyleKeywordWarning:
347 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
348 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
349 return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
351 case IProblem.MaskedCatch:
352 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
354 case IProblem.UnusedImport:
355 return this.options.getSeverity(CompilerOptions.UnusedImport);
357 case IProblem.MethodButWithConstructorName:
358 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
360 case IProblem.OverridingNonVisibleMethod:
361 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
363 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
364 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
365 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
367 case IProblem.OverridingDeprecatedMethod:
368 case IProblem.UsingDeprecatedType:
369 case IProblem.UsingDeprecatedMethod:
370 case IProblem.UsingDeprecatedConstructor:
371 case IProblem.UsingDeprecatedField:
372 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
374 case IProblem.LocalVariableIsNeverUsed:
375 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
377 case IProblem.ArgumentIsNeverUsed:
378 return this.options.getSeverity(CompilerOptions.UnusedArgument);
380 case IProblem.NoImplicitStringConversionForCharArrayExpression:
381 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
383 case IProblem.NeedToEmulateFieldReadAccess:
384 case IProblem.NeedToEmulateFieldWriteAccess:
385 case IProblem.NeedToEmulateMethodAccess:
386 case IProblem.NeedToEmulateConstructorAccess:
387 return this.options.getSeverity(CompilerOptions.AccessEmulation);
389 case IProblem.NonExternalizedStringLiteral:
390 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
392 case IProblem.UseAssertAsAnIdentifier:
393 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
395 case IProblem.NonStaticAccessToStaticMethod:
396 case IProblem.NonStaticAccessToStaticField:
397 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
399 // case IProblem.IndirectAccessToStaticMethod :
400 // case IProblem.IndirectAccessToStaticField :
401 // case IProblem.IndirectAccessToStaticType :
402 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
404 case IProblem.AssignmentHasNoEffect:
405 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
407 case IProblem.UnusedPrivateConstructor:
408 case IProblem.UnusedPrivateMethod:
409 case IProblem.UnusedPrivateField:
410 case IProblem.UnusedPrivateType:
411 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
416 // case IProblem.LocalVariableHidingLocalVariable:
417 // case IProblem.LocalVariableHidingField:
418 // case IProblem.ArgumentHidingLocalVariable:
419 // case IProblem.ArgumentHidingField:
420 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
422 // case IProblem.FieldHidingLocalVariable:
423 // case IProblem.FieldHidingField:
424 // return this.options.getSeverity(CompilerOptions.FieldHiding);
426 // case IProblem.PossibleAccidentalBooleanAssignment:
427 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
429 // case IProblem.SuperfluousSemicolon:
430 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
432 // case IProblem.UndocumentedEmptyBlock:
433 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
435 // case IProblem.UnnecessaryCast:
436 // case IProblem.UnnecessaryArgumentCast:
437 // case IProblem.UnnecessaryInstanceof:
438 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
440 // case IProblem.FinallyMustCompleteNormally:
441 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
443 // case IProblem.UnusedMethodDeclaredThrownException:
444 // case IProblem.UnusedConstructorDeclaredThrownException:
445 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
447 // case IProblem.UnqualifiedFieldAccess:
448 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
451 * Javadoc syntax errors
453 // Javadoc explicit IDs
454 // case IProblem.JavadocUnexpectedTag:
455 // case IProblem.JavadocDuplicateReturnTag:
456 // case IProblem.JavadocInvalidThrowsClass:
457 // case IProblem.JavadocInvalidSeeReference:
458 // case IProblem.JavadocInvalidSeeHref:
459 // case IProblem.JavadocInvalidSeeArgs:
460 // case IProblem.JavadocInvalidTag:
461 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
463 * Javadoc tags resolved references errors
465 // case IProblem.JavadocInvalidParamName:
466 // case IProblem.JavadocDuplicateParamName:
467 // case IProblem.JavadocMissingParamName:
468 // case IProblem.JavadocInvalidThrowsClassName:
469 // case IProblem.JavadocDuplicateThrowsClassName:
470 // case IProblem.JavadocMissingThrowsClassName:
471 // case IProblem.JavadocMissingSeeReference:
472 // case IProblem.JavadocUsingDeprecatedField:
473 // case IProblem.JavadocUsingDeprecatedConstructor:
474 // case IProblem.JavadocUsingDeprecatedMethod:
475 // case IProblem.JavadocUsingDeprecatedType:
476 // case IProblem.JavadocUndefinedField:
477 // case IProblem.JavadocNotVisibleField:
478 // case IProblem.JavadocAmbiguousField:
479 // case IProblem.JavadocUndefinedConstructor:
480 // case IProblem.JavadocNotVisibleConstructor:
481 // case IProblem.JavadocAmbiguousConstructor:
482 // case IProblem.JavadocUndefinedMethod:
483 // case IProblem.JavadocNotVisibleMethod:
484 // case IProblem.JavadocAmbiguousMethod:
485 // case IProblem.JavadocParameterMismatch:
486 // case IProblem.JavadocUndefinedType:
487 // case IProblem.JavadocNotVisibleType:
488 // case IProblem.JavadocAmbiguousType:
489 // case IProblem.JavadocInternalTypeNameProvided:
490 // case IProblem.JavadocNoMessageSendOnArrayType:
491 // case IProblem.JavadocNoMessageSendOnBaseType:
492 // if (!this.options.reportInvalidJavadocTags)
493 // return ProblemSeverities.Ignore;
495 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
497 * Javadoc missing tags errors
499 // case IProblem.JavadocMissingParamTag:
500 // case IProblem.JavadocMissingReturnTag:
501 // case IProblem.JavadocMissingThrowsTag:
502 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
504 * Missing Javadoc errors
506 // case IProblem.JavadocMissing:
507 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
508 // by default problems are errors.
514 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
515 // expression, TypeBinding trueType, TypeBinding falseType) {
517 // IProblem.IncompatibleTypesInConditionalOperator,
518 // new String[] {new String(trueType.readableName()), new
519 // String(falseType.readableName())},
520 // new String[] {new String(trueType.sourceName()), new
521 // String(falseType.sourceName())},
522 // expression.sourceStart,
523 // expression.sourceEnd);
525 // public void conflictingImport(ImportReference importRef) {
526 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
527 // this.handle(IProblem.ConflictingImport, arguments, arguments,
528 // importRef.sourceStart, importRef.sourceEnd);
530 public void constantOutOfFormat(NumberLiteral lit) {
531 // the literal is not in a correct format
532 // this code is called on IntLiteral and LongLiteral
533 // example 000811 ...the 8 is uncorrect.
534 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
535 char[] source = lit.source();
539 if ((source[1] == 'x') || (source[1] == 'X')) {
541 Radix = "Hexa"; //$NON-NLS-1$
544 Radix = "Octal"; //$NON-NLS-1$
546 //look for the first digit that is incorrect
548 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
549 if (Character.digit(source[i], radix) == -1) {
554 String[] arguments = new String[] { Radix + " " + new String(source)
555 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
556 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
558 } catch (IndexOutOfBoundsException ex) {
560 // just in case .... use a predefined error..
561 // we should never come here...(except if the code changes !)
562 this.constantOutOfRange(lit);
566 public void constantOutOfRange(Literal lit) {
567 // lit is some how out of range of it declared type
569 // 9999999999999999999999999999999999999999999999999999999999999999999
570 String[] arguments = new String[] { new String(lit.source()) };
571 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
574 public void deprecatedField(FieldBinding field, ASTNode location) {
575 this.handle(IProblem.UsingDeprecatedField, new String[] { new String(field.declaringClass.readableName()),
576 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
577 location.sourceStart, location.sourceEnd);
580 public void deprecatedMethod(MethodBinding method, ASTNode location) {
581 if (method.isConstructor())
582 this.handle(IProblem.UsingDeprecatedConstructor, new String[] { new String(method.declaringClass.readableName()),
583 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
584 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
586 this.handle(IProblem.UsingDeprecatedMethod, new String[] { new String(method.declaringClass.readableName()),
587 new String(method.selector), parametersAsString(method) }, new String[] {
588 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
589 location.sourceStart, location.sourceEnd);
592 public void deprecatedType(TypeBinding type, ASTNode location) {
593 if (location == null)
594 return; // 1G828DN - no type ref for synthetic arguments
595 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(type
596 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
599 public void duplicateCase(Case statement, Constant constant) {
600 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
601 this.handle(IProblem.DuplicateCase, arguments, arguments, statement.sourceStart, statement.sourceEnd);
604 public void duplicateDefaultCase(DefaultCase statement) {
605 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
608 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
609 this.handle(IProblem.DuplicateField, new String[] { new String(type.sourceName()), fieldDecl.name() }, new String[] {
610 new String(type.shortReadableName()), fieldDecl.name() }, fieldDecl.sourceStart, fieldDecl.sourceEnd);
613 // public void duplicateImport(ImportReference importRef) {
614 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
615 // this.handle(IProblem.DuplicateImport, arguments, arguments,
616 // importRef.sourceStart, importRef.sourceEnd);
618 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
619 String[] arguments = new String[] { new String(field.readableName()) };
620 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, arguments, reference.sourceStart, reference.sourceEnd);
623 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
624 String[] arguments = new String[] { new String(local.readableName()) };
625 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, arguments, location.sourceStart, location.sourceEnd);
628 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
629 String[] arguments = new String[] { new String(methodDecl.selector), new String(type.sourceName()) };
630 this.handle(IProblem.DuplicateMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
633 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
635 * to highlight modifiers use: this.handle( new Problem( DuplicateModifierForField, new String[] {fieldDecl.name()},
636 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
638 String[] arguments = new String[] { fieldDecl.name() };
639 this.handle(IProblem.DuplicateModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
642 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
643 this.handle(IProblem.DuplicateModifierForMethod,
644 new String[] { new String(type.sourceName()), new String(methodDecl.selector) }, new String[] {
645 new String(type.shortReadableName()), new String(methodDecl.selector) }, methodDecl.sourceStart, methodDecl.sourceEnd);
648 public void duplicateModifierForType(SourceTypeBinding type) {
649 String[] arguments = new String[] { new String(type.sourceName()) };
650 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type.sourceStart(), type.sourceEnd());
653 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
654 String[] arguments = new String[] { localDecl.name() };
655 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument : IProblem.DuplicateModifierForVariable, arguments,
656 arguments, localDecl.sourceStart, localDecl.sourceEnd);
659 public void duplicateNestedType(TypeDeclaration typeDecl) {
660 String[] arguments = new String[] { new String(typeDecl.name) };
661 this.handle(IProblem.DuplicateNestedType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
664 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
665 this.handle(IProblem.DuplicateSuperInterface, new String[] { new String(superType.readableName()),
666 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
667 typeDecl.sourceStart, typeDecl.sourceEnd);
670 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
671 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
672 this.referenceContext = typeDecl; // report the problem against the
673 // type not the entire compilation
675 this.handle(IProblem.DuplicateTypes, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
676 compUnitDecl.compilationResult);
679 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
680 StringBuffer buffer = new StringBuffer();
681 StringBuffer shortBuffer = new StringBuffer();
682 for (int i = 0, length = params.length; i < length; i++) {
684 buffer.append(", "); //$NON-NLS-1$
685 shortBuffer.append(", "); //$NON-NLS-1$
687 buffer.append(new String(params[i].readableName()));
688 shortBuffer.append(new String(params[i].shortReadableName()));
690 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType, new String[] {
691 new String(recType.readableName()), new String(messageSend.selector), buffer.toString() }, new String[] {
692 new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString() },
693 messageSend.sourceStart, messageSend.sourceEnd);
696 public void errorThisSuperInStatic(ASTNode reference) {
697 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
698 this.handle(IProblem.ThisInStaticContext, arguments, arguments, reference.sourceStart, reference.sourceEnd);
701 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
702 TypeBinding expectedType) {
703 int problemId = expectedType.problemId();
708 id = IProblem.ExceptionTypeNotFound;
712 id = IProblem.ExceptionTypeNotVisible;
716 id = IProblem.ExceptionTypeAmbiguous;
718 case InternalNameProvided:
720 id = IProblem.ExceptionTypeInternalNameProvided;
722 case InheritedNameHidesEnclosingName:
724 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
729 needImplementation(); // want to fail to see why we were
733 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
734 new String(methodDecl.selector), new String(expectedType.shortReadableName()) }, exceptionType.sourceStart,
735 exceptionType.sourceEnd);
738 public void expressionShouldBeAVariable(Expression expression) {
739 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
742 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
743 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
746 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
747 int problemId = expectedType.problemId();
752 id = IProblem.FieldTypeNotFound;
756 id = IProblem.FieldTypeNotVisible;
760 id = IProblem.FieldTypeAmbiguous;
762 case InternalNameProvided:
764 id = IProblem.FieldTypeInternalNameProvided;
766 case InheritedNameHidesEnclosingName:
768 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
773 needImplementation(); // want to fail to see why we were
777 this.handle(id, new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName()) },
778 new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName()) },
779 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
782 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
784 // Cannot override the final method from %1
785 // 8.4.3.3 - Final methods cannot be overridden or hidden.
786 IProblem.FinalMethodCannotBeOverridden, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
787 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
791 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
792 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
795 // use this private API when the compilation unit result can be found
797 // reference context. Otherwise, use the other API taking a problem and a
798 // compilation result
800 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
801 int problemEndPosition) {
802 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
803 referenceContext == null ? null : referenceContext.compilationResult());
804 referenceContext = null;
807 // use this private API when the compilation unit result can be found
809 // reference context. Otherwise, use the other API taking a problem and a
810 // compilation result
812 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition,
813 int problemEndPosition) {
814 this.handle(problemId, problemArguments, messageArguments, severity, problemStartPosition, problemEndPosition,
815 referenceContext, referenceContext == null ? null : referenceContext.compilationResult());
816 referenceContext = null;
819 // use this private API when the compilation unit result cannot be found
821 // reference context.
822 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
823 int problemEndPosition, CompilationResult unitResult) {
824 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
826 referenceContext = null;
829 public void hidingEnclosingType(TypeDeclaration typeDecl) {
830 String[] arguments = new String[] { new String(typeDecl.name) };
831 this.handle(IProblem.HidingEnclosingType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
834 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
837 String typeName = ""; //$NON-NLS-1$
838 String shortTypeName = ""; //$NON-NLS-1$
839 if (reference == null) { // can only happen when java.lang.Object is
841 start = sourceType.sourceStart();
842 end = sourceType.sourceEnd();
843 typeName = new String(superType.readableName());
844 shortTypeName = new String(superType.sourceName());
846 start = reference.sourceStart;
847 end = reference.sourceEnd;
848 char[][] qName = reference.getTypeName();
849 typeName = CharOperation.toString(qName);
850 shortTypeName = new String(qName[qName.length - 1]);
852 if (sourceType == superType)
853 this.handle(IProblem.HierarchyCircularitySelfReference, new String[] { new String(sourceType.sourceName()), typeName },
854 new String[] { new String(sourceType.sourceName()), shortTypeName }, start, end);
856 this.handle(IProblem.HierarchyCircularity, new String[] { new String(sourceType.sourceName()), typeName }, new String[] {
857 new String(sourceType.sourceName()), shortTypeName }, start, end);
860 public void hierarchyHasProblems(SourceTypeBinding type) {
861 String[] arguments = new String[] { new String(type.sourceName()) };
862 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type.sourceStart(), type.sourceEnd());
865 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
866 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
867 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
868 methodDecl.sourceEnd);
871 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
872 String[] arguments = new String[] { new String(type.sourceName()) };
873 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, arguments, arguments, type.sourceStart(), type
877 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
878 String[] arguments = new String[] { fieldDecl.name() };
879 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, arguments, arguments, fieldDecl.sourceStart,
880 fieldDecl.sourceEnd);
883 public void illegalModifierForClass(SourceTypeBinding type) {
884 String[] arguments = new String[] { new String(type.sourceName()) };
885 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
888 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
889 String[] arguments = new String[] { fieldDecl.name() };
890 this.handle(IProblem.IllegalModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
893 public void illegalModifierForInterface(SourceTypeBinding type) {
894 String[] arguments = new String[] { new String(type.sourceName()) };
895 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
898 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
899 String[] arguments = new String[] { fieldDecl.name() };
900 this.handle(IProblem.IllegalModifierForInterfaceField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
903 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
904 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
905 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
908 public void illegalModifierForLocalClass(SourceTypeBinding type) {
909 String[] arguments = new String[] { new String(type.sourceName()) };
910 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
913 public void illegalModifierForMemberClass(SourceTypeBinding type) {
914 String[] arguments = new String[] { new String(type.sourceName()) };
915 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
918 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
919 String[] arguments = new String[] { new String(type.sourceName()) };
920 this.handle(IProblem.IllegalModifierForMemberInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
923 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
924 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
925 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
928 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
929 String[] arguments = new String[] { localDecl.name() };
930 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument : IProblem.IllegalModifierForVariable, arguments,
931 arguments, localDecl.sourceStart, localDecl.sourceEnd);
934 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
935 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
936 new String[] { new String(enclosingType.readableName()) }, new String[] { new String(enclosingType.shortReadableName()) },
937 location.sourceStart, location.sourceEnd);
940 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
941 String[] arguments = new String[] { new String(type.sourceName()) };
942 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, arguments, type.sourceStart(), type.sourceEnd());
945 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
946 String[] arguments = new String[] { new String(fieldDecl.name()) };
947 this.handle(IProblem.IllegalVisibilityModifierCombinationForField, arguments, arguments, fieldDecl.sourceStart,
948 fieldDecl.sourceEnd);
951 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
952 String[] arguments = new String[] { new String(type.sourceName()) };
953 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, arguments, arguments, type.sourceStart(), type
957 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
958 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
959 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
960 methodDecl.sourceEnd);
963 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
964 String[] arguments = new String[] { new String(type.sourceName()) };
965 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, arguments, arguments, type.sourceStart(), type
969 public void illegalVoidExpression(ASTNode location) {
970 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
973 // public void importProblem(ImportReference importRef, Binding expectedImport) {
974 // int problemId = expectedImport.problemId();
976 // switch (problemId) {
979 // id = IProblem.ImportNotFound;
983 // id = IProblem.ImportNotVisible;
987 // id = IProblem.ImportAmbiguous;
989 // case InternalNameProvided :
991 // id = IProblem.ImportInternalNameProvided;
993 // case InheritedNameHidesEnclosingName :
995 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1000 // needImplementation(); // want to fail to see why we were
1005 // if (expectedImport instanceof ProblemReferenceBinding) {
1006 // argument = CharOperation
1007 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1009 // argument = CharOperation.toString(importRef.tokens);
1011 // String[] arguments = new String[]{argument};
1012 // this.handle(id, arguments, arguments, importRef.sourceStart,
1013 // importRef.sourceEnd);
1015 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod,
1016 MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1017 if (type == currentMethod.declaringClass) {
1019 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1022 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1024 id = IProblem.IncompatibleExceptionInThrowsClause;
1028 // Exception %1 is not compatible with throws
1030 // 9.4.4 - The type of exception in the throws
1031 // clause is incompatible.
1033 new String(exceptionType.sourceName()),
1034 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1035 '.')) }, new String[] {
1036 new String(exceptionType.sourceName()),
1037 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1038 .shortReadableName(), '.')) }, currentMethod.sourceStart(), currentMethod.sourceEnd());
1042 // Exception %1 in throws clause of %2 is not
1043 // compatible with %3
1044 // 9.4.4 - The type of exception in the throws
1045 // clause is incompatible.
1046 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, new String[] {
1047 new String(exceptionType.sourceName()),
1048 new String(CharOperation.concat(currentMethod.declaringClass.sourceName(), currentMethod.readableName(), '.')),
1049 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1050 '.')) }, new String[] {
1051 new String(exceptionType.sourceName()),
1052 new String(CharOperation
1053 .concat(currentMethod.declaringClass.sourceName(), currentMethod.shortReadableName(), '.')),
1054 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1055 .shortReadableName(), '.')) }, type.sourceStart(), type.sourceEnd());
1058 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1059 StringBuffer methodSignature = new StringBuffer();
1060 methodSignature.append(inheritedMethod.declaringClass.readableName()).append('.').append(inheritedMethod.readableName());
1061 StringBuffer shortSignature = new StringBuffer();
1062 shortSignature.append(inheritedMethod.declaringClass.shortReadableName()).append('.').append(
1063 inheritedMethod.shortReadableName());
1065 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1066 // Object protected method
1067 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1069 id = IProblem.IncompatibleReturnType;
1071 this.handle(id, new String[] { methodSignature.toString() }, new String[] { shortSignature.toString() }, currentMethod
1072 .sourceStart(), currentMethod.sourceEnd());
1075 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1076 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, expression.dimensions[index + 1].sourceStart,
1077 expression.dimensions[index + 1].sourceEnd);
1080 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1081 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(testType.readableName()) }, new String[] { new String(
1082 testType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1085 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1086 StringBuffer concreteSignature = new StringBuffer();
1087 concreteSignature.append(concreteMethod.declaringClass.readableName()).append('.').append(concreteMethod.readableName());
1088 StringBuffer shortSignature = new StringBuffer();
1089 shortSignature.append(concreteMethod.declaringClass.shortReadableName()).append('.').append(concreteMethod.shortReadableName());
1091 // The inherited method %1 cannot hide the public abstract method in %2
1092 IProblem.InheritedMethodReducesVisibility, new String[] { new String(concreteSignature.toString()),
1093 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] { new String(shortSignature.toString()),
1094 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
1097 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1098 StringBuffer methodSignatures = new StringBuffer();
1099 StringBuffer shortSignatures = new StringBuffer();
1100 for (int i = length; --i >= 0;) {
1101 methodSignatures.append(inheritedMethods[i].declaringClass.readableName()).append('.').append(
1102 inheritedMethods[i].readableName());
1103 shortSignatures.append(inheritedMethods[i].declaringClass.shortReadableName()).append('.').append(
1104 inheritedMethods[i].shortReadableName());
1106 methodSignatures.append(", "); //$NON-NLS-1$
1107 shortSignatures.append(", "); //$NON-NLS-1$
1111 // Return type is incompatible with %1
1112 // 9.4.2 - The return type from the method is incompatible with
1114 IProblem.IncompatibleReturnType, new String[] { methodSignatures.toString() }, new String[] { shortSignatures.toString() },
1115 type.sourceStart(), type.sourceEnd());
1118 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1119 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1122 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, ASTNode location) {
1123 this.handle(IProblem.CannotDefineStaticInitializerInLocalType, new String[] { new String(innerType.readableName()) },
1124 new String[] { new String(innerType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1127 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1128 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, NoArgument, constructor.sourceStart, constructor.sourceEnd,
1129 constructor, constructor.compilationResult());
1132 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1133 String[] arguments = new String[] { new String(type.sourceName()) };
1134 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1137 public void invalidBreak(ASTNode location) {
1138 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1141 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1142 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1143 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1144 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1145 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1146 int flag = IProblem.UndefinedConstructor; //default...
1147 switch (targetConstructor.problemId()) {
1149 if (insideDefaultConstructor) {
1150 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1151 } else if (insideImplicitConstructorCall) {
1152 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1154 flag = IProblem.UndefinedConstructor;
1158 if (insideDefaultConstructor) {
1159 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1160 } else if (insideImplicitConstructorCall) {
1161 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1163 flag = IProblem.NotVisibleConstructor;
1167 if (insideDefaultConstructor) {
1168 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1169 } else if (insideImplicitConstructorCall) {
1170 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1172 flag = IProblem.AmbiguousConstructor;
1178 needImplementation(); // want to fail to see why we were
1182 this.handle(flag, new String[] { new String(targetConstructor.declaringClass.readableName()),
1183 parametersAsString(targetConstructor) }, new String[] { new String(targetConstructor.declaringClass.shortReadableName()),
1184 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1187 public void invalidContinue(ASTNode location) {
1188 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1191 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1192 if (enclosingType.isAnonymousType())
1193 enclosingType = enclosingType.superclass();
1194 int flag = IProblem.UndefinedType; // default
1195 switch (type.problemId()) {
1198 flag = IProblem.UndefinedType;
1202 flag = IProblem.NotVisibleType;
1206 flag = IProblem.AmbiguousType;
1208 case InternalNameProvided:
1209 flag = IProblem.InternalTypeNameProvided;
1214 needImplementation(); // want to fail to see why we were
1218 this.handle(flag, new String[] { new String(enclosingType.readableName()) + "." + new String(type.readableName()) }, //$NON-NLS-1$
1219 new String[] { new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1220 expression.sourceStart, expression.sourceEnd);
1223 public void invalidExpressionAsStatement(Expression expression) {
1224 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1227 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1228 int severity = Error;
1229 int flag = IProblem.UndefinedField;
1230 FieldBinding field = fieldRef.binding;
1231 switch (field.problemId()) {
1233 flag = IProblem.UndefinedField;
1235 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1240 flag = IProblem.NotVisibleField;
1243 flag = IProblem.AmbiguousField;
1245 case NonStaticReferenceInStaticContext:
1246 flag = IProblem.NonStaticFieldFromStaticInvocation;
1248 case NonStaticReferenceInConstructorInvocation:
1249 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1251 case InheritedNameHidesEnclosingName:
1252 flag = IProblem.InheritedFieldHidesEnclosingName;
1254 case ReceiverTypeNotVisible:
1255 this.handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1256 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, fieldRef.receiver.sourceStart,
1257 fieldRef.receiver.sourceEnd);
1262 needImplementation(); // want to fail to see why we were
1266 String[] arguments = new String[] { new String(field.readableName()) };
1267 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, fieldRef.sourceEnd);
1270 public void invalidField(NameReference nameRef, FieldBinding field) {
1271 int flag = IProblem.UndefinedField;
1272 switch (field.problemId()) {
1274 flag = IProblem.UndefinedField;
1277 flag = IProblem.NotVisibleField;
1280 flag = IProblem.AmbiguousField;
1282 case NonStaticReferenceInStaticContext:
1283 flag = IProblem.NonStaticFieldFromStaticInvocation;
1285 case NonStaticReferenceInConstructorInvocation:
1286 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1288 case InheritedNameHidesEnclosingName:
1289 flag = IProblem.InheritedFieldHidesEnclosingName;
1291 case ReceiverTypeNotVisible:
1292 this.handle(IProblem.NotVisibleType, new String[] { new String(field.declaringClass.leafComponentType().readableName()) },
1293 new String[] { new String(field.declaringClass.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1299 needImplementation(); // want to fail to see why we were
1303 String[] arguments = new String[] { new String(field.readableName()) };
1304 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1307 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1308 //the resolution of the index-th field of qname failed
1309 //qname.otherBindings[index] is the binding that has produced the
1311 //The different targetted errors should be :
1315 if (searchedType.isBaseType()) {
1316 this.handle(IProblem.NoFieldOnBaseType, new String[] { new String(searchedType.readableName()),
1317 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), new String(nameRef.tokens[index]) },
1318 new String[] { new String(searchedType.sourceName()),
1319 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), new String(nameRef.tokens[index]) },
1320 nameRef.sourceStart, nameRef.sourceEnd);
1323 int flag = IProblem.UndefinedField;
1324 switch (field.problemId()) {
1326 flag = IProblem.UndefinedField;
1328 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1333 flag = IProblem.NotVisibleField;
1336 flag = IProblem.AmbiguousField;
1338 case NonStaticReferenceInStaticContext:
1339 flag = IProblem.NonStaticFieldFromStaticInvocation;
1341 case NonStaticReferenceInConstructorInvocation:
1342 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1344 case InheritedNameHidesEnclosingName:
1345 flag = IProblem.InheritedFieldHidesEnclosingName;
1347 case ReceiverTypeNotVisible:
1349 .handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1350 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1356 needImplementation(); // want to fail to see why we were
1360 String[] arguments = new String[] { CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1361 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1364 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1365 // CODE should be UPDATED according to error coding in the different
1366 // method binding errors
1367 // The different targetted errors should be :
1371 // InheritedNameHidesEnclosingName
1372 // InstanceMethodDuringConstructorInvocation
1373 // StaticMethodRequested
1374 int flag = IProblem.UndefinedMethod; //default...
1375 switch (method.problemId()) {
1377 flag = IProblem.UndefinedMethod;
1380 flag = IProblem.NotVisibleMethod;
1383 flag = IProblem.AmbiguousMethod;
1385 case InheritedNameHidesEnclosingName:
1386 flag = IProblem.InheritedMethodHidesEnclosingName;
1388 case NonStaticReferenceInConstructorInvocation:
1389 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1391 case NonStaticReferenceInStaticContext:
1392 flag = IProblem.StaticMethodRequested;
1394 case ReceiverTypeNotVisible:
1395 this.handle(IProblem.NotVisibleType, new String[] { new String(method.declaringClass.leafComponentType().readableName()) },
1396 new String[] { new String(method.declaringClass.leafComponentType().shortReadableName()) },
1397 messageSend.receiver.sourceStart, messageSend.receiver.sourceEnd);
1402 needImplementation(); // want to fail to see why we were
1406 if (flag == IProblem.UndefinedMethod) {
1407 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1408 if (problemMethod.closestMatch != null) {
1409 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1410 String parameterTypeNames = parametersAsString(method);
1411 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1412 String parameterTypeShortNames = parametersAsShortString(method);
1413 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1414 closestParameterTypeShortNames = closestParameterTypeNames;
1415 parameterTypeShortNames = parameterTypeNames;
1417 this.handle(IProblem.ParameterMismatch, new String[] {
1418 new String(problemMethod.closestMatch.declaringClass.readableName()), new String(problemMethod.closestMatch.selector),
1419 closestParameterTypeNames, parameterTypeNames }, new String[] {
1420 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1421 new String(problemMethod.closestMatch.selector), closestParameterTypeShortNames, parameterTypeShortNames },
1422 (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1426 this.handle(flag, new String[] { new String(method.declaringClass.readableName()), new String(method.selector),
1427 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
1428 new String(method.selector), parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32),
1429 (int) messageSend.nameSourcePosition);
1432 public void invalidNullToSynchronize(Expression expression) {
1433 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1436 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1437 String leftName = new String(leftType.readableName());
1438 String rightName = new String(rightType.readableName());
1439 String leftShortName = new String(leftType.shortReadableName());
1440 String rightShortName = new String(rightType.shortReadableName());
1441 if (leftShortName.equals(rightShortName)) {
1442 leftShortName = leftName;
1443 rightShortName = rightName;
1445 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1446 new String[] { expression.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1447 expression.sourceStart, expression.sourceEnd);
1450 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1451 String leftName = new String(leftType.readableName());
1452 String rightName = new String(rightType.readableName());
1453 String leftShortName = new String(leftType.shortReadableName());
1454 String rightShortName = new String(rightType.shortReadableName());
1455 if (leftShortName.equals(rightShortName)) {
1456 leftShortName = leftName;
1457 rightShortName = rightName;
1459 this.handle(IProblem.InvalidOperator, new String[] { assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1460 new String[] { assign.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1461 assign.sourceStart, assign.sourceEnd);
1464 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1465 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), new String(type.readableName()) },
1466 new String[] { expression.operatorToString(), new String(type.shortReadableName()) }, expression.sourceStart,
1467 expression.sourceEnd);
1470 public void invalidParenthesizedExpression(ASTNode reference) {
1471 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
1474 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1475 int problemId = expectedType.problemId();
1477 switch (problemId) {
1480 id = IProblem.SuperclassNotFound;
1484 id = IProblem.SuperclassNotVisible;
1488 id = IProblem.SuperclassAmbiguous;
1490 case InternalNameProvided:
1492 id = IProblem.SuperclassInternalNameProvided;
1494 case InheritedNameHidesEnclosingName:
1496 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1501 needImplementation(); // want to fail to see why we were
1505 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1506 new String(expectedType.shortReadableName()), new String(type.sourceName()) }, superclassRef.sourceStart,
1507 superclassRef.sourceEnd);
1510 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1511 int problemId = expectedType.problemId();
1513 switch (problemId) {
1516 id = IProblem.InterfaceNotFound;
1520 id = IProblem.InterfaceNotVisible;
1524 id = IProblem.InterfaceAmbiguous;
1526 case InternalNameProvided:
1528 id = IProblem.InterfaceInternalNameProvided;
1530 case InheritedNameHidesEnclosingName:
1532 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1537 needImplementation(); // want to fail to see why we were
1541 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1542 new String(expectedType.shortReadableName()), new String(type.sourceName()) }, superinterfaceRef.sourceStart,
1543 superinterfaceRef.sourceEnd);
1546 public void invalidType(ASTNode location, TypeBinding type) {
1547 int flag = IProblem.UndefinedType; // default
1548 switch (type.problemId()) {
1550 flag = IProblem.UndefinedType;
1553 flag = IProblem.NotVisibleType;
1556 flag = IProblem.AmbiguousType;
1558 case InternalNameProvided:
1559 flag = IProblem.InternalTypeNameProvided;
1561 case InheritedNameHidesEnclosingName:
1562 flag = IProblem.InheritedTypeHidesEnclosingName;
1567 needImplementation(); // want to fail to see why we were
1571 this.handle(flag, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1572 location.sourceStart, location.sourceEnd);
1575 public void invalidTypeReference(Expression expression) {
1576 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1579 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1580 this.handle(IProblem.InvalidTypeToSynchronized, new String[] { new String(type.readableName()) }, new String[] { new String(
1581 type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1584 public void invalidUnaryExpression(Expression expression) {
1585 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1588 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
1589 referenceContext = compUnitDecl;
1590 String[] arguments = new String[] { CharOperation.toString(wellKnownTypeName) };
1591 this.handle(IProblem.IsClassPathCorrect, arguments, arguments, AbortCompilation | Error, compUnitDecl == null ? 0
1592 : compUnitDecl.sourceStart, compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
1595 public void maskedExceptionHandler(ReferenceBinding exceptionType, ASTNode location) {
1596 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1599 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1600 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1603 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1605 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1606 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1607 IProblem.BodyForAbstractMethod, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1610 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1611 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1614 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1615 // enclosingType, ASTNode location) {
1616 // boolean insideConstructorCall =
1617 // (location instanceof ExplicitConstructorCall)
1618 // && (((ExplicitConstructorCall) location).accessMode ==
1619 // ExplicitConstructorCall.ImplicitSuper);
1622 // insideConstructorCall
1623 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1624 // : IProblem.MissingEnclosingInstance,
1625 // new String[] {new String(enclosingType.readableName())},
1626 // new String[] {new String(enclosingType.shortReadableName())},
1627 // location.sourceStart,
1628 // location.sourceEnd);
1630 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1631 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1634 public void missingSemiColon(Expression expression) {
1635 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1638 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
1639 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, NoArgument, NoArgument, expression.sourceStart,
1640 expression.sourceEnd);
1643 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1644 String[] arguments = new String[] { new String(compUnitDecl.getFileName()) };
1645 this.handle(IProblem.MustSpecifyPackage, arguments, arguments, compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1648 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
1649 this.handle(IProblem.StaticMethodRequested, new String[] { new String(method.declaringClass.readableName()),
1650 new String(method.selector), parametersAsString(method) }, new String[] {
1651 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
1652 messageSend.sourceStart, messageSend.sourceEnd);
1655 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1656 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
1657 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1660 public void needImplementation() {
1661 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1664 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
1665 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] { new String(field.declaringClass.readableName()),
1666 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
1667 location.sourceStart, location.sourceEnd);
1670 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
1671 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] { new String(field.declaringClass.readableName()),
1672 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
1673 location.sourceStart, location.sourceEnd);
1676 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
1677 if (method.isConstructor())
1678 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] { new String(method.declaringClass.readableName()),
1679 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
1680 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
1682 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] { new String(method.declaringClass.readableName()),
1683 new String(method.selector), parametersAsString(method) }, new String[] {
1684 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
1685 location.sourceStart, location.sourceEnd);
1688 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1689 String[] arguments = new String[] { new String(typeDecl.name) };
1690 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1693 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, ASTNode location) {
1694 String[] arguments = new String[] { new String(local.name) };
1695 this.handle(local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots : IProblem.TooManyArgumentSlots,
1696 arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
1699 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, ASTNode location) {
1700 String[] arguments = new String[] { new String(local.name) };
1701 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
1704 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
1706 if (isConstructorCall) {
1707 //28 = No enclosing instance of type {0} is available due to some
1708 // intermediate constructor invocation
1709 id = IProblem.EnclosingInstanceInConstructorCall;
1710 } else if ((location instanceof ExplicitConstructorCall)
1711 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
1712 //20 = No enclosing instance of type {0} is accessible to invoke
1713 // the super constructor. Must define a constructor and explicitly
1714 // qualify its super constructor invocation with an instance of {0}
1715 // (e.g. x.super() where x is an instance of {0}).
1716 id = IProblem.MissingEnclosingInstanceForConstructorCall;
1717 } else if (location instanceof AllocationExpression
1718 && (((AllocationExpression) location).binding.declaringClass.isMemberType() || (((AllocationExpression) location).binding.declaringClass
1719 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
1720 //21 = No enclosing instance of type {0} is accessible. Must
1721 // qualify the allocation with an enclosing instance of type {0}
1722 // (e.g. x.new A() where x is an instance of {0}).
1723 id = IProblem.MissingEnclosingInstance;
1725 //22 = No enclosing instance of the type {0} is accessible in
1727 id = IProblem.IncorrectEnclosingInstanceReference;
1729 this.handle(id, new String[] { new String(targetType.readableName()) }, new String[] { new String(targetType
1730 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
1733 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
1734 String leftName = new String(leftType.readableName());
1735 String rightName = new String(rightType.readableName());
1736 String leftShortName = new String(leftType.shortReadableName());
1737 String rightShortName = new String(rightType.shortReadableName());
1738 if (leftShortName.equals(rightShortName)) {
1739 leftShortName = leftName;
1740 rightShortName = rightName;
1742 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] { leftName, rightName }, new String[] { leftShortName,
1743 rightShortName }, expression.sourceStart, expression.sourceEnd);
1746 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
1747 String leftName = new String(leftType.readableName());
1748 String rightName = new String(rightType.readableName());
1749 String leftShortName = new String(leftType.shortReadableName());
1750 String rightShortName = new String(rightType.shortReadableName());
1751 if (leftShortName.equals(rightShortName)) {
1752 leftShortName = leftName;
1753 rightShortName = rightName;
1755 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[] { leftName, rightName }, new String[] {
1756 leftShortName, rightShortName }, expression.sourceStart, expression.sourceEnd);
1759 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
1760 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument, type.sourceStart(), type.sourceEnd());
1763 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
1764 String leftName = new String(leftType.readableName());
1765 String rightName = new String(rightType.readableName());
1766 String leftShortName = new String(leftType.shortReadableName());
1767 String rightShortName = new String(rightType.shortReadableName());
1768 if (leftShortName.equals(rightShortName)) {
1769 leftShortName = leftName;
1770 rightShortName = rightName;
1772 this.handle(IProblem.TypeMismatch, new String[] { leftName, rightName }, new String[] { leftShortName, rightShortName },
1773 assignment.sourceStart, assignment.sourceEnd);
1776 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
1777 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
1778 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
1779 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
1780 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
1781 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
1784 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
1785 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
1786 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
1787 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
1788 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
1789 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
1792 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
1793 // String[] arguments = new String[]{CharOperation
1794 // .toString(compUnitDecl.currentPackage.tokens)};
1795 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
1796 // compUnitDecl.currentPackage.sourceStart,
1797 // compUnitDecl.currentPackage.sourceEnd);
1799 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
1800 String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()) };
1801 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0
1802 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
1805 private String parametersAsString(MethodBinding method) {
1806 TypeBinding[] params = method.parameters;
1807 StringBuffer buffer = new StringBuffer();
1808 for (int i = 0, length = params.length; i < length; i++) {
1810 buffer.append(", "); //$NON-NLS-1$
1811 buffer.append(new String(params[i].readableName()));
1813 return buffer.toString();
1816 private String parametersAsShortString(MethodBinding method) {
1817 TypeBinding[] params = method.parameters;
1818 StringBuffer buffer = new StringBuffer();
1819 for (int i = 0, length = params.length; i < length; i++) {
1821 buffer.append(", "); //$NON-NLS-1$
1822 buffer.append(new String(params[i].shortReadableName()));
1824 return buffer.toString();
1827 public void parseError(int startPosition, int endPosition, char[] currentTokenSource, String errorTokenName,
1828 String[] possibleTokens) {
1829 if (possibleTokens.length == 0) { //no suggestion available
1830 if (isKeyword(currentTokenSource)) {
1831 String[] arguments = new String[] { new String(currentTokenSource) };
1832 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments, arguments,
1833 // this is the current -invalid- token position
1834 startPosition, endPosition);
1837 String[] arguments = new String[] { errorTokenName };
1838 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
1839 // this is the current -invalid- token position
1840 startPosition, endPosition);
1844 //build a list of probable right tokens
1845 StringBuffer list = new StringBuffer(20);
1846 for (int i = 0, max = possibleTokens.length; i < max; i++) {
1848 list.append(", "); //$NON-NLS-1$
1850 list.append(possibleTokens[i]);
1853 if (isKeyword(currentTokenSource)) {
1854 String[] arguments = new String[] { new String(currentTokenSource), list.toString() };
1855 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
1856 // this is the current -invalid- token position
1857 startPosition, endPosition);
1860 //extract the literal when it's a literal
1861 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
1862 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
1863 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
1864 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
1865 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
1866 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
1867 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
1868 errorTokenName = new String(currentTokenSource);
1870 String[] arguments = new String[] { errorTokenName, list.toString() };
1871 this.handle(IProblem.ParsingError, arguments, arguments,
1872 // this is the current -invalid- token position
1873 startPosition, endPosition);
1876 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
1877 this.referenceContext = typeDecl; // report the problem against the
1878 // type not the entire compilation
1880 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
1881 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
1882 compUnitDecl.compilationResult);
1885 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
1886 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
1887 new String(constructorCall.binding.declaringClass.readableName()), parametersAsString(constructorCall.binding) },
1888 new String[] { new String(constructorCall.binding.declaringClass.shortReadableName()),
1889 parametersAsShortString(constructorCall.binding) }, constructorCall.sourceStart, constructorCall.sourceEnd);
1892 public void redefineArgument(Argument arg) {
1893 String[] arguments = new String[] { new String(arg.name) };
1894 this.handle(IProblem.RedefinedArgument, arguments, arguments, arg.sourceStart, arg.sourceEnd);
1897 public void redefineLocal(LocalDeclaration localDecl) {
1898 String[] arguments = new String[] { new String(localDecl.name) };
1899 this.handle(IProblem.RedefinedLocal, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
1902 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
1903 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(arrayType.readableName()) }, new String[] { new String(
1904 arrayType.shortReadableName()) }, arrayRef.sourceStart, arrayRef.sourceEnd);
1907 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
1908 String[] arguments = new String[] { new String(methodDecl.selector) };
1909 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1912 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
1913 int problemId = expectedType.problemId();
1915 switch (problemId) {
1918 id = IProblem.ReturnTypeNotFound;
1922 id = IProblem.ReturnTypeNotVisible;
1926 id = IProblem.ReturnTypeAmbiguous;
1928 case InternalNameProvided:
1930 id = IProblem.ReturnTypeInternalNameProvided;
1932 case InheritedNameHidesEnclosingName:
1934 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
1939 needImplementation(); // want to fail to see why we were
1943 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
1944 new String(methodDecl.selector), new String(expectedType.shortReadableName()) }, methodDecl.returnType.sourceStart,
1945 methodDecl.returnType.sourceEnd);
1948 public void scannerError(Parser parser, String errorTokenName) {
1949 Scanner scanner = parser.scanner;
1950 int flag = IProblem.ParsingErrorNoSuggestion;
1951 int startPos = scanner.startPosition;
1952 //special treatment for recognized errors....
1953 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
1954 flag = IProblem.EndOfSource;
1955 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
1956 flag = IProblem.InvalidHexa;
1957 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
1958 flag = IProblem.InvalidOctal;
1959 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
1960 flag = IProblem.InvalidCharacterConstant;
1961 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
1962 flag = IProblem.InvalidEscape;
1963 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
1964 flag = IProblem.InvalidUnicodeEscape;
1965 // better locate the error message
1966 char[] source = scanner.source;
1967 int checkPos = scanner.currentPosition - 1;
1968 if (checkPos >= source.length)
1969 checkPos = source.length - 1;
1970 while (checkPos >= startPos) {
1971 if (source[checkPos] == '\\')
1975 startPos = checkPos;
1976 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
1977 flag = IProblem.InvalidFloat;
1978 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
1979 flag = IProblem.UnterminatedString;
1980 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
1981 flag = IProblem.UnterminatedComment;
1982 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
1983 flag = IProblem.UnterminatedString;
1984 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName } : NoArgument;
1985 this.handle(flag, arguments, arguments,
1986 // this is the current -invalid- token position
1987 startPos, scanner.currentPosition - 1, parser.compilationUnit.compilationResult);
1990 public void shouldReturn(TypeBinding returnType, ASTNode location) {
1991 this.handle(IProblem.ShouldReturnValue, new String[] { new String(returnType.readableName()) }, new String[] { new String(
1992 returnType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1995 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
1996 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, NoArgument, NoArgument, expression.sourceStart,
1997 expression.sourceEnd);
2000 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2001 if (currentMethod.isStatic())
2003 // This static method cannot hide the instance method from %1
2004 // 8.4.6.4 - If a class inherits more than one method with
2005 // the same signature a static (non-abstract) method cannot
2006 // hide an instance method.
2007 IProblem.CannotHideAnInstanceMethodWithAStaticMethod, new String[] { new String(inheritedMethod.declaringClass
2008 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2009 .sourceStart(), currentMethod.sourceEnd());
2012 // This instance method cannot override the static method from %1
2013 // 8.4.6.4 - If a class inherits more than one method with
2014 // the same signature an instance (non-abstract) method
2015 // cannot override a static method.
2016 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, new String[] { new String(inheritedMethod.declaringClass
2017 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2018 .sourceStart(), currentMethod.sourceEnd());
2021 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2022 String[] arguments = new String[] { new String(field.readableName()) };
2023 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2026 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field) {
2027 String[] arguments = new String[] { new String(field.readableName()) };
2028 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2031 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2032 String[] arguments = new String[] { new String(field.readableName()) };
2033 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2036 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2038 // The static method %1 conflicts with the abstract method in %2
2039 // 8.4.6.4 - If a class inherits more than one method with the
2040 // same signature it is an error for one to be static
2041 // (non-abstract) and the other abstract.
2042 IProblem.StaticInheritedMethodConflicts, new String[] { new String(concreteMethod.readableName()),
2043 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
2044 new String(concreteMethod.readableName()), new String(abstractMethods[0].declaringClass.shortReadableName()) }, type
2045 .sourceStart(), type.sourceEnd());
2048 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
2049 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2052 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2053 this.handle(IProblem.SuperclassMustBeAClass,
2054 new String[] { new String(superType.readableName()), new String(type.sourceName()) }, new String[] {
2055 new String(superType.shortReadableName()), new String(type.sourceName()) }, superclassRef.sourceStart,
2056 superclassRef.sourceEnd);
2059 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2060 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] { new String(superType.readableName()),
2061 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
2062 typeDecl.sourceStart, typeDecl.sourceEnd);
2065 public void task(String tag, String message, String priority, int start, int end) {
2066 this.handle(IProblem.Task, new String[] { tag, message, priority /*
2067 * secret argument that is not surfaced in getMessage()
2068 */}, new String[] { tag, message, priority /*
2069 * secret argument that is not surfaced in getMessage()
2073 public void tooManyDimensions(ASTNode expression) {
2074 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2077 public void tooManyFields(TypeDeclaration typeDeclaration) {
2078 this.handle(IProblem.TooManyFields, new String[] { new String(typeDeclaration.binding.readableName()) },
2079 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2080 typeDeclaration.sourceEnd);
2083 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2084 this.handle(IProblem.TooManyMethods, new String[] { new String(typeDeclaration.binding.readableName()) },
2085 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2086 typeDeclaration.sourceEnd);
2089 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2090 String leftName = new String(leftType.readableName());
2091 String rightName = new String(rightType.readableName());
2092 String leftShortName = new String(leftType.shortReadableName());
2093 String rightShortName = new String(rightType.shortReadableName());
2094 if (leftShortName.equals(rightShortName)) {
2095 leftShortName = leftName;
2096 rightShortName = rightName;
2098 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName }, new String[] { rightShortName, leftShortName },
2099 expression.sourceStart, expression.sourceEnd);
2102 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2103 this.referenceContext = typeDecl; // report the problem against the
2104 // type not the entire compilation
2106 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2107 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2108 compUnitDecl.compilationResult);
2111 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, ASTNode location) {
2112 String resultTypeName = new String(resultType.readableName());
2113 String expectedTypeName = new String(expectedType.readableName());
2114 String resultTypeShortName = new String(resultType.shortReadableName());
2115 String expectedTypeShortName = new String(expectedType.shortReadableName());
2116 if (resultTypeShortName.equals(expectedTypeShortName)) {
2117 resultTypeShortName = resultTypeName;
2118 expectedTypeShortName = expectedTypeName;
2120 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName, expectedTypeName }, new String[] { resultTypeShortName,
2121 expectedTypeShortName }, location.sourceStart, location.sourceEnd);
2124 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2125 String constantTypeName = new String(constantType.readableName());
2126 String expectedTypeName = new String(expectedType.readableName());
2127 String constantTypeShortName = new String(constantType.shortReadableName());
2128 String expectedTypeShortName = new String(expectedType.shortReadableName());
2129 if (constantTypeShortName.equals(expectedTypeShortName)) {
2130 constantTypeShortName = constantTypeName;
2131 expectedTypeShortName = expectedTypeName;
2133 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName, expectedTypeName }, new String[] { constantTypeShortName,
2134 expectedTypeShortName }, expression.sourceStart, expression.sourceEnd);
2137 public void undefinedLabel(BranchStatement statement) {
2138 String[] arguments = new String[] { new String(statement.label) };
2139 this.handle(IProblem.UndefinedLabel, arguments, arguments, statement.sourceStart, statement.sourceEnd);
2142 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2143 String[] arguments = new String[] { fieldDecl.name() };
2144 this.handle(IProblem.UnexpectedStaticModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2147 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2148 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2149 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2152 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
2153 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2154 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2155 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2156 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2157 this.handle(insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
2158 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall : IProblem.UnhandledException),
2159 new String[] { new String(exceptionType.readableName()) }, new String[] { new String(exceptionType.shortReadableName()) },
2160 location.sourceStart, location.sourceEnd);
2163 public void uninitializedBlankFinalField(FieldBinding binding, ASTNode location) {
2164 String[] arguments = new String[] { new String(binding.readableName()) };
2165 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments, location.sourceStart, location.sourceEnd);
2168 public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) {
2169 String[] arguments = new String[] { new String(binding.readableName()) };
2170 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, location.sourceStart, location.sourceEnd);
2173 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2174 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position, position, context, compilationResult);
2177 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2178 this.handle(IProblem.IllegalEnclosingInstanceSpecification, new String[] { new String(targetType.readableName()) },
2179 new String[] { new String(targetType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
2182 public void unnecessaryReceiverForStaticMethod(ASTNode location, MethodBinding method) {
2183 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] { new String(method.declaringClass.readableName()),
2184 new String(method.selector), parametersAsString(method) }, new String[] {
2185 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2186 location.sourceStart, location.sourceEnd);
2189 public void unnecessaryReceiverForStaticField(ASTNode location, FieldBinding field) {
2190 this.handle(IProblem.NonStaticAccessToStaticField, new String[] { new String(field.declaringClass.readableName()),
2191 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2192 location.sourceStart, location.sourceEnd);
2195 public void unreachableCode(Statement statement) {
2196 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
2199 public void unreachableExceptionHandler(ReferenceBinding exceptionType, ASTNode location) {
2200 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2203 public void unresolvableReference(NameReference nameRef, Binding binding) {
2204 int severity = Error;
2206 * also need to check that the searchedType is the receiver type if (binding instanceof ProblemBinding) { ProblemBinding problem =
2207 * (ProblemBinding) binding; if (problem.searchType != null && problem.searchType.isHierarchyInconsistent()) severity =
2210 String[] arguments = new String[] { new String(binding.readableName()) };
2211 this.handle(IProblem.UndefinedName, arguments, arguments, severity, nameRef.sourceStart, nameRef.sourceEnd);
2214 public void unusedArgument(LocalDeclaration localDecl) {
2215 String[] arguments = new String[] { localDecl.name() };
2216 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2219 // public void unusedImport(ImportReference importRef) {
2220 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2221 // this.handle(IProblem.UnusedImport, arguments, arguments,
2222 // importRef.sourceStart, importRef.sourceEnd);
2224 public void unusedLocalVariable(LocalDeclaration localDecl) {
2225 String[] arguments = new String[] { localDecl.name() };
2226 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2229 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2230 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2232 // no complaint for no-arg constructors (or default ones) - known
2233 // pattern to block instantiation
2234 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0)
2236 MethodBinding constructor = constructorDecl.binding;
2237 this.handle(IProblem.UnusedPrivateConstructor, new String[] { new String(constructor.declaringClass.readableName()),
2238 parametersAsString(constructor) }, new String[] { new String(constructor.declaringClass.shortReadableName()),
2239 parametersAsShortString(constructor) }, constructorDecl.sourceStart, constructorDecl.sourceEnd);
2242 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2243 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2245 FieldBinding field = fieldDecl.binding;
2246 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) && field.isStatic() && field.isFinal()
2247 && TypeBinding.LongBinding == field.type) {
2248 return; // do not report unused serialVersionUID field
2250 this.handle(IProblem.UnusedPrivateField, new String[] { new String(field.declaringClass.readableName()),
2251 new String(field.name), }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name), },
2252 fieldDecl.sourceStart, fieldDecl.sourceEnd);
2255 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2256 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2258 MethodBinding method = methodDecl.binding;
2259 // no report for serialization support 'void
2260 // readObject(ObjectInputStream)'
2261 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2262 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2263 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
2266 // no report for serialization support 'void
2267 // writeObject(ObjectOutputStream)'
2268 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2269 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2270 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
2273 // no report for serialization support 'Object readResolve()'
2274 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2275 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2278 // no report for serialization support 'Object writeReplace()'
2279 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2280 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2283 this.handle(IProblem.UnusedPrivateMethod, new String[] { new String(method.declaringClass.readableName()),
2284 new String(method.selector), parametersAsString(method) }, new String[] {
2285 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2286 methodDecl.sourceStart, methodDecl.sourceEnd);
2289 public void unusedPrivateType(TypeDeclaration typeDecl) {
2290 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2292 ReferenceBinding type = typeDecl.binding;
2293 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type.readableName()), }, new String[] { new String(type
2294 .shortReadableName()), }, typeDecl.sourceStart, typeDecl.sourceEnd);
2297 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2298 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, sourceStart, sourceEnd);
2301 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2302 String[] arguments = new String[] { new String(varDecl.name) };
2303 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2306 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2307 String[] arguments = new String[] { new String(varDecl.name) };
2308 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2311 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2313 // Cannot reduce the visibility of the inherited method from %1
2314 // 8.4.6.3 - The access modifier of an hiding method must
2315 // provide at least as much access as the hidden method.
2316 // 8.4.6.3 - The access modifier of an overiding method must
2317 // provide at least as much access as the overriden method.
2318 IProblem.MethodReducesVisibility, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
2319 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
2323 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
2324 //the two catch block under and upper are in an incorrect order.
2325 //under should be define BEFORE upper in the source
2326 TypeReference typeRef = statement.catchArguments[under].type;
2327 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, typeRef.sourceStart, typeRef.sourceEnd);
2330 public void nonExternalizedStringLiteral(ASTNode location) {
2331 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2334 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2335 this.handle(IProblem.TooManyBytesForStringConstant, new String[] { new String(typeDeclaration.binding.readableName()) },
2336 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2337 typeDeclaration.sourceEnd);
2340 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2341 this.handle(IProblem.TooManyConstantsInConstantPool, new String[] { new String(typeDeclaration.binding.readableName()) },
2342 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2343 typeDeclaration.sourceEnd);
2346 private boolean isKeyword(char[] tokenSource) {
2348 * This code is heavily grammar dependant
2350 if (tokenSource == null) {
2354 Scanner scanner = new Scanner();
2355 scanner.setSource(tokenSource);
2356 int token = scanner.getNextToken();
2357 char[] currentKeyword;
2359 currentKeyword = scanner.getCurrentIdentifierSource();
2360 } catch (ArrayIndexOutOfBoundsException e) {
2363 int nextToken = scanner.getNextToken();
2364 if (nextToken == Scanner.TokenNameEOF && scanner.startPosition == scanner.source.length) { // to
2371 // ArrayIndexOutOfBoundsException
2372 // while reading the last token
2374 case Scanner.TokenNameERROR:
2375 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2376 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2381 case Scanner.TokenNameabstract:
2382 // case Scanner.TokenNameassert:
2383 // case Scanner.TokenNamebyte:
2384 case Scanner.TokenNamebreak:
2385 // case Scanner.TokenNameboolean:
2386 case Scanner.TokenNamecase:
2387 // case Scanner.TokenNamechar:
2388 case Scanner.TokenNamecatch:
2389 case Scanner.TokenNameclass:
2390 case Scanner.TokenNamecontinue:
2391 case Scanner.TokenNamedo:
2392 // case Scanner.TokenNamedouble:
2393 case Scanner.TokenNamedefault:
2394 case Scanner.TokenNameelse:
2395 case Scanner.TokenNameextends:
2396 case Scanner.TokenNamefor:
2397 // case Scanner.TokenNamefinal:
2398 // case Scanner.TokenNamefloat:
2399 // case Scanner.TokenNamefalse :
2400 case Scanner.TokenNamefinally:
2401 case Scanner.TokenNameif:
2402 // case Scanner.TokenNameint:
2403 // case Scanner.TokenNameimport:
2404 case Scanner.TokenNameinterface:
2405 case Scanner.TokenNameimplements:
2406 case Scanner.TokenNameinstanceof:
2407 // case Scanner.TokenNamelong:
2408 case Scanner.TokenNamenew:
2409 // case Scanner.TokenNamenull :
2410 // case Scanner.TokenNamenative:
2411 case Scanner.TokenNamepublic:
2412 // case Scanner.TokenNamepackage:
2413 case Scanner.TokenNameprivate:
2414 case Scanner.TokenNameprotected:
2415 case Scanner.TokenNamereturn:
2416 // case Scanner.TokenNameshort:
2417 case Scanner.TokenNamesuper:
2418 case Scanner.TokenNamestatic:
2419 case Scanner.TokenNameswitch:
2420 // case Scanner.TokenNamestrictfp:
2421 // case Scanner.TokenNamesynchronized:
2422 case Scanner.TokenNametry:
2423 // case Scanner.TokenNamethis :
2424 // case Scanner.TokenNametrue :
2425 case Scanner.TokenNamethrow:
2426 // case Scanner.TokenNamethrows:
2427 // case Scanner.TokenNametransient:
2428 // case Scanner.TokenNamevoid:
2429 // case Scanner.TokenNamevolatile:
2430 case Scanner.TokenNamewhile:
2438 } catch (InvalidInputException e) {
2444 public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2445 ReferenceContext context, CompilationResult compilationResult) {
2446 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2450 public void phpParsingWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2451 ReferenceContext context, CompilationResult compilationResult) {
2452 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2456 public void phpVarDeprecatedWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2457 CompilationResult compilationResult) {
2458 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2460 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[] {}, problemStartPosition, problemEndPosition, context,
2464 public void phpIncludeNotExistWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2465 CompilationResult compilationResult) {
2466 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
2468 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2472 public void phpKeywordWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2473 ReferenceContext context, CompilationResult compilationResult) {
2474 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
2476 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2477 context, compilationResult);
2480 public void phpUppercaseIdentifierWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2481 CompilationResult compilationResult) {
2482 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
2484 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[] {}, problemStartPosition,
2485 problemEndPosition, context, compilationResult);