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.env.IConstants;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
32 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
33 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
34 import net.sourceforge.phpdt.internal.compiler.util.Util;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.CaseStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
77 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
78 public ReferenceContext referenceContext;
80 public ProblemReporter(IErrorHandlingPolicy policy, CompilerOptions options, IProblemFactory problemFactory) {
82 // IProblemFactory problemFactory) {
83 super(policy, options, problemFactory); //), problemFactory);
86 public void abortDueToInternalError(String errorMessage) {
87 String[] arguments = new String[] { errorMessage };
88 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, 0, 0);
91 public void abortDueToInternalError(String errorMessage, ASTNode location) {
92 String[] arguments = new String[] { errorMessage };
93 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort, location.sourceStart, location.sourceEnd);
96 public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) {
98 // %1 must be abstract since it cannot override the inherited
99 // package-private abstract method %2
100 IProblem.AbstractMethodCannotBeOverridden, new String[] { new String(type.sourceName()),
101 new String(CharOperation.concat(concreteMethod.declaringClass.readableName(), concreteMethod.readableName(), '.')) },
103 new String(type.sourceName()),
104 new String(CharOperation.concat(concreteMethod.declaringClass.shortReadableName(), concreteMethod.shortReadableName(),
105 '.')) }, type.sourceStart(), type.sourceEnd());
108 public void abstractMethodInAbstractClass(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
109 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
110 this.handle(IProblem.AbstractMethodInAbstractClass, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
113 public void abstractMethodMustBeImplemented(SourceTypeBinding type, MethodBinding abstractMethod) {
115 // Must implement the inherited abstract method %1
116 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
117 // must provide a concrete implementation of all of A's
119 IProblem.AbstractMethodMustBeImplemented, new String[] { new String(CharOperation.concat(abstractMethod.declaringClass
120 .readableName(), abstractMethod.readableName(), '.')) }, new String[] { new String(CharOperation.concat(
121 abstractMethod.declaringClass.shortReadableName(), abstractMethod.shortReadableName(), '.')) }, type.sourceStart(),
125 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
126 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument, method.sourceStart, method.sourceEnd, method, method
127 .compilationResult());
130 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
131 String[] arguments = new String[] { new String(labelName) };
132 this.handle(IProblem.DuplicateLabel, arguments, arguments, location.sourceStart, location.sourceEnd);
135 public void anonymousClassCannotExtendFinalClass(Expression expression, TypeBinding type) {
136 this.handle(IProblem.AnonymousClassCannotExtendFinalClass, new String[] { new String(type.readableName()) },
137 new String[] { new String(type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
140 public void argumentTypeCannotBeVoid(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
141 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
142 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
145 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg) {
146 String[] arguments = new String[] { new String(methodDecl.selector), new String(arg.name) };
147 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
150 public void argumentTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, Argument arg,
151 TypeBinding expectedType) {
152 int problemId = expectedType.problemId();
157 id = IProblem.ArgumentTypeNotFound;
161 id = IProblem.ArgumentTypeNotVisible;
165 id = IProblem.ArgumentTypeAmbiguous;
167 case InternalNameProvided:
169 id = IProblem.ArgumentTypeInternalNameProvided;
171 case InheritedNameHidesEnclosingName:
173 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
178 needImplementation(); // want to fail to see why we were
182 this.handle(id, new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.readableName()) },
183 new String[] { new String(methodDecl.selector), arg.name(), new String(expectedType.shortReadableName()) },
184 arg.type.sourceStart, arg.type.sourceEnd);
187 public void arrayConstantsOnlyInArrayInitializers(int sourceStart, int sourceEnd) {
188 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument, NoArgument, sourceStart, sourceEnd);
191 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
192 String[] arguments = new String[] { new String(name) };
193 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments, assignment.sourceStart, assignment.sourceEnd);
196 public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
197 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(expectedType.readableName()) },
198 new String[] { new String(expectedType.shortReadableName()) }, returnStatement.sourceStart, returnStatement.sourceEnd);
201 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
202 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument, returnStatement.sourceStart, returnStatement.sourceEnd);
205 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
207 // String[] arguments = new String[] {new String(location.selector),
208 // parametersAsString(location.binding)};
209 // if (location.isConstructor()) {
211 // IProblem.BytecodeExceeds64KLimitForConstructor,
215 // location.sourceStart,
216 // location.sourceEnd);
219 // IProblem.BytecodeExceeds64KLimit,
223 // location.sourceStart,
224 // location.sourceEnd);
227 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
228 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument, NoArgument, Error | Abort, location.sourceStart,
232 public void cannotAllocateVoidArray(Expression expression) {
233 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
236 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
237 this.handle(IProblem.FinalFieldAssignment, new String[] {
238 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
239 new String(field.readableName()) }, new String[] {
240 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
241 new String(field.shortReadableName()) }, location.sourceStart, location.sourceEnd);
244 public void cannotAssignToFinalLocal(LocalVariableBinding local, ASTNode location) {
245 String[] arguments = new String[] { new String(local.readableName()) };
246 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
249 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
250 String[] arguments = new String[] { new String(local.readableName()) };
251 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments, location.sourceStart, location.sourceEnd);
254 public void cannotDeclareLocalInterface(char[] interfaceName, int sourceStart, int sourceEnd) {
255 String[] arguments = new String[] { new String(interfaceName) };
256 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, sourceStart, sourceEnd);
259 public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) {
260 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, NoArgument, expresssion.sourceStart,
261 expresssion.sourceEnd);
264 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend, MethodBinding method) {
265 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] { new String(method.declaringClass.readableName()),
266 new String(method.selector), parametersAsString(method) }, new String[] {
267 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
268 messageSend.sourceStart, messageSend.sourceEnd);
271 // public void cannotImportPackage(ImportReference importRef) {
272 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
273 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
274 // importRef.sourceStart, importRef.sourceEnd);
276 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
277 this.handle(IProblem.InvalidClassInstantiation, new String[] { new String(type.readableName()) }, new String[] { new String(
278 type.shortReadableName()) }, typeRef.sourceStart, typeRef.sourceEnd);
281 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local, ASTNode location) {
282 String[] arguments = new String[] { new String(local.readableName()) };
283 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments, location.sourceStart, location.sourceEnd);
286 public void cannotReturnInInitializer(ASTNode location) {
287 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
290 public void cannotThrowNull(ThrowStatement statement) {
291 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
294 public void cannotThrowType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
295 TypeBinding expectedType) {
296 this.handle(IProblem.CannotThrowType, new String[] { new String(expectedType.readableName()) }, new String[] { new String(
297 expectedType.shortReadableName()) }, exceptionType.sourceStart, exceptionType.sourceEnd);
300 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
301 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
304 public void cannotUseSuperInCodeSnippet(int start, int end) {
305 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument, NoArgument, Error | Abort, start, end);
308 public void caseExpressionMustBeConstant(Expression expression) {
309 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
312 public void classExtendFinalClass(SourceTypeBinding type, TypeReference superclass, TypeBinding expectedType) {
313 String name = new String(type.sourceName());
314 String expectedFullName = new String(expectedType.readableName());
315 String expectedShortName = new String(expectedType.shortReadableName());
316 if (expectedShortName.equals(name))
317 expectedShortName = expectedFullName;
318 this.handle(IProblem.ClassExtendFinalClass, new String[] { expectedFullName, name }, new String[] { expectedShortName, name },
319 superclass.sourceStart, superclass.sourceEnd);
322 public void codeSnippetMissingClass(String missing, int start, int end) {
323 String[] arguments = new String[] { missing };
324 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments, Error | Abort, start, end);
327 public void codeSnippetMissingMethod(String className, String missingMethod, String argumentTypes, int start, int end) {
328 String[] arguments = new String[] { className, missingMethod, argumentTypes };
329 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments, Error | Abort, start, end);
333 * Given the current configuration, answers which category the problem falls into: Error | Warning | Ignore
335 public int computeSeverity(int problemId) {
337 // severity can have been preset on the problem
338 // if ((problem.severity & Fatal) != 0){
342 // if not then check whether it is a configurable problem
344 case IProblem.PHPIncludeNotExistWarning:
345 return this.options.getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
346 case IProblem.PHPVarDeprecatedWarning:
347 return this.options.getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
348 case IProblem.PHPBadStyleKeywordWarning:
349 return this.options.getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
350 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
351 return this.options.getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
353 case IProblem.MaskedCatch:
354 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
356 case IProblem.UnusedImport:
357 return this.options.getSeverity(CompilerOptions.UnusedImport);
359 case IProblem.MethodButWithConstructorName:
360 return this.options.getSeverity(CompilerOptions.MethodWithConstructorName);
362 case IProblem.OverridingNonVisibleMethod:
363 return this.options.getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
365 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
366 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
367 return this.options.getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
369 case IProblem.OverridingDeprecatedMethod:
370 case IProblem.UsingDeprecatedType:
371 case IProblem.UsingDeprecatedMethod:
372 case IProblem.UsingDeprecatedConstructor:
373 case IProblem.UsingDeprecatedField:
374 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
376 case IProblem.LocalVariableIsNeverUsed:
377 return this.options.getSeverity(CompilerOptions.UnusedLocalVariable);
379 case IProblem.ArgumentIsNeverUsed:
380 return this.options.getSeverity(CompilerOptions.UnusedArgument);
382 case IProblem.NoImplicitStringConversionForCharArrayExpression:
383 return this.options.getSeverity(CompilerOptions.NoImplicitStringConversion);
385 case IProblem.NeedToEmulateFieldReadAccess:
386 case IProblem.NeedToEmulateFieldWriteAccess:
387 case IProblem.NeedToEmulateMethodAccess:
388 case IProblem.NeedToEmulateConstructorAccess:
389 return this.options.getSeverity(CompilerOptions.AccessEmulation);
391 case IProblem.NonExternalizedStringLiteral:
392 return this.options.getSeverity(CompilerOptions.NonExternalizedString);
394 case IProblem.UseAssertAsAnIdentifier:
395 return this.options.getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
397 case IProblem.NonStaticAccessToStaticMethod:
398 case IProblem.NonStaticAccessToStaticField:
399 return this.options.getSeverity(CompilerOptions.NonStaticAccessToStatic);
401 // case IProblem.IndirectAccessToStaticMethod :
402 // case IProblem.IndirectAccessToStaticField :
403 // case IProblem.IndirectAccessToStaticType :
404 // return this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
406 case IProblem.AssignmentHasNoEffect:
407 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
409 case IProblem.UnusedPrivateConstructor:
410 case IProblem.UnusedPrivateMethod:
411 case IProblem.UnusedPrivateField:
412 case IProblem.UnusedPrivateType:
413 return this.options.getSeverity(CompilerOptions.UnusedPrivateMember);
418 // case IProblem.LocalVariableHidingLocalVariable:
419 // case IProblem.LocalVariableHidingField:
420 // case IProblem.ArgumentHidingLocalVariable:
421 // case IProblem.ArgumentHidingField:
422 // return this.options.getSeverity(CompilerOptions.LocalVariableHiding);
424 // case IProblem.FieldHidingLocalVariable:
425 // case IProblem.FieldHidingField:
426 // return this.options.getSeverity(CompilerOptions.FieldHiding);
428 // case IProblem.PossibleAccidentalBooleanAssignment:
429 // return this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
431 // case IProblem.SuperfluousSemicolon:
432 // return this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
434 // case IProblem.UndocumentedEmptyBlock:
435 // return this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
437 // case IProblem.UnnecessaryCast:
438 // case IProblem.UnnecessaryArgumentCast:
439 // case IProblem.UnnecessaryInstanceof:
440 // return this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
442 // case IProblem.FinallyMustCompleteNormally:
443 // return this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
445 // case IProblem.UnusedMethodDeclaredThrownException:
446 // case IProblem.UnusedConstructorDeclaredThrownException:
447 // return this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
449 // case IProblem.UnqualifiedFieldAccess:
450 // return this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
453 * Javadoc syntax errors
455 // Javadoc explicit IDs
456 // case IProblem.JavadocUnexpectedTag:
457 // case IProblem.JavadocDuplicateReturnTag:
458 // case IProblem.JavadocInvalidThrowsClass:
459 // case IProblem.JavadocInvalidSeeReference:
460 // case IProblem.JavadocInvalidSeeHref:
461 // case IProblem.JavadocInvalidSeeArgs:
462 // case IProblem.JavadocInvalidTag:
463 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
465 * Javadoc tags resolved references errors
467 // case IProblem.JavadocInvalidParamName:
468 // case IProblem.JavadocDuplicateParamName:
469 // case IProblem.JavadocMissingParamName:
470 // case IProblem.JavadocInvalidThrowsClassName:
471 // case IProblem.JavadocDuplicateThrowsClassName:
472 // case IProblem.JavadocMissingThrowsClassName:
473 // case IProblem.JavadocMissingSeeReference:
474 // case IProblem.JavadocUsingDeprecatedField:
475 // case IProblem.JavadocUsingDeprecatedConstructor:
476 // case IProblem.JavadocUsingDeprecatedMethod:
477 // case IProblem.JavadocUsingDeprecatedType:
478 // case IProblem.JavadocUndefinedField:
479 // case IProblem.JavadocNotVisibleField:
480 // case IProblem.JavadocAmbiguousField:
481 // case IProblem.JavadocUndefinedConstructor:
482 // case IProblem.JavadocNotVisibleConstructor:
483 // case IProblem.JavadocAmbiguousConstructor:
484 // case IProblem.JavadocUndefinedMethod:
485 // case IProblem.JavadocNotVisibleMethod:
486 // case IProblem.JavadocAmbiguousMethod:
487 // case IProblem.JavadocParameterMismatch:
488 // case IProblem.JavadocUndefinedType:
489 // case IProblem.JavadocNotVisibleType:
490 // case IProblem.JavadocAmbiguousType:
491 // case IProblem.JavadocInternalTypeNameProvided:
492 // case IProblem.JavadocNoMessageSendOnArrayType:
493 // case IProblem.JavadocNoMessageSendOnBaseType:
494 // if (!this.options.reportInvalidJavadocTags)
495 // return ProblemSeverities.Ignore;
497 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
499 * Javadoc missing tags errors
501 // case IProblem.JavadocMissingParamTag:
502 // case IProblem.JavadocMissingReturnTag:
503 // case IProblem.JavadocMissingThrowsTag:
504 // return this.options.getSeverity(CompilerOptions.MissingJavadocTags);
506 * Missing Javadoc errors
508 // case IProblem.JavadocMissing:
509 // return this.options.getSeverity(CompilerOptions.MissingJavadocComments);
510 // by default problems are errors.
516 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
517 // expression, TypeBinding trueType, TypeBinding falseType) {
519 // IProblem.IncompatibleTypesInConditionalOperator,
520 // new String[] {new String(trueType.readableName()), new
521 // String(falseType.readableName())},
522 // new String[] {new String(trueType.sourceName()), new
523 // String(falseType.sourceName())},
524 // expression.sourceStart,
525 // expression.sourceEnd);
527 // public void conflictingImport(ImportReference importRef) {
528 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
529 // this.handle(IProblem.ConflictingImport, arguments, arguments,
530 // importRef.sourceStart, importRef.sourceEnd);
532 public void constantOutOfFormat(NumberLiteral lit) {
533 // the literal is not in a correct format
534 // this code is called on IntLiteral and LongLiteral
535 // example 000811 ...the 8 is uncorrect.
536 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
537 char[] source = lit.source();
541 if ((source[1] == 'x') || (source[1] == 'X')) {
543 Radix = "Hexa"; //$NON-NLS-1$
546 Radix = "Octal"; //$NON-NLS-1$
548 //look for the first digit that is incorrect
550 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
551 if (Character.digit(source[i], radix) == -1) {
556 String[] arguments = new String[] { Radix + " " + new String(source)
557 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
558 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
560 } catch (IndexOutOfBoundsException ex) {
562 // just in case .... use a predefined error..
563 // we should never come here...(except if the code changes !)
564 this.constantOutOfRange(lit);
568 public void constantOutOfRange(Literal lit) {
569 // lit is some how out of range of it declared type
571 // 9999999999999999999999999999999999999999999999999999999999999999999
572 String[] arguments = new String[] { new String(lit.source()) };
573 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments, lit.sourceStart, lit.sourceEnd);
576 public void deprecatedField(FieldBinding field, ASTNode location) {
577 this.handle(IProblem.UsingDeprecatedField, new String[] { new String(field.declaringClass.readableName()),
578 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
579 location.sourceStart, location.sourceEnd);
582 public void deprecatedMethod(MethodBinding method, ASTNode location) {
583 if (method.isConstructor())
584 this.handle(IProblem.UsingDeprecatedConstructor, new String[] { new String(method.declaringClass.readableName()),
585 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
586 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
588 this.handle(IProblem.UsingDeprecatedMethod, new String[] { new String(method.declaringClass.readableName()),
589 new String(method.selector), parametersAsString(method) }, new String[] {
590 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
591 location.sourceStart, location.sourceEnd);
594 public void deprecatedType(TypeBinding type, ASTNode location) {
595 if (location == null)
596 return; // 1G828DN - no type ref for synthetic arguments
597 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(type.readableName()) }, new String[] { new String(type
598 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
601 public void duplicateCase(CaseStatement statement, Constant constant) {
602 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
603 this.handle(IProblem.DuplicateCase, arguments, arguments, statement.sourceStart, statement.sourceEnd);
606 public void duplicateDefaultCase(DefaultCase statement) {
607 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
610 public void duplicateFieldInType(SourceTypeBinding type, FieldDeclaration fieldDecl) {
611 this.handle(IProblem.DuplicateField, new String[] { new String(type.sourceName()), fieldDecl.name() }, new String[] {
612 new String(type.shortReadableName()), fieldDecl.name() }, fieldDecl.sourceStart, fieldDecl.sourceEnd);
615 // public void duplicateImport(ImportReference importRef) {
616 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
617 // this.handle(IProblem.DuplicateImport, arguments, arguments,
618 // importRef.sourceStart, importRef.sourceEnd);
620 public void duplicateInitializationOfBlankFinalField(FieldBinding field, Reference reference) {
621 String[] arguments = new String[] { new String(field.readableName()) };
622 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments, arguments, reference.sourceStart, reference.sourceEnd);
625 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local, ASTNode location) {
626 String[] arguments = new String[] { new String(local.readableName()) };
627 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments, arguments, location.sourceStart, location.sourceEnd);
630 public void duplicateMethodInType(SourceTypeBinding type, AbstractMethodDeclaration methodDecl) {
631 String[] arguments = new String[] { new String(methodDecl.selector), new String(type.sourceName()) };
632 this.handle(IProblem.DuplicateMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
635 public void duplicateModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
637 * to highlight modifiers use: this.handle( new Problem( DuplicateModifierForField, new String[] {fieldDecl.name()},
638 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
640 String[] arguments = new String[] { fieldDecl.name() };
641 this.handle(IProblem.DuplicateModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
644 public void duplicateModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
645 this.handle(IProblem.DuplicateModifierForMethod,
646 new String[] { new String(type.sourceName()), new String(methodDecl.selector) }, new String[] {
647 new String(type.shortReadableName()), new String(methodDecl.selector) }, methodDecl.sourceStart, methodDecl.sourceEnd);
650 public void duplicateModifierForType(SourceTypeBinding type) {
651 String[] arguments = new String[] { new String(type.sourceName()) };
652 this.handle(IProblem.DuplicateModifierForType, arguments, arguments, type.sourceStart(), type.sourceEnd());
655 public void duplicateModifierForVariable(LocalDeclaration localDecl, boolean complainForArgument) {
656 String[] arguments = new String[] { localDecl.name() };
657 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument : IProblem.DuplicateModifierForVariable, arguments,
658 arguments, localDecl.sourceStart, localDecl.sourceEnd);
661 public void duplicateNestedType(TypeDeclaration typeDecl) {
662 String[] arguments = new String[] { new String(typeDecl.name) };
663 this.handle(IProblem.DuplicateNestedType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
666 public void duplicateSuperinterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
667 this.handle(IProblem.DuplicateSuperInterface, new String[] { new String(superType.readableName()),
668 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
669 typeDecl.sourceStart, typeDecl.sourceEnd);
672 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
673 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
674 this.referenceContext = typeDecl; // report the problem against the
675 // type not the entire compilation
677 this.handle(IProblem.DuplicateTypes, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
678 compUnitDecl.compilationResult);
681 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params) {
682 StringBuffer buffer = new StringBuffer();
683 StringBuffer shortBuffer = new StringBuffer();
684 for (int i = 0, length = params.length; i < length; i++) {
686 buffer.append(", "); //$NON-NLS-1$
687 shortBuffer.append(", "); //$NON-NLS-1$
689 buffer.append(new String(params[i].readableName()));
690 shortBuffer.append(new String(params[i].shortReadableName()));
692 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType : IProblem.NoMessageSendOnBaseType, new String[] {
693 new String(recType.readableName()), new String(messageSend.selector), buffer.toString() }, new String[] {
694 new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString() },
695 messageSend.sourceStart, messageSend.sourceEnd);
698 public void errorThisSuperInStatic(ASTNode reference) {
699 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
700 this.handle(IProblem.ThisInStaticContext, arguments, arguments, reference.sourceStart, reference.sourceEnd);
703 public void exceptionTypeProblem(SourceTypeBinding type, AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
704 TypeBinding expectedType) {
705 int problemId = expectedType.problemId();
710 id = IProblem.ExceptionTypeNotFound;
714 id = IProblem.ExceptionTypeNotVisible;
718 id = IProblem.ExceptionTypeAmbiguous;
720 case InternalNameProvided:
722 id = IProblem.ExceptionTypeInternalNameProvided;
724 case InheritedNameHidesEnclosingName:
726 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
731 needImplementation(); // want to fail to see why we were
735 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
736 new String(methodDecl.selector), new String(expectedType.shortReadableName()) }, exceptionType.sourceStart,
737 exceptionType.sourceEnd);
740 public void expressionShouldBeAVariable(Expression expression) {
741 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
744 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
745 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
748 public void fieldTypeProblem(SourceTypeBinding type, FieldDeclaration fieldDecl, TypeBinding expectedType) {
749 int problemId = expectedType.problemId();
754 id = IProblem.FieldTypeNotFound;
758 id = IProblem.FieldTypeNotVisible;
762 id = IProblem.FieldTypeAmbiguous;
764 case InternalNameProvided:
766 id = IProblem.FieldTypeInternalNameProvided;
768 case InheritedNameHidesEnclosingName:
770 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
775 needImplementation(); // want to fail to see why we were
779 this.handle(id, new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.readableName()) },
780 new String[] { fieldDecl.name(), new String(type.sourceName()), new String(expectedType.shortReadableName()) },
781 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
784 public void finalMethodCannotBeOverridden(MethodBinding currentMethod, MethodBinding inheritedMethod) {
786 // Cannot override the final method from %1
787 // 8.4.3.3 - Final methods cannot be overridden or hidden.
788 IProblem.FinalMethodCannotBeOverridden, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
789 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
793 public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) {
794 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
797 // use this private API when the compilation unit result can be found
799 // reference context. Otherwise, use the other API taking a problem and a
800 // compilation result
802 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
803 int problemEndPosition) {
804 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
805 referenceContext == null ? null : referenceContext.compilationResult());
806 referenceContext = null;
809 // use this private API when the compilation unit result can be found
811 // reference context. Otherwise, use the other API taking a problem and a
812 // compilation result
814 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int severity, int problemStartPosition,
815 int problemEndPosition) {
816 this.handle(problemId, problemArguments, messageArguments, severity, problemStartPosition, problemEndPosition,
817 referenceContext, referenceContext == null ? null : referenceContext.compilationResult());
818 referenceContext = null;
821 // use this private API when the compilation unit result cannot be found
823 // reference context.
824 private void handle(int problemId, String[] problemArguments, String[] messageArguments, int problemStartPosition,
825 int problemEndPosition, CompilationResult unitResult) {
826 this.handle(problemId, problemArguments, messageArguments, problemStartPosition, problemEndPosition, referenceContext,
828 referenceContext = null;
831 public void hidingEnclosingType(TypeDeclaration typeDecl) {
832 String[] arguments = new String[] { new String(typeDecl.name) };
833 this.handle(IProblem.HidingEnclosingType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
836 public void hierarchyCircularity(SourceTypeBinding sourceType, ReferenceBinding superType, TypeReference reference) {
839 String typeName = ""; //$NON-NLS-1$
840 String shortTypeName = ""; //$NON-NLS-1$
841 if (reference == null) { // can only happen when java.lang.Object is
843 start = sourceType.sourceStart();
844 end = sourceType.sourceEnd();
845 typeName = new String(superType.readableName());
846 shortTypeName = new String(superType.sourceName());
848 start = reference.sourceStart;
849 end = reference.sourceEnd;
850 char[][] qName = reference.getTypeName();
851 typeName = CharOperation.toString(qName);
852 shortTypeName = new String(qName[qName.length - 1]);
854 if (sourceType == superType)
855 this.handle(IProblem.HierarchyCircularitySelfReference, new String[] { new String(sourceType.sourceName()), typeName },
856 new String[] { new String(sourceType.sourceName()), shortTypeName }, start, end);
858 this.handle(IProblem.HierarchyCircularity, new String[] { new String(sourceType.sourceName()), typeName }, new String[] {
859 new String(sourceType.sourceName()), shortTypeName }, start, end);
862 public void hierarchyHasProblems(SourceTypeBinding type) {
863 String[] arguments = new String[] { new String(type.sourceName()) };
864 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type.sourceStart(), type.sourceEnd());
867 public void illegalAbstractModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
868 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
869 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
870 methodDecl.sourceEnd);
873 public void illegalModifierCombinationFinalAbstractForClass(SourceTypeBinding type) {
874 String[] arguments = new String[] { new String(type.sourceName()) };
875 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass, arguments, arguments, type.sourceStart(), type
879 public void illegalModifierCombinationFinalVolatileForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
880 String[] arguments = new String[] { fieldDecl.name() };
881 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField, arguments, arguments, fieldDecl.sourceStart,
882 fieldDecl.sourceEnd);
885 public void illegalModifierForClass(SourceTypeBinding type) {
886 String[] arguments = new String[] { new String(type.sourceName()) };
887 this.handle(IProblem.IllegalModifierForClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
890 public void illegalModifierForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
891 String[] arguments = new String[] { fieldDecl.name() };
892 this.handle(IProblem.IllegalModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
895 public void illegalModifierForInterface(SourceTypeBinding type) {
896 String[] arguments = new String[] { new String(type.sourceName()) };
897 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
900 public void illegalModifierForInterfaceField(ReferenceBinding type, FieldDeclaration fieldDecl) {
901 String[] arguments = new String[] { fieldDecl.name() };
902 this.handle(IProblem.IllegalModifierForInterfaceField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
905 public void illegalModifierForInterfaceMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
906 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
907 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
910 public void illegalModifierForLocalClass(SourceTypeBinding type) {
911 String[] arguments = new String[] { new String(type.sourceName()) };
912 this.handle(IProblem.IllegalModifierForLocalClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
915 public void illegalModifierForMemberClass(SourceTypeBinding type) {
916 String[] arguments = new String[] { new String(type.sourceName()) };
917 this.handle(IProblem.IllegalModifierForMemberClass, arguments, arguments, type.sourceStart(), type.sourceEnd());
920 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
921 String[] arguments = new String[] { new String(type.sourceName()) };
922 this.handle(IProblem.IllegalModifierForMemberInterface, arguments, arguments, type.sourceStart(), type.sourceEnd());
925 public void illegalModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
926 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
927 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
930 public void illegalModifierForVariable(LocalDeclaration localDecl, boolean complainAsArgument) {
931 String[] arguments = new String[] { localDecl.name() };
932 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument : IProblem.IllegalModifierForVariable, arguments,
933 arguments, localDecl.sourceStart, localDecl.sourceEnd);
936 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(TypeBinding enclosingType, ASTNode location) {
937 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
938 new String[] { new String(enclosingType.readableName()) }, new String[] { new String(enclosingType.shortReadableName()) },
939 location.sourceStart, location.sourceEnd);
942 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
943 String[] arguments = new String[] { new String(type.sourceName()) };
944 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments, arguments, type.sourceStart(), type.sourceEnd());
947 public void illegalVisibilityModifierCombinationForField(ReferenceBinding type, FieldDeclaration fieldDecl) {
948 String[] arguments = new String[] { new String(fieldDecl.name()) };
949 this.handle(IProblem.IllegalVisibilityModifierCombinationForField, arguments, arguments, fieldDecl.sourceStart,
950 fieldDecl.sourceEnd);
953 public void illegalVisibilityModifierCombinationForMemberType(SourceTypeBinding type) {
954 String[] arguments = new String[] { new String(type.sourceName()) };
955 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType, arguments, arguments, type.sourceStart(), type
959 public void illegalVisibilityModifierCombinationForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
960 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
961 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod, arguments, arguments, methodDecl.sourceStart,
962 methodDecl.sourceEnd);
965 public void illegalVisibilityModifierForInterfaceMemberType(SourceTypeBinding type) {
966 String[] arguments = new String[] { new String(type.sourceName()) };
967 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType, arguments, arguments, type.sourceStart(), type
971 public void illegalVoidExpression(ASTNode location) {
972 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
975 // public void importProblem(ImportReference importRef, Binding expectedImport) {
976 // int problemId = expectedImport.problemId();
978 // switch (problemId) {
981 // id = IProblem.ImportNotFound;
985 // id = IProblem.ImportNotVisible;
989 // id = IProblem.ImportAmbiguous;
991 // case InternalNameProvided :
993 // id = IProblem.ImportInternalNameProvided;
995 // case InheritedNameHidesEnclosingName :
997 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1002 // needImplementation(); // want to fail to see why we were
1007 // if (expectedImport instanceof ProblemReferenceBinding) {
1008 // argument = CharOperation
1009 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1011 // argument = CharOperation.toString(importRef.tokens);
1013 // String[] arguments = new String[]{argument};
1014 // this.handle(id, arguments, arguments, importRef.sourceStart,
1015 // importRef.sourceEnd);
1017 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type, MethodBinding currentMethod,
1018 MethodBinding inheritedMethod, ReferenceBinding exceptionType) {
1019 if (type == currentMethod.declaringClass) {
1021 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1024 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1026 id = IProblem.IncompatibleExceptionInThrowsClause;
1030 // Exception %1 is not compatible with throws
1032 // 9.4.4 - The type of exception in the throws
1033 // clause is incompatible.
1035 new String(exceptionType.sourceName()),
1036 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1037 '.')) }, new String[] {
1038 new String(exceptionType.sourceName()),
1039 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1040 .shortReadableName(), '.')) }, currentMethod.sourceStart(), currentMethod.sourceEnd());
1044 // Exception %1 in throws clause of %2 is not
1045 // compatible with %3
1046 // 9.4.4 - The type of exception in the throws
1047 // clause is incompatible.
1048 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause, new String[] {
1049 new String(exceptionType.sourceName()),
1050 new String(CharOperation.concat(currentMethod.declaringClass.sourceName(), currentMethod.readableName(), '.')),
1051 new String(CharOperation.concat(inheritedMethod.declaringClass.readableName(), inheritedMethod.readableName(),
1052 '.')) }, new String[] {
1053 new String(exceptionType.sourceName()),
1054 new String(CharOperation
1055 .concat(currentMethod.declaringClass.sourceName(), currentMethod.shortReadableName(), '.')),
1056 new String(CharOperation.concat(inheritedMethod.declaringClass.shortReadableName(), inheritedMethod
1057 .shortReadableName(), '.')) }, type.sourceStart(), type.sourceEnd());
1060 public void incompatibleReturnType(MethodBinding currentMethod, MethodBinding inheritedMethod) {
1061 StringBuffer methodSignature = new StringBuffer();
1062 methodSignature.append(inheritedMethod.declaringClass.readableName()).append('.').append(inheritedMethod.readableName());
1063 StringBuffer shortSignature = new StringBuffer();
1064 shortSignature.append(inheritedMethod.declaringClass.shortReadableName()).append('.').append(
1065 inheritedMethod.shortReadableName());
1067 if (currentMethod.declaringClass.isInterface() && !inheritedMethod.isPublic()) { // interface inheriting
1068 // Object protected method
1069 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1071 id = IProblem.IncompatibleReturnType;
1073 this.handle(id, new String[] { methodSignature.toString() }, new String[] { shortSignature.toString() }, currentMethod
1074 .sourceStart(), currentMethod.sourceEnd());
1077 public void incorrectLocationForEmptyDimension(ArrayAllocationExpression expression, int index) {
1078 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument, expression.dimensions[index + 1].sourceStart,
1079 expression.dimensions[index + 1].sourceEnd);
1082 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1083 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(testType.readableName()) }, new String[] { new String(
1084 testType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1087 public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1088 StringBuffer concreteSignature = new StringBuffer();
1089 concreteSignature.append(concreteMethod.declaringClass.readableName()).append('.').append(concreteMethod.readableName());
1090 StringBuffer shortSignature = new StringBuffer();
1091 shortSignature.append(concreteMethod.declaringClass.shortReadableName()).append('.').append(concreteMethod.shortReadableName());
1093 // The inherited method %1 cannot hide the public abstract method in %2
1094 IProblem.InheritedMethodReducesVisibility, new String[] { new String(concreteSignature.toString()),
1095 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] { new String(shortSignature.toString()),
1096 new String(abstractMethods[0].declaringClass.shortReadableName()) }, type.sourceStart(), type.sourceEnd());
1099 public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1100 StringBuffer methodSignatures = new StringBuffer();
1101 StringBuffer shortSignatures = new StringBuffer();
1102 for (int i = length; --i >= 0;) {
1103 methodSignatures.append(inheritedMethods[i].declaringClass.readableName()).append('.').append(
1104 inheritedMethods[i].readableName());
1105 shortSignatures.append(inheritedMethods[i].declaringClass.shortReadableName()).append('.').append(
1106 inheritedMethods[i].shortReadableName());
1108 methodSignatures.append(", "); //$NON-NLS-1$
1109 shortSignatures.append(", "); //$NON-NLS-1$
1113 // Return type is incompatible with %1
1114 // 9.4.2 - The return type from the method is incompatible with
1116 IProblem.IncompatibleReturnType, new String[] { methodSignatures.toString() }, new String[] { shortSignatures.toString() },
1117 type.sourceStart(), type.sourceEnd());
1120 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1121 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument, NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1124 public void innerTypesCannotDeclareStaticInitializers(ReferenceBinding innerType, ASTNode location) {
1125 this.handle(IProblem.CannotDefineStaticInitializerInLocalType, new String[] { new String(innerType.readableName()) },
1126 new String[] { new String(innerType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
1129 public void interfaceCannotHaveConstructors(ConstructorDeclaration constructor) {
1130 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument, NoArgument, constructor.sourceStart, constructor.sourceEnd,
1131 constructor, constructor.compilationResult());
1134 public void interfaceCannotHaveInitializers(SourceTypeBinding type, FieldDeclaration fieldDecl) {
1135 String[] arguments = new String[] { new String(type.sourceName()) };
1136 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1139 public void invalidBreak(ASTNode location) {
1140 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1143 public void invalidConstructor(Statement statement, MethodBinding targetConstructor) {
1144 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1145 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
1146 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1147 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1148 int flag = IProblem.UndefinedConstructor; //default...
1149 switch (targetConstructor.problemId()) {
1151 if (insideDefaultConstructor) {
1152 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1153 } else if (insideImplicitConstructorCall) {
1154 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1156 flag = IProblem.UndefinedConstructor;
1160 if (insideDefaultConstructor) {
1161 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1162 } else if (insideImplicitConstructorCall) {
1163 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1165 flag = IProblem.NotVisibleConstructor;
1169 if (insideDefaultConstructor) {
1170 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1171 } else if (insideImplicitConstructorCall) {
1172 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1174 flag = IProblem.AmbiguousConstructor;
1180 needImplementation(); // want to fail to see why we were
1184 this.handle(flag, new String[] { new String(targetConstructor.declaringClass.readableName()),
1185 parametersAsString(targetConstructor) }, new String[] { new String(targetConstructor.declaringClass.shortReadableName()),
1186 parametersAsShortString(targetConstructor) }, statement.sourceStart, statement.sourceEnd);
1189 public void invalidContinue(ASTNode location) {
1190 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
1193 public void invalidEnclosingType(Expression expression, TypeBinding type, ReferenceBinding enclosingType) {
1194 if (enclosingType.isAnonymousType())
1195 enclosingType = enclosingType.superclass();
1196 int flag = IProblem.UndefinedType; // default
1197 switch (type.problemId()) {
1200 flag = IProblem.UndefinedType;
1204 flag = IProblem.NotVisibleType;
1208 flag = IProblem.AmbiguousType;
1210 case InternalNameProvided:
1211 flag = IProblem.InternalTypeNameProvided;
1216 needImplementation(); // want to fail to see why we were
1220 this.handle(flag, new String[] { new String(enclosingType.readableName()) + "." + new String(type.readableName()) }, //$NON-NLS-1$
1221 new String[] { new String(enclosingType.shortReadableName()) + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1222 expression.sourceStart, expression.sourceEnd);
1225 public void invalidExpressionAsStatement(Expression expression) {
1226 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1229 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1230 int severity = Error;
1231 int flag = IProblem.UndefinedField;
1232 FieldBinding field = fieldRef.binding;
1233 switch (field.problemId()) {
1235 flag = IProblem.UndefinedField;
1237 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1242 flag = IProblem.NotVisibleField;
1245 flag = IProblem.AmbiguousField;
1247 case NonStaticReferenceInStaticContext:
1248 flag = IProblem.NonStaticFieldFromStaticInvocation;
1250 case NonStaticReferenceInConstructorInvocation:
1251 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1253 case InheritedNameHidesEnclosingName:
1254 flag = IProblem.InheritedFieldHidesEnclosingName;
1256 case ReceiverTypeNotVisible:
1257 this.handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1258 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, fieldRef.receiver.sourceStart,
1259 fieldRef.receiver.sourceEnd);
1264 needImplementation(); // want to fail to see why we were
1268 String[] arguments = new String[] { new String(field.readableName()) };
1269 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart, fieldRef.sourceEnd);
1272 public void invalidField(NameReference nameRef, FieldBinding field) {
1273 int flag = IProblem.UndefinedField;
1274 switch (field.problemId()) {
1276 flag = IProblem.UndefinedField;
1279 flag = IProblem.NotVisibleField;
1282 flag = IProblem.AmbiguousField;
1284 case NonStaticReferenceInStaticContext:
1285 flag = IProblem.NonStaticFieldFromStaticInvocation;
1287 case NonStaticReferenceInConstructorInvocation:
1288 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1290 case InheritedNameHidesEnclosingName:
1291 flag = IProblem.InheritedFieldHidesEnclosingName;
1293 case ReceiverTypeNotVisible:
1294 this.handle(IProblem.NotVisibleType, new String[] { new String(field.declaringClass.leafComponentType().readableName()) },
1295 new String[] { new String(field.declaringClass.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1301 needImplementation(); // want to fail to see why we were
1305 String[] arguments = new String[] { new String(field.readableName()) };
1306 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1309 public void invalidField(QualifiedNameReference nameRef, FieldBinding field, int index, TypeBinding searchedType) {
1310 //the resolution of the index-th field of qname failed
1311 //qname.otherBindings[index] is the binding that has produced the
1313 //The different targetted errors should be :
1317 if (searchedType.isBaseType()) {
1318 this.handle(IProblem.NoFieldOnBaseType, new String[] { new String(searchedType.readableName()),
1319 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), new String(nameRef.tokens[index]) },
1320 new String[] { new String(searchedType.sourceName()),
1321 CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index)), new String(nameRef.tokens[index]) },
1322 nameRef.sourceStart, nameRef.sourceEnd);
1325 int flag = IProblem.UndefinedField;
1326 switch (field.problemId()) {
1328 flag = IProblem.UndefinedField;
1330 * also need to check that the searchedType is the receiver type if (searchedType.isHierarchyInconsistent()) severity =
1335 flag = IProblem.NotVisibleField;
1338 flag = IProblem.AmbiguousField;
1340 case NonStaticReferenceInStaticContext:
1341 flag = IProblem.NonStaticFieldFromStaticInvocation;
1343 case NonStaticReferenceInConstructorInvocation:
1344 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1346 case InheritedNameHidesEnclosingName:
1347 flag = IProblem.InheritedFieldHidesEnclosingName;
1349 case ReceiverTypeNotVisible:
1351 .handle(IProblem.NotVisibleType, new String[] { new String(searchedType.leafComponentType().readableName()) },
1352 new String[] { new String(searchedType.leafComponentType().shortReadableName()) }, nameRef.sourceStart,
1358 needImplementation(); // want to fail to see why we were
1362 String[] arguments = new String[] { CharOperation.toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1363 this.handle(flag, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
1366 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1367 // CODE should be UPDATED according to error coding in the different
1368 // method binding errors
1369 // The different targetted errors should be :
1373 // InheritedNameHidesEnclosingName
1374 // InstanceMethodDuringConstructorInvocation
1375 // StaticMethodRequested
1376 int flag = IProblem.UndefinedMethod; //default...
1377 switch (method.problemId()) {
1379 flag = IProblem.UndefinedMethod;
1382 flag = IProblem.NotVisibleMethod;
1385 flag = IProblem.AmbiguousMethod;
1387 case InheritedNameHidesEnclosingName:
1388 flag = IProblem.InheritedMethodHidesEnclosingName;
1390 case NonStaticReferenceInConstructorInvocation:
1391 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1393 case NonStaticReferenceInStaticContext:
1394 flag = IProblem.StaticMethodRequested;
1396 case ReceiverTypeNotVisible:
1397 this.handle(IProblem.NotVisibleType, new String[] { new String(method.declaringClass.leafComponentType().readableName()) },
1398 new String[] { new String(method.declaringClass.leafComponentType().shortReadableName()) },
1399 messageSend.receiver.sourceStart, messageSend.receiver.sourceEnd);
1404 needImplementation(); // want to fail to see why we were
1408 if (flag == IProblem.UndefinedMethod) {
1409 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1410 if (problemMethod.closestMatch != null) {
1411 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1412 String parameterTypeNames = parametersAsString(method);
1413 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1414 String parameterTypeShortNames = parametersAsShortString(method);
1415 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)) {
1416 closestParameterTypeShortNames = closestParameterTypeNames;
1417 parameterTypeShortNames = parameterTypeNames;
1419 this.handle(IProblem.ParameterMismatch, new String[] {
1420 new String(problemMethod.closestMatch.declaringClass.readableName()), new String(problemMethod.closestMatch.selector),
1421 closestParameterTypeNames, parameterTypeNames }, new String[] {
1422 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1423 new String(problemMethod.closestMatch.selector), closestParameterTypeShortNames, parameterTypeShortNames },
1424 (int) (messageSend.nameSourcePosition >>> 32), (int) messageSend.nameSourcePosition);
1428 this.handle(flag, new String[] { new String(method.declaringClass.readableName()), new String(method.selector),
1429 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
1430 new String(method.selector), parametersAsShortString(method) }, (int) (messageSend.nameSourcePosition >>> 32),
1431 (int) messageSend.nameSourcePosition);
1434 public void invalidNullToSynchronize(Expression expression) {
1435 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1438 public void invalidOperator(BinaryExpression expression, TypeBinding leftType, TypeBinding rightType) {
1439 String leftName = new String(leftType.readableName());
1440 String rightName = new String(rightType.readableName());
1441 String leftShortName = new String(leftType.shortReadableName());
1442 String rightShortName = new String(rightType.shortReadableName());
1443 if (leftShortName.equals(rightShortName)) {
1444 leftShortName = leftName;
1445 rightShortName = rightName;
1447 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1448 new String[] { expression.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1449 expression.sourceStart, expression.sourceEnd);
1452 public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) {
1453 String leftName = new String(leftType.readableName());
1454 String rightName = new String(rightType.readableName());
1455 String leftShortName = new String(leftType.shortReadableName());
1456 String rightShortName = new String(rightType.shortReadableName());
1457 if (leftShortName.equals(rightShortName)) {
1458 leftShortName = leftName;
1459 rightShortName = rightName;
1461 this.handle(IProblem.InvalidOperator, new String[] { assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1462 new String[] { assign.operatorToString(), leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1463 assign.sourceStart, assign.sourceEnd);
1466 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1467 this.handle(IProblem.InvalidOperator, new String[] { expression.operatorToString(), new String(type.readableName()) },
1468 new String[] { expression.operatorToString(), new String(type.shortReadableName()) }, expression.sourceStart,
1469 expression.sourceEnd);
1472 public void invalidParenthesizedExpression(ASTNode reference) {
1473 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd);
1476 public void invalidSuperclass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding expectedType) {
1477 int problemId = expectedType.problemId();
1479 switch (problemId) {
1482 id = IProblem.SuperclassNotFound;
1486 id = IProblem.SuperclassNotVisible;
1490 id = IProblem.SuperclassAmbiguous;
1492 case InternalNameProvided:
1494 id = IProblem.SuperclassInternalNameProvided;
1496 case InheritedNameHidesEnclosingName:
1498 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1503 needImplementation(); // want to fail to see why we were
1507 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1508 new String(expectedType.shortReadableName()), new String(type.sourceName()) }, superclassRef.sourceStart,
1509 superclassRef.sourceEnd);
1512 public void invalidSuperinterface(SourceTypeBinding type, TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1513 int problemId = expectedType.problemId();
1515 switch (problemId) {
1518 id = IProblem.InterfaceNotFound;
1522 id = IProblem.InterfaceNotVisible;
1526 id = IProblem.InterfaceAmbiguous;
1528 case InternalNameProvided:
1530 id = IProblem.InterfaceInternalNameProvided;
1532 case InheritedNameHidesEnclosingName:
1534 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1539 needImplementation(); // want to fail to see why we were
1543 this.handle(id, new String[] { new String(expectedType.readableName()), new String(type.sourceName()) }, new String[] {
1544 new String(expectedType.shortReadableName()), new String(type.sourceName()) }, superinterfaceRef.sourceStart,
1545 superinterfaceRef.sourceEnd);
1548 public void invalidType(ASTNode location, TypeBinding type) {
1549 int flag = IProblem.UndefinedType; // default
1550 switch (type.problemId()) {
1552 flag = IProblem.UndefinedType;
1555 flag = IProblem.NotVisibleType;
1558 flag = IProblem.AmbiguousType;
1560 case InternalNameProvided:
1561 flag = IProblem.InternalTypeNameProvided;
1563 case InheritedNameHidesEnclosingName:
1564 flag = IProblem.InheritedTypeHidesEnclosingName;
1569 needImplementation(); // want to fail to see why we were
1573 this.handle(flag, new String[] { new String(type.readableName()) }, new String[] { new String(type.shortReadableName()) },
1574 location.sourceStart, location.sourceEnd);
1577 public void invalidTypeReference(Expression expression) {
1578 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1581 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1582 this.handle(IProblem.InvalidTypeToSynchronized, new String[] { new String(type.readableName()) }, new String[] { new String(
1583 type.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
1586 public void invalidUnaryExpression(Expression expression) {
1587 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
1590 public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl) {
1591 referenceContext = compUnitDecl;
1592 String[] arguments = new String[] { CharOperation.toString(wellKnownTypeName) };
1593 this.handle(IProblem.IsClassPathCorrect, arguments, arguments, AbortCompilation | Error, compUnitDecl == null ? 0
1594 : compUnitDecl.sourceStart, compUnitDecl == null ? 1 : compUnitDecl.sourceEnd);
1597 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd){
1598 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1600 public void javadocDeprecatedField(FieldBinding field, ASTNode location, int modifiers) {
1601 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1603 IProblem.JavadocUsingDeprecatedField,
1604 new String[] {new String(field.declaringClass.readableName()), new String(field.name)},
1605 new String[] {new String(field.declaringClass.shortReadableName()), new String(field.name)},
1606 location.sourceStart,
1607 location.sourceEnd);
1610 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location, int modifiers) {
1611 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1612 if (method.isConstructor()) {
1614 IProblem.JavadocUsingDeprecatedConstructor,
1615 new String[] {new String(method.declaringClass.readableName()), parametersAsString(method)},
1616 new String[] {new String(method.declaringClass.shortReadableName()), parametersAsShortString(method)},
1617 location.sourceStart,
1618 location.sourceEnd);
1621 IProblem.JavadocUsingDeprecatedMethod,
1622 new String[] {new String(method.declaringClass.readableName()), new String(method.selector), parametersAsString(method)},
1623 new String[] {new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method)},
1624 location.sourceStart,
1625 location.sourceEnd);
1629 public void javadocDeprecatedType(TypeBinding type, ASTNode location, int modifiers) {
1630 if (location == null) return; // 1G828DN - no type ref for synthetic arguments
1631 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1633 IProblem.JavadocUsingDeprecatedType,
1634 new String[] {new String(type.readableName())},
1635 new String[] {new String(type.shortReadableName())},
1636 location.sourceStart,
1637 location.sourceEnd);
1640 //public void javadocDuplicatedParamTag(JavadocSingleNameReference param, int modifiers) {
1641 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1642 // String[] arguments = new String[] {String.valueOf(param.token)};
1643 // this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1646 public void javadocDuplicatedThrowsClassName(TypeReference typeReference, int modifiers) {
1647 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1648 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
1649 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
1652 public void javadocErrorNoMethodFor(MessageSend messageSend, TypeBinding recType, TypeBinding[] params, int modifiers) {
1653 StringBuffer buffer = new StringBuffer();
1654 StringBuffer shortBuffer = new StringBuffer();
1655 for (int i = 0, length = params.length; i < length; i++) {
1657 buffer.append(", "); //$NON-NLS-1$
1658 shortBuffer.append(", "); //$NON-NLS-1$
1660 buffer.append(new String(params[i].readableName()));
1661 shortBuffer.append(new String(params[i].shortReadableName()));
1664 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType : IProblem.JavadocNoMessageSendOnBaseType;
1665 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1668 new String[] {new String(recType.readableName()), new String(messageSend.selector), buffer.toString()},
1669 new String[] {new String(recType.shortReadableName()), new String(messageSend.selector), shortBuffer.toString()},
1670 messageSend.sourceStart,
1671 messageSend.sourceEnd);
1674 public void javadocInvalidConstructor(Statement statement, MethodBinding targetConstructor, int modifiers) {
1676 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1679 // boolean insideDefaultConstructor =
1680 // (this.referenceContext instanceof ConstructorDeclaration)
1681 // && ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
1682 // boolean insideImplicitConstructorCall =
1683 // (statement instanceof ExplicitConstructorCall)
1684 // && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1686 int id = IProblem.JavadocUndefinedConstructor; //default...
1687 switch (targetConstructor.problemId()) {
1689 // if (insideDefaultConstructor){
1690 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
1691 // } else if (insideImplicitConstructorCall){
1692 // id = IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
1694 id = IProblem.JavadocUndefinedConstructor;
1698 // if (insideDefaultConstructor){
1699 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
1700 // } else if (insideImplicitConstructorCall){
1701 // id = IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
1703 id = IProblem.JavadocNotVisibleConstructor;
1707 // if (insideDefaultConstructor){
1708 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
1709 // } else if (insideImplicitConstructorCall){
1710 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1712 id = IProblem.JavadocAmbiguousConstructor;
1717 needImplementation(); // want to fail to see why we were here...
1723 new String[] {new String(targetConstructor.declaringClass.readableName()), parametersAsString(targetConstructor)},
1724 new String[] {new String(targetConstructor.declaringClass.shortReadableName()), parametersAsShortString(targetConstructor)},
1725 statement.sourceStart,
1726 statement.sourceEnd);
1728 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd, Binding fieldBinding, int modifiers) {
1729 int id = IProblem.JavadocAmbiguousMethodReference;
1730 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1731 String[] arguments = new String[] {new String(fieldBinding.readableName())};
1732 handle(id, arguments, arguments, sourceStart, sourceEnd);
1736 * Similar implementation than invalidField(FieldReference...)
1737 * Note that following problem id cannot occur for Javadoc:
1738 * - NonStaticReferenceInStaticContext :
1739 * - NonStaticReferenceInConstructorInvocation :
1740 * - ReceiverTypeNotVisible :
1742 public void javadocInvalidField(int sourceStart, int sourceEnd, Binding fieldBinding, TypeBinding searchedType, int modifiers) {
1743 int id = IProblem.JavadocUndefinedField;
1744 switch (fieldBinding.problemId()) {
1746 id = IProblem.JavadocUndefinedField;
1749 id = IProblem.JavadocNotVisibleField;
1752 id = IProblem.JavadocAmbiguousField;
1754 case InheritedNameHidesEnclosingName :
1755 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
1759 needImplementation(); // want to fail to see why we were here...
1763 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1764 String[] arguments = new String[] {new String(fieldBinding.readableName())};
1765 handle(id, arguments, arguments, sourceStart, sourceEnd);
1769 * Similar implementation than invalidMethod(MessageSend...)
1770 * Note that following problem id cannot occur for Javadoc:
1771 * - NonStaticReferenceInStaticContext :
1772 * - NonStaticReferenceInConstructorInvocation :
1773 * - ReceiverTypeNotVisible :
1775 public void javadocInvalidMethod(MessageSend messageSend, MethodBinding method, int modifiers) {
1776 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1779 int id = IProblem.JavadocUndefinedMethod; //default...
1780 switch (method.problemId()) {
1782 id = IProblem.JavadocUndefinedMethod;
1785 id = IProblem.JavadocNotVisibleMethod;
1788 id = IProblem.JavadocAmbiguousMethod;
1790 case InheritedNameHidesEnclosingName :
1791 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
1795 needImplementation(); // want to fail to see why we were here...
1799 if (id == IProblem.JavadocUndefinedMethod) {
1800 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1801 if (problemMethod.closestMatch != null) {
1802 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1803 String parameterTypeNames = parametersAsString(method);
1804 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1805 String parameterTypeShortNames = parametersAsShortString(method);
1806 if (closestParameterTypeShortNames.equals(parameterTypeShortNames)){
1807 closestParameterTypeShortNames = closestParameterTypeNames;
1808 parameterTypeShortNames = parameterTypeNames;
1811 IProblem.JavadocParameterMismatch,
1813 new String(problemMethod.closestMatch.declaringClass.readableName()),
1814 new String(problemMethod.closestMatch.selector),
1815 closestParameterTypeNames,
1819 new String(problemMethod.closestMatch.declaringClass.shortReadableName()),
1820 new String(problemMethod.closestMatch.selector),
1821 closestParameterTypeShortNames,
1822 parameterTypeShortNames
1824 (int) (messageSend.nameSourcePosition >>> 32),
1825 (int) messageSend.nameSourcePosition);
1833 new String(method.declaringClass.readableName()),
1834 new String(method.selector), parametersAsString(method)},
1836 new String(method.declaringClass.shortReadableName()),
1837 new String(method.selector), parametersAsShortString(method)},
1838 (int) (messageSend.nameSourcePosition >>> 32),
1839 (int) messageSend.nameSourcePosition);
1841 //public void javadocInvalidParamName(JavadocSingleNameReference param, int modifiers) {
1842 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1843 // String[] arguments = new String[] {String.valueOf(param.token)};
1844 // this.handle(IProblem.JavadocInvalidParamName, arguments, arguments, param.sourceStart, param.sourceEnd);
1847 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
1848 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1850 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
1851 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument, sourceStart, sourceEnd);
1853 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
1854 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument, sourceStart, sourceEnd);
1856 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
1857 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1859 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
1860 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument, sourceStart, sourceEnd);
1862 public void javadocInvalidThrowsClassName(TypeReference typeReference, int modifiers) {
1863 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1864 String[] arguments = new String[] {String.valueOf(typeReference.resolvedType.sourceName())};
1865 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments, arguments, typeReference.sourceStart, typeReference.sourceEnd);
1868 public void javadocInvalidType(ASTNode location, TypeBinding type, int modifiers) {
1869 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility, modifiers)) {
1870 int id = IProblem.JavadocUndefinedType; // default
1871 switch (type.problemId()) {
1873 id = IProblem.JavadocUndefinedType;
1876 id = IProblem.JavadocNotVisibleType;
1879 id = IProblem.JavadocAmbiguousType;
1881 case InternalNameProvided :
1882 id = IProblem.JavadocInternalTypeNameProvided;
1884 case InheritedNameHidesEnclosingName :
1885 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
1889 needImplementation(); // want to fail to see why we were here...
1894 new String[] {new String(type.readableName())},
1895 new String[] {new String(type.shortReadableName())},
1896 location.sourceStart,
1897 location.sourceEnd);
1900 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
1901 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1903 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers){
1904 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
1905 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
1906 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
1908 String arg = javadocVisibilityArgument(this.options.reportMissingJavadocCommentsVisibility, modifiers);
1910 String[] arguments = new String[] { arg };
1911 this.handle(IProblem.JavadocMissing, arguments, arguments, sourceStart, sourceEnd);
1915 public void javadocMissingParamName(int sourceStart, int sourceEnd){
1916 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument, sourceStart, sourceEnd);
1918 public void javadocMissingParamTag(Argument param, int modifiers) {
1919 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
1920 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1921 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1922 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1923 String[] arguments = new String[] { String.valueOf(param.name) };
1924 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments, param.sourceStart, param.sourceEnd);
1927 public void javadocMissingReturnTag(int sourceStart, int sourceEnd, int modifiers){
1928 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
1929 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1930 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1931 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1932 this.handle(IProblem.JavadocMissingReturnTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1935 public void javadocMissingSeeReference(int sourceStart, int sourceEnd){
1936 this.handle(IProblem.JavadocMissingSeeReference, NoArgument, NoArgument, sourceStart, sourceEnd);
1938 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd){
1939 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument, NoArgument, sourceStart, sourceEnd);
1941 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers){
1942 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing+CompilerModifiers.AccOverriding)) != 0;
1943 boolean report = (this.options.getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
1944 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
1945 if (report && javadocVisibility(this.options.reportMissingJavadocTagsVisibility, modifiers)) {
1946 String[] arguments = new String[] { String.valueOf(typeRef.resolvedType.sourceName()) };
1947 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments, typeRef.sourceStart, typeRef.sourceEnd);
1950 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
1951 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1953 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
1954 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument, NoArgument, sourceStart, sourceEnd);
1956 private boolean javadocVisibility(int visibility, int modifiers) {
1957 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
1958 case IConstants.AccPublic :
1960 case IConstants.AccProtected:
1961 return (visibility != IConstants.AccPublic);
1962 // case IConstants.AccDefault:
1963 // return (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate);
1964 case IConstants.AccPrivate:
1965 return (visibility == IConstants.AccPrivate);
1969 private String javadocVisibilityArgument(int visibility, int modifiers) {
1970 String argument = null;
1971 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
1972 case IConstants.AccPublic :
1973 argument = CompilerOptions.PUBLIC;
1975 case IConstants.AccProtected:
1976 if (visibility != IConstants.AccPublic) {
1977 argument = CompilerOptions.PROTECTED;
1980 // case IConstants.AccDefault:
1981 // if (visibility == IConstants.AccDefault || visibility == IConstants.AccPrivate) {
1982 // argument = CompilerOptions.DEFAULT;
1985 case IConstants.AccPrivate:
1986 if (visibility == IConstants.AccPrivate) {
1987 argument = CompilerOptions.PRIVATE;
1994 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1995 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1998 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2000 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
2001 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
2002 IProblem.BodyForAbstractMethod, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2005 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2006 this.handle(IProblem.MethodButWithConstructorName, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2009 //public void missingEnclosingInstanceSpecification(ReferenceBinding
2010 // enclosingType, ASTNode location) {
2011 // boolean insideConstructorCall =
2012 // (location instanceof ExplicitConstructorCall)
2013 // && (((ExplicitConstructorCall) location).accessMode ==
2014 // ExplicitConstructorCall.ImplicitSuper);
2017 // insideConstructorCall
2018 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2019 // : IProblem.MissingEnclosingInstance,
2020 // new String[] {new String(enclosingType.readableName())},
2021 // new String[] {new String(enclosingType.shortReadableName())},
2022 // location.sourceStart,
2023 // location.sourceEnd);
2025 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2026 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2029 public void missingSemiColon(Expression expression) {
2030 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2033 public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) {
2034 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer, NoArgument, NoArgument, expression.sourceStart,
2035 expression.sourceEnd);
2038 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2039 String[] arguments = new String[] { new String(compUnitDecl.getFileName()) };
2040 this.handle(IProblem.MustSpecifyPackage, arguments, arguments, compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
2043 public void mustUseAStaticMethod(MessageSend messageSend, MethodBinding method) {
2044 this.handle(IProblem.StaticMethodRequested, new String[] { new String(method.declaringClass.readableName()),
2045 new String(method.selector), parametersAsString(method) }, new String[] {
2046 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2047 messageSend.sourceStart, messageSend.sourceEnd);
2050 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2051 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2052 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2055 public void needImplementation() {
2056 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2059 public void needToEmulateFieldReadAccess(FieldBinding field, ASTNode location) {
2060 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] { new String(field.declaringClass.readableName()),
2061 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2062 location.sourceStart, location.sourceEnd);
2065 public void needToEmulateFieldWriteAccess(FieldBinding field, ASTNode location) {
2066 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] { new String(field.declaringClass.readableName()),
2067 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2068 location.sourceStart, location.sourceEnd);
2071 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
2072 if (method.isConstructor())
2073 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] { new String(method.declaringClass.readableName()),
2074 parametersAsString(method) }, new String[] { new String(method.declaringClass.shortReadableName()),
2075 parametersAsShortString(method) }, location.sourceStart, location.sourceEnd);
2077 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] { new String(method.declaringClass.readableName()),
2078 new String(method.selector), parametersAsString(method) }, new String[] {
2079 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2080 location.sourceStart, location.sourceEnd);
2083 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2084 String[] arguments = new String[] { new String(typeDecl.name) };
2085 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
2088 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local, ASTNode location) {
2089 String[] arguments = new String[] { new String(local.name) };
2090 this.handle(local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots : IProblem.TooManyArgumentSlots,
2091 arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2094 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local, ASTNode location) {
2095 String[] arguments = new String[] { new String(local.name) };
2096 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments, Abort | Error, location.sourceStart, location.sourceEnd);
2099 public void noSuchEnclosingInstance(TypeBinding targetType, ASTNode location, boolean isConstructorCall) {
2101 if (isConstructorCall) {
2102 //28 = No enclosing instance of type {0} is available due to some
2103 // intermediate constructor invocation
2104 id = IProblem.EnclosingInstanceInConstructorCall;
2105 } else if ((location instanceof ExplicitConstructorCall)
2106 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2107 //20 = No enclosing instance of type {0} is accessible to invoke
2108 // the super constructor. Must define a constructor and explicitly
2109 // qualify its super constructor invocation with an instance of {0}
2110 // (e.g. x.super() where x is an instance of {0}).
2111 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2112 } else if (location instanceof AllocationExpression
2113 && (((AllocationExpression) location).binding.declaringClass.isMemberType() || (((AllocationExpression) location).binding.declaringClass
2114 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass.superclass().isMemberType()))) {
2115 //21 = No enclosing instance of type {0} is accessible. Must
2116 // qualify the allocation with an enclosing instance of type {0}
2117 // (e.g. x.new A() where x is an instance of {0}).
2118 id = IProblem.MissingEnclosingInstance;
2120 //22 = No enclosing instance of the type {0} is accessible in
2122 id = IProblem.IncorrectEnclosingInstanceReference;
2124 this.handle(id, new String[] { new String(targetType.readableName()) }, new String[] { new String(targetType
2125 .shortReadableName()) }, location.sourceStart, location.sourceEnd);
2128 public void notCompatibleTypesError(EqualExpression expression, TypeBinding leftType, TypeBinding rightType) {
2129 String leftName = new String(leftType.readableName());
2130 String rightName = new String(rightType.readableName());
2131 String leftShortName = new String(leftType.shortReadableName());
2132 String rightShortName = new String(rightType.shortReadableName());
2133 if (leftShortName.equals(rightShortName)) {
2134 leftShortName = leftName;
2135 rightShortName = rightName;
2137 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] { leftName, rightName }, new String[] { leftShortName,
2138 rightShortName }, expression.sourceStart, expression.sourceEnd);
2141 public void notCompatibleTypesError(InstanceOfExpression expression, TypeBinding leftType, TypeBinding rightType) {
2142 String leftName = new String(leftType.readableName());
2143 String rightName = new String(rightType.readableName());
2144 String leftShortName = new String(leftType.shortReadableName());
2145 String rightShortName = new String(rightType.shortReadableName());
2146 if (leftShortName.equals(rightShortName)) {
2147 leftShortName = leftName;
2148 rightShortName = rightName;
2150 this.handle(IProblem.IncompatibleTypesInConditionalOperator, new String[] { leftName, rightName }, new String[] {
2151 leftShortName, rightShortName }, expression.sourceStart, expression.sourceEnd);
2154 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2155 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument, NoArgument, type.sourceStart(), type.sourceEnd());
2158 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) {
2159 String leftName = new String(leftType.readableName());
2160 String rightName = new String(rightType.readableName());
2161 String leftShortName = new String(leftType.shortReadableName());
2162 String rightShortName = new String(rightType.shortReadableName());
2163 if (leftShortName.equals(rightShortName)) {
2164 leftShortName = leftName;
2165 rightShortName = rightName;
2167 this.handle(IProblem.TypeMismatch, new String[] { leftName, rightName }, new String[] { leftShortName, rightShortName },
2168 assignment.sourceStart, assignment.sourceEnd);
2171 public void overridesDeprecatedMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2172 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
2173 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2174 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2175 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2176 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2179 public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) {
2180 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
2181 new String(CharOperation.concat(localMethod.declaringClass.readableName(), localMethod.readableName(), '.')),
2182 new String(inheritedMethod.declaringClass.readableName()) }, new String[] {
2183 new String(CharOperation.concat(localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')),
2184 new String(inheritedMethod.declaringClass.shortReadableName()) }, localMethod.sourceStart(), localMethod.sourceEnd());
2187 // public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2188 // String[] arguments = new String[]{CharOperation
2189 // .toString(compUnitDecl.currentPackage.tokens)};
2190 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2191 // compUnitDecl.currentPackage.sourceStart,
2192 // compUnitDecl.currentPackage.sourceEnd);
2194 public void packageIsNotExpectedPackage(CompilationUnitDeclaration compUnitDecl) {
2195 String[] arguments = new String[] { CharOperation.toString(compUnitDecl.compilationResult.compilationUnit.getPackageName()) };
2196 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments, compUnitDecl.currentPackage == null ? 0
2197 : compUnitDecl.currentPackage.sourceStart, compUnitDecl.currentPackage == null ? 0 : compUnitDecl.currentPackage.sourceEnd);
2200 private String parametersAsString(MethodBinding method) {
2201 TypeBinding[] params = method.parameters;
2202 StringBuffer buffer = new StringBuffer();
2203 for (int i = 0, length = params.length; i < length; i++) {
2205 buffer.append(", "); //$NON-NLS-1$
2206 buffer.append(new String(params[i].readableName()));
2208 return buffer.toString();
2211 private String parametersAsShortString(MethodBinding method) {
2212 TypeBinding[] params = method.parameters;
2213 StringBuffer buffer = new StringBuffer();
2214 for (int i = 0, length = params.length; i < length; i++) {
2216 buffer.append(", "); //$NON-NLS-1$
2217 buffer.append(new String(params[i].shortReadableName()));
2219 return buffer.toString();
2222 public void parseError(int startPosition, int endPosition, char[] currentTokenSource, String errorTokenName,
2223 String[] possibleTokens) {
2224 if (possibleTokens.length == 0) { //no suggestion available
2225 if (isKeyword(currentTokenSource)) {
2226 String[] arguments = new String[] { new String(currentTokenSource) };
2227 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion, arguments, arguments,
2228 // this is the current -invalid- token position
2229 startPosition, endPosition);
2232 String[] arguments = new String[] { errorTokenName };
2233 this.handle(IProblem.ParsingErrorNoSuggestion, arguments, arguments,
2234 // this is the current -invalid- token position
2235 startPosition, endPosition);
2239 //build a list of probable right tokens
2240 StringBuffer list = new StringBuffer(20);
2241 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2243 list.append(", "); //$NON-NLS-1$
2245 list.append(possibleTokens[i]);
2248 if (isKeyword(currentTokenSource)) {
2249 String[] arguments = new String[] { new String(currentTokenSource), list.toString() };
2250 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2251 // this is the current -invalid- token position
2252 startPosition, endPosition);
2255 //extract the literal when it's a literal
2256 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2257 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2258 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2259 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2260 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2261 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2262 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2263 errorTokenName = new String(currentTokenSource);
2265 String[] arguments = new String[] { errorTokenName, list.toString() };
2266 this.handle(IProblem.ParsingError, arguments, arguments,
2267 // this is the current -invalid- token position
2268 startPosition, endPosition);
2271 public void publicClassMustMatchFileName(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2272 this.referenceContext = typeDecl; // report the problem against the
2273 // type not the entire compilation
2275 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2276 this.handle(IProblem.PublicClassMustMatchFileName, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2277 compUnitDecl.compilationResult);
2280 public void recursiveConstructorInvocation(ExplicitConstructorCall constructorCall) {
2281 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
2282 new String(constructorCall.binding.declaringClass.readableName()), parametersAsString(constructorCall.binding) },
2283 new String[] { new String(constructorCall.binding.declaringClass.shortReadableName()),
2284 parametersAsShortString(constructorCall.binding) }, constructorCall.sourceStart, constructorCall.sourceEnd);
2287 public void redefineArgument(Argument arg) {
2288 String[] arguments = new String[] { new String(arg.name) };
2289 this.handle(IProblem.RedefinedArgument, arguments, arguments, arg.sourceStart, arg.sourceEnd);
2292 public void redefineLocal(LocalDeclaration localDecl) {
2293 String[] arguments = new String[] { new String(localDecl.name) };
2294 this.handle(IProblem.RedefinedLocal, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2297 public void referenceMustBeArrayTypeAt(TypeBinding arrayType, ArrayReference arrayRef) {
2298 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(arrayType.readableName()) }, new String[] { new String(
2299 arrayType.shortReadableName()) }, arrayRef.sourceStart, arrayRef.sourceEnd);
2302 public void returnTypeCannotBeVoidArray(SourceTypeBinding type, MethodDeclaration methodDecl) {
2303 String[] arguments = new String[] { new String(methodDecl.selector) };
2304 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2307 public void returnTypeProblem(SourceTypeBinding type, MethodDeclaration methodDecl, TypeBinding expectedType) {
2308 int problemId = expectedType.problemId();
2310 switch (problemId) {
2313 id = IProblem.ReturnTypeNotFound;
2317 id = IProblem.ReturnTypeNotVisible;
2321 id = IProblem.ReturnTypeAmbiguous;
2323 case InternalNameProvided:
2325 id = IProblem.ReturnTypeInternalNameProvided;
2327 case InheritedNameHidesEnclosingName:
2329 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2334 needImplementation(); // want to fail to see why we were
2338 this.handle(id, new String[] { new String(methodDecl.selector), new String(expectedType.readableName()) }, new String[] {
2339 new String(methodDecl.selector), new String(expectedType.shortReadableName()) }, methodDecl.returnType.sourceStart,
2340 methodDecl.returnType.sourceEnd);
2343 public void scannerError(Parser parser, String errorTokenName) {
2344 Scanner scanner = parser.scanner;
2345 int flag = IProblem.ParsingErrorNoSuggestion;
2346 int startPos = scanner.startPosition;
2347 //special treatment for recognized errors....
2348 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2349 flag = IProblem.EndOfSource;
2350 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2351 flag = IProblem.InvalidHexa;
2352 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2353 flag = IProblem.InvalidOctal;
2354 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2355 flag = IProblem.InvalidCharacterConstant;
2356 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2357 flag = IProblem.InvalidEscape;
2358 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2359 flag = IProblem.InvalidUnicodeEscape;
2360 // better locate the error message
2361 char[] source = scanner.source;
2362 int checkPos = scanner.currentPosition - 1;
2363 if (checkPos >= source.length)
2364 checkPos = source.length - 1;
2365 while (checkPos >= startPos) {
2366 if (source[checkPos] == '\\')
2370 startPos = checkPos;
2371 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2372 flag = IProblem.InvalidFloat;
2373 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2374 flag = IProblem.UnterminatedString;
2375 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2376 flag = IProblem.UnterminatedComment;
2377 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2378 flag = IProblem.UnterminatedString;
2379 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName } : NoArgument;
2380 this.handle(flag, arguments, arguments,
2381 // this is the current -invalid- token position
2382 startPos, scanner.currentPosition - 1, parser.compilationUnit.compilationResult);
2385 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2386 this.handle(IProblem.ShouldReturnValue, new String[] { new String(returnType.readableName()) }, new String[] { new String(
2387 returnType.shortReadableName()) }, location.sourceStart, location.sourceEnd);
2390 public void signalNoImplicitStringConversionForCharArrayExpression(Expression expression) {
2391 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression, NoArgument, NoArgument, expression.sourceStart,
2392 expression.sourceEnd);
2395 public void staticAndInstanceConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2396 if (currentMethod.isStatic())
2398 // This static method cannot hide the instance method from %1
2399 // 8.4.6.4 - If a class inherits more than one method with
2400 // the same signature a static (non-abstract) method cannot
2401 // hide an instance method.
2402 IProblem.CannotHideAnInstanceMethodWithAStaticMethod, new String[] { new String(inheritedMethod.declaringClass
2403 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2404 .sourceStart(), currentMethod.sourceEnd());
2407 // This instance method cannot override the static method from %1
2408 // 8.4.6.4 - If a class inherits more than one method with
2409 // the same signature an instance (non-abstract) method
2410 // cannot override a static method.
2411 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod, new String[] { new String(inheritedMethod.declaringClass
2412 .readableName()) }, new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod
2413 .sourceStart(), currentMethod.sourceEnd());
2416 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef, FieldBinding field) {
2417 String[] arguments = new String[] { new String(field.readableName()) };
2418 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2421 public void staticFieldAccessToNonStaticVariable(QualifiedNameReference nameRef, FieldBinding field) {
2422 String[] arguments = new String[] { new String(field.readableName()) };
2423 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2426 public void staticFieldAccessToNonStaticVariable(SingleNameReference nameRef, FieldBinding field) {
2427 String[] arguments = new String[] { new String(field.readableName()) };
2428 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments, arguments, nameRef.sourceStart, nameRef.sourceEnd);
2431 public void staticInheritedMethodConflicts(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2433 // The static method %1 conflicts with the abstract method in %2
2434 // 8.4.6.4 - If a class inherits more than one method with the
2435 // same signature it is an error for one to be static
2436 // (non-abstract) and the other abstract.
2437 IProblem.StaticInheritedMethodConflicts, new String[] { new String(concreteMethod.readableName()),
2438 new String(abstractMethods[0].declaringClass.readableName()) }, new String[] {
2439 new String(concreteMethod.readableName()), new String(abstractMethods[0].declaringClass.shortReadableName()) }, type
2440 .sourceStart(), type.sourceEnd());
2443 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
2444 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2447 public void superclassMustBeAClass(SourceTypeBinding type, TypeReference superclassRef, ReferenceBinding superType) {
2448 this.handle(IProblem.SuperclassMustBeAClass,
2449 new String[] { new String(superType.readableName()), new String(type.sourceName()) }, new String[] {
2450 new String(superType.shortReadableName()), new String(type.sourceName()) }, superclassRef.sourceStart,
2451 superclassRef.sourceEnd);
2454 public void superinterfaceMustBeAnInterface(SourceTypeBinding type, TypeDeclaration typeDecl, ReferenceBinding superType) {
2455 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] { new String(superType.readableName()),
2456 new String(type.sourceName()) }, new String[] { new String(superType.shortReadableName()), new String(type.sourceName()) },
2457 typeDecl.sourceStart, typeDecl.sourceEnd);
2460 public void task(String tag, String message, String priority, int start, int end) {
2461 this.handle(IProblem.Task, new String[] { tag, message, priority /*
2462 * secret argument that is not surfaced in getMessage()
2463 */}, new String[] { tag, message, priority /*
2464 * secret argument that is not surfaced in getMessage()
2468 public void tooManyDimensions(ASTNode expression) {
2469 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd);
2472 public void tooManyFields(TypeDeclaration typeDeclaration) {
2473 this.handle(IProblem.TooManyFields, new String[] { new String(typeDeclaration.binding.readableName()) },
2474 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2475 typeDeclaration.sourceEnd);
2478 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2479 this.handle(IProblem.TooManyMethods, new String[] { new String(typeDeclaration.binding.readableName()) },
2480 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2481 typeDeclaration.sourceEnd);
2484 public void typeCastError(CastExpression expression, TypeBinding leftType, TypeBinding rightType) {
2485 String leftName = new String(leftType.readableName());
2486 String rightName = new String(rightType.readableName());
2487 String leftShortName = new String(leftType.shortReadableName());
2488 String rightShortName = new String(rightType.shortReadableName());
2489 if (leftShortName.equals(rightShortName)) {
2490 leftShortName = leftName;
2491 rightShortName = rightName;
2493 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName }, new String[] { rightShortName, leftShortName },
2494 expression.sourceStart, expression.sourceEnd);
2497 public void typeCollidesWithPackage(CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2498 this.referenceContext = typeDecl; // report the problem against the
2499 // type not the entire compilation
2501 String[] arguments = new String[] { new String(compUnitDecl.getFileName()), new String(typeDecl.name) };
2502 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2503 compUnitDecl.compilationResult);
2506 public void typeMismatchError(TypeBinding resultType, TypeBinding expectedType, ASTNode location) {
2507 String resultTypeName = new String(resultType.readableName());
2508 String expectedTypeName = new String(expectedType.readableName());
2509 String resultTypeShortName = new String(resultType.shortReadableName());
2510 String expectedTypeShortName = new String(expectedType.shortReadableName());
2511 if (resultTypeShortName.equals(expectedTypeShortName)) {
2512 resultTypeShortName = resultTypeName;
2513 expectedTypeShortName = expectedTypeName;
2515 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName, expectedTypeName }, new String[] { resultTypeShortName,
2516 expectedTypeShortName }, location.sourceStart, location.sourceEnd);
2519 public void typeMismatchErrorActualTypeExpectedType(Expression expression, TypeBinding constantType, TypeBinding expectedType) {
2520 String constantTypeName = new String(constantType.readableName());
2521 String expectedTypeName = new String(expectedType.readableName());
2522 String constantTypeShortName = new String(constantType.shortReadableName());
2523 String expectedTypeShortName = new String(expectedType.shortReadableName());
2524 if (constantTypeShortName.equals(expectedTypeShortName)) {
2525 constantTypeShortName = constantTypeName;
2526 expectedTypeShortName = expectedTypeName;
2528 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName, expectedTypeName }, new String[] { constantTypeShortName,
2529 expectedTypeShortName }, expression.sourceStart, expression.sourceEnd);
2532 public void undefinedLabel(BranchStatement statement) {
2533 String[] arguments = new String[] { new String(statement.label) };
2534 this.handle(IProblem.UndefinedLabel, arguments, arguments, statement.sourceStart, statement.sourceEnd);
2537 public void unexpectedStaticModifierForField(SourceTypeBinding type, FieldDeclaration fieldDecl) {
2538 String[] arguments = new String[] { fieldDecl.name() };
2539 this.handle(IProblem.UnexpectedStaticModifierForField, arguments, arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2542 public void unexpectedStaticModifierForMethod(ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
2543 String[] arguments = new String[] { new String(type.sourceName()), new String(methodDecl.selector) };
2544 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments, arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2547 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
2548 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2549 && ((ConstructorDeclaration) referenceContext).isDefaultConstructor();
2550 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2551 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2552 this.handle(insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
2553 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall : IProblem.UnhandledException),
2554 new String[] { new String(exceptionType.readableName()) }, new String[] { new String(exceptionType.shortReadableName()) },
2555 location.sourceStart, location.sourceEnd);
2558 public void uninitializedBlankFinalField(FieldBinding binding, ASTNode location) {
2559 String[] arguments = new String[] { new String(binding.readableName()) };
2560 this.handle(IProblem.UninitializedBlankFinalField, arguments, arguments, location.sourceStart, location.sourceEnd);
2563 public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) {
2564 String[] arguments = new String[] { new String(binding.readableName()) };
2565 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments, location.sourceStart, location.sourceEnd);
2568 public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
2569 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument, position, position, context, compilationResult);
2572 public void unnecessaryEnclosingInstanceSpecification(Expression expression, ReferenceBinding targetType) {
2573 this.handle(IProblem.IllegalEnclosingInstanceSpecification, new String[] { new String(targetType.readableName()) },
2574 new String[] { new String(targetType.shortReadableName()) }, expression.sourceStart, expression.sourceEnd);
2577 public void unnecessaryReceiverForStaticMethod(ASTNode location, MethodBinding method) {
2578 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] { new String(method.declaringClass.readableName()),
2579 new String(method.selector), parametersAsString(method) }, new String[] {
2580 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2581 location.sourceStart, location.sourceEnd);
2584 public void unnecessaryReceiverForStaticField(ASTNode location, FieldBinding field) {
2585 this.handle(IProblem.NonStaticAccessToStaticField, new String[] { new String(field.declaringClass.readableName()),
2586 new String(field.name) }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name) },
2587 location.sourceStart, location.sourceEnd);
2590 public void unreachableCode(Statement statement) {
2591 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument, statement.sourceStart, statement.sourceEnd);
2594 public void unreachableExceptionHandler(ReferenceBinding exceptionType, ASTNode location) {
2595 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2598 public void unresolvableReference(NameReference nameRef, Binding binding) {
2599 int severity = Error;
2601 * also need to check that the searchedType is the receiver type if (binding instanceof ProblemBinding) { ProblemBinding problem =
2602 * (ProblemBinding) binding; if (problem.searchType != null && problem.searchType.isHierarchyInconsistent()) severity =
2605 String[] arguments = new String[] { new String(binding.readableName()) };
2606 this.handle(IProblem.UndefinedName, arguments, arguments, severity, nameRef.sourceStart, nameRef.sourceEnd);
2609 public void unusedArgument(LocalDeclaration localDecl) {
2610 String[] arguments = new String[] { localDecl.name() };
2611 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2614 // public void unusedImport(ImportReference importRef) {
2615 // String[] arguments = new String[]{CharOperation.toString(importRef.tokens)};
2616 // this.handle(IProblem.UnusedImport, arguments, arguments,
2617 // importRef.sourceStart, importRef.sourceEnd);
2619 public void unusedLocalVariable(LocalDeclaration localDecl) {
2620 String[] arguments = new String[] { localDecl.name() };
2621 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments, localDecl.sourceStart, localDecl.sourceEnd);
2624 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2625 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2627 // no complaint for no-arg constructors (or default ones) - known
2628 // pattern to block instantiation
2629 if (constructorDecl.arguments == null || constructorDecl.arguments.length == 0)
2631 MethodBinding constructor = constructorDecl.binding;
2632 this.handle(IProblem.UnusedPrivateConstructor, new String[] { new String(constructor.declaringClass.readableName()),
2633 parametersAsString(constructor) }, new String[] { new String(constructor.declaringClass.shortReadableName()),
2634 parametersAsShortString(constructor) }, constructorDecl.sourceStart, constructorDecl.sourceEnd);
2637 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2638 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2640 FieldBinding field = fieldDecl.binding;
2641 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name) && field.isStatic() && field.isFinal()
2642 && TypeBinding.LongBinding == field.type) {
2643 return; // do not report unused serialVersionUID field
2645 this.handle(IProblem.UnusedPrivateField, new String[] { new String(field.declaringClass.readableName()),
2646 new String(field.name), }, new String[] { new String(field.declaringClass.shortReadableName()), new String(field.name), },
2647 fieldDecl.sourceStart, fieldDecl.sourceEnd);
2650 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2651 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2653 MethodBinding method = methodDecl.binding;
2654 // no report for serialization support 'void
2655 // readObject(ObjectInputStream)'
2656 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2657 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.READOBJECT)
2658 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM, method.parameters[0].readableName())) {
2661 // no report for serialization support 'void
2662 // writeObject(ObjectOutputStream)'
2663 if (!method.isStatic() && TypeBinding.VoidBinding == method.returnType && method.parameters.length == 1
2664 && method.parameters[0].dimensions() == 0 && CharOperation.equals(method.selector, TypeConstants.WRITEOBJECT)
2665 && CharOperation.equals(TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM, method.parameters[0].readableName())) {
2668 // no report for serialization support 'Object readResolve()'
2669 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2670 && CharOperation.equals(method.selector, TypeConstants.READRESOLVE)) {
2673 // no report for serialization support 'Object writeReplace()'
2674 if (!method.isStatic() && TypeBinding.T_Object == method.returnType.id && method.parameters.length == 0
2675 && CharOperation.equals(method.selector, TypeConstants.WRITEREPLACE)) {
2678 this.handle(IProblem.UnusedPrivateMethod, new String[] { new String(method.declaringClass.readableName()),
2679 new String(method.selector), parametersAsString(method) }, new String[] {
2680 new String(method.declaringClass.shortReadableName()), new String(method.selector), parametersAsShortString(method) },
2681 methodDecl.sourceStart, methodDecl.sourceEnd);
2684 public void unusedPrivateType(TypeDeclaration typeDecl) {
2685 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2687 ReferenceBinding type = typeDecl.binding;
2688 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type.readableName()), }, new String[] { new String(type
2689 .shortReadableName()), }, typeDecl.sourceStart, typeDecl.sourceEnd);
2692 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2693 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument, sourceStart, sourceEnd);
2696 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2697 String[] arguments = new String[] { new String(varDecl.name) };
2698 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2701 public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
2702 String[] arguments = new String[] { new String(varDecl.name) };
2703 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments, arguments, varDecl.sourceStart, varDecl.sourceEnd);
2706 public void visibilityConflict(MethodBinding currentMethod, MethodBinding inheritedMethod) {
2708 // Cannot reduce the visibility of the inherited method from %1
2709 // 8.4.6.3 - The access modifier of an hiding method must
2710 // provide at least as much access as the hidden method.
2711 // 8.4.6.3 - The access modifier of an overiding method must
2712 // provide at least as much access as the overriden method.
2713 IProblem.MethodReducesVisibility, new String[] { new String(inheritedMethod.declaringClass.readableName()) },
2714 new String[] { new String(inheritedMethod.declaringClass.shortReadableName()) }, currentMethod.sourceStart(), currentMethod
2718 public void wrongSequenceOfExceptionTypesError(TryStatement statement, int under, int upper) {
2719 //the two catch block under and upper are in an incorrect order.
2720 //under should be define BEFORE upper in the source
2721 TypeReference typeRef = statement.catchArguments[under].type;
2722 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument, typeRef.sourceStart, typeRef.sourceEnd);
2725 public void nonExternalizedStringLiteral(ASTNode location) {
2726 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument, NoArgument, location.sourceStart, location.sourceEnd);
2729 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2730 this.handle(IProblem.TooManyBytesForStringConstant, new String[] { new String(typeDeclaration.binding.readableName()) },
2731 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2732 typeDeclaration.sourceEnd);
2735 public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) {
2736 this.handle(IProblem.TooManyConstantsInConstantPool, new String[] { new String(typeDeclaration.binding.readableName()) },
2737 new String[] { new String(typeDeclaration.binding.shortReadableName()) }, Abort | Error, typeDeclaration.sourceStart,
2738 typeDeclaration.sourceEnd);
2741 private boolean isKeyword(char[] tokenSource) {
2743 * This code is heavily grammar dependant
2745 if (tokenSource == null) {
2749 Scanner scanner = new Scanner();
2750 scanner.setSource(tokenSource);
2751 int token = scanner.getNextToken();
2752 char[] currentKeyword;
2754 currentKeyword = scanner.getCurrentIdentifierSource();
2755 } catch (ArrayIndexOutOfBoundsException e) {
2758 int nextToken = scanner.getNextToken();
2759 if (nextToken == Scanner.TokenNameEOF && scanner.startPosition == scanner.source.length) { // to
2766 // ArrayIndexOutOfBoundsException
2767 // while reading the last token
2769 case Scanner.TokenNameERROR:
2770 if (CharOperation.equals("goto".toCharArray(), currentKeyword)
2771 || CharOperation.equals("const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2776 case Scanner.TokenNameabstract:
2777 // case Scanner.TokenNameassert:
2778 // case Scanner.TokenNamebyte:
2779 case Scanner.TokenNamebreak:
2780 // case Scanner.TokenNameboolean:
2781 case Scanner.TokenNamecase:
2782 // case Scanner.TokenNamechar:
2783 case Scanner.TokenNamecatch:
2784 case Scanner.TokenNameclass:
2785 case Scanner.TokenNamecontinue:
2786 case Scanner.TokenNamedo:
2787 // case Scanner.TokenNamedouble:
2788 case Scanner.TokenNamedefault:
2789 case Scanner.TokenNameelse:
2790 case Scanner.TokenNameextends:
2791 case Scanner.TokenNamefor:
2792 // case Scanner.TokenNamefinal:
2793 // case Scanner.TokenNamefloat:
2794 // case Scanner.TokenNamefalse :
2795 case Scanner.TokenNamefinally:
2796 case Scanner.TokenNameif:
2797 // case Scanner.TokenNameint:
2798 // case Scanner.TokenNameimport:
2799 case Scanner.TokenNameinterface:
2800 case Scanner.TokenNameimplements:
2801 case Scanner.TokenNameinstanceof:
2802 // case Scanner.TokenNamelong:
2803 case Scanner.TokenNamenew:
2804 // case Scanner.TokenNamenull :
2805 // case Scanner.TokenNamenative:
2806 case Scanner.TokenNamepublic:
2807 // case Scanner.TokenNamepackage:
2808 case Scanner.TokenNameprivate:
2809 case Scanner.TokenNameprotected:
2810 case Scanner.TokenNamereturn:
2811 // case Scanner.TokenNameshort:
2812 case Scanner.TokenNamesuper:
2813 case Scanner.TokenNamestatic:
2814 case Scanner.TokenNameswitch:
2815 // case Scanner.TokenNamestrictfp:
2816 // case Scanner.TokenNamesynchronized:
2817 case Scanner.TokenNametry:
2818 // case Scanner.TokenNamethis :
2819 // case Scanner.TokenNametrue :
2820 case Scanner.TokenNamethrow:
2821 // case Scanner.TokenNamethrows:
2822 // case Scanner.TokenNametransient:
2823 // case Scanner.TokenNamevoid:
2824 // case Scanner.TokenNamevolatile:
2825 case Scanner.TokenNamewhile:
2833 } catch (InvalidInputException e) {
2839 public void phpParsingError(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2840 ReferenceContext context, CompilationResult compilationResult) {
2841 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2845 public void phpParsingWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2846 ReferenceContext context, CompilationResult compilationResult) {
2847 this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2851 public void phpVarDeprecatedWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2852 CompilationResult compilationResult) {
2853 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
2855 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument, new String[] {}, problemStartPosition, problemEndPosition, context,
2859 public void phpIncludeNotExistWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition, ReferenceContext context,
2860 CompilationResult compilationResult) {
2861 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
2863 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition, context,
2867 public void phpKeywordWarning(String[] messageArguments, int problemStartPosition, int problemEndPosition,
2868 ReferenceContext context, CompilationResult compilationResult) {
2869 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
2871 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument, messageArguments, problemStartPosition, problemEndPosition,
2872 context, compilationResult);
2875 public void phpUppercaseIdentifierWarning(int problemStartPosition, int problemEndPosition, ReferenceContext context,
2876 CompilationResult compilationResult) {
2877 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
2879 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument, new String[] {}, problemStartPosition,
2880 problemEndPosition, context, compilationResult);