1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
16 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
17 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
18 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
19 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
20 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
22 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemMethodBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
27 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
28 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
29 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.SyntheticArgumentBinding;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
32 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
33 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
34 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
35 import net.sourceforge.phpdt.internal.compiler.util.Util;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractVariableDeclaration;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.AllocationExpression;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayAllocationExpression;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.ArrayReference;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.Assignment;
43 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
44 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
45 import net.sourceforge.phpeclipse.internal.compiler.ast.BranchStatement;
46 import net.sourceforge.phpeclipse.internal.compiler.ast.Case;
47 import net.sourceforge.phpeclipse.internal.compiler.ast.CastExpression;
48 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
49 import net.sourceforge.phpeclipse.internal.compiler.ast.CompoundAssignment;
50 import net.sourceforge.phpeclipse.internal.compiler.ast.ConstructorDeclaration;
51 import net.sourceforge.phpeclipse.internal.compiler.ast.DefaultCase;
52 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
53 import net.sourceforge.phpeclipse.internal.compiler.ast.ExplicitConstructorCall;
54 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
55 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldReference;
57 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
58 import net.sourceforge.phpeclipse.internal.compiler.ast.InstanceOfExpression;
59 import net.sourceforge.phpeclipse.internal.compiler.ast.IntLiteral;
60 import net.sourceforge.phpeclipse.internal.compiler.ast.Literal;
61 import net.sourceforge.phpeclipse.internal.compiler.ast.LocalDeclaration;
62 import net.sourceforge.phpeclipse.internal.compiler.ast.LongLiteral;
63 import net.sourceforge.phpeclipse.internal.compiler.ast.MessageSend;
64 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
65 import net.sourceforge.phpeclipse.internal.compiler.ast.NameReference;
66 import net.sourceforge.phpeclipse.internal.compiler.ast.NumberLiteral;
67 import net.sourceforge.phpeclipse.internal.compiler.ast.QualifiedNameReference;
68 import net.sourceforge.phpeclipse.internal.compiler.ast.Reference;
69 import net.sourceforge.phpeclipse.internal.compiler.ast.ReturnStatement;
70 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleNameReference;
71 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
72 import net.sourceforge.phpeclipse.internal.compiler.ast.ThisReference;
73 import net.sourceforge.phpeclipse.internal.compiler.ast.ThrowStatement;
74 import net.sourceforge.phpeclipse.internal.compiler.ast.TryStatement;
75 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
76 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
77 import net.sourceforge.phpeclipse.internal.compiler.ast.UnaryExpression;
78 public class ProblemReporter extends ProblemHandler implements ProblemReasons {
79 public ReferenceContext referenceContext;
80 public ProblemReporter(IErrorHandlingPolicy policy,
81 IProblemFactory problemFactory) {
82 //CompilerOptions options, IProblemFactory problemFactory) {
83 super(policy, problemFactory);//options, problemFactory);
85 public void abortDueToInternalError(String errorMessage) {
86 String[] arguments = new String[]{errorMessage};
87 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
90 public void abortDueToInternalError(String errorMessage, AstNode location) {
91 String[] arguments = new String[]{errorMessage};
92 this.handle(IProblem.Unclassified, arguments, arguments, Error | Abort,
93 location.sourceStart, location.sourceEnd);
95 public void abstractMethodCannotBeOverridden(SourceTypeBinding type,
96 MethodBinding concreteMethod) {
98 // %1 must be abstract since it cannot override the inherited
99 // package-private abstract method %2
100 IProblem.AbstractMethodCannotBeOverridden, new String[]{
101 new String(type.sourceName()),
102 new String(CharOperation.concat(
103 concreteMethod.declaringClass.readableName(),
104 concreteMethod.readableName(), '.'))},
106 new String(type.sourceName()),
107 new String(CharOperation.concat(
108 concreteMethod.declaringClass
109 .shortReadableName(), concreteMethod
110 .shortReadableName(), '.'))}, type
111 .sourceStart(), type.sourceEnd());
113 public void abstractMethodInAbstractClass(SourceTypeBinding type,
114 AbstractMethodDeclaration methodDecl) {
115 String[] arguments = new String[]{new String(type.sourceName()),
116 new String(methodDecl.selector)};
117 this.handle(IProblem.AbstractMethodInAbstractClass, arguments,
118 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
120 public void abstractMethodMustBeImplemented(SourceTypeBinding type,
121 MethodBinding abstractMethod) {
123 // Must implement the inherited abstract method %1
124 // 8.4.3 - Every non-abstract subclass of an abstract type, A,
125 // must provide a concrete implementation of all of A's
127 IProblem.AbstractMethodMustBeImplemented,
128 new String[]{new String(CharOperation.concat(
129 abstractMethod.declaringClass.readableName(),
130 abstractMethod.readableName(), '.'))},
131 new String[]{new String(CharOperation.concat(
132 abstractMethod.declaringClass.shortReadableName(),
133 abstractMethod.shortReadableName(), '.'))}, type
134 .sourceStart(), type.sourceEnd());
136 public void abstractMethodNeedingNoBody(AbstractMethodDeclaration method) {
137 this.handle(IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
138 method.sourceStart, method.sourceEnd, method, method
139 .compilationResult());
141 public void alreadyDefinedLabel(char[] labelName, AstNode location) {
142 String[] arguments = new String[]{new String(labelName)};
143 this.handle(IProblem.DuplicateLabel, arguments, arguments,
144 location.sourceStart, location.sourceEnd);
146 public void anonymousClassCannotExtendFinalClass(Expression expression,
148 this.handle(IProblem.AnonymousClassCannotExtendFinalClass,
149 new String[]{new String(type.readableName())},
150 new String[]{new String(type.shortReadableName())},
151 expression.sourceStart, expression.sourceEnd);
153 public void argumentTypeCannotBeVoid(SourceTypeBinding type,
154 AbstractMethodDeclaration methodDecl, Argument arg) {
155 String[] arguments = new String[]{new String(methodDecl.selector),
156 new String(arg.name)};
157 this.handle(IProblem.ArgumentTypeCannotBeVoid, arguments, arguments,
158 methodDecl.sourceStart, methodDecl.sourceEnd);
160 public void argumentTypeCannotBeVoidArray(SourceTypeBinding type,
161 AbstractMethodDeclaration methodDecl, Argument arg) {
162 String[] arguments = new String[]{new String(methodDecl.selector),
163 new String(arg.name)};
164 this.handle(IProblem.ArgumentTypeCannotBeVoidArray, arguments,
165 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
167 public void argumentTypeProblem(SourceTypeBinding type,
168 AbstractMethodDeclaration methodDecl, Argument arg,
169 TypeBinding expectedType) {
170 int problemId = expectedType.problemId();
175 id = IProblem.ArgumentTypeNotFound;
179 id = IProblem.ArgumentTypeNotVisible;
183 id = IProblem.ArgumentTypeAmbiguous;
185 case InternalNameProvided :
187 id = IProblem.ArgumentTypeInternalNameProvided;
189 case InheritedNameHidesEnclosingName :
191 id = IProblem.ArgumentTypeInheritedNameHidesEnclosingName;
196 needImplementation(); // want to fail to see why we were
200 this.handle(id, new String[]{new String(methodDecl.selector),
201 arg.name(), new String(expectedType.readableName())},
202 new String[]{new String(methodDecl.selector), arg.name(),
203 new String(expectedType.shortReadableName())},
204 arg.type.sourceStart, arg.type.sourceEnd);
206 public void arrayConstantsOnlyInArrayInitializers(int sourceStart,
208 this.handle(IProblem.ArrayConstantsOnlyInArrayInitializers, NoArgument,
209 NoArgument, sourceStart, sourceEnd);
211 public void assignmentHasNoEffect(Assignment assignment, char[] name) {
212 String[] arguments = new String[]{new String(name)};
213 this.handle(IProblem.AssignmentHasNoEffect, arguments, arguments,
214 assignment.sourceStart, assignment.sourceEnd);
216 public void attemptToReturnNonVoidExpression(
217 ReturnStatement returnStatement, TypeBinding expectedType) {
218 this.handle(IProblem.VoidMethodReturnsValue, new String[]{new String(
219 expectedType.readableName())}, new String[]{new String(
220 expectedType.shortReadableName())},
221 returnStatement.sourceStart, returnStatement.sourceEnd);
223 public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
224 this.handle(IProblem.MethodReturnsVoid, NoArgument, NoArgument,
225 returnStatement.sourceStart, returnStatement.sourceEnd);
227 //public void bytecodeExceeds64KLimit(AbstractMethodDeclaration location)
229 // String[] arguments = new String[] {new String(location.selector),
230 // parametersAsString(location.binding)};
231 // if (location.isConstructor()) {
233 // IProblem.BytecodeExceeds64KLimitForConstructor,
237 // location.sourceStart,
238 // location.sourceEnd);
241 // IProblem.BytecodeExceeds64KLimit,
245 // location.sourceStart,
246 // location.sourceEnd);
249 public void bytecodeExceeds64KLimit(TypeDeclaration location) {
250 this.handle(IProblem.BytecodeExceeds64KLimitForClinit, NoArgument,
251 NoArgument, Error | Abort, location.sourceStart,
254 public void cannotAllocateVoidArray(Expression expression) {
255 this.handle(IProblem.CannotAllocateVoidArray, NoArgument, NoArgument,
256 expression.sourceStart, expression.sourceEnd);
258 public void cannotAssignToFinalField(FieldBinding field, AstNode location) {
259 this.handle(IProblem.FinalFieldAssignment, new String[]{
260 (field.declaringClass == null ? "array" : new String(
261 field.declaringClass.readableName())), //$NON-NLS-1$
262 new String(field.readableName())}, new String[]{
263 (field.declaringClass == null ? "array" : new String(
264 field.declaringClass.shortReadableName())), //$NON-NLS-1$
265 new String(field.shortReadableName())}, location.sourceStart,
268 public void cannotAssignToFinalLocal(LocalVariableBinding local,
270 String[] arguments = new String[]{new String(local.readableName())};
271 this.handle(IProblem.NonBlankFinalLocalAssignment, arguments,
272 arguments, location.sourceStart, location.sourceEnd);
274 public void cannotAssignToFinalOuterLocal(LocalVariableBinding local,
276 String[] arguments = new String[]{new String(local.readableName())};
277 this.handle(IProblem.FinalOuterLocalAssignment, arguments, arguments,
278 location.sourceStart, location.sourceEnd);
280 public void cannotDeclareLocalInterface(char[] interfaceName,
281 int sourceStart, int sourceEnd) {
282 String[] arguments = new String[]{new String(interfaceName)};
283 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
284 arguments, sourceStart, sourceEnd);
286 public void cannotDefineDimensionsAndInitializer(
287 ArrayAllocationExpression expresssion) {
288 this.handle(IProblem.CannotDefineDimensionExpressionsWithInit,
289 NoArgument, NoArgument, expresssion.sourceStart,
290 expresssion.sourceEnd);
292 public void cannotDireclyInvokeAbstractMethod(MessageSend messageSend,
293 MethodBinding method) {
294 this.handle(IProblem.DirectInvocationOfAbstractMethod, new String[]{
295 new String(method.declaringClass.readableName()),
296 new String(method.selector), parametersAsString(method)},
298 new String(method.declaringClass.shortReadableName()),
299 new String(method.selector),
300 parametersAsShortString(method)},
301 messageSend.sourceStart, messageSend.sourceEnd);
303 public void cannotImportPackage(ImportReference importRef) {
304 String[] arguments = new String[]{CharOperation
305 .toString(importRef.tokens)};
306 this.handle(IProblem.CannotImportPackage, arguments, arguments,
307 importRef.sourceStart, importRef.sourceEnd);
309 public void cannotInstantiate(TypeReference typeRef, TypeBinding type) {
310 this.handle(IProblem.InvalidClassInstantiation,
311 new String[]{new String(type.readableName())},
312 new String[]{new String(type.shortReadableName())},
313 typeRef.sourceStart, typeRef.sourceEnd);
315 public void cannotReferToNonFinalOuterLocal(LocalVariableBinding local,
317 String[] arguments = new String[]{new String(local.readableName())};
318 this.handle(IProblem.OuterLocalMustBeFinal, arguments, arguments,
319 location.sourceStart, location.sourceEnd);
321 public void cannotReturnInInitializer(AstNode location) {
322 this.handle(IProblem.CannotReturnInInitializer, NoArgument, NoArgument,
323 location.sourceStart, location.sourceEnd);
325 public void cannotThrowNull(ThrowStatement statement) {
326 this.handle(IProblem.CannotThrowNull, NoArgument, NoArgument,
327 statement.sourceStart, statement.sourceEnd);
329 public void cannotThrowType(SourceTypeBinding type,
330 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
331 TypeBinding expectedType) {
332 this.handle(IProblem.CannotThrowType, new String[]{new String(
333 expectedType.readableName())}, new String[]{new String(
334 expectedType.shortReadableName())}, exceptionType.sourceStart,
335 exceptionType.sourceEnd);
337 public void cannotUseSuperInJavaLangObject(AstNode reference) {
338 this.handle(IProblem.ObjectHasNoSuperclass, NoArgument, NoArgument,
339 reference.sourceStart, reference.sourceEnd);
341 public void cannotUseSuperInCodeSnippet(int start, int end) {
342 this.handle(IProblem.CannotUseSuperInCodeSnippet, NoArgument,
343 NoArgument, Error | Abort, start, end);
345 public void caseExpressionMustBeConstant(Expression expression) {
346 this.handle(IProblem.NonConstantExpression, NoArgument, NoArgument,
347 expression.sourceStart, expression.sourceEnd);
349 public void classExtendFinalClass(SourceTypeBinding type,
350 TypeReference superclass, TypeBinding expectedType) {
351 String name = new String(type.sourceName());
352 String expectedFullName = new String(expectedType.readableName());
353 String expectedShortName = new String(expectedType.shortReadableName());
354 if (expectedShortName.equals(name))
355 expectedShortName = expectedFullName;
356 this.handle(IProblem.ClassExtendFinalClass, new String[]{
357 expectedFullName, name}, new String[]{expectedShortName, name},
358 superclass.sourceStart, superclass.sourceEnd);
360 public void codeSnippetMissingClass(String missing, int start, int end) {
361 String[] arguments = new String[]{missing};
362 this.handle(IProblem.CodeSnippetMissingClass, arguments, arguments,
363 Error | Abort, start, end);
365 public void codeSnippetMissingMethod(String className,
366 String missingMethod, String argumentTypes, int start, int end) {
367 String[] arguments = new String[]{className, missingMethod,
369 this.handle(IProblem.CodeSnippetMissingMethod, arguments, arguments,
370 Error | Abort, start, end);
373 * Given the current configuration, answers which category the problem
374 * falls into: Error | Warning | Ignore
376 //public int computeSeverity(int problemId){
378 // // severity can have been preset on the problem
379 //// if ((problem.severity & Fatal) != 0){
383 // // if not then check whether it is a configurable problem
384 // int errorThreshold = options.errorThreshold;
385 // int warningThreshold = options.warningThreshold;
387 // switch(problemId){
389 // case IProblem.UnreachableCatch :
390 // case IProblem.CodeCannotBeReached :
391 // if ((errorThreshold & CompilerOptions.UnreachableCode) != 0){
394 // if ((warningThreshold & CompilerOptions.UnreachableCode) != 0){
399 // case IProblem.MaskedCatch :
400 // if ((errorThreshold & CompilerOptions.MaskedCatchBlock) != 0){
403 // if ((warningThreshold & CompilerOptions.MaskedCatchBlock) != 0){
410 // if ((errorThreshold & ParsingOptionalError) != 0){
413 // if ((warningThreshold & ParsingOptionalError) != 0){
418 // case IProblem.ImportNotFound :
419 // case IProblem.ImportNotVisible :
420 // case IProblem.ImportAmbiguous :
421 // case IProblem.ImportInternalNameProvided :
422 // case IProblem.ImportInheritedNameHidesEnclosingName :
423 // case IProblem.DuplicateImport :
424 // case IProblem.ConflictingImport :
425 // case IProblem.CannotImportPackage :
426 // if ((errorThreshold & CompilerOptions.ImportProblem) != 0){
429 // if ((warningThreshold & CompilerOptions.ImportProblem) != 0){
434 // case IProblem.UnusedImport :
435 // // if import problem are disabled, then ignore
436 // if ((errorThreshold & CompilerOptions.ImportProblem) == 0
437 // && (warningThreshold & CompilerOptions.ImportProblem) == 0){
440 // if ((errorThreshold & CompilerOptions.UnusedImport) != 0){
443 // if ((warningThreshold & CompilerOptions.UnusedImport) != 0){
448 // case IProblem.MethodButWithConstructorName :
449 // if ((errorThreshold & CompilerOptions.MethodWithConstructorName) != 0){
452 // if ((warningThreshold & CompilerOptions.MethodWithConstructorName) !=
458 // case IProblem.OverridingNonVisibleMethod :
459 // if ((errorThreshold & CompilerOptions.OverriddenPackageDefaultMethod) !=
463 // if ((warningThreshold & CompilerOptions.OverriddenPackageDefaultMethod)
469 // case IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod :
471 // IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod
473 // if ((errorThreshold &
474 // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
477 // if ((warningThreshold &
478 // CompilerOptions.IncompatibleNonInheritedInterfaceMethod) != 0){
483 // case IProblem.OverridingDeprecatedMethod :
484 // case IProblem.UsingDeprecatedType :
485 // case IProblem.UsingDeprecatedMethod :
486 // case IProblem.UsingDeprecatedConstructor :
487 // case IProblem.UsingDeprecatedField :
488 // if ((errorThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
491 // if ((warningThreshold & CompilerOptions.UsingDeprecatedAPI) != 0){
496 // case IProblem.LocalVariableIsNeverUsed :
497 // if ((errorThreshold & CompilerOptions.UnusedLocalVariable) != 0){
500 // if ((warningThreshold & CompilerOptions.UnusedLocalVariable) != 0){
505 // case IProblem.ArgumentIsNeverUsed :
506 // if ((errorThreshold & CompilerOptions.UnusedArgument) != 0){
509 // if ((warningThreshold & CompilerOptions.UnusedArgument) != 0){
514 // case IProblem.NoImplicitStringConversionForCharArrayExpression :
515 // if ((errorThreshold & CompilerOptions.NoImplicitStringConversion) != 0){
518 // if ((warningThreshold & CompilerOptions.NoImplicitStringConversion) !=
524 // case IProblem.NeedToEmulateFieldReadAccess :
525 // case IProblem.NeedToEmulateFieldWriteAccess :
526 // case IProblem.NeedToEmulateMethodAccess :
527 // case IProblem.NeedToEmulateConstructorAccess :
528 // if ((errorThreshold & CompilerOptions.AccessEmulation) != 0){
531 // if ((warningThreshold & CompilerOptions.AccessEmulation) != 0){
535 // case IProblem.NonExternalizedStringLiteral :
536 // if ((errorThreshold & CompilerOptions.NonExternalizedString) != 0){
539 // if ((warningThreshold & CompilerOptions.NonExternalizedString) != 0){
543 // case IProblem.UseAssertAsAnIdentifier :
544 // if ((errorThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
547 // if ((warningThreshold & CompilerOptions.AssertUsedAsAnIdentifier) != 0){
551 // case IProblem.NonStaticAccessToStaticMethod :
552 // case IProblem.NonStaticAccessToStaticField :
553 // if ((errorThreshold & CompilerOptions.StaticAccessReceiver) != 0){
556 // if ((warningThreshold & CompilerOptions.StaticAccessReceiver) != 0){
560 // case IProblem.AssignmentHasNoEffect:
561 // if ((errorThreshold & CompilerOptions.NoEffectAssignment) != 0){
564 // if ((warningThreshold & CompilerOptions.NoEffectAssignment) != 0){
568 // case IProblem.UnusedPrivateConstructor:
569 // case IProblem.UnusedPrivateMethod:
570 // case IProblem.UnusedPrivateField:
571 // case IProblem.UnusedPrivateType:
572 // if ((errorThreshold & CompilerOptions.UnusedPrivateMember) != 0){
575 // if ((warningThreshold & CompilerOptions.UnusedPrivateMember) != 0){
580 // case IProblem.Task :
586 //public void conditionalArgumentsIncompatibleTypes(ConditionalExpression
587 // expression, TypeBinding trueType, TypeBinding falseType) {
589 // IProblem.IncompatibleTypesInConditionalOperator,
590 // new String[] {new String(trueType.readableName()), new
591 // String(falseType.readableName())},
592 // new String[] {new String(trueType.sourceName()), new
593 // String(falseType.sourceName())},
594 // expression.sourceStart,
595 // expression.sourceEnd);
597 public void conflictingImport(ImportReference importRef) {
598 String[] arguments = new String[]{CharOperation
599 .toString(importRef.tokens)};
600 this.handle(IProblem.ConflictingImport, arguments, arguments,
601 importRef.sourceStart, importRef.sourceEnd);
603 public void constantOutOfFormat(NumberLiteral lit) {
604 // the literal is not in a correct format
605 // this code is called on IntLiteral and LongLiteral
606 // example 000811 ...the 8 is uncorrect.
607 if ((lit instanceof LongLiteral) || (lit instanceof IntLiteral)) {
608 char[] source = lit.source();
612 if ((source[1] == 'x') || (source[1] == 'X')) {
614 Radix = "Hexa"; //$NON-NLS-1$
617 Radix = "Octal"; //$NON-NLS-1$
619 //look for the first digit that is incorrect
621 label : for (int i = radix == 8 ? 1 : 2; i < source.length; i++) {
622 if (Character.digit(source[i], radix) == -1) {
627 String[] arguments = new String[]{Radix + " "
628 + new String(source) + " (digit "
629 + new String(new char[]{source[place]}) + ")"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
630 this.handle(IProblem.NumericValueOutOfRange, arguments,
631 arguments, lit.sourceStart, lit.sourceEnd);
633 } catch (IndexOutOfBoundsException ex) {
635 // just in case .... use a predefined error..
636 // we should never come here...(except if the code changes !)
637 this.constantOutOfRange(lit);
640 public void constantOutOfRange(Literal lit) {
641 // lit is some how out of range of it declared type
643 // 9999999999999999999999999999999999999999999999999999999999999999999
644 String[] arguments = new String[]{new String(lit.source())};
645 this.handle(IProblem.NumericValueOutOfRange, arguments, arguments,
646 lit.sourceStart, lit.sourceEnd);
648 public void deprecatedField(FieldBinding field, AstNode location) {
649 this.handle(IProblem.UsingDeprecatedField, new String[]{
650 new String(field.declaringClass.readableName()),
651 new String(field.name)}, new String[]{
652 new String(field.declaringClass.shortReadableName()),
653 new String(field.name)}, location.sourceStart,
656 public void deprecatedMethod(MethodBinding method, AstNode location) {
657 if (method.isConstructor())
658 this.handle(IProblem.UsingDeprecatedConstructor, new String[]{
659 new String(method.declaringClass.readableName()),
660 parametersAsString(method)}, new String[]{
661 new String(method.declaringClass.shortReadableName()),
662 parametersAsShortString(method)}, location.sourceStart,
665 this.handle(IProblem.UsingDeprecatedMethod, new String[]{
666 new String(method.declaringClass.readableName()),
667 new String(method.selector), parametersAsString(method)},
669 new String(method.declaringClass
670 .shortReadableName()),
671 new String(method.selector),
672 parametersAsShortString(method)},
673 location.sourceStart, location.sourceEnd);
675 public void deprecatedType(TypeBinding type, AstNode location) {
676 if (location == null)
677 return; // 1G828DN - no type ref for synthetic arguments
678 this.handle(IProblem.UsingDeprecatedType, new String[]{new String(type
679 .readableName())}, new String[]{new String(type
680 .shortReadableName())}, location.sourceStart,
683 public void duplicateCase(Case statement, Constant constant) {
684 String[] arguments = new String[]{String.valueOf(constant.intValue())};
685 this.handle(IProblem.DuplicateCase, arguments, arguments,
686 statement.sourceStart, statement.sourceEnd);
688 public void duplicateDefaultCase(DefaultCase statement) {
689 this.handle(IProblem.DuplicateDefaultCase, NoArgument, NoArgument,
690 statement.sourceStart, statement.sourceEnd);
692 public void duplicateFieldInType(SourceTypeBinding type,
693 FieldDeclaration fieldDecl) {
694 this.handle(IProblem.DuplicateField, new String[]{
695 new String(type.sourceName()), fieldDecl.name()}, new String[]{
696 new String(type.shortReadableName()), fieldDecl.name()},
697 fieldDecl.sourceStart, fieldDecl.sourceEnd);
699 public void duplicateImport(ImportReference importRef) {
700 String[] arguments = new String[]{CharOperation
701 .toString(importRef.tokens)};
702 this.handle(IProblem.DuplicateImport, arguments, arguments,
703 importRef.sourceStart, importRef.sourceEnd);
705 public void duplicateInitializationOfBlankFinalField(FieldBinding field,
706 Reference reference) {
707 String[] arguments = new String[]{new String(field.readableName())};
708 this.handle(IProblem.DuplicateBlankFinalFieldInitialization, arguments,
709 arguments, reference.sourceStart, reference.sourceEnd);
711 public void duplicateInitializationOfFinalLocal(LocalVariableBinding local,
713 String[] arguments = new String[]{new String(local.readableName())};
714 this.handle(IProblem.DuplicateFinalLocalInitialization, arguments,
715 arguments, location.sourceStart, location.sourceEnd);
717 public void duplicateMethodInType(SourceTypeBinding type,
718 AbstractMethodDeclaration methodDecl) {
719 String[] arguments = new String[]{new String(methodDecl.selector),
720 new String(type.sourceName())};
721 this.handle(IProblem.DuplicateMethod, arguments, arguments,
722 methodDecl.sourceStart, methodDecl.sourceEnd);
724 public void duplicateModifierForField(ReferenceBinding type,
725 FieldDeclaration fieldDecl) {
727 * to highlight modifiers use: this.handle( new Problem(
728 * DuplicateModifierForField, new String[] {fieldDecl.name()},
729 * fieldDecl.modifiers.sourceStart, fieldDecl.modifiers.sourceEnd));
731 String[] arguments = new String[]{fieldDecl.name()};
732 this.handle(IProblem.DuplicateModifierForField, arguments, arguments,
733 fieldDecl.sourceStart, fieldDecl.sourceEnd);
735 public void duplicateModifierForMethod(ReferenceBinding type,
736 AbstractMethodDeclaration methodDecl) {
737 this.handle(IProblem.DuplicateModifierForMethod,
738 new String[]{new String(type.sourceName()),
739 new String(methodDecl.selector)}, new String[]{
740 new String(type.shortReadableName()),
741 new String(methodDecl.selector)},
742 methodDecl.sourceStart, methodDecl.sourceEnd);
744 public void duplicateModifierForType(SourceTypeBinding type) {
745 String[] arguments = new String[]{new String(type.sourceName())};
746 this.handle(IProblem.DuplicateModifierForType, arguments, arguments,
747 type.sourceStart(), type.sourceEnd());
749 public void duplicateModifierForVariable(LocalDeclaration localDecl,
750 boolean complainForArgument) {
751 String[] arguments = new String[]{localDecl.name()};
752 this.handle(complainForArgument
753 ? IProblem.DuplicateModifierForArgument
754 : IProblem.DuplicateModifierForVariable, arguments, arguments,
755 localDecl.sourceStart, localDecl.sourceEnd);
757 public void duplicateNestedType(TypeDeclaration typeDecl) {
758 String[] arguments = new String[]{new String(typeDecl.name)};
759 this.handle(IProblem.DuplicateNestedType, arguments, arguments,
760 typeDecl.sourceStart, typeDecl.sourceEnd);
762 public void duplicateSuperinterface(SourceTypeBinding type,
763 TypeDeclaration typeDecl, ReferenceBinding superType) {
764 this.handle(IProblem.DuplicateSuperInterface, new String[]{
765 new String(superType.readableName()),
766 new String(type.sourceName())}, new String[]{
767 new String(superType.shortReadableName()),
768 new String(type.sourceName())}, typeDecl.sourceStart,
771 public void duplicateTypes(CompilationUnitDeclaration compUnitDecl,
772 TypeDeclaration typeDecl) {
773 String[] arguments = new String[]{
774 new String(compUnitDecl.getFileName()),
775 new String(typeDecl.name)};
776 this.referenceContext = typeDecl; // report the problem against the
777 // type not the entire compilation
779 this.handle(IProblem.DuplicateTypes, arguments, arguments,
780 typeDecl.sourceStart, typeDecl.sourceEnd,
781 compUnitDecl.compilationResult);
783 public void errorNoMethodFor(MessageSend messageSend, TypeBinding recType,
784 TypeBinding[] params) {
785 StringBuffer buffer = new StringBuffer();
786 StringBuffer shortBuffer = new StringBuffer();
787 for (int i = 0, length = params.length; i < length; i++) {
789 buffer.append(", "); //$NON-NLS-1$
790 shortBuffer.append(", "); //$NON-NLS-1$
792 buffer.append(new String(params[i].readableName()));
793 shortBuffer.append(new String(params[i].shortReadableName()));
795 this.handle(recType.isArrayType()
796 ? IProblem.NoMessageSendOnArrayType
797 : IProblem.NoMessageSendOnBaseType, new String[]{
798 new String(recType.readableName()),
799 new String(messageSend.selector), buffer.toString()},
800 new String[]{new String(recType.shortReadableName()),
801 new String(messageSend.selector),
802 shortBuffer.toString()}, messageSend.sourceStart,
803 messageSend.sourceEnd);
805 public void errorThisSuperInStatic(AstNode reference) {
806 String[] arguments = new String[]{reference.isSuper()
808 : "this"}; //$NON-NLS-2$ //$NON-NLS-1$
809 this.handle(IProblem.ThisInStaticContext, arguments, arguments,
810 reference.sourceStart, reference.sourceEnd);
812 public void exceptionTypeProblem(SourceTypeBinding type,
813 AbstractMethodDeclaration methodDecl, TypeReference exceptionType,
814 TypeBinding expectedType) {
815 int problemId = expectedType.problemId();
820 id = IProblem.ExceptionTypeNotFound;
824 id = IProblem.ExceptionTypeNotVisible;
828 id = IProblem.ExceptionTypeAmbiguous;
830 case InternalNameProvided :
832 id = IProblem.ExceptionTypeInternalNameProvided;
834 case InheritedNameHidesEnclosingName :
836 id = IProblem.ExceptionTypeInheritedNameHidesEnclosingName;
841 needImplementation(); // want to fail to see why we were
845 this.handle(id, new String[]{new String(methodDecl.selector),
846 new String(expectedType.readableName())}, new String[]{
847 new String(methodDecl.selector),
848 new String(expectedType.shortReadableName())},
849 exceptionType.sourceStart, exceptionType.sourceEnd);
851 public void expressionShouldBeAVariable(Expression expression) {
852 this.handle(IProblem.ExpressionShouldBeAVariable, NoArgument,
853 NoArgument, expression.sourceStart, expression.sourceEnd);
855 public void fieldsOrThisBeforeConstructorInvocation(ThisReference reference) {
856 this.handle(IProblem.ThisSuperDuringConstructorInvocation, NoArgument,
857 NoArgument, reference.sourceStart, reference.sourceEnd);
859 public void fieldTypeProblem(SourceTypeBinding type,
860 FieldDeclaration fieldDecl, TypeBinding expectedType) {
861 int problemId = expectedType.problemId();
866 id = IProblem.FieldTypeNotFound;
870 id = IProblem.FieldTypeNotVisible;
874 id = IProblem.FieldTypeAmbiguous;
876 case InternalNameProvided :
878 id = IProblem.FieldTypeInternalNameProvided;
880 case InheritedNameHidesEnclosingName :
882 id = IProblem.FieldTypeInheritedNameHidesEnclosingName;
887 needImplementation(); // want to fail to see why we were
891 this.handle(id, new String[]{fieldDecl.name(),
892 new String(type.sourceName()),
893 new String(expectedType.readableName())}, new String[]{
894 fieldDecl.name(), new String(type.sourceName()),
895 new String(expectedType.shortReadableName())},
896 fieldDecl.type.sourceStart, fieldDecl.type.sourceEnd);
898 public void finalMethodCannotBeOverridden(MethodBinding currentMethod,
899 MethodBinding inheritedMethod) {
901 // Cannot override the final method from %1
902 // 8.4.3.3 - Final methods cannot be overridden or hidden.
903 IProblem.FinalMethodCannotBeOverridden,
904 new String[]{new String(inheritedMethod.declaringClass
905 .readableName())}, new String[]{new String(
906 inheritedMethod.declaringClass.shortReadableName())},
907 currentMethod.sourceStart(), currentMethod.sourceEnd());
909 public void forwardReference(Reference reference, int indexInQualification,
911 this.handle(IProblem.ReferenceToForwardField, NoArgument, NoArgument,
912 reference.sourceStart, reference.sourceEnd);
914 // use this private API when the compilation unit result can be found
916 // reference context. Otherwise, use the other API taking a problem and a
917 // compilation result
919 private void handle(int problemId, String[] problemArguments,
920 String[] messageArguments, int problemStartPosition,
921 int problemEndPosition) {
922 this.handle(problemId, problemArguments, messageArguments,
923 problemStartPosition, problemEndPosition, referenceContext,
924 referenceContext == null ? null : referenceContext
925 .compilationResult());
926 referenceContext = null;
928 // use this private API when the compilation unit result can be found
930 // reference context. Otherwise, use the other API taking a problem and a
931 // compilation result
933 private void handle(int problemId, String[] problemArguments,
934 String[] messageArguments, int severity, int problemStartPosition,
935 int problemEndPosition) {
936 this.handle(problemId, problemArguments, messageArguments, severity,
937 problemStartPosition, problemEndPosition, referenceContext,
938 referenceContext == null ? null : referenceContext
939 .compilationResult());
940 referenceContext = null;
942 // use this private API when the compilation unit result cannot be found
944 // reference context.
945 private void handle(int problemId, String[] problemArguments,
946 String[] messageArguments, int problemStartPosition,
947 int problemEndPosition, CompilationResult unitResult) {
948 this.handle(problemId, problemArguments, messageArguments,
949 problemStartPosition, problemEndPosition, referenceContext,
951 referenceContext = null;
953 public void hidingEnclosingType(TypeDeclaration typeDecl) {
954 String[] arguments = new String[]{new String(typeDecl.name)};
955 this.handle(IProblem.HidingEnclosingType, arguments, arguments,
956 typeDecl.sourceStart, typeDecl.sourceEnd);
958 public void hierarchyCircularity(SourceTypeBinding sourceType,
959 ReferenceBinding superType, TypeReference reference) {
962 String typeName = ""; //$NON-NLS-1$
963 String shortTypeName = ""; //$NON-NLS-1$
964 if (reference == null) { // can only happen when java.lang.Object is
966 start = sourceType.sourceStart();
967 end = sourceType.sourceEnd();
968 typeName = new String(superType.readableName());
969 shortTypeName = new String(superType.sourceName());
971 start = reference.sourceStart;
972 end = reference.sourceEnd;
973 char[][] qName = reference.getTypeName();
974 typeName = CharOperation.toString(qName);
975 shortTypeName = new String(qName[qName.length - 1]);
977 if (sourceType == superType)
979 .handle(IProblem.HierarchyCircularitySelfReference,
980 new String[]{new String(sourceType.sourceName()),
981 typeName}, new String[]{
982 new String(sourceType.sourceName()),
983 shortTypeName}, start, end);
985 this.handle(IProblem.HierarchyCircularity, new String[]{
986 new String(sourceType.sourceName()), typeName},
987 new String[]{new String(sourceType.sourceName()),
988 shortTypeName}, start, end);
990 public void hierarchyHasProblems(SourceTypeBinding type) {
991 String[] arguments = new String[]{new String(type.sourceName())};
992 this.handle(IProblem.HierarchyHasProblems, arguments, arguments, type
993 .sourceStart(), type.sourceEnd());
995 public void illegalAbstractModifierCombinationForMethod(
996 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
997 String[] arguments = new String[]{new String(type.sourceName()),
998 new String(methodDecl.selector)};
999 this.handle(IProblem.IllegalAbstractModifierCombinationForMethod,
1000 arguments, arguments, methodDecl.sourceStart,
1001 methodDecl.sourceEnd);
1003 public void illegalModifierCombinationFinalAbstractForClass(
1004 SourceTypeBinding type) {
1005 String[] arguments = new String[]{new String(type.sourceName())};
1006 this.handle(IProblem.IllegalModifierCombinationFinalAbstractForClass,
1007 arguments, arguments, type.sourceStart(), type.sourceEnd());
1009 public void illegalModifierCombinationFinalVolatileForField(
1010 ReferenceBinding type, FieldDeclaration fieldDecl) {
1011 String[] arguments = new String[]{fieldDecl.name()};
1012 this.handle(IProblem.IllegalModifierCombinationFinalVolatileForField,
1013 arguments, arguments, fieldDecl.sourceStart,
1014 fieldDecl.sourceEnd);
1016 public void illegalModifierForClass(SourceTypeBinding type) {
1017 String[] arguments = new String[]{new String(type.sourceName())};
1018 this.handle(IProblem.IllegalModifierForClass, arguments, arguments,
1019 type.sourceStart(), type.sourceEnd());
1021 public void illegalModifierForField(ReferenceBinding type,
1022 FieldDeclaration fieldDecl) {
1023 String[] arguments = new String[]{fieldDecl.name()};
1024 this.handle(IProblem.IllegalModifierForField, arguments, arguments,
1025 fieldDecl.sourceStart, fieldDecl.sourceEnd);
1027 public void illegalModifierForInterface(SourceTypeBinding type) {
1028 String[] arguments = new String[]{new String(type.sourceName())};
1029 this.handle(IProblem.IllegalModifierForInterface, arguments, arguments,
1030 type.sourceStart(), type.sourceEnd());
1032 public void illegalModifierForInterfaceField(ReferenceBinding type,
1033 FieldDeclaration fieldDecl) {
1034 String[] arguments = new String[]{fieldDecl.name()};
1035 this.handle(IProblem.IllegalModifierForInterfaceField, arguments,
1036 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1038 public void illegalModifierForInterfaceMethod(ReferenceBinding type,
1039 AbstractMethodDeclaration methodDecl) {
1040 String[] arguments = new String[]{new String(type.sourceName()),
1041 new String(methodDecl.selector)};
1042 this.handle(IProblem.IllegalModifierForInterfaceMethod, arguments,
1043 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1045 public void illegalModifierForLocalClass(SourceTypeBinding type) {
1046 String[] arguments = new String[]{new String(type.sourceName())};
1047 this.handle(IProblem.IllegalModifierForLocalClass, arguments,
1048 arguments, type.sourceStart(), type.sourceEnd());
1050 public void illegalModifierForMemberClass(SourceTypeBinding type) {
1051 String[] arguments = new String[]{new String(type.sourceName())};
1052 this.handle(IProblem.IllegalModifierForMemberClass, arguments,
1053 arguments, type.sourceStart(), type.sourceEnd());
1055 public void illegalModifierForMemberInterface(SourceTypeBinding type) {
1056 String[] arguments = new String[]{new String(type.sourceName())};
1057 this.handle(IProblem.IllegalModifierForMemberInterface, arguments,
1058 arguments, type.sourceStart(), type.sourceEnd());
1060 public void illegalModifierForMethod(ReferenceBinding type,
1061 AbstractMethodDeclaration methodDecl) {
1062 String[] arguments = new String[]{new String(type.sourceName()),
1063 new String(methodDecl.selector)};
1064 this.handle(IProblem.IllegalModifierForMethod, arguments, arguments,
1065 methodDecl.sourceStart, methodDecl.sourceEnd);
1067 public void illegalModifierForVariable(LocalDeclaration localDecl,
1068 boolean complainAsArgument) {
1069 String[] arguments = new String[]{localDecl.name()};
1070 this.handle(complainAsArgument
1071 ? IProblem.IllegalModifierForArgument
1072 : IProblem.IllegalModifierForVariable, arguments, arguments,
1073 localDecl.sourceStart, localDecl.sourceEnd);
1075 public void illegalPrimitiveOrArrayTypeForEnclosingInstance(
1076 TypeBinding enclosingType, AstNode location) {
1077 this.handle(IProblem.IllegalPrimitiveOrArrayTypeForEnclosingInstance,
1078 new String[]{new String(enclosingType.readableName())},
1079 new String[]{new String(enclosingType.shortReadableName())},
1080 location.sourceStart, location.sourceEnd);
1082 public void illegalStaticModifierForMemberType(SourceTypeBinding type) {
1083 String[] arguments = new String[]{new String(type.sourceName())};
1084 this.handle(IProblem.IllegalStaticModifierForMemberType, arguments,
1085 arguments, type.sourceStart(), type.sourceEnd());
1087 public void illegalVisibilityModifierCombinationForField(
1088 ReferenceBinding type, FieldDeclaration fieldDecl) {
1089 String[] arguments = new String[]{new String(fieldDecl.name())};
1090 this.handle(IProblem.IllegalVisibilityModifierCombinationForField,
1091 arguments, arguments, fieldDecl.sourceStart,
1092 fieldDecl.sourceEnd);
1094 public void illegalVisibilityModifierCombinationForMemberType(
1095 SourceTypeBinding type) {
1096 String[] arguments = new String[]{new String(type.sourceName())};
1097 this.handle(IProblem.IllegalVisibilityModifierCombinationForMemberType,
1098 arguments, arguments, type.sourceStart(), type.sourceEnd());
1100 public void illegalVisibilityModifierCombinationForMethod(
1101 ReferenceBinding type, AbstractMethodDeclaration methodDecl) {
1102 String[] arguments = new String[]{new String(type.sourceName()),
1103 new String(methodDecl.selector)};
1104 this.handle(IProblem.IllegalVisibilityModifierCombinationForMethod,
1105 arguments, arguments, methodDecl.sourceStart,
1106 methodDecl.sourceEnd);
1108 public void illegalVisibilityModifierForInterfaceMemberType(
1109 SourceTypeBinding type) {
1110 String[] arguments = new String[]{new String(type.sourceName())};
1111 this.handle(IProblem.IllegalVisibilityModifierForInterfaceMemberType,
1112 arguments, arguments, type.sourceStart(), type.sourceEnd());
1114 public void illegalVoidExpression(AstNode location) {
1115 this.handle(IProblem.InvalidVoidExpression, NoArgument, NoArgument,
1116 location.sourceStart, location.sourceEnd);
1118 public void importProblem(ImportReference importRef, Binding expectedImport) {
1119 int problemId = expectedImport.problemId();
1121 switch (problemId) {
1124 id = IProblem.ImportNotFound;
1128 id = IProblem.ImportNotVisible;
1132 id = IProblem.ImportAmbiguous;
1134 case InternalNameProvided :
1136 id = IProblem.ImportInternalNameProvided;
1138 case InheritedNameHidesEnclosingName :
1140 id = IProblem.ImportInheritedNameHidesEnclosingName;
1145 needImplementation(); // want to fail to see why we were
1150 if (expectedImport instanceof ProblemReferenceBinding) {
1151 argument = CharOperation
1152 .toString(((ProblemReferenceBinding) expectedImport).compoundName);
1154 argument = CharOperation.toString(importRef.tokens);
1156 String[] arguments = new String[]{argument};
1157 this.handle(id, arguments, arguments, importRef.sourceStart,
1158 importRef.sourceEnd);
1160 public void incompatibleExceptionInThrowsClause(SourceTypeBinding type,
1161 MethodBinding currentMethod, MethodBinding inheritedMethod,
1162 ReferenceBinding exceptionType) {
1163 if (type == currentMethod.declaringClass) {
1165 if (currentMethod.declaringClass.isInterface()
1166 && !inheritedMethod.isPublic()) { // interface inheriting
1169 id = IProblem.IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod;
1171 id = IProblem.IncompatibleExceptionInThrowsClause;
1175 // Exception %1 is not compatible with throws
1177 // 9.4.4 - The type of exception in the throws
1178 // clause is incompatible.
1181 new String(exceptionType.sourceName()),
1185 inheritedMethod.declaringClass
1191 new String(exceptionType.sourceName()),
1195 inheritedMethod.declaringClass
1196 .shortReadableName(),
1198 .shortReadableName(),
1200 currentMethod.sourceStart(), currentMethod
1205 // Exception %1 in throws clause of %2 is not
1206 // compatible with %3
1207 // 9.4.4 - The type of exception in the throws
1208 // clause is incompatible.
1209 IProblem.IncompatibleExceptionInInheritedMethodThrowsClause,
1211 new String(exceptionType.sourceName()),
1212 new String(CharOperation.concat(
1213 currentMethod.declaringClass
1215 currentMethod.readableName(), '.')),
1219 inheritedMethod.declaringClass
1225 new String(exceptionType.sourceName()),
1226 new String(CharOperation.concat(
1227 currentMethod.declaringClass
1229 currentMethod.shortReadableName(),
1234 inheritedMethod.declaringClass
1235 .shortReadableName(),
1237 .shortReadableName(),
1239 .sourceStart(), type.sourceEnd());
1241 public void incompatibleReturnType(MethodBinding currentMethod,
1242 MethodBinding inheritedMethod) {
1243 StringBuffer methodSignature = new StringBuffer();
1244 methodSignature.append(inheritedMethod.declaringClass.readableName())
1245 .append('.').append(inheritedMethod.readableName());
1246 StringBuffer shortSignature = new StringBuffer();
1247 shortSignature.append(
1248 inheritedMethod.declaringClass.shortReadableName()).append('.')
1249 .append(inheritedMethod.shortReadableName());
1251 if (currentMethod.declaringClass.isInterface()
1252 && !inheritedMethod.isPublic()) { // interface inheriting
1253 // Object protected method
1254 id = IProblem.IncompatibleReturnTypeForNonInheritedInterfaceMethod;
1256 id = IProblem.IncompatibleReturnType;
1258 this.handle(id, new String[]{methodSignature.toString()},
1259 new String[]{shortSignature.toString()}, currentMethod
1260 .sourceStart(), currentMethod.sourceEnd());
1262 public void incorrectLocationForEmptyDimension(
1263 ArrayAllocationExpression expression, int index) {
1264 this.handle(IProblem.IllegalDimension, NoArgument, NoArgument,
1265 expression.dimensions[index + 1].sourceStart,
1266 expression.dimensions[index + 1].sourceEnd);
1268 public void incorrectSwitchType(Expression expression, TypeBinding testType) {
1269 this.handle(IProblem.IncorrectSwitchType, new String[]{new String(
1270 testType.readableName())}, new String[]{new String(testType
1271 .shortReadableName())}, expression.sourceStart,
1272 expression.sourceEnd);
1274 public void inheritedMethodReducesVisibility(SourceTypeBinding type,
1275 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
1276 StringBuffer concreteSignature = new StringBuffer();
1277 concreteSignature.append(concreteMethod.declaringClass.readableName())
1278 .append('.').append(concreteMethod.readableName());
1279 StringBuffer shortSignature = new StringBuffer();
1281 .append(concreteMethod.declaringClass.shortReadableName())
1282 .append('.').append(concreteMethod.shortReadableName());
1284 // The inherited method %1 cannot hide the public abstract method in %2
1285 IProblem.InheritedMethodReducesVisibility, new String[]{
1286 new String(concreteSignature.toString()),
1287 new String(abstractMethods[0].declaringClass
1288 .readableName())}, new String[]{
1289 new String(shortSignature.toString()),
1290 new String(abstractMethods[0].declaringClass
1291 .shortReadableName())}, type.sourceStart(),
1294 public void inheritedMethodsHaveIncompatibleReturnTypes(
1295 SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
1296 StringBuffer methodSignatures = new StringBuffer();
1297 StringBuffer shortSignatures = new StringBuffer();
1298 for (int i = length; --i >= 0;) {
1299 methodSignatures.append(
1300 inheritedMethods[i].declaringClass.readableName()).append(
1301 '.').append(inheritedMethods[i].readableName());
1302 shortSignatures.append(
1303 inheritedMethods[i].declaringClass.shortReadableName())
1305 .append(inheritedMethods[i].shortReadableName());
1307 methodSignatures.append(", "); //$NON-NLS-1$
1308 shortSignatures.append(", "); //$NON-NLS-1$
1312 // Return type is incompatible with %1
1313 // 9.4.2 - The return type from the method is incompatible with
1315 IProblem.IncompatibleReturnType, new String[]{methodSignatures
1316 .toString()}, new String[]{shortSignatures.toString()},
1317 type.sourceStart(), type.sourceEnd());
1319 public void initializerMustCompleteNormally(FieldDeclaration fieldDecl) {
1320 this.handle(IProblem.InitializerMustCompleteNormally, NoArgument,
1321 NoArgument, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1323 public void innerTypesCannotDeclareStaticInitializers(
1324 ReferenceBinding innerType, AstNode location) {
1325 this.handle(IProblem.CannotDefineStaticInitializerInLocalType,
1326 new String[]{new String(innerType.readableName())},
1327 new String[]{new String(innerType.shortReadableName())},
1328 location.sourceStart, location.sourceEnd);
1330 public void interfaceCannotHaveConstructors(
1331 ConstructorDeclaration constructor) {
1332 this.handle(IProblem.InterfaceCannotHaveConstructors, NoArgument,
1333 NoArgument, constructor.sourceStart, constructor.sourceEnd,
1334 constructor, constructor.compilationResult());
1336 public void interfaceCannotHaveInitializers(SourceTypeBinding type,
1337 FieldDeclaration fieldDecl) {
1338 String[] arguments = new String[]{new String(type.sourceName())};
1339 this.handle(IProblem.InterfaceCannotHaveInitializers, arguments,
1340 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
1342 public void invalidBreak(AstNode location) {
1343 this.handle(IProblem.InvalidBreak, NoArgument, NoArgument,
1344 location.sourceStart, location.sourceEnd);
1346 public void invalidConstructor(Statement statement,
1347 MethodBinding targetConstructor) {
1348 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
1349 && ((ConstructorDeclaration) referenceContext)
1350 .isDefaultConstructor();
1351 boolean insideImplicitConstructorCall = (statement instanceof ExplicitConstructorCall)
1352 && (((ExplicitConstructorCall) statement).accessMode == ExplicitConstructorCall.ImplicitSuper);
1353 int flag = IProblem.UndefinedConstructor; //default...
1354 switch (targetConstructor.problemId()) {
1356 if (insideDefaultConstructor) {
1357 flag = IProblem.UndefinedConstructorInDefaultConstructor;
1358 } else if (insideImplicitConstructorCall) {
1359 flag = IProblem.UndefinedConstructorInImplicitConstructorCall;
1361 flag = IProblem.UndefinedConstructor;
1365 if (insideDefaultConstructor) {
1366 flag = IProblem.NotVisibleConstructorInDefaultConstructor;
1367 } else if (insideImplicitConstructorCall) {
1368 flag = IProblem.NotVisibleConstructorInImplicitConstructorCall;
1370 flag = IProblem.NotVisibleConstructor;
1374 if (insideDefaultConstructor) {
1375 flag = IProblem.AmbiguousConstructorInDefaultConstructor;
1376 } else if (insideImplicitConstructorCall) {
1377 flag = IProblem.AmbiguousConstructorInImplicitConstructorCall;
1379 flag = IProblem.AmbiguousConstructor;
1385 needImplementation(); // want to fail to see why we were
1389 this.handle(flag, new String[]{
1390 new String(targetConstructor.declaringClass.readableName()),
1391 parametersAsString(targetConstructor)},
1393 new String(targetConstructor.declaringClass
1394 .shortReadableName()),
1395 parametersAsShortString(targetConstructor)},
1396 statement.sourceStart, statement.sourceEnd);
1398 public void invalidContinue(AstNode location) {
1399 this.handle(IProblem.InvalidContinue, NoArgument, NoArgument,
1400 location.sourceStart, location.sourceEnd);
1402 public void invalidEnclosingType(Expression expression, TypeBinding type,
1403 ReferenceBinding enclosingType) {
1404 if (enclosingType.isAnonymousType())
1405 enclosingType = enclosingType.superclass();
1406 int flag = IProblem.UndefinedType; // default
1407 switch (type.problemId()) {
1410 flag = IProblem.UndefinedType;
1414 flag = IProblem.NotVisibleType;
1418 flag = IProblem.AmbiguousType;
1420 case InternalNameProvided :
1421 flag = IProblem.InternalTypeNameProvided;
1426 needImplementation(); // want to fail to see why we were
1430 this.handle(flag, new String[]{new String(enclosingType.readableName())
1431 + "." + new String(type.readableName())}, //$NON-NLS-1$
1432 new String[]{new String(enclosingType.shortReadableName())
1433 + "." + new String(type.shortReadableName())}, //$NON-NLS-1$
1434 expression.sourceStart, expression.sourceEnd);
1436 public void invalidExpressionAsStatement(Expression expression) {
1437 this.handle(IProblem.InvalidExpressionAsStatement, NoArgument,
1438 NoArgument, expression.sourceStart, expression.sourceEnd);
1440 public void invalidField(FieldReference fieldRef, TypeBinding searchedType) {
1441 int severity = Error;
1442 int flag = IProblem.UndefinedField;
1443 FieldBinding field = fieldRef.binding;
1444 switch (field.problemId()) {
1446 flag = IProblem.UndefinedField;
1448 * also need to check that the searchedType is the receiver
1449 * type if (searchedType.isHierarchyInconsistent()) severity =
1454 flag = IProblem.NotVisibleField;
1457 flag = IProblem.AmbiguousField;
1459 case NonStaticReferenceInStaticContext :
1460 flag = IProblem.NonStaticFieldFromStaticInvocation;
1462 case NonStaticReferenceInConstructorInvocation :
1463 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1465 case InheritedNameHidesEnclosingName :
1466 flag = IProblem.InheritedFieldHidesEnclosingName;
1468 case ReceiverTypeNotVisible :
1469 this.handle(IProblem.NotVisibleType, new String[]{new String(
1470 searchedType.leafComponentType().readableName())},
1471 new String[]{new String(searchedType
1472 .leafComponentType().shortReadableName())},
1473 fieldRef.receiver.sourceStart,
1474 fieldRef.receiver.sourceEnd);
1479 needImplementation(); // want to fail to see why we were
1483 String[] arguments = new String[]{new String(field.readableName())};
1484 this.handle(flag, arguments, arguments, severity, fieldRef.sourceStart,
1485 fieldRef.sourceEnd);
1487 public void invalidField(NameReference nameRef, FieldBinding field) {
1488 int flag = IProblem.UndefinedField;
1489 switch (field.problemId()) {
1491 flag = IProblem.UndefinedField;
1494 flag = IProblem.NotVisibleField;
1497 flag = IProblem.AmbiguousField;
1499 case NonStaticReferenceInStaticContext :
1500 flag = IProblem.NonStaticFieldFromStaticInvocation;
1502 case NonStaticReferenceInConstructorInvocation :
1503 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1505 case InheritedNameHidesEnclosingName :
1506 flag = IProblem.InheritedFieldHidesEnclosingName;
1508 case ReceiverTypeNotVisible :
1509 this.handle(IProblem.NotVisibleType,
1510 new String[]{new String(field.declaringClass
1511 .leafComponentType().readableName())},
1512 new String[]{new String(field.declaringClass
1513 .leafComponentType().shortReadableName())},
1514 nameRef.sourceStart, nameRef.sourceEnd);
1519 needImplementation(); // want to fail to see why we were
1523 String[] arguments = new String[]{new String(field.readableName())};
1524 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1527 public void invalidField(QualifiedNameReference nameRef,
1528 FieldBinding field, int index, TypeBinding searchedType) {
1529 //the resolution of the index-th field of qname failed
1530 //qname.otherBindings[index] is the binding that has produced the
1532 //The different targetted errors should be :
1536 if (searchedType.isBaseType()) {
1537 this.handle(IProblem.NoFieldOnBaseType, new String[]{
1538 new String(searchedType.readableName()),
1539 CharOperation.toString(CharOperation.subarray(
1540 nameRef.tokens, 0, index)),
1541 new String(nameRef.tokens[index])}, new String[]{
1542 new String(searchedType.sourceName()),
1543 CharOperation.toString(CharOperation.subarray(
1544 nameRef.tokens, 0, index)),
1545 new String(nameRef.tokens[index])}, nameRef.sourceStart,
1549 int flag = IProblem.UndefinedField;
1550 switch (field.problemId()) {
1552 flag = IProblem.UndefinedField;
1554 * also need to check that the searchedType is the receiver
1555 * type if (searchedType.isHierarchyInconsistent()) severity =
1560 flag = IProblem.NotVisibleField;
1563 flag = IProblem.AmbiguousField;
1565 case NonStaticReferenceInStaticContext :
1566 flag = IProblem.NonStaticFieldFromStaticInvocation;
1568 case NonStaticReferenceInConstructorInvocation :
1569 flag = IProblem.InstanceFieldDuringConstructorInvocation;
1571 case InheritedNameHidesEnclosingName :
1572 flag = IProblem.InheritedFieldHidesEnclosingName;
1574 case ReceiverTypeNotVisible :
1575 this.handle(IProblem.NotVisibleType, new String[]{new String(
1576 searchedType.leafComponentType().readableName())},
1577 new String[]{new String(searchedType
1578 .leafComponentType().shortReadableName())},
1579 nameRef.sourceStart, nameRef.sourceEnd);
1584 needImplementation(); // want to fail to see why we were
1588 String[] arguments = new String[]{CharOperation.toString(CharOperation
1589 .subarray(nameRef.tokens, 0, index + 1))};
1590 this.handle(flag, arguments, arguments, nameRef.sourceStart,
1593 public void invalidMethod(MessageSend messageSend, MethodBinding method) {
1594 // CODE should be UPDATED according to error coding in the different
1595 // method binding errors
1596 // The different targetted errors should be :
1600 // InheritedNameHidesEnclosingName
1601 // InstanceMethodDuringConstructorInvocation
1602 // StaticMethodRequested
1603 int flag = IProblem.UndefinedMethod; //default...
1604 switch (method.problemId()) {
1606 flag = IProblem.UndefinedMethod;
1609 flag = IProblem.NotVisibleMethod;
1612 flag = IProblem.AmbiguousMethod;
1614 case InheritedNameHidesEnclosingName :
1615 flag = IProblem.InheritedMethodHidesEnclosingName;
1617 case NonStaticReferenceInConstructorInvocation :
1618 flag = IProblem.InstanceMethodDuringConstructorInvocation;
1620 case NonStaticReferenceInStaticContext :
1621 flag = IProblem.StaticMethodRequested;
1623 case ReceiverTypeNotVisible :
1624 this.handle(IProblem.NotVisibleType, new String[]{new String(
1625 method.declaringClass.leafComponentType()
1626 .readableName())}, new String[]{new String(
1627 method.declaringClass.leafComponentType()
1628 .shortReadableName())},
1629 messageSend.receiver.sourceStart,
1630 messageSend.receiver.sourceEnd);
1635 needImplementation(); // want to fail to see why we were
1639 if (flag == IProblem.UndefinedMethod) {
1640 ProblemMethodBinding problemMethod = (ProblemMethodBinding) method;
1641 if (problemMethod.closestMatch != null) {
1642 String closestParameterTypeNames = parametersAsString(problemMethod.closestMatch);
1643 String parameterTypeNames = parametersAsString(method);
1644 String closestParameterTypeShortNames = parametersAsShortString(problemMethod.closestMatch);
1645 String parameterTypeShortNames = parametersAsShortString(method);
1646 if (closestParameterTypeShortNames
1647 .equals(parameterTypeShortNames)) {
1648 closestParameterTypeShortNames = closestParameterTypeNames;
1649 parameterTypeShortNames = parameterTypeNames;
1653 IProblem.ParameterMismatch,
1656 problemMethod.closestMatch.declaringClass
1659 problemMethod.closestMatch.selector),
1660 closestParameterTypeNames,
1661 parameterTypeNames},
1664 problemMethod.closestMatch.declaringClass
1665 .shortReadableName()),
1667 problemMethod.closestMatch.selector),
1668 closestParameterTypeShortNames,
1669 parameterTypeShortNames},
1670 (int) (messageSend.nameSourcePosition >>> 32),
1671 (int) messageSend.nameSourcePosition);
1675 this.handle(flag, new String[]{
1676 new String(method.declaringClass.readableName()),
1677 new String(method.selector), parametersAsString(method)},
1679 new String(method.declaringClass.shortReadableName()),
1680 new String(method.selector),
1681 parametersAsShortString(method)},
1682 (int) (messageSend.nameSourcePosition >>> 32),
1683 (int) messageSend.nameSourcePosition);
1685 public void invalidNullToSynchronize(Expression expression) {
1686 this.handle(IProblem.InvalidNullToSynchronized, NoArgument, NoArgument,
1687 expression.sourceStart, expression.sourceEnd);
1689 public void invalidOperator(BinaryExpression expression,
1690 TypeBinding leftType, TypeBinding rightType) {
1691 String leftName = new String(leftType.readableName());
1692 String rightName = new String(rightType.readableName());
1693 String leftShortName = new String(leftType.shortReadableName());
1694 String rightShortName = new String(rightType.shortReadableName());
1695 if (leftShortName.equals(rightShortName)) {
1696 leftShortName = leftName;
1697 rightShortName = rightName;
1699 this.handle(IProblem.InvalidOperator, new String[]{
1700 expression.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1701 new String[]{expression.operatorToString(),
1702 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1703 expression.sourceStart, expression.sourceEnd);
1705 public void invalidOperator(CompoundAssignment assign,
1706 TypeBinding leftType, TypeBinding rightType) {
1707 String leftName = new String(leftType.readableName());
1708 String rightName = new String(rightType.readableName());
1709 String leftShortName = new String(leftType.shortReadableName());
1710 String rightShortName = new String(rightType.shortReadableName());
1711 if (leftShortName.equals(rightShortName)) {
1712 leftShortName = leftName;
1713 rightShortName = rightName;
1715 this.handle(IProblem.InvalidOperator, new String[]{
1716 assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$
1717 new String[]{assign.operatorToString(),
1718 leftShortName + ", " + rightShortName}, //$NON-NLS-1$
1719 assign.sourceStart, assign.sourceEnd);
1721 public void invalidOperator(UnaryExpression expression, TypeBinding type) {
1722 this.handle(IProblem.InvalidOperator,
1723 new String[]{expression.operatorToString(),
1724 new String(type.readableName())}, new String[]{
1725 expression.operatorToString(),
1726 new String(type.shortReadableName())},
1727 expression.sourceStart, expression.sourceEnd);
1729 public void invalidParenthesizedExpression(AstNode reference) {
1730 this.handle(IProblem.InvalidParenthesizedExpression, NoArgument,
1731 NoArgument, reference.sourceStart, reference.sourceEnd);
1733 public void invalidSuperclass(SourceTypeBinding type,
1734 TypeReference superclassRef, ReferenceBinding expectedType) {
1735 int problemId = expectedType.problemId();
1737 switch (problemId) {
1740 id = IProblem.SuperclassNotFound;
1744 id = IProblem.SuperclassNotVisible;
1748 id = IProblem.SuperclassAmbiguous;
1750 case InternalNameProvided :
1752 id = IProblem.SuperclassInternalNameProvided;
1754 case InheritedNameHidesEnclosingName :
1756 id = IProblem.SuperclassInheritedNameHidesEnclosingName;
1761 needImplementation(); // want to fail to see why we were
1765 this.handle(id, new String[]{new String(expectedType.readableName()),
1766 new String(type.sourceName())}, new String[]{
1767 new String(expectedType.shortReadableName()),
1768 new String(type.sourceName())}, superclassRef.sourceStart,
1769 superclassRef.sourceEnd);
1771 public void invalidSuperinterface(SourceTypeBinding type,
1772 TypeReference superinterfaceRef, ReferenceBinding expectedType) {
1773 int problemId = expectedType.problemId();
1775 switch (problemId) {
1778 id = IProblem.InterfaceNotFound;
1782 id = IProblem.InterfaceNotVisible;
1786 id = IProblem.InterfaceAmbiguous;
1788 case InternalNameProvided :
1790 id = IProblem.InterfaceInternalNameProvided;
1792 case InheritedNameHidesEnclosingName :
1794 id = IProblem.InterfaceInheritedNameHidesEnclosingName;
1799 needImplementation(); // want to fail to see why we were
1803 this.handle(id, new String[]{new String(expectedType.readableName()),
1804 new String(type.sourceName())}, new String[]{
1805 new String(expectedType.shortReadableName()),
1806 new String(type.sourceName())}, superinterfaceRef.sourceStart,
1807 superinterfaceRef.sourceEnd);
1809 public void invalidType(AstNode location, TypeBinding type) {
1810 int flag = IProblem.UndefinedType; // default
1811 switch (type.problemId()) {
1813 flag = IProblem.UndefinedType;
1816 flag = IProblem.NotVisibleType;
1819 flag = IProblem.AmbiguousType;
1821 case InternalNameProvided :
1822 flag = IProblem.InternalTypeNameProvided;
1824 case InheritedNameHidesEnclosingName :
1825 flag = IProblem.InheritedTypeHidesEnclosingName;
1830 needImplementation(); // want to fail to see why we were
1834 this.handle(flag, new String[]{new String(type.readableName())},
1835 new String[]{new String(type.shortReadableName())},
1836 location.sourceStart, location.sourceEnd);
1838 public void invalidTypeReference(Expression expression) {
1839 this.handle(IProblem.InvalidTypeExpression, NoArgument, NoArgument,
1840 expression.sourceStart, expression.sourceEnd);
1842 public void invalidTypeToSynchronize(Expression expression, TypeBinding type) {
1843 this.handle(IProblem.InvalidTypeToSynchronized,
1844 new String[]{new String(type.readableName())},
1845 new String[]{new String(type.shortReadableName())},
1846 expression.sourceStart, expression.sourceEnd);
1848 public void invalidUnaryExpression(Expression expression) {
1849 this.handle(IProblem.InvalidUnaryExpression, NoArgument, NoArgument,
1850 expression.sourceStart, expression.sourceEnd);
1852 public void isClassPathCorrect(char[][] wellKnownTypeName,
1853 CompilationUnitDeclaration compUnitDecl) {
1854 referenceContext = compUnitDecl;
1855 String[] arguments = new String[]{CharOperation
1856 .toString(wellKnownTypeName)};
1857 this.handle(IProblem.IsClassPathCorrect, arguments, arguments,
1858 AbortCompilation | Error, compUnitDecl == null
1860 : compUnitDecl.sourceStart, compUnitDecl == null
1862 : compUnitDecl.sourceEnd);
1864 public void maskedExceptionHandler(ReferenceBinding exceptionType,
1866 this.handle(IProblem.MaskedCatch, NoArgument, NoArgument,
1867 location.sourceStart, location.sourceEnd);
1869 public void methodNeedingAbstractModifier(MethodDeclaration methodDecl) {
1870 this.handle(IProblem.MethodRequiresBody, NoArgument, NoArgument,
1871 methodDecl.sourceStart, methodDecl.sourceEnd);
1873 public void methodNeedingNoBody(MethodDeclaration methodDecl) {
1875 // ((methodDecl.modifiers & CompilerModifiers.AccNative) != 0) ?
1876 // IProblem.BodyForNativeMethod : IProblem.BodyForAbstractMethod,
1877 IProblem.BodyForAbstractMethod, NoArgument, NoArgument,
1878 methodDecl.sourceStart, methodDecl.sourceEnd);
1880 public void methodWithConstructorName(MethodDeclaration methodDecl) {
1881 this.handle(IProblem.MethodButWithConstructorName, NoArgument,
1882 NoArgument, methodDecl.sourceStart, methodDecl.sourceEnd);
1884 //public void missingEnclosingInstanceSpecification(ReferenceBinding
1885 // enclosingType, AstNode location) {
1886 // boolean insideConstructorCall =
1887 // (location instanceof ExplicitConstructorCall)
1888 // && (((ExplicitConstructorCall) location).accessMode ==
1889 // ExplicitConstructorCall.ImplicitSuper);
1892 // insideConstructorCall
1893 // ? IProblem.MissingEnclosingInstanceForConstructorCall
1894 // : IProblem.MissingEnclosingInstance,
1895 // new String[] {new String(enclosingType.readableName())},
1896 // new String[] {new String(enclosingType.shortReadableName())},
1897 // location.sourceStart,
1898 // location.sourceEnd);
1900 public void missingReturnType(AbstractMethodDeclaration methodDecl) {
1901 this.handle(IProblem.MissingReturnType, NoArgument, NoArgument,
1902 methodDecl.sourceStart, methodDecl.sourceEnd);
1904 public void missingSemiColon(Expression expression) {
1905 this.handle(IProblem.MissingSemiColon, NoArgument, NoArgument,
1906 expression.sourceStart, expression.sourceEnd);
1908 public void mustDefineDimensionsOrInitializer(
1909 ArrayAllocationExpression expression) {
1910 this.handle(IProblem.MustDefineEitherDimensionExpressionsOrInitializer,
1911 NoArgument, NoArgument, expression.sourceStart,
1912 expression.sourceEnd);
1914 public void mustSpecifyPackage(CompilationUnitDeclaration compUnitDecl) {
1915 String[] arguments = new String[]{new String(compUnitDecl.getFileName())};
1916 this.handle(IProblem.MustSpecifyPackage, arguments, arguments,
1917 compUnitDecl.sourceStart, compUnitDecl.sourceStart + 1);
1919 public void mustUseAStaticMethod(MessageSend messageSend,
1920 MethodBinding method) {
1921 this.handle(IProblem.StaticMethodRequested, new String[]{
1922 new String(method.declaringClass.readableName()),
1923 new String(method.selector), parametersAsString(method)},
1925 new String(method.declaringClass.shortReadableName()),
1926 new String(method.selector),
1927 parametersAsShortString(method)},
1928 messageSend.sourceStart, messageSend.sourceEnd);
1930 public void nativeMethodsCannotBeStrictfp(ReferenceBinding type,
1931 AbstractMethodDeclaration methodDecl) {
1932 String[] arguments = new String[]{new String(type.sourceName()),
1933 new String(methodDecl.selector)};
1934 this.handle(IProblem.NativeMethodsCannotBeStrictfp, arguments,
1935 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
1937 public void needImplementation() {
1938 this.abortDueToInternalError(Util.bind("abort.missingCode")); //$NON-NLS-1$
1940 public void needToEmulateFieldReadAccess(FieldBinding field,
1942 this.handle(IProblem.NeedToEmulateFieldReadAccess, new String[]{
1943 new String(field.declaringClass.readableName()),
1944 new String(field.name)}, new String[]{
1945 new String(field.declaringClass.shortReadableName()),
1946 new String(field.name)}, location.sourceStart,
1947 location.sourceEnd);
1949 public void needToEmulateFieldWriteAccess(FieldBinding field,
1951 this.handle(IProblem.NeedToEmulateFieldWriteAccess, new String[]{
1952 new String(field.declaringClass.readableName()),
1953 new String(field.name)}, new String[]{
1954 new String(field.declaringClass.shortReadableName()),
1955 new String(field.name)}, location.sourceStart,
1956 location.sourceEnd);
1958 public void needToEmulateMethodAccess(MethodBinding method, AstNode location) {
1959 if (method.isConstructor())
1960 this.handle(IProblem.NeedToEmulateConstructorAccess, new String[]{
1961 new String(method.declaringClass.readableName()),
1962 parametersAsString(method)}, new String[]{
1963 new String(method.declaringClass.shortReadableName()),
1964 parametersAsShortString(method)}, location.sourceStart,
1965 location.sourceEnd);
1967 this.handle(IProblem.NeedToEmulateMethodAccess, new String[]{
1968 new String(method.declaringClass.readableName()),
1969 new String(method.selector), parametersAsString(method)},
1971 new String(method.declaringClass
1972 .shortReadableName()),
1973 new String(method.selector),
1974 parametersAsShortString(method)},
1975 location.sourceStart, location.sourceEnd);
1977 public void nestedClassCannotDeclareInterface(TypeDeclaration typeDecl) {
1978 String[] arguments = new String[]{new String(typeDecl.name)};
1979 this.handle(IProblem.CannotDefineInterfaceInLocalType, arguments,
1980 arguments, typeDecl.sourceStart, typeDecl.sourceEnd);
1982 public void noMoreAvailableSpaceForArgument(LocalVariableBinding local,
1984 String[] arguments = new String[]{new String(local.name)};
1985 this.handle(local instanceof SyntheticArgumentBinding
1986 ? IProblem.TooManySyntheticArgumentSlots
1987 : IProblem.TooManyArgumentSlots, arguments, arguments, Abort
1988 | Error, location.sourceStart, location.sourceEnd);
1990 public void noMoreAvailableSpaceForLocal(LocalVariableBinding local,
1992 String[] arguments = new String[]{new String(local.name)};
1993 this.handle(IProblem.TooManyLocalVariableSlots, arguments, arguments,
1994 Abort | Error, location.sourceStart, location.sourceEnd);
1996 public void noSuchEnclosingInstance(TypeBinding targetType,
1997 AstNode location, boolean isConstructorCall) {
1999 if (isConstructorCall) {
2000 //28 = No enclosing instance of type {0} is available due to some
2001 // intermediate constructor invocation
2002 id = IProblem.EnclosingInstanceInConstructorCall;
2003 } else if ((location instanceof ExplicitConstructorCall)
2004 && ((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper) {
2005 //20 = No enclosing instance of type {0} is accessible to invoke
2006 // the super constructor. Must define a constructor and explicitly
2007 // qualify its super constructor invocation with an instance of {0}
2008 // (e.g. x.super() where x is an instance of {0}).
2009 id = IProblem.MissingEnclosingInstanceForConstructorCall;
2010 } else if (location instanceof AllocationExpression
2011 && (((AllocationExpression) location).binding.declaringClass
2012 .isMemberType() || (((AllocationExpression) location).binding.declaringClass
2013 .isAnonymousType() && ((AllocationExpression) location).binding.declaringClass
2014 .superclass().isMemberType()))) {
2015 //21 = No enclosing instance of type {0} is accessible. Must
2016 // qualify the allocation with an enclosing instance of type {0}
2017 // (e.g. x.new A() where x is an instance of {0}).
2018 id = IProblem.MissingEnclosingInstance;
2020 //22 = No enclosing instance of the type {0} is accessible in
2022 id = IProblem.IncorrectEnclosingInstanceReference;
2024 this.handle(id, new String[]{new String(targetType.readableName())},
2025 new String[]{new String(targetType.shortReadableName())},
2026 location.sourceStart, location.sourceEnd);
2028 public void notCompatibleTypesError(EqualExpression expression,
2029 TypeBinding leftType, TypeBinding rightType) {
2030 String leftName = new String(leftType.readableName());
2031 String rightName = new String(rightType.readableName());
2032 String leftShortName = new String(leftType.shortReadableName());
2033 String rightShortName = new String(rightType.shortReadableName());
2034 if (leftShortName.equals(rightShortName)) {
2035 leftShortName = leftName;
2036 rightShortName = rightName;
2038 this.handle(IProblem.IncompatibleTypesInEqualityOperator, new String[]{
2039 leftName, rightName}, new String[]{leftShortName,
2040 rightShortName}, expression.sourceStart, expression.sourceEnd);
2042 public void notCompatibleTypesError(InstanceOfExpression expression,
2043 TypeBinding leftType, TypeBinding rightType) {
2044 String leftName = new String(leftType.readableName());
2045 String rightName = new String(rightType.readableName());
2046 String leftShortName = new String(leftType.shortReadableName());
2047 String rightShortName = new String(rightType.shortReadableName());
2048 if (leftShortName.equals(rightShortName)) {
2049 leftShortName = leftName;
2050 rightShortName = rightName;
2052 this.handle(IProblem.IncompatibleTypesInConditionalOperator,
2053 new String[]{leftName, rightName}, new String[]{leftShortName,
2054 rightShortName}, expression.sourceStart,
2055 expression.sourceEnd);
2057 public void objectCannotHaveSuperTypes(SourceTypeBinding type) {
2058 this.handle(IProblem.ObjectCannotHaveSuperTypes, NoArgument,
2059 NoArgument, type.sourceStart(), type.sourceEnd());
2061 public void operatorOnlyValidOnNumericType(CompoundAssignment assignment,
2062 TypeBinding leftType, TypeBinding rightType) {
2063 String leftName = new String(leftType.readableName());
2064 String rightName = new String(rightType.readableName());
2065 String leftShortName = new String(leftType.shortReadableName());
2066 String rightShortName = new String(rightType.shortReadableName());
2067 if (leftShortName.equals(rightShortName)) {
2068 leftShortName = leftName;
2069 rightShortName = rightName;
2071 this.handle(IProblem.TypeMismatch, new String[]{leftName, rightName},
2072 new String[]{leftShortName, rightShortName},
2073 assignment.sourceStart, assignment.sourceEnd);
2075 public void overridesDeprecatedMethod(MethodBinding localMethod,
2076 MethodBinding inheritedMethod) {
2077 this.handle(IProblem.OverridingDeprecatedMethod, new String[]{
2078 new String(CharOperation.concat(localMethod.declaringClass
2079 .readableName(), localMethod.readableName(), '.')),
2080 new String(inheritedMethod.declaringClass.readableName())},
2082 new String(CharOperation.concat(
2083 localMethod.declaringClass.shortReadableName(),
2084 localMethod.shortReadableName(), '.')),
2085 new String(inheritedMethod.declaringClass
2086 .shortReadableName())}, localMethod
2087 .sourceStart(), localMethod.sourceEnd());
2089 public void overridesPackageDefaultMethod(MethodBinding localMethod,
2090 MethodBinding inheritedMethod) {
2091 this.handle(IProblem.OverridingNonVisibleMethod, new String[]{
2092 new String(CharOperation.concat(localMethod.declaringClass
2093 .readableName(), localMethod.readableName(), '.')),
2094 new String(inheritedMethod.declaringClass.readableName())},
2096 new String(CharOperation.concat(
2097 localMethod.declaringClass.shortReadableName(),
2098 localMethod.shortReadableName(), '.')),
2099 new String(inheritedMethod.declaringClass
2100 .shortReadableName())}, localMethod
2101 .sourceStart(), localMethod.sourceEnd());
2103 public void packageCollidesWithType(CompilationUnitDeclaration compUnitDecl) {
2104 String[] arguments = new String[]{CharOperation
2105 .toString(compUnitDecl.currentPackage.tokens)};
2106 this.handle(IProblem.PackageCollidesWithType, arguments, arguments,
2107 compUnitDecl.currentPackage.sourceStart,
2108 compUnitDecl.currentPackage.sourceEnd);
2110 public void packageIsNotExpectedPackage(
2111 CompilationUnitDeclaration compUnitDecl) {
2112 String[] arguments = new String[]{CharOperation
2113 .toString(compUnitDecl.compilationResult.compilationUnit
2114 .getPackageName())};
2115 this.handle(IProblem.PackageIsNotExpectedPackage, arguments, arguments,
2116 compUnitDecl.currentPackage == null
2118 : compUnitDecl.currentPackage.sourceStart,
2119 compUnitDecl.currentPackage == null
2121 : compUnitDecl.currentPackage.sourceEnd);
2123 private String parametersAsString(MethodBinding method) {
2124 TypeBinding[] params = method.parameters;
2125 StringBuffer buffer = new StringBuffer();
2126 for (int i = 0, length = params.length; i < length; i++) {
2128 buffer.append(", "); //$NON-NLS-1$
2129 buffer.append(new String(params[i].readableName()));
2131 return buffer.toString();
2133 private String parametersAsShortString(MethodBinding method) {
2134 TypeBinding[] params = method.parameters;
2135 StringBuffer buffer = new StringBuffer();
2136 for (int i = 0, length = params.length; i < length; i++) {
2138 buffer.append(", "); //$NON-NLS-1$
2139 buffer.append(new String(params[i].shortReadableName()));
2141 return buffer.toString();
2143 public void parseError(int startPosition, int endPosition,
2144 char[] currentTokenSource, String errorTokenName,
2145 String[] possibleTokens) {
2146 if (possibleTokens.length == 0) { //no suggestion available
2147 if (isKeyword(currentTokenSource)) {
2148 String[] arguments = new String[]{new String(currentTokenSource)};
2149 this.handle(IProblem.ParsingErrorOnKeywordNoSuggestion,
2150 arguments, arguments,
2151 // this is the current -invalid- token position
2152 startPosition, endPosition);
2155 String[] arguments = new String[]{errorTokenName};
2156 this.handle(IProblem.ParsingErrorNoSuggestion, arguments,
2158 // this is the current -invalid- token position
2159 startPosition, endPosition);
2163 //build a list of probable right tokens
2164 StringBuffer list = new StringBuffer(20);
2165 for (int i = 0, max = possibleTokens.length; i < max; i++) {
2167 list.append(", "); //$NON-NLS-1$
2169 list.append(possibleTokens[i]);
2172 if (isKeyword(currentTokenSource)) {
2173 String[] arguments = new String[]{new String(currentTokenSource),
2175 this.handle(IProblem.ParsingErrorOnKeyword, arguments, arguments,
2176 // this is the current -invalid- token position
2177 startPosition, endPosition);
2180 //extract the literal when it's a literal
2181 if ((errorTokenName.equals("IntegerLiteral")) || //$NON-NLS-1$
2182 (errorTokenName.equals("LongLiteral")) || //$NON-NLS-1$
2183 (errorTokenName.equals("FloatingPointLiteral")) || //$NON-NLS-1$
2184 (errorTokenName.equals("DoubleLiteral")) || //$NON-NLS-1$
2185 (errorTokenName.equals("StringLiteral")) || //$NON-NLS-1$
2186 (errorTokenName.equals("CharacterLiteral")) || //$NON-NLS-1$
2187 (errorTokenName.equals("Identifier"))) { //$NON-NLS-1$
2188 errorTokenName = new String(currentTokenSource);
2190 String[] arguments = new String[]{errorTokenName, list.toString()};
2191 this.handle(IProblem.ParsingError, arguments, arguments,
2192 // this is the current -invalid- token position
2193 startPosition, endPosition);
2195 public void publicClassMustMatchFileName(
2196 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2197 this.referenceContext = typeDecl; // report the problem against the
2198 // type not the entire compilation
2200 String[] arguments = new String[]{
2201 new String(compUnitDecl.getFileName()),
2202 new String(typeDecl.name)};
2203 this.handle(IProblem.PublicClassMustMatchFileName, arguments,
2204 arguments, typeDecl.sourceStart, typeDecl.sourceEnd,
2205 compUnitDecl.compilationResult);
2207 public void recursiveConstructorInvocation(
2208 ExplicitConstructorCall constructorCall) {
2209 this.handle(IProblem.RecursiveConstructorInvocation, new String[]{
2210 new String(constructorCall.binding.declaringClass
2212 parametersAsString(constructorCall.binding)}, new String[]{
2213 new String(constructorCall.binding.declaringClass
2214 .shortReadableName()),
2215 parametersAsShortString(constructorCall.binding)},
2216 constructorCall.sourceStart, constructorCall.sourceEnd);
2218 public void redefineArgument(Argument arg) {
2219 String[] arguments = new String[]{new String(arg.name)};
2220 this.handle(IProblem.RedefinedArgument, arguments, arguments,
2221 arg.sourceStart, arg.sourceEnd);
2223 public void redefineLocal(LocalDeclaration localDecl) {
2224 String[] arguments = new String[]{new String(localDecl.name)};
2225 this.handle(IProblem.RedefinedLocal, arguments, arguments,
2226 localDecl.sourceStart, localDecl.sourceEnd);
2228 public void referenceMustBeArrayTypeAt(TypeBinding arrayType,
2229 ArrayReference arrayRef) {
2230 this.handle(IProblem.ArrayReferenceRequired, new String[]{new String(
2231 arrayType.readableName())}, new String[]{new String(arrayType
2232 .shortReadableName())}, arrayRef.sourceStart,
2233 arrayRef.sourceEnd);
2235 public void returnTypeCannotBeVoidArray(SourceTypeBinding type,
2236 MethodDeclaration methodDecl) {
2237 String[] arguments = new String[]{new String(methodDecl.selector)};
2238 this.handle(IProblem.ReturnTypeCannotBeVoidArray, arguments, arguments,
2239 methodDecl.sourceStart, methodDecl.sourceEnd);
2241 public void returnTypeProblem(SourceTypeBinding type,
2242 MethodDeclaration methodDecl, TypeBinding expectedType) {
2243 int problemId = expectedType.problemId();
2245 switch (problemId) {
2248 id = IProblem.ReturnTypeNotFound;
2252 id = IProblem.ReturnTypeNotVisible;
2256 id = IProblem.ReturnTypeAmbiguous;
2258 case InternalNameProvided :
2260 id = IProblem.ReturnTypeInternalNameProvided;
2262 case InheritedNameHidesEnclosingName :
2264 id = IProblem.ReturnTypeInheritedNameHidesEnclosingName;
2269 needImplementation(); // want to fail to see why we were
2273 this.handle(id, new String[]{new String(methodDecl.selector),
2274 new String(expectedType.readableName())}, new String[]{
2275 new String(methodDecl.selector),
2276 new String(expectedType.shortReadableName())},
2277 methodDecl.returnType.sourceStart,
2278 methodDecl.returnType.sourceEnd);
2280 public void scannerError(Parser parser, String errorTokenName) {
2281 Scanner scanner = parser.scanner;
2282 int flag = IProblem.ParsingErrorNoSuggestion;
2283 int startPos = scanner.startPosition;
2284 //special treatment for recognized errors....
2285 if (errorTokenName.equals(Scanner.END_OF_SOURCE))
2286 flag = IProblem.EndOfSource;
2287 else if (errorTokenName.equals(Scanner.INVALID_HEXA))
2288 flag = IProblem.InvalidHexa;
2289 else if (errorTokenName.equals(Scanner.INVALID_OCTAL))
2290 flag = IProblem.InvalidOctal;
2291 else if (errorTokenName.equals(Scanner.INVALID_CHARACTER_CONSTANT))
2292 flag = IProblem.InvalidCharacterConstant;
2293 else if (errorTokenName.equals(Scanner.INVALID_ESCAPE))
2294 flag = IProblem.InvalidEscape;
2295 else if (errorTokenName.equals(Scanner.INVALID_UNICODE_ESCAPE)) {
2296 flag = IProblem.InvalidUnicodeEscape;
2297 // better locate the error message
2298 char[] source = scanner.source;
2299 int checkPos = scanner.currentPosition - 1;
2300 if (checkPos >= source.length)
2301 checkPos = source.length - 1;
2302 while (checkPos >= startPos) {
2303 if (source[checkPos] == '\\')
2307 startPos = checkPos;
2308 } else if (errorTokenName.equals(Scanner.INVALID_FLOAT))
2309 flag = IProblem.InvalidFloat;
2310 else if (errorTokenName.equals(Scanner.UNTERMINATED_STRING))
2311 flag = IProblem.UnterminatedString;
2312 else if (errorTokenName.equals(Scanner.UNTERMINATED_COMMENT))
2313 flag = IProblem.UnterminatedComment;
2314 else if (errorTokenName.equals(Scanner.INVALID_CHAR_IN_STRING))
2315 flag = IProblem.UnterminatedString;
2316 String[] arguments = flag == IProblem.ParsingErrorNoSuggestion
2317 ? new String[]{errorTokenName}
2319 this.handle(flag, arguments, arguments,
2320 // this is the current -invalid- token position
2321 startPos, scanner.currentPosition - 1,
2322 parser.compilationUnit.compilationResult);
2324 public void shouldReturn(TypeBinding returnType, AstNode location) {
2325 this.handle(IProblem.ShouldReturnValue, new String[]{new String(
2326 returnType.readableName())}, new String[]{new String(returnType
2327 .shortReadableName())}, location.sourceStart,
2328 location.sourceEnd);
2330 public void signalNoImplicitStringConversionForCharArrayExpression(
2331 Expression expression) {
2332 this.handle(IProblem.NoImplicitStringConversionForCharArrayExpression,
2333 NoArgument, NoArgument, expression.sourceStart,
2334 expression.sourceEnd);
2336 public void staticAndInstanceConflict(MethodBinding currentMethod,
2337 MethodBinding inheritedMethod) {
2338 if (currentMethod.isStatic())
2340 // This static method cannot hide the instance method from %1
2341 // 8.4.6.4 - If a class inherits more than one method with
2342 // the same signature a static (non-abstract) method cannot
2343 // hide an instance method.
2344 IProblem.CannotHideAnInstanceMethodWithAStaticMethod,
2345 new String[]{new String(inheritedMethod.declaringClass
2347 new String[]{new String(inheritedMethod.declaringClass
2348 .shortReadableName())},
2349 currentMethod.sourceStart(), currentMethod.sourceEnd());
2352 // This instance method cannot override the static method from %1
2353 // 8.4.6.4 - If a class inherits more than one method with
2354 // the same signature an instance (non-abstract) method
2355 // cannot override a static method.
2356 IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod,
2357 new String[]{new String(inheritedMethod.declaringClass
2359 new String[]{new String(inheritedMethod.declaringClass
2360 .shortReadableName())},
2361 currentMethod.sourceStart(), currentMethod.sourceEnd());
2363 public void staticFieldAccessToNonStaticVariable(FieldReference fieldRef,
2364 FieldBinding field) {
2365 String[] arguments = new String[]{new String(field.readableName())};
2366 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2367 arguments, fieldRef.sourceStart, fieldRef.sourceEnd);
2369 public void staticFieldAccessToNonStaticVariable(
2370 QualifiedNameReference nameRef, FieldBinding field) {
2371 String[] arguments = new String[]{new String(field.readableName())};
2372 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2373 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2375 public void staticFieldAccessToNonStaticVariable(
2376 SingleNameReference nameRef, FieldBinding field) {
2377 String[] arguments = new String[]{new String(field.readableName())};
2378 this.handle(IProblem.NonStaticFieldFromStaticInvocation, arguments,
2379 arguments, nameRef.sourceStart, nameRef.sourceEnd);
2381 public void staticInheritedMethodConflicts(SourceTypeBinding type,
2382 MethodBinding concreteMethod, MethodBinding[] abstractMethods) {
2384 // The static method %1 conflicts with the abstract method in %2
2385 // 8.4.6.4 - If a class inherits more than one method with the
2386 // same signature it is an error for one to be static
2387 // (non-abstract) and the other abstract.
2388 IProblem.StaticInheritedMethodConflicts, new String[]{
2389 new String(concreteMethod.readableName()),
2390 new String(abstractMethods[0].declaringClass
2391 .readableName())}, new String[]{
2392 new String(concreteMethod.readableName()),
2393 new String(abstractMethods[0].declaringClass
2394 .shortReadableName())}, type.sourceStart(),
2397 public void stringConstantIsExceedingUtf8Limit(AstNode location) {
2398 this.handle(IProblem.StringConstantIsExceedingUtf8Limit, NoArgument,
2399 NoArgument, location.sourceStart, location.sourceEnd);
2401 public void superclassMustBeAClass(SourceTypeBinding type,
2402 TypeReference superclassRef, ReferenceBinding superType) {
2403 this.handle(IProblem.SuperclassMustBeAClass, new String[]{
2404 new String(superType.readableName()),
2405 new String(type.sourceName())}, new String[]{
2406 new String(superType.shortReadableName()),
2407 new String(type.sourceName())}, superclassRef.sourceStart,
2408 superclassRef.sourceEnd);
2410 public void superinterfaceMustBeAnInterface(SourceTypeBinding type,
2411 TypeDeclaration typeDecl, ReferenceBinding superType) {
2412 this.handle(IProblem.SuperInterfaceMustBeAnInterface, new String[]{
2413 new String(superType.readableName()),
2414 new String(type.sourceName())}, new String[]{
2415 new String(superType.shortReadableName()),
2416 new String(type.sourceName())}, typeDecl.sourceStart,
2417 typeDecl.sourceEnd);
2419 public void task(String tag, String message, String priority, int start,
2424 new String[]{tag, message, priority/*
2430 new String[]{tag, message, priority/*
2438 public void tooManyDimensions(AstNode expression) {
2439 this.handle(IProblem.TooManyArrayDimensions, NoArgument, NoArgument,
2440 expression.sourceStart, expression.sourceEnd);
2442 public void tooManyFields(TypeDeclaration typeDeclaration) {
2443 this.handle(IProblem.TooManyFields, new String[]{new String(
2444 typeDeclaration.binding.readableName())},
2445 new String[]{new String(typeDeclaration.binding
2446 .shortReadableName())}, Abort | Error,
2447 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2449 public void tooManyMethods(TypeDeclaration typeDeclaration) {
2450 this.handle(IProblem.TooManyMethods, new String[]{new String(
2451 typeDeclaration.binding.readableName())},
2452 new String[]{new String(typeDeclaration.binding
2453 .shortReadableName())}, Abort | Error,
2454 typeDeclaration.sourceStart, typeDeclaration.sourceEnd);
2456 public void typeCastError(CastExpression expression, TypeBinding leftType,
2457 TypeBinding rightType) {
2458 String leftName = new String(leftType.readableName());
2459 String rightName = new String(rightType.readableName());
2460 String leftShortName = new String(leftType.shortReadableName());
2461 String rightShortName = new String(rightType.shortReadableName());
2462 if (leftShortName.equals(rightShortName)) {
2463 leftShortName = leftName;
2464 rightShortName = rightName;
2466 this.handle(IProblem.IllegalCast, new String[]{rightName, leftName},
2467 new String[]{rightShortName, leftShortName},
2468 expression.sourceStart, expression.sourceEnd);
2470 public void typeCollidesWithPackage(
2471 CompilationUnitDeclaration compUnitDecl, TypeDeclaration typeDecl) {
2472 this.referenceContext = typeDecl; // report the problem against the
2473 // type not the entire compilation
2475 String[] arguments = new String[]{
2476 new String(compUnitDecl.getFileName()),
2477 new String(typeDecl.name)};
2478 this.handle(IProblem.TypeCollidesWithPackage, arguments, arguments,
2479 typeDecl.sourceStart, typeDecl.sourceEnd,
2480 compUnitDecl.compilationResult);
2482 public void typeMismatchError(TypeBinding resultType,
2483 TypeBinding expectedType, AstNode location) {
2484 String resultTypeName = new String(resultType.readableName());
2485 String expectedTypeName = new String(expectedType.readableName());
2486 String resultTypeShortName = new String(resultType.shortReadableName());
2487 String expectedTypeShortName = new String(expectedType
2488 .shortReadableName());
2489 if (resultTypeShortName.equals(expectedTypeShortName)) {
2490 resultTypeShortName = resultTypeName;
2491 expectedTypeShortName = expectedTypeName;
2493 this.handle(IProblem.TypeMismatch, new String[]{resultTypeName,
2494 expectedTypeName}, new String[]{resultTypeShortName,
2495 expectedTypeShortName}, location.sourceStart,
2496 location.sourceEnd);
2498 public void typeMismatchErrorActualTypeExpectedType(Expression expression,
2499 TypeBinding constantType, TypeBinding expectedType) {
2500 String constantTypeName = new String(constantType.readableName());
2501 String expectedTypeName = new String(expectedType.readableName());
2502 String constantTypeShortName = new String(constantType
2503 .shortReadableName());
2504 String expectedTypeShortName = new String(expectedType
2505 .shortReadableName());
2506 if (constantTypeShortName.equals(expectedTypeShortName)) {
2507 constantTypeShortName = constantTypeName;
2508 expectedTypeShortName = expectedTypeName;
2510 this.handle(IProblem.TypeMismatch, new String[]{constantTypeName,
2511 expectedTypeName}, new String[]{constantTypeShortName,
2512 expectedTypeShortName}, expression.sourceStart,
2513 expression.sourceEnd);
2515 public void undefinedLabel(BranchStatement statement) {
2516 String[] arguments = new String[]{new String(statement.label)};
2517 this.handle(IProblem.UndefinedLabel, arguments, arguments,
2518 statement.sourceStart, statement.sourceEnd);
2520 public void unexpectedStaticModifierForField(SourceTypeBinding type,
2521 FieldDeclaration fieldDecl) {
2522 String[] arguments = new String[]{fieldDecl.name()};
2523 this.handle(IProblem.UnexpectedStaticModifierForField, arguments,
2524 arguments, fieldDecl.sourceStart, fieldDecl.sourceEnd);
2526 public void unexpectedStaticModifierForMethod(ReferenceBinding type,
2527 AbstractMethodDeclaration methodDecl) {
2528 String[] arguments = new String[]{new String(type.sourceName()),
2529 new String(methodDecl.selector)};
2530 this.handle(IProblem.UnexpectedStaticModifierForMethod, arguments,
2531 arguments, methodDecl.sourceStart, methodDecl.sourceEnd);
2533 public void unhandledException(TypeBinding exceptionType, AstNode location) {
2534 boolean insideDefaultConstructor = (referenceContext instanceof ConstructorDeclaration)
2535 && ((ConstructorDeclaration) referenceContext)
2536 .isDefaultConstructor();
2537 boolean insideImplicitConstructorCall = (location instanceof ExplicitConstructorCall)
2538 && (((ExplicitConstructorCall) location).accessMode == ExplicitConstructorCall.ImplicitSuper);
2541 insideDefaultConstructor
2542 ? IProblem.UnhandledExceptionInDefaultConstructor
2543 : (insideImplicitConstructorCall
2544 ? IProblem.UndefinedConstructorInImplicitConstructorCall
2545 : IProblem.UnhandledException),
2546 new String[]{new String(exceptionType.readableName())},
2547 new String[]{new String(exceptionType
2548 .shortReadableName())}, location.sourceStart,
2549 location.sourceEnd);
2551 public void uninitializedBlankFinalField(FieldBinding binding,
2553 String[] arguments = new String[]{new String(binding.readableName())};
2554 this.handle(IProblem.UninitializedBlankFinalField, arguments,
2555 arguments, location.sourceStart, location.sourceEnd);
2557 public void uninitializedLocalVariable(LocalVariableBinding binding,
2559 String[] arguments = new String[]{new String(binding.readableName())};
2560 this.handle(IProblem.UninitializedLocalVariable, arguments, arguments,
2561 location.sourceStart, location.sourceEnd);
2563 public void unmatchedBracket(int position, ReferenceContext context,
2564 CompilationResult compilationResult) {
2565 this.handle(IProblem.UnmatchedBracket, NoArgument, NoArgument,
2566 position, position, context, compilationResult);
2568 public void unnecessaryEnclosingInstanceSpecification(
2569 Expression expression, ReferenceBinding targetType) {
2570 this.handle(IProblem.IllegalEnclosingInstanceSpecification,
2571 new String[]{new String(targetType.readableName())},
2572 new String[]{new String(targetType.shortReadableName())},
2573 expression.sourceStart, expression.sourceEnd);
2575 public void unnecessaryReceiverForStaticMethod(AstNode location,
2576 MethodBinding method) {
2577 this.handle(IProblem.NonStaticAccessToStaticMethod, new String[]{
2578 new String(method.declaringClass.readableName()),
2579 new String(method.selector), parametersAsString(method)},
2581 new String(method.declaringClass.shortReadableName()),
2582 new String(method.selector),
2583 parametersAsShortString(method)}, location.sourceStart,
2584 location.sourceEnd);
2586 public void unnecessaryReceiverForStaticField(AstNode location,
2587 FieldBinding field) {
2588 this.handle(IProblem.NonStaticAccessToStaticField, new String[]{
2589 new String(field.declaringClass.readableName()),
2590 new String(field.name)}, new String[]{
2591 new String(field.declaringClass.shortReadableName()),
2592 new String(field.name)}, location.sourceStart,
2593 location.sourceEnd);
2595 public void unreachableCode(Statement statement) {
2596 this.handle(IProblem.CodeCannotBeReached, NoArgument, NoArgument,
2597 statement.sourceStart, statement.sourceEnd);
2599 public void unreachableExceptionHandler(ReferenceBinding exceptionType,
2601 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2602 location.sourceStart, location.sourceEnd);
2604 public void unresolvableReference(NameReference nameRef, Binding binding) {
2605 int severity = Error;
2607 * also need to check that the searchedType is the receiver type if
2608 * (binding instanceof ProblemBinding) { ProblemBinding problem =
2609 * (ProblemBinding) binding; if (problem.searchType != null &&
2610 * problem.searchType.isHierarchyInconsistent()) severity =
2613 String[] arguments = new String[]{new String(binding.readableName())};
2614 this.handle(IProblem.UndefinedName, arguments, arguments, severity,
2615 nameRef.sourceStart, nameRef.sourceEnd);
2617 public void unusedArgument(LocalDeclaration localDecl) {
2618 String[] arguments = new String[]{localDecl.name()};
2619 this.handle(IProblem.ArgumentIsNeverUsed, arguments, arguments,
2620 localDecl.sourceStart, localDecl.sourceEnd);
2622 public void unusedImport(ImportReference importRef) {
2623 String[] arguments = new String[]{CharOperation
2624 .toString(importRef.tokens)};
2625 this.handle(IProblem.UnusedImport, arguments, arguments,
2626 importRef.sourceStart, importRef.sourceEnd);
2628 public void unusedLocalVariable(LocalDeclaration localDecl) {
2629 String[] arguments = new String[]{localDecl.name()};
2630 this.handle(IProblem.LocalVariableIsNeverUsed, arguments, arguments,
2631 localDecl.sourceStart, localDecl.sourceEnd);
2633 public void unusedPrivateConstructor(ConstructorDeclaration constructorDecl) {
2634 if (computeSeverity(IProblem.UnusedPrivateConstructor) == Ignore)
2636 // no complaint for no-arg constructors (or default ones) - known
2637 // pattern to block instantiation
2638 if (constructorDecl.arguments == null
2639 || constructorDecl.arguments.length == 0)
2641 MethodBinding constructor = constructorDecl.binding;
2642 this.handle(IProblem.UnusedPrivateConstructor, new String[]{
2643 new String(constructor.declaringClass.readableName()),
2644 parametersAsString(constructor)}, new String[]{
2645 new String(constructor.declaringClass.shortReadableName()),
2646 parametersAsShortString(constructor)},
2647 constructorDecl.sourceStart, constructorDecl.sourceEnd);
2649 public void unusedPrivateField(FieldDeclaration fieldDecl) {
2650 if (computeSeverity(IProblem.UnusedPrivateField) == Ignore)
2652 FieldBinding field = fieldDecl.binding;
2653 if (CharOperation.equals(TypeConstants.SERIALVERSIONUID, field.name)
2654 && field.isStatic() && field.isFinal()
2655 && TypeBinding.LongBinding == field.type) {
2656 return; // do not report unused serialVersionUID field
2658 this.handle(IProblem.UnusedPrivateField, new String[]{
2659 new String(field.declaringClass.readableName()),
2660 new String(field.name),}, new String[]{
2661 new String(field.declaringClass.shortReadableName()),
2662 new String(field.name),}, fieldDecl.sourceStart,
2663 fieldDecl.sourceEnd);
2665 public void unusedPrivateMethod(AbstractMethodDeclaration methodDecl) {
2666 if (computeSeverity(IProblem.UnusedPrivateMethod) == Ignore)
2668 MethodBinding method = methodDecl.binding;
2669 // no report for serialization support 'void
2670 // readObject(ObjectInputStream)'
2671 if (!method.isStatic()
2672 && TypeBinding.VoidBinding == method.returnType
2673 && method.parameters.length == 1
2674 && method.parameters[0].dimensions() == 0
2675 && CharOperation.equals(method.selector,
2676 TypeConstants.READOBJECT)
2677 && CharOperation.equals(
2678 TypeConstants.CharArray_JAVA_IO_OBJECTINPUTSTREAM,
2679 method.parameters[0].readableName())) {
2682 // no report for serialization support 'void
2683 // writeObject(ObjectOutputStream)'
2684 if (!method.isStatic()
2685 && TypeBinding.VoidBinding == method.returnType
2686 && method.parameters.length == 1
2687 && method.parameters[0].dimensions() == 0
2688 && CharOperation.equals(method.selector,
2689 TypeConstants.WRITEOBJECT)
2690 && CharOperation.equals(
2691 TypeConstants.CharArray_JAVA_IO_OBJECTOUTPUTSTREAM,
2692 method.parameters[0].readableName())) {
2695 // no report for serialization support 'Object readResolve()'
2696 if (!method.isStatic()
2697 && TypeBinding.T_Object == method.returnType.id
2698 && method.parameters.length == 0
2699 && CharOperation.equals(method.selector,
2700 TypeConstants.READRESOLVE)) {
2703 // no report for serialization support 'Object writeReplace()'
2704 if (!method.isStatic()
2705 && TypeBinding.T_Object == method.returnType.id
2706 && method.parameters.length == 0
2707 && CharOperation.equals(method.selector,
2708 TypeConstants.WRITEREPLACE)) {
2711 this.handle(IProblem.UnusedPrivateMethod, new String[]{
2712 new String(method.declaringClass.readableName()),
2713 new String(method.selector), parametersAsString(method)},
2715 new String(method.declaringClass.shortReadableName()),
2716 new String(method.selector),
2717 parametersAsShortString(method)},
2718 methodDecl.sourceStart, methodDecl.sourceEnd);
2720 public void unusedPrivateType(TypeDeclaration typeDecl) {
2721 if (computeSeverity(IProblem.UnusedPrivateType) == Ignore)
2723 ReferenceBinding type = typeDecl.binding;
2724 this.handle(IProblem.UnusedPrivateType, new String[]{new String(type
2725 .readableName()),}, new String[]{new String(type
2726 .shortReadableName()),}, typeDecl.sourceStart,
2727 typeDecl.sourceEnd);
2729 public void useAssertAsAnIdentifier(int sourceStart, int sourceEnd) {
2730 this.handle(IProblem.UseAssertAsAnIdentifier, NoArgument, NoArgument,
2731 sourceStart, sourceEnd);
2733 public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
2734 String[] arguments = new String[]{new String(varDecl.name)};
2735 this.handle(IProblem.VariableTypeCannotBeVoid, arguments, arguments,
2736 varDecl.sourceStart, varDecl.sourceEnd);
2738 public void variableTypeCannotBeVoidArray(
2739 AbstractVariableDeclaration varDecl) {
2740 String[] arguments = new String[]{new String(varDecl.name)};
2741 this.handle(IProblem.VariableTypeCannotBeVoidArray, arguments,
2742 arguments, varDecl.sourceStart, varDecl.sourceEnd);
2744 public void visibilityConflict(MethodBinding currentMethod,
2745 MethodBinding inheritedMethod) {
2747 // Cannot reduce the visibility of the inherited method from %1
2748 // 8.4.6.3 - The access modifier of an hiding method must
2749 // provide at least as much access as the hidden method.
2750 // 8.4.6.3 - The access modifier of an overiding method must
2751 // provide at least as much access as the overriden method.
2752 IProblem.MethodReducesVisibility, new String[]{new String(
2753 inheritedMethod.declaringClass.readableName())},
2754 new String[]{new String(inheritedMethod.declaringClass
2755 .shortReadableName())}, currentMethod.sourceStart(),
2756 currentMethod.sourceEnd());
2758 public void wrongSequenceOfExceptionTypesError(TryStatement statement,
2759 int under, int upper) {
2760 //the two catch block under and upper are in an incorrect order.
2761 //under should be define BEFORE upper in the source
2762 TypeReference typeRef = statement.catchArguments[under].type;
2763 this.handle(IProblem.UnreachableCatch, NoArgument, NoArgument,
2764 typeRef.sourceStart, typeRef.sourceEnd);
2766 public void nonExternalizedStringLiteral(AstNode location) {
2767 this.handle(IProblem.NonExternalizedStringLiteral, NoArgument,
2768 NoArgument, location.sourceStart, location.sourceEnd);
2770 public void noMoreAvailableSpaceForConstant(TypeDeclaration typeDeclaration) {
2772 .handle(IProblem.TooManyBytesForStringConstant,
2773 new String[]{new String(typeDeclaration.binding
2774 .readableName())}, new String[]{new String(
2775 typeDeclaration.binding.shortReadableName())},
2776 Abort | Error, typeDeclaration.sourceStart,
2777 typeDeclaration.sourceEnd);
2779 public void noMoreAvailableSpaceInConstantPool(
2780 TypeDeclaration typeDeclaration) {
2782 .handle(IProblem.TooManyConstantsInConstantPool,
2783 new String[]{new String(typeDeclaration.binding
2784 .readableName())}, new String[]{new String(
2785 typeDeclaration.binding.shortReadableName())},
2786 Abort | Error, typeDeclaration.sourceStart,
2787 typeDeclaration.sourceEnd);
2789 private boolean isKeyword(char[] tokenSource) {
2791 * This code is heavily grammar dependant
2793 if (tokenSource == null) {
2797 Scanner scanner = new Scanner();
2798 scanner.setSource(tokenSource);
2799 int token = scanner.getNextToken();
2800 char[] currentKeyword;
2802 currentKeyword = scanner.getCurrentIdentifierSource();
2803 } catch (ArrayIndexOutOfBoundsException e) {
2806 int nextToken = scanner.getNextToken();
2807 if (nextToken == Scanner.TokenNameEOF
2808 && scanner.startPosition == scanner.source.length) { // to
2815 // ArrayIndexOutOfBoundsException
2816 // while reading the last token
2818 case Scanner.TokenNameERROR :
2819 if (CharOperation.equals("goto".toCharArray(),
2821 || CharOperation.equals("const".toCharArray(),
2822 currentKeyword)) { //$NON-NLS-1$ //$NON-NLS-2$
2827 case Scanner.TokenNameabstract :
2828 // case Scanner.TokenNameassert:
2829 // case Scanner.TokenNamebyte:
2830 case Scanner.TokenNamebreak :
2831 // case Scanner.TokenNameboolean:
2832 case Scanner.TokenNamecase :
2833 // case Scanner.TokenNamechar:
2834 case Scanner.TokenNamecatch :
2835 case Scanner.TokenNameclass :
2836 case Scanner.TokenNamecontinue :
2837 case Scanner.TokenNamedo :
2838 // case Scanner.TokenNamedouble:
2839 case Scanner.TokenNamedefault :
2840 case Scanner.TokenNameelse :
2841 case Scanner.TokenNameextends :
2842 case Scanner.TokenNamefor :
2843 // case Scanner.TokenNamefinal:
2844 // case Scanner.TokenNamefloat:
2845 case Scanner.TokenNamefalse :
2846 case Scanner.TokenNamefinally :
2847 case Scanner.TokenNameif :
2848 // case Scanner.TokenNameint:
2849 // case Scanner.TokenNameimport:
2850 case Scanner.TokenNameinterface :
2851 case Scanner.TokenNameimplements :
2852 case Scanner.TokenNameinstanceof :
2853 // case Scanner.TokenNamelong:
2854 case Scanner.TokenNamenew :
2855 case Scanner.TokenNamenull :
2856 // case Scanner.TokenNamenative:
2857 case Scanner.TokenNamepublic :
2858 // case Scanner.TokenNamepackage:
2859 case Scanner.TokenNameprivate :
2860 case Scanner.TokenNameprotected :
2861 case Scanner.TokenNamereturn :
2862 // case Scanner.TokenNameshort:
2863 case Scanner.TokenNamesuper :
2864 case Scanner.TokenNamestatic :
2865 case Scanner.TokenNameswitch :
2866 // case Scanner.TokenNamestrictfp:
2867 // case Scanner.TokenNamesynchronized:
2868 case Scanner.TokenNametry :
2869 case Scanner.TokenNamethis :
2870 case Scanner.TokenNametrue :
2871 case Scanner.TokenNamethrow :
2872 // case Scanner.TokenNamethrows:
2873 // case Scanner.TokenNametransient:
2874 // case Scanner.TokenNamevoid:
2875 // case Scanner.TokenNamevolatile:
2876 case Scanner.TokenNamewhile :
2884 } catch (InvalidInputException e) {
2889 public void phpParsingError(String[] messageArguments,
2890 int problemStartPosition, int problemEndPosition,
2891 ReferenceContext context, CompilationResult compilationResult) {
2892 this.handle(IProblem.PHPParsingError, NoArgument, messageArguments,
2893 problemStartPosition, problemEndPosition, context,