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.ITerminalSymbols.TokenName;
13 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
14 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
15 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
16 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
17 import net.sourceforge.phpdt.internal.compiler.ast.ASTNode;
18 import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
19 import net.sourceforge.phpdt.internal.compiler.ast.AbstractVariableDeclaration;
20 import net.sourceforge.phpdt.internal.compiler.ast.AllocationExpression;
21 import net.sourceforge.phpdt.internal.compiler.ast.Argument;
22 import net.sourceforge.phpdt.internal.compiler.ast.ArrayAllocationExpression;
23 import net.sourceforge.phpdt.internal.compiler.ast.ArrayReference;
24 import net.sourceforge.phpdt.internal.compiler.ast.Assignment;
25 import net.sourceforge.phpdt.internal.compiler.ast.BinaryExpression;
26 import net.sourceforge.phpdt.internal.compiler.ast.CaseStatement;
27 import net.sourceforge.phpdt.internal.compiler.ast.CastExpression;
28 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
29 import net.sourceforge.phpdt.internal.compiler.ast.CompoundAssignment;
30 import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
31 import net.sourceforge.phpdt.internal.compiler.ast.DefaultCase;
32 import net.sourceforge.phpdt.internal.compiler.ast.EqualExpression;
33 import net.sourceforge.phpdt.internal.compiler.ast.ExplicitConstructorCall;
34 import net.sourceforge.phpdt.internal.compiler.ast.Expression;
35 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
36 import net.sourceforge.phpdt.internal.compiler.ast.FieldReference;
37 import net.sourceforge.phpdt.internal.compiler.ast.InstanceOfExpression;
38 import net.sourceforge.phpdt.internal.compiler.ast.IntLiteral;
39 import net.sourceforge.phpdt.internal.compiler.ast.Literal;
40 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
41 import net.sourceforge.phpdt.internal.compiler.ast.LongLiteral;
42 import net.sourceforge.phpdt.internal.compiler.ast.MessageSend;
43 import net.sourceforge.phpdt.internal.compiler.ast.MethodDeclaration;
44 import net.sourceforge.phpdt.internal.compiler.ast.NameReference;
45 import net.sourceforge.phpdt.internal.compiler.ast.NumberLiteral;
46 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedNameReference;
47 import net.sourceforge.phpdt.internal.compiler.ast.Reference;
48 import net.sourceforge.phpdt.internal.compiler.ast.ReturnStatement;
49 import net.sourceforge.phpdt.internal.compiler.ast.SingleNameReference;
50 import net.sourceforge.phpdt.internal.compiler.ast.Statement;
51 import net.sourceforge.phpdt.internal.compiler.ast.ThisReference;
52 import net.sourceforge.phpdt.internal.compiler.ast.ThrowStatement;
53 import net.sourceforge.phpdt.internal.compiler.ast.TryStatement;
54 import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
55 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
56 import net.sourceforge.phpdt.internal.compiler.ast.UnaryExpression;
57 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
58 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
59 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
60 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
61 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
62 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
63 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
64 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
65 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
66 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
67 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
68 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
69 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
70 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
71 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
72 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
73 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
74 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
75 import net.sourceforge.phpdt.internal.compiler.util.Util;
77 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
78 public ReferenceContext referenceContext;
80 public ProblemReporter(IErrorHandlingPolicy policy,
81 CompilerOptions options, IProblemFactory problemFactory) {
83 // IProblemFactory problemFactory) {
84 super(policy, options, problemFactory); // ), problemFactory);
87 public void abortDueToInternalError(String errorMessage) {
88 String[] arguments = new String[] { errorMessage };
89 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
93 public void abortDueToInternalError(String errorMessage, ASTNode location) {
94 String[] arguments = new String[] { errorMessage };
95 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
96 location.sourceStart, location.sourceEnd);
99 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
100 MethodBinding concreteMethod) {
102 // %1 must be abstract since it cannot override the inherited
103 // package-private abstract method %2
104 IProblem.AbstractMethodCannotBeOverridden, new String[] {
105 new String(type.sourceName()),
106 new String(CharOperation.concat(
107 concreteMethod.declaringClass.readableName(),
108 concreteMethod.readableName(), '.')) },
110 new String(type.sourceName()),
111 new String(CharOperation.concat(
112 concreteMethod.declaringClass
113 .shortReadableName(), concreteMethod
114 .shortReadableName(), '.')) }, type
115 .sourceStart(), type.sourceEnd());
118 public void abstractMethodInAbstractClass(SourceTypeBinding type,
119 AbstractMethodDeclaration methodDecl) {
120 String[] arguments = new String[] { new String(type.sourceName()),
121 new String(methodDecl.selector) };
122 this.handle(IProblem.AbstractMethodInAbstractClass, arguments,
123 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
126 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
127 MethodBinding abstractMethod) {
129 // Must implement the inherited abstract method %1
130 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
131 // must provide a concrete implementation of all of A's
133 IProblem.AbstractMethodMustBeImplemented,
134 new String[] { new String(CharOperation.concat(
135 abstractMethod.declaringClass.readableName(),
136 abstractMethod.readableName(), '.')) },
137 new String[] { new String(CharOperation.concat(
138 abstractMethod.declaringClass.shortReadableName(),
139 abstractMethod.shortReadableName(), '.')) }, type
140 .sourceStart(), type.sourceEnd());
143 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
144 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
145 method.sourceStart, method.sourceEnd, method, method
146 .compilationResult());
149 public void alreadyDefinedLabel(char[] labelName, ASTNode location) {
150 String[] arguments = new String[] { new String(labelName) };
151 this.handle(IProblem.DuplicateLabel, arguments, arguments,
152 location.sourceStart, location.sourceEnd);
155 public void anonymousClassCannotExtendFinalClass(Expression expression,
157 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
158 new String[] { new String(type.readableName()) },
159 new String[] { new String(type.shortReadableName()) },
160 expression.sourceStart, expression.sourceEnd);
163 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
164 AbstractMethodDeclaration methodDecl, Argument arg) {
165 String[] arguments = new String[] { new String(methodDecl.selector),
166 new String(arg.name) };
167 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
168 methodDecl.sourceStart, methodDecl.sourceEnd);
171 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
172 AbstractMethodDeclaration methodDecl, Argument arg) {
173 String[] arguments = new String[] { new String(methodDecl.selector),
174 new String(arg.name) };
175 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments,
176 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
179 public void argumentTypeProblem(SourceTypeBinding type,
180 AbstractMethodDeclaration methodDecl, Argument arg,
181 TypeBinding expectedType) {
182 int problemId = expectedType.problemId();
187 id = IProblem.ArgumentTypeNotFound;
191 id = IProblem.ArgumentTypeNotVisible;
195 id = IProblem.ArgumentTypeAmbiguous;
197 case InternalNameProvided:
199 id = IProblem.ArgumentTypeInternalNameProvided;
201 case InheritedNameHidesEnclosingName:
203 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
208 needImplementation(); // want to fail to see why we were
212 this.handle(id, new String[] { new String(methodDecl.selector),
213 arg.name(), new String(expectedType.readableName()) },
214 new String[] { new String(methodDecl.selector), arg.name(),
215 new String(expectedType.shortReadableName()) },
216 arg.type.sourceStart, arg.type.sourceEnd);
219 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
221 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
222 NoArgument, sourceStart, sourceEnd);
225 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
226 String[] arguments = new String[] { new String(name) };
227 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
228 assignment.sourceStart, assignment.sourceEnd);
231 public void attemptToReturnNonVoidExpression(
232 ReturnStatement returnStatement, TypeBinding expectedType) {
233 this.handle(IProblem.VoidMethodReturnsValue, new String[] { new String(
234 expectedType.readableName()) }, new String[] { new String(
235 expectedType.shortReadableName()) },
236 returnStatement.sourceStart, returnStatement.sourceEnd);
239 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
240 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
241 returnStatement.sourceStart, returnStatement.sourceEnd);
244 // public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
246 // String[] arguments = new String[] {new String(location.selector),
247 // parametersAsString(location.binding)};
248 // if (location.isConstructor()) {
250 // IProblem.BytecodeExceeds64KLimitForConstructor,
254 // location.sourceStart,
255 // location.sourceEnd);
258 // IProblem.BytecodeExceeds64KLimit,
262 // location.sourceStart,
263 // location.sourceEnd);
266 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
267 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
268 NoArgument, Error | Abort, location.sourceStart,
272 public void cannotAllocateVoidArray(Expression expression) {
273 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
274 expression.sourceStart, expression.sourceEnd);
277 public void cannotAssignToFinalField(FieldBinding field, ASTNode location) {
280 IProblem.FinalFieldAssignment,
282 (field.declaringClass == null ? "array" : new String(field.declaringClass.readableName())), //$NON-NLS-1$
283 new String(field.readableName()) },
285 (field.declaringClass == null ? "array" : new String(field.declaringClass.shortReadableName())), //$NON-NLS-1$
286 new String(field.shortReadableName()) },
287 location.sourceStart, location.sourceEnd);
290 public void cannotAssignToFinalLocal(LocalVariableBinding local,
292 String[] arguments = new String[] { new String(local.readableName()) };
293 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments,
294 arguments, location.sourceStart, location.sourceEnd);
297 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
299 String[] arguments = new String[] { new String(local.readableName()) };
300 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
301 location.sourceStart, location.sourceEnd);
304 public void cannotDeclareLocalInterface(char[] interfaceName,
305 int sourceStart, int sourceEnd) {
306 String[] arguments = new String[] { new String(interfaceName) };
307 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
308 arguments, sourceStart, sourceEnd);
311 public void cannotDefineDimensionsAndInitializer(
312 ArrayAllocationExpression expresssion) {
313 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit,
314 NoArgument, NoArgument, expresssion.sourceStart,
315 expresssion.sourceEnd);
318 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
319 MethodBinding method) {
320 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[] {
321 new String(method.declaringClass.readableName()),
322 new String(method.selector), parametersAsString(method) },
324 new String(method.declaringClass.shortReadableName()),
325 new String(method.selector),
326 parametersAsShortString(method) },
327 messageSend.sourceStart, messageSend.sourceEnd);
330 // public void cannotImportPackage(ImportReference importRef) {
331 // String[] arguments = new
332 // String[]{CharOperation.toString(importRef.tokens)};
333 // this.handle(IProblem.CannotImportPackage, arguments, arguments,
334 // importRef.sourceStart, importRef.sourceEnd);
336 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
337 this.handle(IProblem.InvalidClassInstantiation,
338 new String[] { new String(type.readableName()) },
339 new String[] { new String(type.shortReadableName()) },
340 typeRef.sourceStart, typeRef.sourceEnd);
343 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
345 String[] arguments = new String[] { new String(local.readableName()) };
346 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
347 location.sourceStart, location.sourceEnd);
350 public void cannotReturnInInitializer(ASTNode location) {
351 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
352 location.sourceStart, location.sourceEnd);
355 public void cannotThrowNull(ThrowStatement statement) {
356 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
357 statement.sourceStart, statement.sourceEnd);
360 public void cannotThrowType(SourceTypeBinding type,
361 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
362 TypeBinding expectedType) {
363 this.handle(IProblem.CannotThrowType, new String[] { new String(
364 expectedType.readableName()) }, new String[] { new String(
365 expectedType.shortReadableName()) }, exceptionType.sourceStart,
366 exceptionType.sourceEnd);
369 public void cannotUseSuperInJavaLangObject(ASTNode reference) {
370 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
371 reference.sourceStart, reference.sourceEnd);
374 public void cannotUseSuperInCodeSnippet(int start, int end) {
375 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument,
376 NoArgument, Error | Abort, start, end);
379 public void caseExpressionMustBeConstant(Expression expression) {
380 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
381 expression.sourceStart, expression.sourceEnd);
384 public void classExtendFinalClass(SourceTypeBinding type,
385 TypeReference superclass, TypeBinding expectedType) {
386 String name = new String(type.sourceName());
387 String expectedFullName = new String(expectedType.readableName());
388 String expectedShortName = new String(expectedType.shortReadableName());
389 if (expectedShortName.equals(name))
390 expectedShortName = expectedFullName;
391 this.handle(IProblem.ClassExtendFinalClass, new String[] {
392 expectedFullName, name }, new String[] { expectedShortName,
393 name }, superclass.sourceStart, superclass.sourceEnd);
396 public void codeSnippetMissingClass(String missing, int start, int end) {
397 String[] arguments = new String[] { missing };
398 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments,
399 Error | Abort, start, end);
402 public void codeSnippetMissingMethod(String className,
403 String missingMethod, String argumentTypes, int start, int end) {
404 String[] arguments = new String[] { className, missingMethod,
406 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments,
407 Error | Abort, start, end);
411 * Given the current configuration, answers which category the problem falls
412 * into: Error | Warning | Ignore
414 public int computeSeverity(int problemId) {
416 // severity can have been preset on the problem
417 // if ((problem.severity & Fatal) != 0){
421 // if not then check whether it is a configurable problem
423 case IProblem.PHPIncludeNotExistWarning:
425 .getSeverity(CompilerOptions.PHPIncludeNotExistWarning);
426 case IProblem.PHPVarDeprecatedWarning:
428 .getSeverity(CompilerOptions.PHPVarDeprecatedWarning);
429 case IProblem.PHPBadStyleKeywordWarning:
431 .getSeverity(CompilerOptions.PHPBadStyleKeywordWarning);
432 case IProblem.PHPBadStyleUppercaseIdentifierWarning:
434 .getSeverity(CompilerOptions.PHPBadStyleUppercaseIdentifierWarning);
436 case IProblem.UninitializedLocalVariable:
438 .getSeverity(CompilerOptions.UninitializedLocalVariableWarning);
439 case IProblem.CodeCannotBeReached:
441 .getSeverity(CompilerOptions.CodeCannotBeReachedWarning);
443 case IProblem.MaskedCatch:
444 return this.options.getSeverity(CompilerOptions.MaskedCatchBlock);
446 case IProblem.UnusedImport:
447 return this.options.getSeverity(CompilerOptions.UnusedImport);
449 case IProblem.MethodButWithConstructorName:
451 .getSeverity(CompilerOptions.MethodWithConstructorName);
453 case IProblem.OverridingNonVisibleMethod:
455 .getSeverity(CompilerOptions.OverriddenPackageDefaultMethod);
457 case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod:
458 case IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod:
460 .getSeverity(CompilerOptions.IncompatibleNonInheritedInterfaceMethod);
462 case IProblem.OverridingDeprecatedMethod:
463 case IProblem.UsingDeprecatedType:
464 case IProblem.UsingDeprecatedMethod:
465 case IProblem.UsingDeprecatedConstructor:
466 case IProblem.UsingDeprecatedField:
467 return this.options.getSeverity(CompilerOptions.UsingDeprecatedAPI);
469 case IProblem.LocalVariableIsNeverUsed:
471 .getSeverity(CompilerOptions.UnusedLocalVariable);
473 case IProblem.ArgumentIsNeverUsed:
474 return this.options.getSeverity(CompilerOptions.UnusedArgument);
476 case IProblem.NoImplicitStringConversionForCharArrayExpression:
478 .getSeverity(CompilerOptions.NoImplicitStringConversion);
480 case IProblem.NeedToEmulateFieldReadAccess:
481 case IProblem.NeedToEmulateFieldWriteAccess:
482 case IProblem.NeedToEmulateMethodAccess:
483 case IProblem.NeedToEmulateConstructorAccess:
484 return this.options.getSeverity(CompilerOptions.AccessEmulation);
486 case IProblem.NonExternalizedStringLiteral:
488 .getSeverity(CompilerOptions.NonExternalizedString);
490 case IProblem.UseAssertAsAnIdentifier:
492 .getSeverity(CompilerOptions.AssertUsedAsAnIdentifier);
494 case IProblem.NonStaticAccessToStaticMethod:
495 case IProblem.NonStaticAccessToStaticField:
497 .getSeverity(CompilerOptions.NonStaticAccessToStatic);
499 // case IProblem.IndirectAccessToStaticMethod :
500 // case IProblem.IndirectAccessToStaticField :
501 // case IProblem.IndirectAccessToStaticType :
503 // this.options.getSeverity(CompilerOptions.IndirectStaticAccess);
505 case IProblem.AssignmentHasNoEffect:
506 return this.options.getSeverity(CompilerOptions.NoEffectAssignment);
508 case IProblem.UnusedPrivateConstructor:
509 case IProblem.UnusedPrivateMethod:
510 case IProblem.UnusedPrivateField:
511 case IProblem.UnusedPrivateType:
513 .getSeverity(CompilerOptions.UnusedPrivateMember);
518 // case IProblem.LocalVariableHidingLocalVariable:
519 // case IProblem.LocalVariableHidingField:
520 // case IProblem.ArgumentHidingLocalVariable:
521 // case IProblem.ArgumentHidingField:
523 // this.options.getSeverity(CompilerOptions.LocalVariableHiding);
525 // case IProblem.FieldHidingLocalVariable:
526 // case IProblem.FieldHidingField:
527 // return this.options.getSeverity(CompilerOptions.FieldHiding);
529 // case IProblem.PossibleAccidentalBooleanAssignment:
531 // this.options.getSeverity(CompilerOptions.AccidentalBooleanAssign);
533 // case IProblem.SuperfluousSemicolon:
535 // this.options.getSeverity(CompilerOptions.SuperfluousSemicolon);
537 // case IProblem.UndocumentedEmptyBlock:
539 // this.options.getSeverity(CompilerOptions.UndocumentedEmptyBlock);
541 // case IProblem.UnnecessaryCast:
542 // case IProblem.UnnecessaryArgumentCast:
543 // case IProblem.UnnecessaryInstanceof:
545 // this.options.getSeverity(CompilerOptions.UnnecessaryTypeCheck);
547 // case IProblem.FinallyMustCompleteNormally:
549 // this.options.getSeverity(CompilerOptions.FinallyBlockNotCompleting);
551 // case IProblem.UnusedMethodDeclaredThrownException:
552 // case IProblem.UnusedConstructorDeclaredThrownException:
554 // this.options.getSeverity(CompilerOptions.UnusedDeclaredThrownException);
556 // case IProblem.UnqualifiedFieldAccess:
558 // this.options.getSeverity(CompilerOptions.UnqualifiedFieldAccess);
561 * Javadoc syntax errors
563 // Javadoc explicit IDs
564 // case IProblem.JavadocUnexpectedTag:
565 // case IProblem.JavadocDuplicateReturnTag:
566 // case IProblem.JavadocInvalidThrowsClass:
567 // case IProblem.JavadocInvalidSeeReference:
568 // case IProblem.JavadocInvalidSeeHref:
569 // case IProblem.JavadocInvalidSeeArgs:
570 // case IProblem.JavadocInvalidTag:
571 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
573 * Javadoc tags resolved references errors
575 // case IProblem.JavadocInvalidParamName:
576 // case IProblem.JavadocDuplicateParamName:
577 // case IProblem.JavadocMissingParamName:
578 // case IProblem.JavadocInvalidThrowsClassName:
579 // case IProblem.JavadocDuplicateThrowsClassName:
580 // case IProblem.JavadocMissingThrowsClassName:
581 // case IProblem.JavadocMissingSeeReference:
582 // case IProblem.JavadocUsingDeprecatedField:
583 // case IProblem.JavadocUsingDeprecatedConstructor:
584 // case IProblem.JavadocUsingDeprecatedMethod:
585 // case IProblem.JavadocUsingDeprecatedType:
586 // case IProblem.JavadocUndefinedField:
587 // case IProblem.JavadocNotVisibleField:
588 // case IProblem.JavadocAmbiguousField:
589 // case IProblem.JavadocUndefinedConstructor:
590 // case IProblem.JavadocNotVisibleConstructor:
591 // case IProblem.JavadocAmbiguousConstructor:
592 // case IProblem.JavadocUndefinedMethod:
593 // case IProblem.JavadocNotVisibleMethod:
594 // case IProblem.JavadocAmbiguousMethod:
595 // case IProblem.JavadocParameterMismatch:
596 // case IProblem.JavadocUndefinedType:
597 // case IProblem.JavadocNotVisibleType:
598 // case IProblem.JavadocAmbiguousType:
599 // case IProblem.JavadocInternalTypeNameProvided:
600 // case IProblem.JavadocNoMessageSendOnArrayType:
601 // case IProblem.JavadocNoMessageSendOnBaseType:
602 // if (!this.options.reportInvalidJavadocTags)
603 // return ProblemSeverities.Ignore;
605 // return this.options.getSeverity(CompilerOptions.InvalidJavadoc);
607 * Javadoc missing tags errors
609 // case IProblem.JavadocMissingParamTag:
610 // case IProblem.JavadocMissingReturnTag:
611 // case IProblem.JavadocMissingThrowsTag:
613 // this.options.getSeverity(CompilerOptions.MissingJavadocTags);
615 * Missing Javadoc errors
617 // case IProblem.JavadocMissing:
619 // this.options.getSeverity(CompilerOptions.MissingJavadocComments);
620 // by default problems are errors.
626 // public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
627 // expression, TypeBinding trueType, TypeBinding falseType) {
629 // IProblem.IncompatibleTypesInConditionalOperator,
630 // new String[] {new String(trueType.readableName()), new
631 // String(falseType.readableName())},
632 // new String[] {new String(trueType.sourceName()), new
633 // String(falseType.sourceName())},
634 // expression.sourceStart,
635 // expression.sourceEnd);
637 // public void conflictingImport(ImportReference importRef) {
638 // String[] arguments = new
639 // String[]{CharOperation.toString(importRef.tokens)};
640 // this.handle(IProblem.ConflictingImport, arguments, arguments,
641 // importRef.sourceStart, importRef.sourceEnd);
643 public void constantOutOfFormat(NumberLiteral lit) {
644 // the literal is not in a correct format
645 // this code is called on IntLiteral and LongLiteral
646 // example 000811 ...the 8 is uncorrect.
647 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
648 char[] source = lit.source();
652 if ((source[1] == 'x') || (source[1] == 'X')) {
654 Radix = "Hexa"; //$NON-NLS-1$
657 Radix = "Octal"; //$NON-NLS-1$
659 // look for the first digit that is incorrect
661 label: for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
662 if (Character.digit(source[i], radix) == -1) {
667 String[] arguments = new String[] { Radix
670 + " (digit " + new String(new char[] { source[place] }) + ")" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
671 this.handle(IProblem.NumericValueOutOfRange, arguments,
672 arguments, lit.sourceStart, lit.sourceEnd);
674 } catch (IndexOutOfBoundsException ex) {
676 // just in case .... use a predefined error..
677 // we should never come here...(except if the code changes !)
678 this.constantOutOfRange(lit);
682 public void constantOutOfRange(Literal lit) {
683 // lit is some how out of range of it declared type
685 // 9999999999999999999999999999999999999999999999999999999999999999999
686 String[] arguments = new String[] { new String(lit.source()) };
687 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
688 lit.sourceStart, lit.sourceEnd);
691 public void deprecatedField(FieldBinding field, ASTNode location) {
692 this.handle(IProblem.UsingDeprecatedField, new String[] {
693 new String(field.declaringClass.readableName()),
694 new String(field.name) }, new String[] {
695 new String(field.declaringClass.shortReadableName()),
696 new String(field.name) }, location.sourceStart,
700 public void deprecatedMethod(MethodBinding method, ASTNode location) {
701 if (method.isConstructor())
702 this.handle(IProblem.UsingDeprecatedConstructor, new String[] {
703 new String(method.declaringClass.readableName()),
704 parametersAsString(method) }, new String[] {
705 new String(method.declaringClass.shortReadableName()),
706 parametersAsShortString(method) }, location.sourceStart,
709 this.handle(IProblem.UsingDeprecatedMethod, new String[] {
710 new String(method.declaringClass.readableName()),
711 new String(method.selector), parametersAsString(method) },
713 new String(method.declaringClass
714 .shortReadableName()),
715 new String(method.selector),
716 parametersAsShortString(method) },
717 location.sourceStart, location.sourceEnd);
720 public void deprecatedType(TypeBinding type, ASTNode location) {
721 if (location == null)
722 return; // 1G828DN - no type ref for synthetic arguments
723 this.handle(IProblem.UsingDeprecatedType, new String[] { new String(
724 type.readableName()) }, new String[] { new String(type
725 .shortReadableName()) }, location.sourceStart,
729 public void duplicateCase(CaseStatement statement, Constant constant) {
730 String[] arguments = new String[] { String.valueOf(constant.intValue()) };
731 this.handle(IProblem.DuplicateCase, arguments, arguments,
732 statement.sourceStart, statement.sourceEnd);
735 public void duplicateDefaultCase(DefaultCase statement) {
736 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
737 statement.sourceStart, statement.sourceEnd);
740 public void duplicateFieldInType(SourceTypeBinding type,
741 FieldDeclaration fieldDecl) {
742 this.handle(IProblem.DuplicateField, new String[] {
743 new String(type.sourceName()), fieldDecl.name() },
744 new String[] { new String(type.shortReadableName()),
745 fieldDecl.name() }, fieldDecl.sourceStart,
746 fieldDecl.sourceEnd);
749 // public void duplicateImport(ImportReference importRef) {
750 // String[] arguments = new
751 // String[]{CharOperation.toString(importRef.tokens)};
752 // this.handle(IProblem.DuplicateImport, arguments, arguments,
753 // importRef.sourceStart, importRef.sourceEnd);
755 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
756 Reference reference) {
757 String[] arguments = new String[] { new String(field.readableName()) };
758 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
759 arguments, reference.sourceStart, reference.sourceEnd);
762 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
764 String[] arguments = new String[] { new String(local.readableName()) };
765 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
766 arguments, location.sourceStart, location.sourceEnd);
769 public void duplicateMethodInType(SourceTypeBinding type,
770 AbstractMethodDeclaration methodDecl) {
771 String[] arguments = new String[] { new String(methodDecl.selector),
772 new String(type.sourceName()) };
773 this.handle(IProblem.DuplicateMethod, arguments, arguments,
774 methodDecl.sourceStart, methodDecl.sourceEnd);
777 public void duplicateModifierForField(ReferenceBinding type,
778 FieldDeclaration fieldDecl) {
780 * to highlight modifiers use: this.handle( new Problem(
781 * DuplicateModifierForField, new String[] {fieldDecl.name()},
782 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
784 String[] arguments = new String[] { fieldDecl.name() };
785 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
786 fieldDecl.sourceStart, fieldDecl.sourceEnd);
789 public void duplicateModifierForMethod(ReferenceBinding type,
790 AbstractMethodDeclaration methodDecl) {
791 this.handle(IProblem.DuplicateModifierForMethod,
792 new String[] { new String(type.sourceName()),
793 new String(methodDecl.selector) }, new String[] {
794 new String(type.shortReadableName()),
795 new String(methodDecl.selector) },
796 methodDecl.sourceStart, methodDecl.sourceEnd);
799 public void duplicateModifierForType(SourceTypeBinding type) {
800 String[] arguments = new String[] { new String(type.sourceName()) };
801 this.handle(IProblem.DuplicateModifierForType, arguments, arguments,
802 type.sourceStart(), type.sourceEnd());
805 public void duplicateModifierForVariable(LocalDeclaration localDecl,
806 boolean complainForArgument) {
807 String[] arguments = new String[] { localDecl.name() };
808 this.handle(complainForArgument ? IProblem.DuplicateModifierForArgument
809 : IProblem.DuplicateModifierForVariable, arguments, arguments,
810 localDecl.sourceStart, localDecl.sourceEnd);
813 public void duplicateNestedType(TypeDeclaration typeDecl) {
814 String[] arguments = new String[] { new String(typeDecl.name) };
815 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
816 typeDecl.sourceStart, typeDecl.sourceEnd);
819 public void duplicateSuperinterface(SourceTypeBinding type,
820 TypeDeclaration typeDecl, ReferenceBinding superType) {
821 this.handle(IProblem.DuplicateSuperInterface, new String[] {
822 new String(superType.readableName()),
823 new String(type.sourceName()) }, new String[] {
824 new String(superType.shortReadableName()),
825 new String(type.sourceName()) }, typeDecl.sourceStart,
829 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
830 TypeDeclaration typeDecl) {
831 String[] arguments = new String[] {
832 new String(compUnitDecl.getFileName()),
833 new String(typeDecl.name) };
834 this.referenceContext = typeDecl; // report the problem against the
835 // type not the entire compilation
837 this.handle(IProblem.DuplicateTypes, arguments, arguments,
838 typeDecl.sourceStart, typeDecl.sourceEnd,
839 compUnitDecl.compilationResult);
842 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
843 TypeBinding[] params) {
844 StringBuffer buffer = new StringBuffer();
845 StringBuffer shortBuffer = new StringBuffer();
846 for (int i = 0, length = params.length; i < length; i++) {
848 buffer.append(", "); //$NON-NLS-1$
849 shortBuffer.append(", "); //$NON-NLS-1$
851 buffer.append(new String(params[i].readableName()));
852 shortBuffer.append(new String(params[i].shortReadableName()));
854 this.handle(recType.isArrayType() ? IProblem.NoMessageSendOnArrayType
855 : IProblem.NoMessageSendOnBaseType, new String[] {
856 new String(recType.readableName()),
857 new String(messageSend.selector), buffer.toString() },
858 new String[] { new String(recType.shortReadableName()),
859 new String(messageSend.selector),
860 shortBuffer.toString() }, messageSend.sourceStart,
861 messageSend.sourceEnd);
864 public void errorThisSuperInStatic(ASTNode reference) {
865 String[] arguments = new String[] { reference.isSuper() ? "super" : "this" }; //$NON-NLS-2$ //$NON-NLS-1$
866 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
867 reference.sourceStart, reference.sourceEnd);
870 public void exceptionTypeProblem(SourceTypeBinding type,
871 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
872 TypeBinding expectedType) {
873 int problemId = expectedType.problemId();
878 id = IProblem.ExceptionTypeNotFound;
882 id = IProblem.ExceptionTypeNotVisible;
886 id = IProblem.ExceptionTypeAmbiguous;
888 case InternalNameProvided:
890 id = IProblem.ExceptionTypeInternalNameProvided;
892 case InheritedNameHidesEnclosingName:
894 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
899 needImplementation(); // want to fail to see why we were
903 this.handle(id, new String[] { new String(methodDecl.selector),
904 new String(expectedType.readableName()) }, new String[] {
905 new String(methodDecl.selector),
906 new String(expectedType.shortReadableName()) },
907 exceptionType.sourceStart, exceptionType.sourceEnd);
910 public void expressionShouldBeAVariable(Expression expression) {
911 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument,
912 NoArgument, expression.sourceStart, expression.sourceEnd);
915 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
916 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
917 NoArgument, reference.sourceStart, reference.sourceEnd);
920 public void fieldTypeProblem(SourceTypeBinding type,
921 FieldDeclaration fieldDecl, TypeBinding expectedType) {
922 int problemId = expectedType.problemId();
927 id = IProblem.FieldTypeNotFound;
931 id = IProblem.FieldTypeNotVisible;
935 id = IProblem.FieldTypeAmbiguous;
937 case InternalNameProvided:
939 id = IProblem.FieldTypeInternalNameProvided;
941 case InheritedNameHidesEnclosingName:
943 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
948 needImplementation(); // want to fail to see why we were
952 this.handle(id, new String[] { fieldDecl.name(),
953 new String(type.sourceName()),
954 new String(expectedType.readableName()) }, new String[] {
955 fieldDecl.name(), new String(type.sourceName()),
956 new String(expectedType.shortReadableName()) },
957 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
960 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
961 MethodBinding inheritedMethod) {
963 // Cannot override the final method from %1
964 // 8.4.3.3 - Final methods cannot be overridden or hidden.
965 IProblem.FinalMethodCannotBeOverridden,
966 new String[] { new String(inheritedMethod.declaringClass
967 .readableName()) }, new String[] { new String(
968 inheritedMethod.declaringClass.shortReadableName()) },
969 currentMethod.sourceStart(), currentMethod.sourceEnd());
972 public void forwardReference(Reference reference, int indexInQualification,
974 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
975 reference.sourceStart, reference.sourceEnd);
978 // use this private API when the compilation unit result can be found
980 // reference context. Otherwise, use the other API taking a problem and a
981 // compilation result
983 private void handle(int problemId, String[] problemArguments,
984 String[] messageArguments, int problemStartPosition,
985 int problemEndPosition) {
986 this.handle(problemId, problemArguments, messageArguments,
987 problemStartPosition, problemEndPosition, referenceContext,
988 referenceContext == null ? null : referenceContext
989 .compilationResult());
990 referenceContext = null;
993 // use this private API when the compilation unit result can be found
995 // reference context. Otherwise, use the other API taking a problem and a
996 // compilation result
998 private void handle(int problemId, String[] problemArguments,
999 String[] messageArguments, int severity, int problemStartPosition,
1000 int problemEndPosition) {
1001 this.handle(problemId, problemArguments, messageArguments, severity,
1002 problemStartPosition, problemEndPosition, referenceContext,
1003 referenceContext == null ? null : referenceContext
1004 .compilationResult());
1005 referenceContext = null;
1008 // use this private API when the compilation unit result cannot be found
1010 // reference context.
1011 private void handle(int problemId, String[] problemArguments,
1012 String[] messageArguments, int problemStartPosition,
1013 int problemEndPosition, CompilationResult unitResult) {
1014 this.handle(problemId, problemArguments, messageArguments,
1015 problemStartPosition, problemEndPosition, referenceContext,
1017 referenceContext = null;
1020 public void hidingEnclosingType(TypeDeclaration typeDecl) {
1021 String[] arguments = new String[] { new String(typeDecl.name) };
1022 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
1023 typeDecl.sourceStart, typeDecl.sourceEnd);
1026 public void hierarchyCircularity(SourceTypeBinding sourceType,
1027 ReferenceBinding superType, TypeReference reference) {
1030 String typeName = ""; //$NON-NLS-1$
1031 String shortTypeName = ""; //$NON-NLS-1$
1032 if (reference == null) { // can only happen when java.lang.Object is
1034 start = sourceType.sourceStart();
1035 end = sourceType.sourceEnd();
1036 typeName = new String(superType.readableName());
1037 shortTypeName = new String(superType.sourceName());
1039 start = reference.sourceStart;
1040 end = reference.sourceEnd;
1041 char[][] qName = reference.getTypeName();
1042 typeName = CharOperation.toString(qName);
1043 shortTypeName = new String(qName[qName.length - 1]);
1045 if (sourceType == superType)
1046 this.handle(IProblem.HierarchyCircularitySelfReference,
1047 new String[] { new String(sourceType.sourceName()),
1049 new String[] { new String(sourceType.sourceName()),
1050 shortTypeName }, start, end);
1052 this.handle(IProblem.HierarchyCircularity, new String[] {
1053 new String(sourceType.sourceName()), typeName },
1054 new String[] { new String(sourceType.sourceName()),
1055 shortTypeName }, start, end);
1058 public void hierarchyHasProblems(SourceTypeBinding type) {
1059 String[] arguments = new String[] { new String(type.sourceName()) };
1060 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
1061 .sourceStart(), type.sourceEnd());
1064 public void illegalAbstractModifierCombinationForMethod(
1065 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1066 String[] arguments = new String[] { new String(type.sourceName()),
1067 new String(methodDecl.selector) };
1068 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
1069 arguments, arguments, methodDecl.sourceStart,
1070 methodDecl.sourceEnd);
1073 public void illegalModifierCombinationFinalAbstractForClass(
1074 SourceTypeBinding type) {
1075 String[] arguments = new String[] { new String(type.sourceName()) };
1076 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
1077 arguments, arguments, type.sourceStart(), type.sourceEnd());
1080 public void illegalModifierCombinationFinalVolatileForField(
1081 ReferenceBinding type, FieldDeclaration fieldDecl) {
1082 String[] arguments = new String[] { fieldDecl.name() };
1083 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
1084 arguments, arguments, fieldDecl.sourceStart,
1085 fieldDecl.sourceEnd);
1088 public void illegalModifierForClass(SourceTypeBinding type) {
1089 String[] arguments = new String[] { new String(type.sourceName()) };
1090 this.handle(IProblem.IllegalModifierForClass, arguments, arguments,
1091 type.sourceStart(), type.sourceEnd());
1094 public void illegalModifierForField(ReferenceBinding type,
1095 FieldDeclaration fieldDecl) {
1096 String[] arguments = new String[] { fieldDecl.name() };
1097 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
1098 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1101 public void illegalModifierForInterface(SourceTypeBinding type) {
1102 String[] arguments = new String[] { new String(type.sourceName()) };
1103 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
1104 type.sourceStart(), type.sourceEnd());
1107 public void illegalModifierForInterfaceField(ReferenceBinding type,
1108 FieldDeclaration fieldDecl) {
1109 String[] arguments = new String[] { fieldDecl.name() };
1110 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
1111 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1114 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
1115 AbstractMethodDeclaration methodDecl) {
1116 String[] arguments = new String[] { new String(type.sourceName()),
1117 new String(methodDecl.selector) };
1118 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
1119 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1122 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1123 String[] arguments = new String[] { new String(type.sourceName()) };
1124 this.handle(IProblem.IllegalModifierForLocalClass, arguments,
1125 arguments, type.sourceStart(), type.sourceEnd());
1128 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1129 String[] arguments = new String[] { new String(type.sourceName()) };
1130 this.handle(IProblem.IllegalModifierForMemberClass, arguments,
1131 arguments, type.sourceStart(), type.sourceEnd());
1134 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1135 String[] arguments = new String[] { new String(type.sourceName()) };
1136 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
1137 arguments, type.sourceStart(), type.sourceEnd());
1140 public void illegalModifierForMethod(ReferenceBinding type,
1141 AbstractMethodDeclaration methodDecl) {
1142 String[] arguments = new String[] { new String(type.sourceName()),
1143 new String(methodDecl.selector) };
1144 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1145 methodDecl.sourceStart, methodDecl.sourceEnd);
1148 public void illegalModifierForVariable(LocalDeclaration localDecl,
1149 boolean complainAsArgument) {
1150 String[] arguments = new String[] { localDecl.name() };
1151 this.handle(complainAsArgument ? IProblem.IllegalModifierForArgument
1152 : IProblem.IllegalModifierForVariable, arguments, arguments,
1153 localDecl.sourceStart, localDecl.sourceEnd);
1156 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1157 TypeBinding enclosingType, ASTNode location) {
1158 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1159 new String[] { new String(enclosingType.readableName()) },
1160 new String[] { new String(enclosingType.shortReadableName()) },
1161 location.sourceStart, location.sourceEnd);
1164 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1165 String[] arguments = new String[] { new String(type.sourceName()) };
1166 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1167 arguments, type.sourceStart(), type.sourceEnd());
1170 public void illegalVisibilityModifierCombinationForField(
1171 ReferenceBinding type, FieldDeclaration fieldDecl) {
1172 String[] arguments = new String[] { new String(fieldDecl.name()) };
1173 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1174 arguments, arguments, fieldDecl.sourceStart,
1175 fieldDecl.sourceEnd);
1178 public void illegalVisibilityModifierCombinationForMemberType(
1179 SourceTypeBinding type) {
1180 String[] arguments = new String[] { new String(type.sourceName()) };
1181 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1182 arguments, arguments, type.sourceStart(), type.sourceEnd());
1185 public void illegalVisibilityModifierCombinationForMethod(
1186 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1187 String[] arguments = new String[] { new String(type.sourceName()),
1188 new String(methodDecl.selector) };
1189 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1190 arguments, arguments, methodDecl.sourceStart,
1191 methodDecl.sourceEnd);
1194 public void illegalVisibilityModifierForInterfaceMemberType(
1195 SourceTypeBinding type) {
1196 String[] arguments = new String[] { new String(type.sourceName()) };
1197 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1198 arguments, arguments, type.sourceStart(), type.sourceEnd());
1201 public void illegalVoidExpression(ASTNode location) {
1202 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1203 location.sourceStart, location.sourceEnd);
1206 // public void importProblem(ImportReference importRef, Binding
1207 // expectedImport) {
1208 // int problemId = expectedImport.problemId();
1210 // switch (problemId) {
1213 // id = IProblem.ImportNotFound;
1215 // case NotVisible :
1217 // id = IProblem.ImportNotVisible;
1221 // id = IProblem.ImportAmbiguous;
1223 // case InternalNameProvided :
1225 // id = IProblem.ImportInternalNameProvided;
1227 // case InheritedNameHidesEnclosingName :
1229 // id = IProblem.ImportInheritedNameHidesEnclosingName;
1234 // needImplementation(); // want to fail to see why we were
1239 // if (expectedImport instanceof ProblemReferenceBinding) {
1240 // argument = CharOperation
1241 // .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1243 // argument = CharOperation.toString(importRef.tokens);
1245 // String[] arguments = new String[]{argument};
1246 // this.handle(id, arguments, arguments, importRef.sourceStart,
1247 // importRef.sourceEnd);
1249 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1250 MethodBinding currentMethod, MethodBinding inheritedMethod,
1251 ReferenceBinding exceptionType) {
1252 if (type == currentMethod.declaringClass) {
1254 if (currentMethod.declaringClass.isInterface()
1255 && !inheritedMethod.isPublic()) { // interface inheriting
1258 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1260 id = IProblem.IncompatibleExceptionInThrowsClause;
1264 // Exception %1 is not compatible with throws
1266 // 9.4.4 - The type of exception in the throws
1267 // clause is incompatible.
1270 new String(exceptionType.sourceName()),
1274 inheritedMethod.declaringClass
1280 new String(exceptionType.sourceName()),
1284 inheritedMethod.declaringClass
1285 .shortReadableName(),
1287 .shortReadableName(),
1289 currentMethod.sourceStart(), currentMethod
1294 // Exception %1 in throws clause of %2 is not
1295 // compatible with %3
1296 // 9.4.4 - The type of exception in the throws
1297 // clause is incompatible.
1298 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1300 new String(exceptionType.sourceName()),
1301 new String(CharOperation.concat(
1302 currentMethod.declaringClass
1304 currentMethod.readableName(), '.')),
1308 inheritedMethod.declaringClass
1314 new String(exceptionType.sourceName()),
1315 new String(CharOperation.concat(
1316 currentMethod.declaringClass
1318 currentMethod.shortReadableName(),
1323 inheritedMethod.declaringClass
1324 .shortReadableName(),
1326 .shortReadableName(),
1328 .sourceStart(), type.sourceEnd());
1331 public void incompatibleReturnType(MethodBinding currentMethod,
1332 MethodBinding inheritedMethod) {
1333 StringBuffer methodSignature = new StringBuffer();
1334 methodSignature.append(inheritedMethod.declaringClass.readableName())
1335 .append('.').append(inheritedMethod.readableName());
1336 StringBuffer shortSignature = new StringBuffer();
1337 shortSignature.append(
1338 inheritedMethod.declaringClass.shortReadableName()).append('.')
1339 .append(inheritedMethod.shortReadableName());
1341 if (currentMethod.declaringClass.isInterface()
1342 && !inheritedMethod.isPublic()) { // interface inheriting
1343 // Object protected method
1344 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1346 id = IProblem.IncompatibleReturnType;
1348 this.handle(id, new String[] { methodSignature.toString() },
1349 new String[] { shortSignature.toString() }, currentMethod
1350 .sourceStart(), currentMethod.sourceEnd());
1353 public void incorrectLocationForEmptyDimension(
1354 ArrayAllocationExpression expression, int index) {
1355 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1356 expression.dimensions[index + 1].sourceStart,
1357 expression.dimensions[index + 1].sourceEnd);
1360 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1361 this.handle(IProblem.IncorrectSwitchType, new String[] { new String(
1362 testType.readableName()) }, new String[] { new String(testType
1363 .shortReadableName()) }, expression.sourceStart,
1364 expression.sourceEnd);
1367 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1368 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1369 StringBuffer concreteSignature = new StringBuffer();
1370 concreteSignature.append(concreteMethod.declaringClass.readableName())
1371 .append('.').append(concreteMethod.readableName());
1372 StringBuffer shortSignature = new StringBuffer();
1374 .append(concreteMethod.declaringClass.shortReadableName())
1375 .append('.').append(concreteMethod.shortReadableName());
1377 // The inherited method %1 cannot hide the public abstract
1379 IProblem.InheritedMethodReducesVisibility, new String[] {
1380 new String(concreteSignature.toString()),
1381 new String(abstractMethods[0].declaringClass
1382 .readableName()) }, new String[] {
1383 new String(shortSignature.toString()),
1384 new String(abstractMethods[0].declaringClass
1385 .shortReadableName()) }, type.sourceStart(),
1389 public void inheritedMethodsHaveIncompatibleReturnTypes(
1390 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1391 StringBuffer methodSignatures = new StringBuffer();
1392 StringBuffer shortSignatures = new StringBuffer();
1393 for (int i = length; --i >= 0;) {
1394 methodSignatures.append(
1395 inheritedMethods[i].declaringClass.readableName()).append(
1396 '.').append(inheritedMethods[i].readableName());
1397 shortSignatures.append(
1398 inheritedMethods[i].declaringClass.shortReadableName())
1400 .append(inheritedMethods[i].shortReadableName());
1402 methodSignatures.append(", "); //$NON-NLS-1$
1403 shortSignatures.append(", "); //$NON-NLS-1$
1407 // Return type is incompatible with %1
1408 // 9.4.2 - The return type from the method is incompatible with
1410 IProblem.IncompatibleReturnType,
1411 new String[] { methodSignatures.toString() },
1412 new String[] { shortSignatures.toString() },
1413 type.sourceStart(), type.sourceEnd());
1416 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1417 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1418 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1421 public void innerTypesCannotDeclareStaticInitializers(
1422 ReferenceBinding innerType, ASTNode location) {
1423 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1424 new String[] { new String(innerType.readableName()) },
1425 new String[] { new String(innerType.shortReadableName()) },
1426 location.sourceStart, location.sourceEnd);
1429 public void interfaceCannotHaveConstructors(
1430 ConstructorDeclaration constructor) {
1431 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1432 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1433 constructor, constructor.compilationResult());
1436 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1437 FieldDeclaration fieldDecl) {
1438 String[] arguments = new String[] { new String(type.sourceName()) };
1439 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments,
1440 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1443 public void invalidBreak(ASTNode location) {
1444 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1445 location.sourceStart, location.sourceEnd);
1448 public void invalidConstructor(Statement statement,
1449 MethodBinding targetConstructor) {
1450 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1451 && ((ConstructorDeclaration) referenceContext)
1452 .isDefaultConstructor();
1453 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1454 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1455 int flag = IProblem.UndefinedConstructor; // default...
1456 switch (targetConstructor.problemId()) {
1458 if (insideDefaultConstructor) {
1459 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1460 } else if (insideImplicitConstructorCall) {
1461 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1463 flag = IProblem.UndefinedConstructor;
1467 if (insideDefaultConstructor) {
1468 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1469 } else if (insideImplicitConstructorCall) {
1470 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1472 flag = IProblem.NotVisibleConstructor;
1476 if (insideDefaultConstructor) {
1477 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1478 } else if (insideImplicitConstructorCall) {
1479 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1481 flag = IProblem.AmbiguousConstructor;
1487 needImplementation(); // want to fail to see why we were
1491 this.handle(flag, new String[] {
1492 new String(targetConstructor.declaringClass.readableName()),
1493 parametersAsString(targetConstructor) },
1495 new String(targetConstructor.declaringClass
1496 .shortReadableName()),
1497 parametersAsShortString(targetConstructor) },
1498 statement.sourceStart, statement.sourceEnd);
1501 public void invalidContinue(ASTNode location) {
1502 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1503 location.sourceStart, location.sourceEnd);
1506 public void invalidEnclosingType(Expression expression, TypeBinding type,
1507 ReferenceBinding enclosingType) {
1508 if (enclosingType.isAnonymousType())
1509 enclosingType = enclosingType.superclass();
1510 int flag = IProblem.UndefinedType; // default
1511 switch (type.problemId()) {
1514 flag = IProblem.UndefinedType;
1518 flag = IProblem.NotVisibleType;
1522 flag = IProblem.AmbiguousType;
1524 case InternalNameProvided:
1525 flag = IProblem.InternalTypeNameProvided;
1530 needImplementation(); // want to fail to see why we were
1534 this.handle(flag, new String[] { new String(enclosingType
1536 + "." + new String(type.readableName()) }, //$NON-NLS-1$
1537 new String[] { new String(enclosingType.shortReadableName())
1538 + "." + new String(type.shortReadableName()) }, //$NON-NLS-1$
1539 expression.sourceStart, expression.sourceEnd);
1542 public void invalidExpressionAsStatement(Expression expression) {
1543 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument,
1544 NoArgument, expression.sourceStart, expression.sourceEnd);
1547 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1548 int severity = Error;
1549 int flag = IProblem.UndefinedField;
1550 FieldBinding field = fieldRef.binding;
1551 switch (field.problemId()) {
1553 flag = IProblem.UndefinedField;
1555 * also need to check that the searchedType is the receiver type if
1556 * (searchedType.isHierarchyInconsistent()) severity =
1561 flag = IProblem.NotVisibleField;
1564 flag = IProblem.AmbiguousField;
1566 case NonStaticReferenceInStaticContext:
1567 flag = IProblem.NonStaticFieldFromStaticInvocation;
1569 case NonStaticReferenceInConstructorInvocation:
1570 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1572 case InheritedNameHidesEnclosingName:
1573 flag = IProblem.InheritedFieldHidesEnclosingName;
1575 case ReceiverTypeNotVisible:
1576 this.handle(IProblem.NotVisibleType, new String[] { new String(
1577 searchedType.leafComponentType().readableName()) },
1578 new String[] { new String(searchedType.leafComponentType()
1579 .shortReadableName()) },
1580 fieldRef.receiver.sourceStart, fieldRef.receiver.sourceEnd);
1585 needImplementation(); // want to fail to see why we were
1589 String[] arguments = new String[] { new String(field.readableName()) };
1590 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1591 fieldRef.sourceEnd);
1594 public void invalidField(NameReference nameRef, FieldBinding field) {
1595 int flag = IProblem.UndefinedField;
1596 switch (field.problemId()) {
1598 flag = IProblem.UndefinedField;
1601 flag = IProblem.NotVisibleField;
1604 flag = IProblem.AmbiguousField;
1606 case NonStaticReferenceInStaticContext:
1607 flag = IProblem.NonStaticFieldFromStaticInvocation;
1609 case NonStaticReferenceInConstructorInvocation:
1610 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1612 case InheritedNameHidesEnclosingName:
1613 flag = IProblem.InheritedFieldHidesEnclosingName;
1615 case ReceiverTypeNotVisible:
1616 this.handle(IProblem.NotVisibleType, new String[] { new String(
1617 field.declaringClass.leafComponentType().readableName()) },
1618 new String[] { new String(field.declaringClass
1619 .leafComponentType().shortReadableName()) },
1620 nameRef.sourceStart, nameRef.sourceEnd);
1625 needImplementation(); // want to fail to see why we were
1629 String[] arguments = new String[] { new String(field.readableName()) };
1630 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1634 public void invalidField(QualifiedNameReference nameRef,
1635 FieldBinding field, int index, TypeBinding searchedType) {
1636 // the resolution of the index-th field of qname failed
1637 // qname.otherBindings[index] is the binding that has produced the
1639 // The different targetted errors should be :
1643 if (searchedType.isBaseType()) {
1644 this.handle(IProblem.NoFieldOnBaseType, new String[] {
1645 new String(searchedType.readableName()),
1646 CharOperation.toString(CharOperation.subarray(
1647 nameRef.tokens, 0, index)),
1648 new String(nameRef.tokens[index]) }, new String[] {
1649 new String(searchedType.sourceName()),
1650 CharOperation.toString(CharOperation.subarray(
1651 nameRef.tokens, 0, index)),
1652 new String(nameRef.tokens[index]) }, nameRef.sourceStart,
1656 int flag = IProblem.UndefinedField;
1657 switch (field.problemId()) {
1659 flag = IProblem.UndefinedField;
1661 * also need to check that the searchedType is the receiver type if
1662 * (searchedType.isHierarchyInconsistent()) severity =
1667 flag = IProblem.NotVisibleField;
1670 flag = IProblem.AmbiguousField;
1672 case NonStaticReferenceInStaticContext:
1673 flag = IProblem.NonStaticFieldFromStaticInvocation;
1675 case NonStaticReferenceInConstructorInvocation:
1676 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1678 case InheritedNameHidesEnclosingName:
1679 flag = IProblem.InheritedFieldHidesEnclosingName;
1681 case ReceiverTypeNotVisible:
1682 this.handle(IProblem.NotVisibleType, new String[] { new String(
1683 searchedType.leafComponentType().readableName()) },
1684 new String[] { new String(searchedType.leafComponentType()
1685 .shortReadableName()) }, nameRef.sourceStart,
1691 needImplementation(); // want to fail to see why we were
1695 String[] arguments = new String[] { CharOperation
1696 .toString(CharOperation.subarray(nameRef.tokens, 0, index + 1)) };
1697 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1701 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1702 // CODE should be UPDATED according to error coding in the different
1703 // method binding errors
1704 // The different targetted errors should be :
1708 // InheritedNameHidesEnclosingName
1709 // InstanceMethodDuringConstructorInvocation
1710 // StaticMethodRequested
1711 int flag = IProblem.UndefinedMethod; // default...
1712 switch (method.problemId()) {
1714 flag = IProblem.UndefinedMethod;
1717 flag = IProblem.NotVisibleMethod;
1720 flag = IProblem.AmbiguousMethod;
1722 case InheritedNameHidesEnclosingName:
1723 flag = IProblem.InheritedMethodHidesEnclosingName;
1725 case NonStaticReferenceInConstructorInvocation:
1726 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1728 case NonStaticReferenceInStaticContext:
1729 flag = IProblem.StaticMethodRequested;
1731 case ReceiverTypeNotVisible:
1732 this.handle(IProblem.NotVisibleType,
1733 new String[] { new String(method.declaringClass
1734 .leafComponentType().readableName()) },
1735 new String[] { new String(method.declaringClass
1736 .leafComponentType().shortReadableName()) },
1737 messageSend.receiver.sourceStart,
1738 messageSend.receiver.sourceEnd);
1743 needImplementation(); // want to fail to see why we were
1747 if (flag == IProblem.UndefinedMethod) {
1748 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1749 if (problemMethod.closestMatch != null) {
1750 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1751 String parameterTypeNames = parametersAsString(method);
1752 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1753 String parameterTypeShortNames = parametersAsShortString(method);
1754 if (closestParameterTypeShortNames
1755 .equals(parameterTypeShortNames)) {
1756 closestParameterTypeShortNames = closestParameterTypeNames;
1757 parameterTypeShortNames = parameterTypeNames;
1761 IProblem.ParameterMismatch,
1764 problemMethod.closestMatch.declaringClass
1767 problemMethod.closestMatch.selector),
1768 closestParameterTypeNames,
1769 parameterTypeNames },
1772 problemMethod.closestMatch.declaringClass
1773 .shortReadableName()),
1775 problemMethod.closestMatch.selector),
1776 closestParameterTypeShortNames,
1777 parameterTypeShortNames },
1778 (int) (messageSend.nameSourcePosition >>> 32),
1779 (int) messageSend.nameSourcePosition);
1783 this.handle(flag, new String[] {
1784 new String(method.declaringClass.readableName()),
1785 new String(method.selector), parametersAsString(method) },
1787 new String(method.declaringClass.shortReadableName()),
1788 new String(method.selector),
1789 parametersAsShortString(method) },
1790 (int) (messageSend.nameSourcePosition >>> 32),
1791 (int) messageSend.nameSourcePosition);
1794 public void invalidNullToSynchronize(Expression expression) {
1795 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1796 expression.sourceStart, expression.sourceEnd);
1799 public void invalidOperator(BinaryExpression expression,
1800 TypeBinding leftType, TypeBinding rightType) {
1801 String leftName = new String(leftType.readableName());
1802 String rightName = new String(rightType.readableName());
1803 String leftShortName = new String(leftType.shortReadableName());
1804 String rightShortName = new String(rightType.shortReadableName());
1805 if (leftShortName.equals(rightShortName)) {
1806 leftShortName = leftName;
1807 rightShortName = rightName;
1809 this.handle(IProblem.InvalidOperator, new String[] {
1810 expression.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1811 new String[] { expression.operatorToString(),
1812 leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1813 expression.sourceStart, expression.sourceEnd);
1816 public void invalidOperator(CompoundAssignment assign,
1817 TypeBinding leftType, TypeBinding rightType) {
1818 String leftName = new String(leftType.readableName());
1819 String rightName = new String(rightType.readableName());
1820 String leftShortName = new String(leftType.shortReadableName());
1821 String rightShortName = new String(rightType.shortReadableName());
1822 if (leftShortName.equals(rightShortName)) {
1823 leftShortName = leftName;
1824 rightShortName = rightName;
1826 this.handle(IProblem.InvalidOperator, new String[] {
1827 assign.operatorToString(), leftName + ", " + rightName }, //$NON-NLS-1$
1828 new String[] { assign.operatorToString(),
1829 leftShortName + ", " + rightShortName }, //$NON-NLS-1$
1830 assign.sourceStart, assign.sourceEnd);
1833 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1834 this.handle(IProblem.InvalidOperator,
1835 new String[] { expression.operatorToString(),
1836 new String(type.readableName()) }, new String[] {
1837 expression.operatorToString(),
1838 new String(type.shortReadableName()) },
1839 expression.sourceStart, expression.sourceEnd);
1842 public void invalidParenthesizedExpression(ASTNode reference) {
1843 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1844 NoArgument, reference.sourceStart, reference.sourceEnd);
1847 public void invalidSuperclass(SourceTypeBinding type,
1848 TypeReference superclassRef, ReferenceBinding expectedType) {
1849 int problemId = expectedType.problemId();
1851 switch (problemId) {
1854 id = IProblem.SuperclassNotFound;
1858 id = IProblem.SuperclassNotVisible;
1862 id = IProblem.SuperclassAmbiguous;
1864 case InternalNameProvided:
1866 id = IProblem.SuperclassInternalNameProvided;
1868 case InheritedNameHidesEnclosingName:
1870 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1875 needImplementation(); // want to fail to see why we were
1879 this.handle(id, new String[] { new String(expectedType.readableName()),
1880 new String(type.sourceName()) }, new String[] {
1881 new String(expectedType.shortReadableName()),
1882 new String(type.sourceName()) }, superclassRef.sourceStart,
1883 superclassRef.sourceEnd);
1886 public void invalidSuperinterface(SourceTypeBinding type,
1887 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1888 int problemId = expectedType.problemId();
1890 switch (problemId) {
1893 id = IProblem.InterfaceNotFound;
1897 id = IProblem.InterfaceNotVisible;
1901 id = IProblem.InterfaceAmbiguous;
1903 case InternalNameProvided:
1905 id = IProblem.InterfaceInternalNameProvided;
1907 case InheritedNameHidesEnclosingName:
1909 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1914 needImplementation(); // want to fail to see why we were
1918 this.handle(id, new String[] { new String(expectedType.readableName()),
1919 new String(type.sourceName()) }, new String[] {
1920 new String(expectedType.shortReadableName()),
1921 new String(type.sourceName()) }, superinterfaceRef.sourceStart,
1922 superinterfaceRef.sourceEnd);
1925 public void invalidType(ASTNode location, TypeBinding type) {
1926 int flag = IProblem.UndefinedType; // default
1927 switch (type.problemId()) {
1929 flag = IProblem.UndefinedType;
1932 flag = IProblem.NotVisibleType;
1935 flag = IProblem.AmbiguousType;
1937 case InternalNameProvided:
1938 flag = IProblem.InternalTypeNameProvided;
1940 case InheritedNameHidesEnclosingName:
1941 flag = IProblem.InheritedTypeHidesEnclosingName;
1946 needImplementation(); // want to fail to see why we were
1950 this.handle(flag, new String[] { new String(type.readableName()) },
1951 new String[] { new String(type.shortReadableName()) },
1952 location.sourceStart, location.sourceEnd);
1955 public void invalidTypeReference(Expression expression) {
1956 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1957 expression.sourceStart, expression.sourceEnd);
1960 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1961 this.handle(IProblem.InvalidTypeToSynchronized,
1962 new String[] { new String(type.readableName()) },
1963 new String[] { new String(type.shortReadableName()) },
1964 expression.sourceStart, expression.sourceEnd);
1967 public void invalidUnaryExpression(Expression expression) {
1968 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1969 expression.sourceStart, expression.sourceEnd);
1972 public void isClassPathCorrect(char[][] wellKnownTypeName,
1973 CompilationUnitDeclaration compUnitDecl) {
1974 referenceContext = compUnitDecl;
1975 String[] arguments = new String[] { CharOperation
1976 .toString(wellKnownTypeName) };
1977 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1978 AbortCompilation | Error, compUnitDecl == null ? 0
1979 : compUnitDecl.sourceStart, compUnitDecl == null ? 1
1980 : compUnitDecl.sourceEnd);
1983 public void javadocDuplicatedReturnTag(int sourceStart, int sourceEnd) {
1984 this.handle(IProblem.JavadocDuplicateReturnTag, NoArgument, NoArgument,
1985 sourceStart, sourceEnd);
1988 public void javadocDeprecatedField(FieldBinding field, ASTNode location,
1990 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
1992 this.handle(IProblem.JavadocUsingDeprecatedField, new String[] {
1993 new String(field.declaringClass.readableName()),
1994 new String(field.name) }, new String[] {
1995 new String(field.declaringClass.shortReadableName()),
1996 new String(field.name) }, location.sourceStart,
1997 location.sourceEnd);
2001 public void javadocDeprecatedMethod(MethodBinding method, ASTNode location,
2003 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2005 if (method.isConstructor()) {
2007 .handle(IProblem.JavadocUsingDeprecatedConstructor,
2009 new String(method.declaringClass
2011 parametersAsString(method) },
2013 new String(method.declaringClass
2014 .shortReadableName()),
2015 parametersAsShortString(method) },
2016 location.sourceStart, location.sourceEnd);
2019 .handle(IProblem.JavadocUsingDeprecatedMethod,
2021 new String(method.declaringClass
2023 new String(method.selector),
2024 parametersAsString(method) },
2026 new String(method.declaringClass
2027 .shortReadableName()),
2028 new String(method.selector),
2029 parametersAsShortString(method) },
2030 location.sourceStart, location.sourceEnd);
2035 public void javadocDeprecatedType(TypeBinding type, ASTNode location,
2037 if (location == null)
2038 return; // 1G828DN - no type ref for synthetic arguments
2039 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2041 this.handle(IProblem.JavadocUsingDeprecatedType,
2042 new String[] { new String(type.readableName()) },
2043 new String[] { new String(type.shortReadableName()) },
2044 location.sourceStart, location.sourceEnd);
2048 // public void javadocDuplicatedParamTag(JavadocSingleNameReference param,
2050 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2052 // String[] arguments = new String[] {String.valueOf(param.token)};
2053 // this.handle(IProblem.JavadocDuplicateParamName, arguments, arguments,
2054 // param.sourceStart, param.sourceEnd);
2057 public void javadocDuplicatedThrowsClassName(TypeReference typeReference,
2059 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2061 String[] arguments = new String[] { String
2062 .valueOf(typeReference.resolvedType.sourceName()) };
2063 this.handle(IProblem.JavadocDuplicateThrowsClassName, arguments,
2064 arguments, typeReference.sourceStart,
2065 typeReference.sourceEnd);
2069 public void javadocErrorNoMethodFor(MessageSend messageSend,
2070 TypeBinding recType, TypeBinding[] params, int modifiers) {
2071 StringBuffer buffer = new StringBuffer();
2072 StringBuffer shortBuffer = new StringBuffer();
2073 for (int i = 0, length = params.length; i < length; i++) {
2075 buffer.append(", "); //$NON-NLS-1$
2076 shortBuffer.append(", "); //$NON-NLS-1$
2078 buffer.append(new String(params[i].readableName()));
2079 shortBuffer.append(new String(params[i].shortReadableName()));
2082 int id = recType.isArrayType() ? IProblem.JavadocNoMessageSendOnArrayType
2083 : IProblem.JavadocNoMessageSendOnBaseType;
2084 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2086 this.handle(id, new String[] { new String(recType.readableName()),
2087 new String(messageSend.selector), buffer.toString() },
2088 new String[] { new String(recType.shortReadableName()),
2089 new String(messageSend.selector),
2090 shortBuffer.toString() }, messageSend.sourceStart,
2091 messageSend.sourceEnd);
2095 public void javadocInvalidConstructor(Statement statement,
2096 MethodBinding targetConstructor, int modifiers) {
2098 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2102 // boolean insideDefaultConstructor =
2103 // (this.referenceContext instanceof ConstructorDeclaration)
2105 // ((ConstructorDeclaration)this.referenceContext).isDefaultConstructor();
2106 // boolean insideImplicitConstructorCall =
2107 // (statement instanceof ExplicitConstructorCall)
2108 // && (((ExplicitConstructorCall) statement).accessMode ==
2109 // ExplicitConstructorCall.ImplicitSuper);
2111 int id = IProblem.JavadocUndefinedConstructor; // default...
2112 switch (targetConstructor.problemId()) {
2114 // if (insideDefaultConstructor){
2115 // id = IProblem.JavadocUndefinedConstructorInDefaultConstructor;
2116 // } else if (insideImplicitConstructorCall){
2118 // IProblem.JavadocUndefinedConstructorInImplicitConstructorCall;
2120 id = IProblem.JavadocUndefinedConstructor;
2124 // if (insideDefaultConstructor){
2125 // id = IProblem.JavadocNotVisibleConstructorInDefaultConstructor;
2126 // } else if (insideImplicitConstructorCall){
2128 // IProblem.JavadocNotVisibleConstructorInImplicitConstructorCall;
2130 id = IProblem.JavadocNotVisibleConstructor;
2134 // if (insideDefaultConstructor){
2135 // id = IProblem.AmbiguousConstructorInDefaultConstructor;
2136 // } else if (insideImplicitConstructorCall){
2137 // id = IProblem.AmbiguousConstructorInImplicitConstructorCall;
2139 id = IProblem.JavadocAmbiguousConstructor;
2144 needImplementation(); // want to fail to see why we were here...
2148 this.handle(id, new String[] {
2149 new String(targetConstructor.declaringClass.readableName()),
2150 parametersAsString(targetConstructor) },
2152 new String(targetConstructor.declaringClass
2153 .shortReadableName()),
2154 parametersAsShortString(targetConstructor) },
2155 statement.sourceStart, statement.sourceEnd);
2158 public void javadocAmbiguousMethodReference(int sourceStart, int sourceEnd,
2159 Binding fieldBinding, int modifiers) {
2160 int id = IProblem.JavadocAmbiguousMethodReference;
2161 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2163 String[] arguments = new String[] { new String(fieldBinding
2165 handle(id, arguments, arguments, sourceStart, sourceEnd);
2170 * Similar implementation than invalidField(FieldReference...) Note that
2171 * following problem id cannot occur for Javadoc: -
2172 * NonStaticReferenceInStaticContext : -
2173 * NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
2175 public void javadocInvalidField(int sourceStart, int sourceEnd,
2176 Binding fieldBinding, TypeBinding searchedType, int modifiers) {
2177 int id = IProblem.JavadocUndefinedField;
2178 switch (fieldBinding.problemId()) {
2180 id = IProblem.JavadocUndefinedField;
2183 id = IProblem.JavadocNotVisibleField;
2186 id = IProblem.JavadocAmbiguousField;
2188 case InheritedNameHidesEnclosingName:
2189 id = IProblem.JavadocInheritedFieldHidesEnclosingName;
2193 needImplementation(); // want to fail to see why we were here...
2197 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2199 String[] arguments = new String[] { new String(fieldBinding
2201 handle(id, arguments, arguments, sourceStart, sourceEnd);
2206 * Similar implementation than invalidMethod(MessageSend...) Note that
2207 * following problem id cannot occur for Javadoc: -
2208 * NonStaticReferenceInStaticContext : -
2209 * NonStaticReferenceInConstructorInvocation : - ReceiverTypeNotVisible :
2211 public void javadocInvalidMethod(MessageSend messageSend,
2212 MethodBinding method, int modifiers) {
2213 if (!javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2217 int id = IProblem.JavadocUndefinedMethod; // default...
2218 switch (method.problemId()) {
2220 id = IProblem.JavadocUndefinedMethod;
2223 id = IProblem.JavadocNotVisibleMethod;
2226 id = IProblem.JavadocAmbiguousMethod;
2228 case InheritedNameHidesEnclosingName:
2229 id = IProblem.JavadocInheritedMethodHidesEnclosingName;
2233 needImplementation(); // want to fail to see why we were here...
2237 if (id == IProblem.JavadocUndefinedMethod) {
2238 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
2239 if (problemMethod.closestMatch != null) {
2240 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
2241 String parameterTypeNames = parametersAsString(method);
2242 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
2243 String parameterTypeShortNames = parametersAsShortString(method);
2244 if (closestParameterTypeShortNames
2245 .equals(parameterTypeShortNames)) {
2246 closestParameterTypeShortNames = closestParameterTypeNames;
2247 parameterTypeShortNames = parameterTypeNames;
2251 IProblem.JavadocParameterMismatch,
2254 problemMethod.closestMatch.declaringClass
2257 problemMethod.closestMatch.selector),
2258 closestParameterTypeNames,
2259 parameterTypeNames },
2262 problemMethod.closestMatch.declaringClass
2263 .shortReadableName()),
2265 problemMethod.closestMatch.selector),
2266 closestParameterTypeShortNames,
2267 parameterTypeShortNames },
2268 (int) (messageSend.nameSourcePosition >>> 32),
2269 (int) messageSend.nameSourcePosition);
2274 this.handle(id, new String[] {
2275 new String(method.declaringClass.readableName()),
2276 new String(method.selector), parametersAsString(method) },
2278 new String(method.declaringClass.shortReadableName()),
2279 new String(method.selector),
2280 parametersAsShortString(method) },
2281 (int) (messageSend.nameSourcePosition >>> 32),
2282 (int) messageSend.nameSourcePosition);
2285 // public void javadocInvalidParamName(JavadocSingleNameReference param, int
2287 // if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2289 // String[] arguments = new String[] {String.valueOf(param.token)};
2290 // this.handle(IProblem.JavadocInvalidParamName, arguments, arguments,
2291 // param.sourceStart, param.sourceEnd);
2294 public void javadocInvalidSeeReference(int sourceStart, int sourceEnd) {
2295 this.handle(IProblem.JavadocInvalidSeeReference, NoArgument,
2296 NoArgument, sourceStart, sourceEnd);
2299 public void javadocInvalidSeeReferenceArgs(int sourceStart, int sourceEnd) {
2300 this.handle(IProblem.JavadocInvalidSeeArgs, NoArgument, NoArgument,
2301 sourceStart, sourceEnd);
2304 public void javadocInvalidSeeUrlReference(int sourceStart, int sourceEnd) {
2305 this.handle(IProblem.JavadocInvalidSeeHref, NoArgument, NoArgument,
2306 sourceStart, sourceEnd);
2309 public void javadocInvalidTag(int sourceStart, int sourceEnd) {
2310 this.handle(IProblem.JavadocInvalidTag, NoArgument, NoArgument,
2311 sourceStart, sourceEnd);
2314 public void javadocInvalidThrowsClass(int sourceStart, int sourceEnd) {
2315 this.handle(IProblem.JavadocInvalidThrowsClass, NoArgument, NoArgument,
2316 sourceStart, sourceEnd);
2319 public void javadocInvalidThrowsClassName(TypeReference typeReference,
2321 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2323 String[] arguments = new String[] { String
2324 .valueOf(typeReference.resolvedType.sourceName()) };
2325 this.handle(IProblem.JavadocInvalidThrowsClassName, arguments,
2326 arguments, typeReference.sourceStart,
2327 typeReference.sourceEnd);
2331 public void javadocInvalidType(ASTNode location, TypeBinding type,
2333 if (javadocVisibility(this.options.reportInvalidJavadocTagsVisibility,
2335 int id = IProblem.JavadocUndefinedType; // default
2336 switch (type.problemId()) {
2338 id = IProblem.JavadocUndefinedType;
2341 id = IProblem.JavadocNotVisibleType;
2344 id = IProblem.JavadocAmbiguousType;
2346 case InternalNameProvided:
2347 id = IProblem.JavadocInternalTypeNameProvided;
2349 case InheritedNameHidesEnclosingName:
2350 id = IProblem.JavadocInheritedNameHidesEnclosingTypeName;
2354 needImplementation(); // want to fail to see why we were
2358 this.handle(id, new String[] { new String(type.readableName()) },
2359 new String[] { new String(type.shortReadableName()) },
2360 location.sourceStart, location.sourceEnd);
2364 public void javadocMalformedSeeReference(int sourceStart, int sourceEnd) {
2365 this.handle(IProblem.JavadocMalformedSeeReference, NoArgument,
2366 NoArgument, sourceStart, sourceEnd);
2369 public void javadocMissing(int sourceStart, int sourceEnd, int modifiers) {
2370 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2371 boolean report = (this.options
2372 .getSeverity(CompilerOptions.MissingJavadocComments) != ProblemSeverities.Ignore)
2373 && (!overriding || this.options.reportMissingJavadocCommentsOverriding);
2375 String arg = javadocVisibilityArgument(
2376 this.options.reportMissingJavadocCommentsVisibility,
2379 String[] arguments = new String[] { arg };
2380 this.handle(IProblem.JavadocMissing, arguments, arguments,
2381 sourceStart, sourceEnd);
2386 public void javadocMissingParamName(int sourceStart, int sourceEnd) {
2387 this.handle(IProblem.JavadocMissingParamName, NoArgument, NoArgument,
2388 sourceStart, sourceEnd);
2391 public void javadocMissingParamTag(Argument param, int modifiers) {
2392 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2393 boolean report = (this.options
2394 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2395 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2397 && javadocVisibility(
2398 this.options.reportMissingJavadocTagsVisibility,
2400 String[] arguments = new String[] { String.valueOf(param.name) };
2401 this.handle(IProblem.JavadocMissingParamTag, arguments, arguments,
2402 param.sourceStart, param.sourceEnd);
2406 public void javadocMissingReturnTag(int sourceStart, int sourceEnd,
2408 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2409 boolean report = (this.options
2410 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2411 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2413 && javadocVisibility(
2414 this.options.reportMissingJavadocTagsVisibility,
2416 this.handle(IProblem.JavadocMissingReturnTag, NoArgument,
2417 NoArgument, sourceStart, sourceEnd);
2421 public void javadocMissingSeeReference(int sourceStart, int sourceEnd) {
2422 this.handle(IProblem.JavadocMissingSeeReference, NoArgument,
2423 NoArgument, sourceStart, sourceEnd);
2426 public void javadocMissingThrowsClassName(int sourceStart, int sourceEnd) {
2427 this.handle(IProblem.JavadocMissingThrowsClassName, NoArgument,
2428 NoArgument, sourceStart, sourceEnd);
2431 public void javadocMissingThrowsTag(TypeReference typeRef, int modifiers) {
2432 boolean overriding = (modifiers & (CompilerModifiers.AccImplementing + CompilerModifiers.AccOverriding)) != 0;
2433 boolean report = (this.options
2434 .getSeverity(CompilerOptions.MissingJavadocTags) != ProblemSeverities.Ignore)
2435 && (!overriding || this.options.reportMissingJavadocTagsOverriding);
2437 && javadocVisibility(
2438 this.options.reportMissingJavadocTagsVisibility,
2440 String[] arguments = new String[] { String
2441 .valueOf(typeRef.resolvedType.sourceName()) };
2442 this.handle(IProblem.JavadocMissingThrowsTag, arguments, arguments,
2443 typeRef.sourceStart, typeRef.sourceEnd);
2447 public void javadocUnexpectedTag(int sourceStart, int sourceEnd) {
2448 this.handle(IProblem.JavadocUnexpectedTag, NoArgument, NoArgument,
2449 sourceStart, sourceEnd);
2452 public void javadocUnterminatedInlineTag(int sourceStart, int sourceEnd) {
2453 this.handle(IProblem.JavadocUnterminatedInlineTag, NoArgument,
2454 NoArgument, sourceStart, sourceEnd);
2457 private boolean javadocVisibility(int visibility, int modifiers) {
2458 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2459 case IConstants.AccPublic:
2461 case IConstants.AccProtected:
2462 return (visibility != IConstants.AccPublic);
2463 // case IConstants.AccDefault:
2464 // return (visibility == IConstants.AccDefault || visibility ==
2465 // IConstants.AccPrivate);
2466 case IConstants.AccPrivate:
2467 return (visibility == IConstants.AccPrivate);
2472 private String javadocVisibilityArgument(int visibility, int modifiers) {
2473 String argument = null;
2474 switch (modifiers & CompilerModifiers.AccVisibilityMASK) {
2475 case IConstants.AccPublic:
2476 argument = CompilerOptions.PUBLIC;
2478 case IConstants.AccProtected:
2479 if (visibility != IConstants.AccPublic) {
2480 argument = CompilerOptions.PROTECTED;
2483 // case IConstants.AccDefault:
2484 // if (visibility == IConstants.AccDefault || visibility ==
2485 // IConstants.AccPrivate) {
2486 // argument = CompilerOptions.DEFAULT;
2489 case IConstants.AccPrivate:
2490 if (visibility == IConstants.AccPrivate) {
2491 argument = CompilerOptions.PRIVATE;
2498 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
2499 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
2500 methodDecl.sourceStart, methodDecl.sourceEnd);
2503 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
2505 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
2506 // IProblem.BodyForNativeMethod :
2507 // IProblem.BodyForAbstractMethod,
2508 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
2509 methodDecl.sourceStart, methodDecl.sourceEnd);
2512 public void methodWithConstructorName(MethodDeclaration methodDecl) {
2513 this.handle(IProblem.MethodButWithConstructorName, NoArgument,
2514 NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
2517 // public void missingEnclosingInstanceSpecification(ReferenceBinding
2518 // enclosingType, ASTNode location) {
2519 // boolean insideConstructorCall =
2520 // (location instanceof ExplicitConstructorCall)
2521 // && (((ExplicitConstructorCall) location).accessMode ==
2522 // ExplicitConstructorCall.ImplicitSuper);
2525 // insideConstructorCall
2526 // ? IProblem.MissingEnclosingInstanceForConstructorCall
2527 // : IProblem.MissingEnclosingInstance,
2528 // new String[] {new String(enclosingType.readableName())},
2529 // new String[] {new String(enclosingType.shortReadableName())},
2530 // location.sourceStart,
2531 // location.sourceEnd);
2533 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
2534 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
2535 methodDecl.sourceStart, methodDecl.sourceEnd);
2538 public void missingSemiColon(Expression expression) {
2539 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
2540 expression.sourceStart, expression.sourceEnd);
2543 public void mustDefineDimensionsOrInitializer(
2544 ArrayAllocationExpression expression) {
2545 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
2546 NoArgument, NoArgument, expression.sourceStart,
2547 expression.sourceEnd);
2550 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
2551 String[] arguments = new String[] { new String(compUnitDecl
2553 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
2554 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
2557 public void mustUseAStaticMethod(MessageSend messageSend,
2558 MethodBinding method) {
2559 this.handle(IProblem.StaticMethodRequested, new String[] {
2560 new String(method.declaringClass.readableName()),
2561 new String(method.selector), parametersAsString(method) },
2563 new String(method.declaringClass.shortReadableName()),
2564 new String(method.selector),
2565 parametersAsShortString(method) },
2566 messageSend.sourceStart, messageSend.sourceEnd);
2569 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
2570 AbstractMethodDeclaration methodDecl) {
2571 String[] arguments = new String[] { new String(type.sourceName()),
2572 new String(methodDecl.selector) };
2573 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments,
2574 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2577 public void needImplementation() {
2578 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
2581 public void needToEmulateFieldReadAccess(FieldBinding field,
2583 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[] {
2584 new String(field.declaringClass.readableName()),
2585 new String(field.name) }, new String[] {
2586 new String(field.declaringClass.shortReadableName()),
2587 new String(field.name) }, location.sourceStart,
2588 location.sourceEnd);
2591 public void needToEmulateFieldWriteAccess(FieldBinding field,
2593 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[] {
2594 new String(field.declaringClass.readableName()),
2595 new String(field.name) }, new String[] {
2596 new String(field.declaringClass.shortReadableName()),
2597 new String(field.name) }, location.sourceStart,
2598 location.sourceEnd);
2601 public void needToEmulateMethodAccess(MethodBinding method, ASTNode location) {
2602 if (method.isConstructor())
2603 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[] {
2604 new String(method.declaringClass.readableName()),
2605 parametersAsString(method) }, new String[] {
2606 new String(method.declaringClass.shortReadableName()),
2607 parametersAsShortString(method) }, location.sourceStart,
2608 location.sourceEnd);
2610 this.handle(IProblem.NeedToEmulateMethodAccess, new String[] {
2611 new String(method.declaringClass.readableName()),
2612 new String(method.selector), parametersAsString(method) },
2614 new String(method.declaringClass
2615 .shortReadableName()),
2616 new String(method.selector),
2617 parametersAsShortString(method) },
2618 location.sourceStart, location.sourceEnd);
2621 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
2622 String[] arguments = new String[] { new String(typeDecl.name) };
2623 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
2624 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
2627 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
2629 String[] arguments = new String[] { new String(local.name) };
2632 local instanceof SyntheticArgumentBinding ? IProblem.TooManySyntheticArgumentSlots
2633 : IProblem.TooManyArgumentSlots, arguments,
2634 arguments, Abort | Error, location.sourceStart,
2635 location.sourceEnd);
2638 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
2640 String[] arguments = new String[] { new String(local.name) };
2641 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments,
2642 Abort | Error, location.sourceStart, location.sourceEnd);
2645 public void noSuchEnclosingInstance(TypeBinding targetType,
2646 ASTNode location, boolean isConstructorCall) {
2648 if (isConstructorCall) {
2649 // 28 = No enclosing instance of type {0} is available due to some
2650 // intermediate constructor invocation
2651 id = IProblem.EnclosingInstanceInConstructorCall;
2652 } else if ((location instanceof ExplicitConstructorCall)
2653 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2654 // 20 = No enclosing instance of type {0} is accessible to invoke
2655 // the super constructor. Must define a constructor and explicitly
2656 // qualify its super constructor invocation with an instance of {0}
2657 // (e.g. x.super() where x is an instance of {0}).
2658 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2659 } else if (location instanceof AllocationExpression
2660 && (((AllocationExpression) location).binding.declaringClass
2661 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
2662 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
2663 .superclass().isMemberType()))) {
2664 // 21 = No enclosing instance of type {0} is accessible. Must
2665 // qualify the allocation with an enclosing instance of type {0}
2666 // (e.g. x.new A() where x is an instance of {0}).
2667 id = IProblem.MissingEnclosingInstance;
2669 // 22 = No enclosing instance of the type {0} is accessible in
2671 id = IProblem.IncorrectEnclosingInstanceReference;
2673 this.handle(id, new String[] { new String(targetType.readableName()) },
2674 new String[] { new String(targetType.shortReadableName()) },
2675 location.sourceStart, location.sourceEnd);
2678 public void notCompatibleTypesError(EqualExpression expression,
2679 TypeBinding leftType, TypeBinding rightType) {
2680 String leftName = new String(leftType.readableName());
2681 String rightName = new String(rightType.readableName());
2682 String leftShortName = new String(leftType.shortReadableName());
2683 String rightShortName = new String(rightType.shortReadableName());
2684 if (leftShortName.equals(rightShortName)) {
2685 leftShortName = leftName;
2686 rightShortName = rightName;
2688 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[] {
2689 leftName, rightName }, new String[] { leftShortName,
2690 rightShortName }, expression.sourceStart, expression.sourceEnd);
2693 public void notCompatibleTypesError(InstanceOfExpression expression,
2694 TypeBinding leftType, TypeBinding rightType) {
2695 String leftName = new String(leftType.readableName());
2696 String rightName = new String(rightType.readableName());
2697 String leftShortName = new String(leftType.shortReadableName());
2698 String rightShortName = new String(rightType.shortReadableName());
2699 if (leftShortName.equals(rightShortName)) {
2700 leftShortName = leftName;
2701 rightShortName = rightName;
2703 this.handle(IProblem.IncompatibleTypesInConditionalOperator,
2704 new String[] { leftName, rightName }, new String[] {
2705 leftShortName, rightShortName },
2706 expression.sourceStart, expression.sourceEnd);
2709 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2710 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument,
2711 NoArgument, type.sourceStart(), type.sourceEnd());
2714 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
2715 TypeBinding leftType, TypeBinding rightType) {
2716 String leftName = new String(leftType.readableName());
2717 String rightName = new String(rightType.readableName());
2718 String leftShortName = new String(leftType.shortReadableName());
2719 String rightShortName = new String(rightType.shortReadableName());
2720 if (leftShortName.equals(rightShortName)) {
2721 leftShortName = leftName;
2722 rightShortName = rightName;
2724 this.handle(IProblem.TypeMismatch,
2725 new String[] { leftName, rightName }, new String[] {
2726 leftShortName, rightShortName },
2727 assignment.sourceStart, assignment.sourceEnd);
2730 public void overridesDeprecatedMethod(MethodBinding localMethod,
2731 MethodBinding inheritedMethod) {
2732 this.handle(IProblem.OverridingDeprecatedMethod, new String[] {
2733 new String(CharOperation.concat(localMethod.declaringClass
2734 .readableName(), localMethod.readableName(), '.')),
2735 new String(inheritedMethod.declaringClass.readableName()) },
2737 new String(CharOperation.concat(
2738 localMethod.declaringClass.shortReadableName(),
2739 localMethod.shortReadableName(), '.')),
2740 new String(inheritedMethod.declaringClass
2741 .shortReadableName()) }, localMethod
2742 .sourceStart(), localMethod.sourceEnd());
2745 public void overridesPackageDefaultMethod(MethodBinding localMethod,
2746 MethodBinding inheritedMethod) {
2747 this.handle(IProblem.OverridingNonVisibleMethod, new String[] {
2748 new String(CharOperation.concat(localMethod.declaringClass
2749 .readableName(), localMethod.readableName(), '.')),
2750 new String(inheritedMethod.declaringClass.readableName()) },
2752 new String(CharOperation.concat(
2753 localMethod.declaringClass.shortReadableName(),
2754 localMethod.shortReadableName(), '.')),
2755 new String(inheritedMethod.declaringClass
2756 .shortReadableName()) }, localMethod
2757 .sourceStart(), localMethod.sourceEnd());
2760 // public void packageCollidesWithType(CompilationUnitDeclaration
2762 // String[] arguments = new String[]{CharOperation
2763 // .toString(compUnitDecl.currentPackage.tokens)};
2764 // this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2765 // compUnitDecl.currentPackage.sourceStart,
2766 // compUnitDecl.currentPackage.sourceEnd);
2768 public void packageIsNotExpectedPackage(
2769 CompilationUnitDeclaration compUnitDecl) {
2770 String[] arguments = new String[] { CharOperation
2771 .toString(compUnitDecl.compilationResult.compilationUnit
2772 .getPackageName()) };
2773 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
2774 compUnitDecl.currentPackage == null ? 0
2775 : compUnitDecl.currentPackage.sourceStart,
2776 compUnitDecl.currentPackage == null ? 0
2777 : compUnitDecl.currentPackage.sourceEnd);
2780 private String parametersAsString(MethodBinding method) {
2781 TypeBinding[] params = method.parameters;
2782 StringBuffer buffer = new StringBuffer();
2783 for (int i = 0, length = params.length; i < length; i++) {
2785 buffer.append(", "); //$NON-NLS-1$
2786 buffer.append(new String(params[i].readableName()));
2788 return buffer.toString();
2791 private String parametersAsShortString(MethodBinding method) {
2792 TypeBinding[] params = method.parameters;
2793 StringBuffer buffer = new StringBuffer();
2794 for (int i = 0, length = params.length; i < length; i++) {
2796 buffer.append(", "); //$NON-NLS-1$
2797 buffer.append(new String(params[i].shortReadableName()));
2799 return buffer.toString();
2802 public void parseError(int startPosition, int endPosition,
2803 char[] currentTokenSource, String errorTokenName,
2804 String[] possibleTokens) {
2805 if (possibleTokens.length == 0) { // no suggestion available
2806 if (isKeyword(currentTokenSource)) {
2807 String[] arguments = new String[] { new String(
2808 currentTokenSource) };
2809 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion,
2810 arguments, arguments,
2811 // this is the current -invalid- token position
2812 startPosition, endPosition);
2815 String[] arguments = new String[] { errorTokenName };
2816 this.handle(IProblem.ParsingErrorNoSuggestion, arguments,
2818 // this is the current -invalid- token position
2819 startPosition, endPosition);
2823 // build a list of probable right tokens
2824 StringBuffer list = new StringBuffer(20);
2825 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2827 list.append(", "); //$NON-NLS-1$
2829 list.append(possibleTokens[i]);
2832 if (isKeyword(currentTokenSource)) {
2833 String[] arguments = new String[] { new String(currentTokenSource),
2835 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2836 // this is the current -invalid- token position
2837 startPosition, endPosition);
2840 // extract the literal when it's a literal
2841 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2842 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2843 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2844 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2845 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2846 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2847 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2848 errorTokenName = new String(currentTokenSource);
2850 String[] arguments = new String[] { errorTokenName, list.toString() };
2851 this.handle(IProblem.ParsingError, arguments, arguments,
2852 // this is the current -invalid- token position
2853 startPosition, endPosition);
2856 public void publicClassMustMatchFileName(
2857 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2858 this.referenceContext = typeDecl; // report the problem against the
2859 // type not the entire compilation
2861 String[] arguments = new String[] {
2862 new String(compUnitDecl.getFileName()),
2863 new String(typeDecl.name) };
2864 this.handle(IProblem.PublicClassMustMatchFileName, arguments,
2865 arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2866 compUnitDecl.compilationResult);
2869 public void recursiveConstructorInvocation(
2870 ExplicitConstructorCall constructorCall) {
2871 this.handle(IProblem.RecursiveConstructorInvocation, new String[] {
2872 new String(constructorCall.binding.declaringClass
2874 parametersAsString(constructorCall.binding) }, new String[] {
2875 new String(constructorCall.binding.declaringClass
2876 .shortReadableName()),
2877 parametersAsShortString(constructorCall.binding) },
2878 constructorCall.sourceStart, constructorCall.sourceEnd);
2881 public void redefineArgument(Argument arg) {
2882 String[] arguments = new String[] { new String(arg.name) };
2883 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2884 arg.sourceStart, arg.sourceEnd);
2887 public void redefineLocal(LocalDeclaration localDecl) {
2888 String[] arguments = new String[] { new String(localDecl.name) };
2889 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2890 localDecl.sourceStart, localDecl.sourceEnd);
2893 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2894 ArrayReference arrayRef) {
2895 this.handle(IProblem.ArrayReferenceRequired, new String[] { new String(
2896 arrayType.readableName()) }, new String[] { new String(
2897 arrayType.shortReadableName()) }, arrayRef.sourceStart,
2898 arrayRef.sourceEnd);
2901 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2902 MethodDeclaration methodDecl) {
2903 String[] arguments = new String[] { new String(methodDecl.selector) };
2904 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2905 methodDecl.sourceStart, methodDecl.sourceEnd);
2908 public void returnTypeProblem(SourceTypeBinding type,
2909 MethodDeclaration methodDecl, TypeBinding expectedType) {
2910 int problemId = expectedType.problemId();
2912 switch (problemId) {
2915 id = IProblem.ReturnTypeNotFound;
2919 id = IProblem.ReturnTypeNotVisible;
2923 id = IProblem.ReturnTypeAmbiguous;
2925 case InternalNameProvided:
2927 id = IProblem.ReturnTypeInternalNameProvided;
2929 case InheritedNameHidesEnclosingName:
2931 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2936 needImplementation(); // want to fail to see why we were
2940 this.handle(id, new String[] { new String(methodDecl.selector),
2941 new String(expectedType.readableName()) }, new String[] {
2942 new String(methodDecl.selector),
2943 new String(expectedType.shortReadableName()) },
2944 methodDecl.returnType.sourceStart,
2945 methodDecl.returnType.sourceEnd);
2948 public void scannerError(Parser parser, String errorTokenName) {
2949 Scanner scanner = parser.scanner;
2950 int flag = IProblem.ParsingErrorNoSuggestion;
2951 int startPos = scanner.startPosition;
2952 // special treatment for recognized errors....
2953 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2954 flag = IProblem.EndOfSource;
2955 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2956 flag = IProblem.InvalidHexa;
2957 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2958 flag = IProblem.InvalidOctal;
2959 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2960 flag = IProblem.InvalidCharacterConstant;
2961 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2962 flag = IProblem.InvalidEscape;
2963 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2964 flag = IProblem.InvalidUnicodeEscape;
2965 // better locate the error message
2966 char[] source = scanner.source;
2967 int checkPos = scanner.currentPosition - 1;
2968 if (checkPos >= source.length)
2969 checkPos = source.length - 1;
2970 while (checkPos >= startPos) {
2971 if (source[checkPos] == '\\')
2975 startPos = checkPos;
2976 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2977 flag = IProblem.InvalidFloat;
2978 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2979 flag = IProblem.UnterminatedString;
2980 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2981 flag = IProblem.UnterminatedComment;
2982 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2983 flag = IProblem.UnterminatedString;
2984 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion ? new String[] { errorTokenName }
2986 this.handle(flag, arguments, arguments,
2987 // this is the current -invalid- token position
2988 startPos, scanner.currentPosition - 1,
2989 parser.compilationUnit.compilationResult);
2992 public void shouldReturn(TypeBinding returnType, ASTNode location) {
2993 this.handle(IProblem.ShouldReturnValue, new String[] { new String(
2994 returnType.readableName()) }, new String[] { new String(
2995 returnType.shortReadableName()) }, location.sourceStart,
2996 location.sourceEnd);
2999 public void signalNoImplicitStringConversionForCharArrayExpression(
3000 Expression expression) {
3001 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
3002 NoArgument, NoArgument, expression.sourceStart,
3003 expression.sourceEnd);
3006 public void staticAndInstanceConflict(MethodBinding currentMethod,
3007 MethodBinding inheritedMethod) {
3008 if (currentMethod.isStatic())
3010 // This static method cannot hide the instance method from
3012 // 8.4.6.4 - If a class inherits more than one method with
3013 // the same signature a static (non-abstract) method cannot
3014 // hide an instance method.
3015 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
3016 new String[] { new String(inheritedMethod.declaringClass
3018 new String[] { new String(inheritedMethod.declaringClass
3019 .shortReadableName()) }, currentMethod
3020 .sourceStart(), currentMethod.sourceEnd());
3023 // This instance method cannot override the static method
3025 // 8.4.6.4 - If a class inherits more than one method with
3026 // the same signature an instance (non-abstract) method
3027 // cannot override a static method.
3028 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
3029 new String[] { new String(inheritedMethod.declaringClass
3031 new String[] { new String(inheritedMethod.declaringClass
3032 .shortReadableName()) }, currentMethod
3033 .sourceStart(), currentMethod.sourceEnd());
3036 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
3037 FieldBinding field) {
3038 String[] arguments = new String[] { new String(field.readableName()) };
3039 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3040 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
3043 public void staticFieldAccessToNonStaticVariable(
3044 QualifiedNameReference nameRef, FieldBinding field) {
3045 String[] arguments = new String[] { new String(field.readableName()) };
3046 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3047 arguments, nameRef.sourceStart, nameRef.sourceEnd);
3050 public void staticFieldAccessToNonStaticVariable(
3051 SingleNameReference nameRef, FieldBinding field) {
3052 String[] arguments = new String[] { new String(field.readableName()) };
3053 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
3054 arguments, nameRef.sourceStart, nameRef.sourceEnd);
3057 public void staticInheritedMethodConflicts(SourceTypeBinding type,
3058 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
3060 // The static method %1 conflicts with the abstract method in %2
3061 // 8.4.6.4 - If a class inherits more than one method with the
3062 // same signature it is an error for one to be static
3063 // (non-abstract) and the other abstract.
3064 IProblem.StaticInheritedMethodConflicts, new String[] {
3065 new String(concreteMethod.readableName()),
3066 new String(abstractMethods[0].declaringClass
3067 .readableName()) }, new String[] {
3068 new String(concreteMethod.readableName()),
3069 new String(abstractMethods[0].declaringClass
3070 .shortReadableName()) }, type.sourceStart(),
3074 public void stringConstantIsExceedingUtf8Limit(ASTNode location) {
3075 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
3076 NoArgument, location.sourceStart, location.sourceEnd);
3079 public void superclassMustBeAClass(SourceTypeBinding type,
3080 TypeReference superclassRef, ReferenceBinding superType) {
3081 this.handle(IProblem.SuperclassMustBeAClass, new String[] {
3082 new String(superType.readableName()),
3083 new String(type.sourceName()) }, new String[] {
3084 new String(superType.shortReadableName()),
3085 new String(type.sourceName()) }, superclassRef.sourceStart,
3086 superclassRef.sourceEnd);
3089 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
3090 TypeDeclaration typeDecl, ReferenceBinding superType) {
3091 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[] {
3092 new String(superType.readableName()),
3093 new String(type.sourceName()) }, new String[] {
3094 new String(superType.shortReadableName()),
3095 new String(type.sourceName()) }, typeDecl.sourceStart,
3096 typeDecl.sourceEnd);
3099 public void task(String tag, String message, String priority, int start,
3101 this.handle(IProblem.Task, new String[] { tag, message, priority /*
3110 */}, new String[] { tag, message, priority /*
3111 * secret argument that is
3117 public void tooManyDimensions(ASTNode expression) {
3118 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
3119 expression.sourceStart, expression.sourceEnd);
3122 public void tooManyFields(TypeDeclaration typeDeclaration) {
3123 this.handle(IProblem.TooManyFields, new String[] { new String(
3124 typeDeclaration.binding.readableName()) },
3125 new String[] { new String(typeDeclaration.binding
3126 .shortReadableName()) }, Abort | Error,
3127 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
3130 public void tooManyMethods(TypeDeclaration typeDeclaration) {
3131 this.handle(IProblem.TooManyMethods, new String[] { new String(
3132 typeDeclaration.binding.readableName()) },
3133 new String[] { new String(typeDeclaration.binding
3134 .shortReadableName()) }, Abort | Error,
3135 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
3138 public void typeCastError(CastExpression expression, TypeBinding leftType,
3139 TypeBinding rightType) {
3140 String leftName = new String(leftType.readableName());
3141 String rightName = new String(rightType.readableName());
3142 String leftShortName = new String(leftType.shortReadableName());
3143 String rightShortName = new String(rightType.shortReadableName());
3144 if (leftShortName.equals(rightShortName)) {
3145 leftShortName = leftName;
3146 rightShortName = rightName;
3148 this.handle(IProblem.IllegalCast, new String[] { rightName, leftName },
3149 new String[] { rightShortName, leftShortName },
3150 expression.sourceStart, expression.sourceEnd);
3153 public void typeCollidesWithPackage(
3154 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
3155 this.referenceContext = typeDecl; // report the problem against the
3156 // type not the entire compilation
3158 String[] arguments = new String[] {
3159 new String(compUnitDecl.getFileName()),
3160 new String(typeDecl.name) };
3161 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
3162 typeDecl.sourceStart, typeDecl.sourceEnd,
3163 compUnitDecl.compilationResult);
3166 public void typeMismatchError(TypeBinding resultType,
3167 TypeBinding expectedType, ASTNode location) {
3168 String resultTypeName = new String(resultType.readableName());
3169 String expectedTypeName = new String(expectedType.readableName());
3170 String resultTypeShortName = new String(resultType.shortReadableName());
3171 String expectedTypeShortName = new String(expectedType
3172 .shortReadableName());
3173 if (resultTypeShortName.equals(expectedTypeShortName)) {
3174 resultTypeShortName = resultTypeName;
3175 expectedTypeShortName = expectedTypeName;
3177 this.handle(IProblem.TypeMismatch, new String[] { resultTypeName,
3178 expectedTypeName }, new String[] { resultTypeShortName,
3179 expectedTypeShortName }, location.sourceStart,
3180 location.sourceEnd);
3183 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
3184 TypeBinding constantType, TypeBinding expectedType) {
3185 String constantTypeName = new String(constantType.readableName());
3186 String expectedTypeName = new String(expectedType.readableName());
3187 String constantTypeShortName = new String(constantType
3188 .shortReadableName());
3189 String expectedTypeShortName = new String(expectedType
3190 .shortReadableName());
3191 if (constantTypeShortName.equals(expectedTypeShortName)) {
3192 constantTypeShortName = constantTypeName;
3193 expectedTypeShortName = expectedTypeName;
3195 this.handle(IProblem.TypeMismatch, new String[] { constantTypeName,
3196 expectedTypeName }, new String[] { constantTypeShortName,
3197 expectedTypeShortName }, expression.sourceStart,
3198 expression.sourceEnd);
3201 // public void undefinedLabel(BranchStatement statement) {
3202 // String[] arguments = new String[] { new String(statement.label) };
3203 // this.handle(IProblem.UndefinedLabel, arguments, arguments,
3204 // statement.sourceStart, statement.sourceEnd);
3207 public void unexpectedStaticModifierForField(SourceTypeBinding type,
3208 FieldDeclaration fieldDecl) {
3209 String[] arguments = new String[] { fieldDecl.name() };
3210 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
3211 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
3214 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
3215 AbstractMethodDeclaration methodDecl) {
3216 String[] arguments = new String[] { new String(type.sourceName()),
3217 new String(methodDecl.selector) };
3218 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
3219 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
3222 public void unhandledException(TypeBinding exceptionType, ASTNode location) {
3223 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
3224 && ((ConstructorDeclaration) referenceContext)
3225 .isDefaultConstructor();
3226 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
3227 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
3230 insideDefaultConstructor ? IProblem.UnhandledExceptionInDefaultConstructor
3231 : (insideImplicitConstructorCall ? IProblem.UndefinedConstructorInImplicitConstructorCall
3232 : IProblem.UnhandledException),
3233 new String[] { new String(exceptionType.readableName()) },
3234 new String[] { new String(exceptionType
3235 .shortReadableName()) }, location.sourceStart,
3236 location.sourceEnd);
3239 public void uninitializedBlankFinalField(FieldBinding binding,
3241 String[] arguments = new String[] { new String(binding.readableName()) };
3242 this.handle(IProblem.UninitializedBlankFinalField, arguments,
3243 arguments, location.sourceStart, location.sourceEnd);
3246 public void unmatchedBracket(int position, ReferenceContext context,
3247 CompilationResult compilationResult) {
3248 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument,
3249 position, position, context, compilationResult);
3252 public void unnecessaryEnclosingInstanceSpecification(
3253 Expression expression, ReferenceBinding targetType) {
3254 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
3255 new String[] { new String(targetType.readableName()) },
3256 new String[] { new String(targetType.shortReadableName()) },
3257 expression.sourceStart, expression.sourceEnd);
3260 public void unnecessaryReceiverForStaticMethod(ASTNode location,
3261 MethodBinding method) {
3262 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[] {
3263 new String(method.declaringClass.readableName()),
3264 new String(method.selector), parametersAsString(method) },
3266 new String(method.declaringClass.shortReadableName()),
3267 new String(method.selector),
3268 parametersAsShortString(method) },
3269 location.sourceStart, location.sourceEnd);
3272 public void unnecessaryReceiverForStaticField(ASTNode location,
3273 FieldBinding field) {
3274 this.handle(IProblem.NonStaticAccessToStaticField, new String[] {
3275 new String(field.declaringClass.readableName()),
3276 new String(field.name) }, new String[] {
3277 new String(field.declaringClass.shortReadableName()),
3278 new String(field.name) }, location.sourceStart,
3279 location.sourceEnd);
3282 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
3284 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
3285 location.sourceStart, location.sourceEnd);
3288 public void unresolvableReference(NameReference nameRef, Binding binding) {
3289 int severity = Error;
3291 * also need to check that the searchedType is the receiver type if
3292 * (binding instanceof ProblemBinding) { ProblemBinding problem =
3293 * (ProblemBinding) binding; if (problem.searchType != null &&
3294 * problem.searchType.isHierarchyInconsistent()) severity =
3297 String[] arguments = new String[] { new String(binding.readableName()) };
3298 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
3299 nameRef.sourceStart, nameRef.sourceEnd);
3302 public void unusedArgument(LocalDeclaration localDecl) {
3303 String[] arguments = new String[] { localDecl.name() };
3304 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
3305 localDecl.sourceStart, localDecl.sourceEnd);
3308 // public void unusedImport(ImportReference importRef) {
3309 // String[] arguments = new
3310 // String[]{CharOperation.toString(importRef.tokens)};
3311 // this.handle(IProblem.UnusedImport, arguments, arguments,
3312 // importRef.sourceStart, importRef.sourceEnd);
3314 public void unusedLocalVariable(LocalDeclaration localDecl) {
3315 String[] arguments = new String[] { localDecl.name() };
3316 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
3317 localDecl.sourceStart, localDecl.sourceEnd);
3320 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
3321 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
3323 // no complaint for no-arg constructors (or default ones) - known
3324 // pattern to block instantiation
3325 if (constructorDecl.arguments == null
3326 || constructorDecl.arguments.length == 0)
3328 MethodBinding constructor = constructorDecl.binding;
3329 this.handle(IProblem.UnusedPrivateConstructor, new String[] {
3330 new String(constructor.declaringClass.readableName()),
3331 parametersAsString(constructor) }, new String[] {
3332 new String(constructor.declaringClass.shortReadableName()),
3333 parametersAsShortString(constructor) },
3334 constructorDecl.sourceStart, constructorDecl.sourceEnd);
3337 public void unusedPrivateField(FieldDeclaration fieldDecl) {
3338 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
3340 FieldBinding field = fieldDecl.binding;
3341 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
3342 && field.isStatic() && field.isFinal()
3343 && TypeBinding.LongBinding == field.type) {
3344 return; // do not report unused serialVersionUID field
3346 this.handle(IProblem.UnusedPrivateField, new String[] {
3347 new String(field.declaringClass.readableName()),
3348 new String(field.name), }, new String[] {
3349 new String(field.declaringClass.shortReadableName()),
3350 new String(field.name), }, fieldDecl.sourceStart,
3351 fieldDecl.sourceEnd);
3354 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
3355 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
3357 MethodBinding method = methodDecl.binding;
3358 // no report for serialization support 'void
3359 // readObject(ObjectInputStream)'
3360 if (!method.isStatic()
3361 && TypeBinding.VoidBinding == method.returnType
3362 && method.parameters.length == 1
3363 && method.parameters[0].dimensions() == 0
3364 && CharOperation.equals(method.selector,
3365 TypeConstants.READOBJECT)
3366 && CharOperation.equals(
3367 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
3368 method.parameters[0].readableName())) {
3371 // no report for serialization support 'void
3372 // writeObject(ObjectOutputStream)'
3373 if (!method.isStatic()
3374 && TypeBinding.VoidBinding == method.returnType
3375 && method.parameters.length == 1
3376 && method.parameters[0].dimensions() == 0
3377 && CharOperation.equals(method.selector,
3378 TypeConstants.WRITEOBJECT)
3379 && CharOperation.equals(
3380 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
3381 method.parameters[0].readableName())) {
3384 // no report for serialization support 'Object readResolve()'
3385 if (!method.isStatic()
3386 && TypeBinding.T_Object == method.returnType.id
3387 && method.parameters.length == 0
3388 && CharOperation.equals(method.selector,
3389 TypeConstants.READRESOLVE)) {
3392 // no report for serialization support 'Object writeReplace()'
3393 if (!method.isStatic()
3394 && TypeBinding.T_Object == method.returnType.id
3395 && method.parameters.length == 0
3396 && CharOperation.equals(method.selector,
3397 TypeConstants.WRITEREPLACE)) {
3400 this.handle(IProblem.UnusedPrivateMethod, new String[] {
3401 new String(method.declaringClass.readableName()),
3402 new String(method.selector), parametersAsString(method) },
3404 new String(method.declaringClass.shortReadableName()),
3405 new String(method.selector),
3406 parametersAsShortString(method) },
3407 methodDecl.sourceStart, methodDecl.sourceEnd);
3410 public void unusedPrivateType(TypeDeclaration typeDecl) {
3411 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
3413 ReferenceBinding type = typeDecl.binding;
3414 this.handle(IProblem.UnusedPrivateType, new String[] { new String(type
3415 .readableName()), }, new String[] { new String(type
3416 .shortReadableName()), }, typeDecl.sourceStart,
3417 typeDecl.sourceEnd);
3420 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
3421 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
3422 sourceStart, sourceEnd);
3425 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
3426 String[] arguments = new String[] { new String(varDecl.name) };
3427 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
3428 varDecl.sourceStart, varDecl.sourceEnd);
3431 public void variableTypeCannotBeVoidArray(
3432 AbstractVariableDeclaration varDecl) {
3433 String[] arguments = new String[] { new String(varDecl.name) };
3434 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments,
3435 arguments, varDecl.sourceStart, varDecl.sourceEnd);
3438 public void visibilityConflict(MethodBinding currentMethod,
3439 MethodBinding inheritedMethod) {
3441 // Cannot reduce the visibility of the inherited method from %1
3442 // 8.4.6.3 - The access modifier of an hiding method must
3443 // provide at least as much access as the hidden method.
3444 // 8.4.6.3 - The access modifier of an overiding method must
3445 // provide at least as much access as the overriden method.
3446 IProblem.MethodReducesVisibility, new String[] { new String(
3447 inheritedMethod.declaringClass.readableName()) },
3448 new String[] { new String(inheritedMethod.declaringClass
3449 .shortReadableName()) }, currentMethod.sourceStart(),
3450 currentMethod.sourceEnd());
3453 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
3454 int under, int upper) {
3455 // the two catch block under and upper are in an incorrect order.
3456 // under should be define BEFORE upper in the source
3457 TypeReference typeRef = statement.catchArguments[under].type;
3458 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
3459 typeRef.sourceStart, typeRef.sourceEnd);
3462 public void nonExternalizedStringLiteral(ASTNode location) {
3463 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument,
3464 NoArgument, location.sourceStart, location.sourceEnd);
3467 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
3468 this.handle(IProblem.TooManyBytesForStringConstant,
3469 new String[] { new String(typeDeclaration.binding
3470 .readableName()) }, new String[] { new String(
3471 typeDeclaration.binding.shortReadableName()) }, Abort
3472 | Error, typeDeclaration.sourceStart,
3473 typeDeclaration.sourceEnd);
3476 public void noMoreAvailableSpaceInConstantPool(
3477 TypeDeclaration typeDeclaration) {
3478 this.handle(IProblem.TooManyConstantsInConstantPool,
3479 new String[] { new String(typeDeclaration.binding
3480 .readableName()) }, new String[] { new String(
3481 typeDeclaration.binding.shortReadableName()) }, Abort
3482 | Error, typeDeclaration.sourceStart,
3483 typeDeclaration.sourceEnd);
3486 private boolean isKeyword(char[] tokenSource) {
3488 * This code is heavily grammar dependant
3490 if (tokenSource == null) {
3494 Scanner scanner = new Scanner();
3495 scanner.setSource(tokenSource);
3496 TokenName token = scanner.getNextToken();
3497 char[] currentKeyword;
3499 currentKeyword = scanner.getCurrentIdentifierSource();
3500 } catch (ArrayIndexOutOfBoundsException e) {
3503 TokenName nextToken = scanner.getNextToken();
3504 if (nextToken == Scanner.TokenName.EOF
3505 && scanner.startPosition == scanner.source.length) { // to
3512 // ArrayIndexOutOfBoundsException
3513 // while reading the last token
3516 if (CharOperation.equals("goto".toCharArray(),
3518 || CharOperation.equals(
3519 "const".toCharArray(), currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
3564 // case SYNCHRONIZED:
3581 } catch (InvalidInputException e) {
3587 public void phpParsingError(String[] messageArguments,
3588 int problemStartPosition, int problemEndPosition,
3589 ReferenceContext context, CompilationResult compilationResult) {
3590 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
3591 problemStartPosition, problemEndPosition, context,
3595 // public void phpParsingWarning(String[] messageArguments,
3596 // int problemStartPosition, int problemEndPosition,
3597 // ReferenceContext context, CompilationResult compilationResult) {
3598 // this.handle(IProblem.PHPParsingWarning, NoArgument, messageArguments,
3599 // problemStartPosition, problemEndPosition, context,
3600 // compilationResult);
3603 public void phpVarDeprecatedWarning(int problemStartPosition,
3604 int problemEndPosition, ReferenceContext context,
3605 CompilationResult compilationResult) {
3606 if (computeSeverity(IProblem.PHPVarDeprecatedWarning) == Ignore)
3608 this.handle(IProblem.PHPVarDeprecatedWarning, NoArgument,
3609 new String[] {}, problemStartPosition, problemEndPosition,
3610 context, compilationResult);
3613 public void phpIncludeNotExistWarning(String[] messageArguments,
3614 int problemStartPosition, int problemEndPosition,
3615 ReferenceContext context, CompilationResult compilationResult) {
3616 if (computeSeverity(IProblem.PHPIncludeNotExistWarning) == Ignore)
3618 this.handle(IProblem.PHPIncludeNotExistWarning, NoArgument,
3619 messageArguments, problemStartPosition, problemEndPosition,
3620 context, compilationResult);
3623 public void phpKeywordWarning(String[] messageArguments,
3624 int problemStartPosition, int problemEndPosition,
3625 ReferenceContext context, CompilationResult compilationResult) {
3626 if (computeSeverity(IProblem.PHPBadStyleKeywordWarning) == Ignore)
3628 this.handle(IProblem.PHPBadStyleKeywordWarning, NoArgument,
3629 messageArguments, problemStartPosition, problemEndPosition,
3630 context, compilationResult);
3633 public void phpUppercaseIdentifierWarning(int problemStartPosition,
3634 int problemEndPosition, ReferenceContext context,
3635 CompilationResult compilationResult) {
3636 if (computeSeverity(IProblem.PHPBadStyleUppercaseIdentifierWarning) == Ignore)
3638 this.handle(IProblem.PHPBadStyleUppercaseIdentifierWarning, NoArgument,
3639 new String[] {}, problemStartPosition, problemEndPosition,
3640 context, compilationResult);
3643 public void uninitializedLocalVariable(String token,
3644 int problemStartPosition, int problemEndPosition,
3645 ReferenceContext context, CompilationResult compilationResult) {
3646 if (computeSeverity(IProblem.UninitializedLocalVariable) == Ignore)
3648 // String[] arguments = new String[] { new
3649 // String(binding.readableName()) };
3650 String[] arguments = new String[] { token };
3651 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
3652 problemStartPosition, problemEndPosition, context,
3656 public void unreachableCode(String token, int problemStartPosition,
3657 int problemEndPosition, ReferenceContext context,
3658 CompilationResult compilationResult) {
3659 if (computeSeverity(IProblem.CodeCannotBeReached) == Ignore)
3661 this.handle(IProblem.CodeCannotBeReached, NoArgument, new String[] {},
3662 problemStartPosition, problemEndPosition, context,