2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.codeInsight
.daemon
.impl
.analysis
;
18 import com
.intellij
.codeHighlighting
.Pass
;
19 import com
.intellij
.codeInsight
.daemon
.DaemonCodeAnalyzer
;
20 import com
.intellij
.codeInsight
.daemon
.JavaErrorMessages
;
21 import com
.intellij
.codeInsight
.daemon
.impl
.*;
22 import com
.intellij
.codeInsight
.daemon
.impl
.quickfix
.QuickFixAction
;
23 import com
.intellij
.codeInsight
.daemon
.impl
.quickfix
.SetupJDKFix
;
24 import com
.intellij
.lang
.injection
.InjectedLanguageManager
;
25 import com
.intellij
.openapi
.diagnostic
.Logger
;
26 import com
.intellij
.openapi
.editor
.Document
;
27 import com
.intellij
.openapi
.progress
.ProgressManager
;
28 import com
.intellij
.openapi
.project
.DumbAware
;
29 import com
.intellij
.openapi
.project
.IndexNotReadyException
;
30 import com
.intellij
.openapi
.project
.Project
;
31 import com
.intellij
.openapi
.util
.Pair
;
32 import com
.intellij
.openapi
.util
.TextRange
;
33 import com
.intellij
.pom
.java
.LanguageLevel
;
34 import com
.intellij
.psi
.*;
35 import com
.intellij
.psi
.controlFlow
.ControlFlowUtil
;
36 import com
.intellij
.psi
.impl
.source
.javadoc
.PsiDocMethodOrFieldRef
;
37 import com
.intellij
.psi
.impl
.source
.jsp
.jspJava
.JspClass
;
38 import com
.intellij
.psi
.impl
.source
.tree
.injected
.InjectedLanguageUtil
;
39 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
40 import com
.intellij
.psi
.javadoc
.PsiDocTagValue
;
41 import com
.intellij
.psi
.templateLanguages
.OuterLanguageElement
;
42 import com
.intellij
.psi
.util
.MethodSignatureBackedByPsiMethod
;
43 import com
.intellij
.psi
.util
.PsiTreeUtil
;
44 import com
.intellij
.psi
.util
.PsiUtil
;
45 import com
.intellij
.psi
.xml
.XmlAttributeValue
;
46 import gnu
.trove
.THashMap
;
47 import org
.jetbrains
.annotations
.NonNls
;
48 import org
.jetbrains
.annotations
.NotNull
;
50 import java
.util
.Collection
;
51 import java
.util
.List
;
54 public class HighlightVisitorImpl
extends JavaElementVisitor
implements HighlightVisitor
, DumbAware
{
55 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl");
57 private final PsiResolveHelper myResolveHelper
;
59 private HighlightInfoHolder myHolder
;
61 private RefCountHolder myRefCountHolder
;
63 // map codeBlock->List of PsiReferenceExpression of uninitialized final variables
64 private final Map
<PsiElement
, Collection
<PsiReferenceExpression
>> myUninitializedVarProblems
= new THashMap
<PsiElement
, Collection
<PsiReferenceExpression
>>();
65 // map codeBlock->List of PsiReferenceExpression of extra initialization of final variable
66 private final Map
<PsiElement
, Collection
<ControlFlowUtil
.VariableInfo
>> myFinalVarProblems
= new THashMap
<PsiElement
, Collection
<ControlFlowUtil
.VariableInfo
>>();
67 private final Map
<PsiParameter
, Boolean
> myParameterIsReassigned
= new THashMap
<PsiParameter
, Boolean
>();
69 private final Map
<String
, Pair
<PsiImportStatementBase
, PsiClass
>> mySingleImportedClasses
= new THashMap
<String
, Pair
<PsiImportStatementBase
, PsiClass
>>();
70 private final Map
<String
, Pair
<PsiImportStaticReferenceElement
, PsiField
>> mySingleImportedFields
= new THashMap
<String
, Pair
<PsiImportStaticReferenceElement
, PsiField
>>();
71 private PsiFile myFile
;
72 private final PsiElementVisitor REGISTER_REFERENCES_VISITOR
= new PsiRecursiveElementWalkingVisitor() {
73 @Override public void visitElement(PsiElement element
) {
74 super.visitElement(element
);
75 for (PsiReference reference
: element
.getReferences()) {
76 PsiElement resolved
= reference
.resolve();
77 if (resolved
instanceof PsiNamedElement
) {
78 myRefCountHolder
.registerLocallyReferenced((PsiNamedElement
)resolved
);
84 @SuppressWarnings({"UnusedDeclaration"}) //in plugin.xml
85 public HighlightVisitorImpl(Project project
) {
86 this(JavaPsiFacade
.getInstance(project
).getResolveHelper());
89 private HighlightVisitorImpl(@NotNull PsiResolveHelper resolveHelper
) {
90 myResolveHelper
= resolveHelper
;
93 public HighlightVisitorImpl
clone() {
94 return new HighlightVisitorImpl(myResolveHelper
);
101 public boolean suitableForFile(PsiFile file
) {
102 return !InjectedLanguageManager
.getInstance(file
.getProject()).isInjectedFragment(file
);
105 public void visit(PsiElement element
, HighlightInfoHolder holder
) {
108 if (LOG
.isDebugEnabled()) {
109 LOG
.assertTrue(element
.isValid());
111 element
.accept(this);
113 if (myRefCountHolder
!= null) {
114 registerReferencesFromInjectedFragments(element
);
118 private void registerReferencesFromInjectedFragments(final PsiElement element
) {
119 InjectedLanguageUtil
.enumerate(element
, myFile
, new PsiLanguageInjectionHost
.InjectedPsiVisitor() {
120 public void visit(@NotNull final PsiFile injectedPsi
, @NotNull final List
<PsiLanguageInjectionHost
.Shred
> places
) {
121 injectedPsi
.accept(REGISTER_REFERENCES_VISITOR
);
126 public boolean analyze(final Runnable action
, final boolean updateWholeFile
, final PsiFile file
) {
128 boolean success
= true;
130 if (updateWholeFile
) {
131 Project project
= file
.getProject();
132 DaemonCodeAnalyzer daemonCodeAnalyzer
= DaemonCodeAnalyzer
.getInstance(project
);
133 FileStatusMap fileStatusMap
= ((DaemonCodeAnalyzerImpl
)daemonCodeAnalyzer
).getFileStatusMap();
134 RefCountHolder refCountHolder
= RefCountHolder
.getInstance(file
);
135 myRefCountHolder
= refCountHolder
;
136 Document document
= PsiDocumentManager
.getInstance(project
).getDocument(file
);
137 TextRange dirtyScope
= document
== null ? file
.getTextRange() : fileStatusMap
.getFileDirtyScope(document
, Pass
.UPDATE_ALL
);
138 success
= refCountHolder
.analyze(action
, dirtyScope
, file
);
141 myRefCountHolder
= null;
146 myUninitializedVarProblems
.clear();
147 myFinalVarProblems
.clear();
148 mySingleImportedClasses
.clear();
149 mySingleImportedFields
.clear();
150 myParameterIsReassigned
.clear();
152 myRefCountHolder
= null;
160 public void visitElement(final PsiElement element
) {
161 if (element
instanceof XmlAttributeValue
) {
163 for (PsiReference reference
: element
.getReferences()) {
164 if(reference
instanceof PsiJavaReference
&& myRefCountHolder
!= null){
165 final PsiJavaReference psiJavaReference
= (PsiJavaReference
)reference
;
166 myRefCountHolder
.registerReference(psiJavaReference
, psiJavaReference
.advancedResolve(false));
170 catch (IndexNotReadyException ignored
) {
175 @Override public void visitAnnotation(PsiAnnotation annotation
) {
176 super.visitAnnotation(annotation
);
177 if (!PsiUtil
.isLanguageLevel5OrHigher(annotation
)) {
178 HighlightInfo info
= HighlightInfo
.createHighlightInfo(HighlightInfoType
.ERROR
, annotation
, JavaErrorMessages
.message("annotations.prior.15"));
179 QuickFixAction
.registerQuickFixAction(info
, new IncreaseLanguageLevelFix(LanguageLevel
.JDK_1_5
));
184 myHolder
.add(AnnotationsHighlightUtil
.checkApplicability(annotation
));
185 if (!myHolder
.hasErrorResults()) myHolder
.add(AnnotationsHighlightUtil
.checkAnnotationType(annotation
));
186 if (!myHolder
.hasErrorResults()) myHolder
.add(AnnotationsHighlightUtil
.checkMissingAttributes(annotation
));
187 if (!myHolder
.hasErrorResults()) myHolder
.add(AnnotationsHighlightUtil
.checkTargetAnnotationDuplicates(annotation
));
188 if (!myHolder
.hasErrorResults()) myHolder
.add(AnnotationsHighlightUtil
.checkDuplicatedAnnotations(annotation
));
191 @Override public void visitAnnotationArrayInitializer(PsiArrayInitializerMemberValue initializer
) {
192 PsiMethod method
= null;
193 PsiElement parent
= initializer
.getParent();
194 if (parent
instanceof PsiNameValuePair
) {
195 method
= (PsiMethod
)parent
.getReference().resolve();
197 else if (parent
instanceof PsiAnnotationMethod
) {
198 method
= (PsiMethod
)parent
;
200 if (method
!= null) {
201 PsiType type
= method
.getReturnType();
202 if (type
instanceof PsiArrayType
) {
203 type
= ((PsiArrayType
)type
).getComponentType();
204 PsiAnnotationMemberValue
[] initializers
= initializer
.getInitializers();
205 for (PsiAnnotationMemberValue initializer1
: initializers
) {
206 myHolder
.add(AnnotationsHighlightUtil
.checkMemberValueType(initializer1
, type
));
212 @Override public void visitAnnotationMethod(PsiAnnotationMethod method
) {
213 PsiType returnType
= method
.getReturnType();
214 PsiAnnotationMemberValue value
= method
.getDefaultValue();
215 if (returnType
!= null && value
!= null) {
216 myHolder
.add(AnnotationsHighlightUtil
.checkMemberValueType(value
, returnType
));
219 myHolder
.add(AnnotationsHighlightUtil
.checkValidAnnotationType(method
.getReturnTypeElement()));
220 myHolder
.add(AnnotationsHighlightUtil
.checkCyclicMemberType(method
.getReturnTypeElement(), method
.getContainingClass()));
223 @Override public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression
) {
224 super.visitArrayInitializerExpression(expression
);
225 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkArrayInitializerApplicable(expression
));
226 if (!(expression
.getParent() instanceof PsiNewExpression
)) {
227 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkGenericArrayCreation(expression
, expression
.getType()));
231 @Override public void visitAssignmentExpression(PsiAssignmentExpression assignment
) {
232 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkAssignmentCompatibleTypes(assignment
));
233 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkAssignmentOperatorApplicable(assignment
));
234 if (!myHolder
.hasErrorResults()) visitExpression(assignment
);
237 @Override public void visitBinaryExpression(PsiBinaryExpression expression
) {
238 super.visitBinaryExpression(expression
);
239 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkBinaryOperatorApplicable(expression
));
242 @Override public void visitBreakStatement(PsiBreakStatement statement
) {
243 super.visitBreakStatement(statement
);
244 if (!myHolder
.hasErrorResults()) {
245 myHolder
.add(HighlightUtil
.checkLabelDefined(statement
.getLabelIdentifier(), statement
.findExitedStatement()));
249 @Override public void visitClass(PsiClass aClass
) {
250 super.visitClass(aClass
);
251 if (aClass
instanceof JspClass
) return;
252 if (aClass
.isAnnotationType()) {
253 if (!PsiUtil
.isLanguageLevel5OrHigher(aClass
)) {
254 HighlightInfo info
= HighlightInfo
255 .createHighlightInfo(HighlightInfoType
.ERROR
, aClass
.getNameIdentifier(), JavaErrorMessages
.message("annotations.prior.15"));
256 QuickFixAction
.registerQuickFixAction(info
, new IncreaseLanguageLevelFix(LanguageLevel
.JDK_1_5
));
260 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkInterfaceMultipleInheritance(aClass
));
261 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkDuplicateTopLevelClass(aClass
));
262 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkEnumMustNotBeLocal(aClass
));
263 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkImplicitThisReferenceBeforeSuper(aClass
));
266 @Override public void visitClassInitializer(PsiClassInitializer initializer
) {
267 super.visitClassInitializer(initializer
);
268 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkInitializerCompleteNormally(initializer
));
269 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkUnreachableStatement(initializer
.getBody()));
270 if (!myHolder
.hasErrorResults()) {
271 myHolder
.add(HighlightClassUtil
.checkThingNotAllowedInInterface(initializer
, initializer
.getContainingClass()));
275 @Override public void visitClassObjectAccessExpression(PsiClassObjectAccessExpression expression
) {
276 super.visitClassObjectAccessExpression(expression
);
277 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkClassObjectAccessExpression(expression
));
280 @Override public void visitComment(PsiComment comment
) {
281 super.visitComment(comment
);
282 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkUnclosedComment(comment
));
285 @Override public void visitContinueStatement(PsiContinueStatement statement
) {
286 super.visitContinueStatement(statement
);
287 if (!myHolder
.hasErrorResults()) {
288 myHolder
.add(HighlightUtil
.checkLabelDefined(statement
.getLabelIdentifier(), statement
.findContinuedStatement()));
292 @Override public void visitJavaToken(PsiJavaToken token
) {
293 super.visitJavaToken(token
);
294 if (!myHolder
.hasErrorResults()
295 && token
.getTokenType() == JavaTokenType
.RBRACE
296 && token
.getParent() instanceof PsiCodeBlock
297 && token
.getParent().getParent() instanceof PsiMethod
) {
298 PsiMethod method
= (PsiMethod
)token
.getParent().getParent();
299 myHolder
.add(HighlightControlFlowUtil
.checkMissingReturnStatement(method
));
304 @Override public void visitDocComment(PsiDocComment comment
) {
305 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkUnclosedComment(comment
));
308 @Override public void visitDocTagValue(PsiDocTagValue value
) {
309 if (value
.getReference() != null) {
310 PsiReference reference
= value
.getReference();
311 if (reference
!= null) {
312 PsiElement element
= reference
.resolve();
313 if (element
instanceof PsiMethod
) {
314 myHolder
.add(HighlightNamesUtil
.highlightMethodName((PsiMethod
)element
, ((PsiDocMethodOrFieldRef
)value
).getNameElement(), false));
316 else if (element
instanceof PsiParameter
) {
317 myHolder
.add(HighlightNamesUtil
.highlightVariable((PsiVariable
)element
, value
.getNavigationElement()));
323 @Override public void visitEnumConstant(PsiEnumConstant enumConstant
) {
324 super.visitEnumConstant(enumConstant
);
325 if (!myHolder
.hasErrorResults()) GenericsHighlightUtil
.checkEnumConstantForConstructorProblems(enumConstant
, myHolder
);
326 if (!myHolder
.hasErrorResults()) registerConstructorCall(enumConstant
);
329 @Override public void visitEnumConstantInitializer(PsiEnumConstantInitializer enumConstantInitializer
) {
330 super.visitEnumConstantInitializer(enumConstantInitializer
);
331 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkClassMustBeAbstract(enumConstantInitializer
));
334 @Override public void visitExpression(PsiExpression expression
) {
335 ProgressManager
.checkCanceled(); // visitLiteralExpression is invoked very often in array initializers
337 super.visitExpression(expression
);
338 if (myHolder
.add(HighlightUtil
.checkMustBeBoolean(expression
))) return;
339 if (expression
instanceof PsiArrayAccessExpression
340 && ((PsiArrayAccessExpression
)expression
).getIndexExpression() != null) {
341 myHolder
.add(HighlightUtil
.checkValidArrayAccessExpression(((PsiArrayAccessExpression
)expression
).getArrayExpression(),
342 ((PsiArrayAccessExpression
)expression
).getIndexExpression()));
344 if (expression
.getParent() instanceof PsiNewExpression
345 && ((PsiNewExpression
)expression
.getParent()).getQualifier() != expression
346 && ((PsiNewExpression
)expression
.getParent()).getArrayInitializer() != expression
) {
347 // like in 'new String["s"]'
348 myHolder
.add(HighlightUtil
.checkValidArrayAccessExpression(null, expression
));
350 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkCannotWriteToFinal(expression
));
351 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkVariableExpected(expression
));
352 if (!myHolder
.hasErrorResults()) HighlightUtil
.checkArrayInitalizer(expression
, myHolder
);
353 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkTernaryOperatorConditionIsBoolean(expression
));
354 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkAssertOperatorTypes(expression
));
355 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkSynchronizedExpressionType(expression
));
356 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkConditionalExpressionBranchTypesMatch(expression
));
357 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkConstantExpressionOverflow(expression
));
358 if (!myHolder
.hasErrorResults()
359 && expression
.getParent() instanceof PsiThrowStatement
360 && ((PsiThrowStatement
)expression
.getParent()).getException() == expression
) {
361 PsiType type
= expression
.getType();
362 myHolder
.add(HighlightUtil
.checkMustBeThrowable(type
, expression
, true));
365 if (!myHolder
.hasErrorResults()) {
366 myHolder
.add(AnnotationsHighlightUtil
.checkConstantExpression(expression
));
370 @Override public void visitField(PsiField field
) {
371 super.visitField(field
);
372 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkFinalFieldInitialized(field
));
375 @Override public void visitForeachStatement(PsiForeachStatement statement
) {
376 if (!PsiUtil
.isLanguageLevel5OrHigher(statement
)) {
377 HighlightInfo info
= HighlightInfo
.createHighlightInfo(HighlightInfoType
.ERROR
, statement
.getFirstChild(), JavaErrorMessages
.message("foreach.prior.15"));
378 QuickFixAction
.registerQuickFixAction(info
, new IncreaseLanguageLevelFix(LanguageLevel
.JDK_1_5
));
383 @Override public void visitImportStaticStatement(PsiImportStaticStatement statement
) {
384 if (!PsiUtil
.isLanguageLevel5OrHigher(statement
)) {
385 HighlightInfo info
= HighlightInfo
.createHighlightInfo(HighlightInfoType
.ERROR
, statement
.getFirstChild(), JavaErrorMessages
.message("static.imports.prior.15"));
386 QuickFixAction
.registerQuickFixAction(info
, new IncreaseLanguageLevelFix(LanguageLevel
.JDK_1_5
));
391 @Override public void visitIdentifier(PsiIdentifier identifier
) {
392 PsiElement parent
= identifier
.getParent();
393 if (parent
instanceof PsiVariable
) {
394 myHolder
.add(HighlightUtil
.checkVariableAlreadyDefined((PsiVariable
)parent
));
396 else if (parent
instanceof PsiClass
) {
397 myHolder
.add(HighlightClassUtil
.checkClassAlreadyImported((PsiClass
)parent
, identifier
));
398 myHolder
.add(HighlightClassUtil
.checkExternalizableHasPublicNoArgsConstructor((PsiClass
)parent
, identifier
));
399 if (!(parent
instanceof PsiAnonymousClass
)) {
400 myHolder
.add(HighlightNamesUtil
.highlightClassName((PsiClass
)parent
, ((PsiClass
)parent
).getNameIdentifier()));
403 else if (parent
instanceof PsiMethod
) {
404 PsiMethod method
= (PsiMethod
)parent
;
405 if (method
.isConstructor()) {
406 myHolder
.add(HighlightMethodUtil
.checkConstructorName(method
));
409 super.visitIdentifier(identifier
);
412 @Override public void visitImportStatement(PsiImportStatement statement
) {
413 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkSingleImportClassConflict(statement
, mySingleImportedClasses
));
416 @Override public void visitImportStaticReferenceElement(PsiImportStaticReferenceElement ref
) {
417 String refName
= ref
.getReferenceName();
418 JavaResolveResult
[] results
= ref
.multiResolve(false);
420 if (results
.length
== 0) {
421 String description
= JavaErrorMessages
.message("cannot.resolve.symbol", refName
);
422 HighlightInfo info
= HighlightInfo
.createHighlightInfo(HighlightInfoType
.WRONG_REF
, ref
.getReferenceNameElement(), description
);
424 QuickFixAction
.registerQuickFixAction(info
, SetupJDKFix
.getInstnace());
427 PsiManager manager
= ref
.getManager();
428 for (JavaResolveResult result
: results
) {
429 PsiElement element
= result
.getElement();
430 if (!(element
instanceof PsiModifierListOwner
) || !((PsiModifierListOwner
)element
).hasModifierProperty(PsiModifier
.STATIC
)) {
433 @NonNls String messageKey
= null;
434 if (element
instanceof PsiClass
) {
435 Pair
<PsiImportStatementBase
, PsiClass
> imported
= mySingleImportedClasses
.get(refName
);
436 PsiClass aClass
= imported
== null ?
null : imported
.getSecond();
437 PsiImportStaticStatement statement
= (PsiImportStaticStatement
)ref
.getParent();
439 if (aClass
!= null && !manager
.areElementsEquivalent(aClass
, element
) && !imported
.getFirst().equals(statement
)) {
440 messageKey
= "class.is.already.defined.in.single.type.import";
442 mySingleImportedClasses
.put(refName
, Pair
.<PsiImportStatementBase
, PsiClass
>create(statement
, (PsiClass
)element
));
444 else if (element
instanceof PsiField
) {
445 Pair
<PsiImportStaticReferenceElement
, PsiField
> imported
= mySingleImportedFields
.get(refName
);
446 PsiField field
= imported
== null ?
null : imported
.getSecond();
448 if (field
!= null && !manager
.areElementsEquivalent(field
, element
) && !imported
.getFirst().equals(ref
.getParent())) {
449 messageKey
= "field.is.already.defined.in.single.type.import";
451 mySingleImportedFields
.put(refName
, Pair
.create(ref
, (PsiField
)element
));
454 if (messageKey
!= null) {
455 String description
= JavaErrorMessages
.message(messageKey
, refName
);
456 myHolder
.add(HighlightInfo
.createHighlightInfo(HighlightInfoType
.ERROR
, ref
, description
));
462 @Override public void visitInstanceOfExpression(PsiInstanceOfExpression expression
) {
463 super.visitInstanceOfExpression(expression
);
464 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkInstanceOfApplicable(expression
));
465 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkInstanceOfGenericType(expression
));
468 @Override public void visitKeyword(PsiKeyword keyword
) {
469 super.visitKeyword(keyword
);
470 PsiElement parent
= keyword
.getParent();
471 if (parent
instanceof PsiModifierList
) {
472 PsiModifierList psiModifierList
= (PsiModifierList
)parent
;
473 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkNotAllowedModifier(keyword
, psiModifierList
));
474 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkIllegalModifierCombination(keyword
, psiModifierList
));
475 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkPublicClassInRightFile(keyword
, psiModifierList
));
476 if (PsiModifier
.ABSTRACT
.equals(keyword
.getText()) && psiModifierList
.getParent() instanceof PsiMethod
) {
477 if (!myHolder
.hasErrorResults()) {
478 myHolder
.add(HighlightMethodUtil
.checkAbstractMethodInConcreteClass((PsiMethod
)psiModifierList
.getParent(), keyword
));
482 else if (keyword
.getText().equals(PsiKeyword
.CONTINUE
) && parent
instanceof PsiContinueStatement
) {
483 PsiContinueStatement statement
= (PsiContinueStatement
)parent
;
484 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkContinueOutsideLoop(statement
));
486 else if (keyword
.getText().equals(PsiKeyword
.BREAK
) && parent
instanceof PsiBreakStatement
) {
487 PsiBreakStatement statement
= (PsiBreakStatement
)parent
;
488 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkBreakOutsideLoop(statement
));
490 else if (PsiKeyword
.INTERFACE
.equals(keyword
.getText()) && parent
instanceof PsiClass
) {
491 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkInterfaceCannotBeLocal((PsiClass
)parent
));
493 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkStaticDeclarationInInnerClass(keyword
));
494 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkIllegalVoidType(keyword
));
496 if (PsiTreeUtil
.getParentOfType(keyword
, PsiDocTagValue
.class) != null) {
497 myHolder
.add(HighlightInfo
.createHighlightInfo(HighlightInfoType
.JAVA_KEYWORD
, keyword
, null));
501 @Override public void visitLabeledStatement(PsiLabeledStatement statement
) {
502 super.visitLabeledStatement(statement
);
503 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkLabelWithoutStatement(statement
));
504 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkLabelAlreadyInUse(statement
));
507 @Override public void visitLiteralExpression(PsiLiteralExpression expression
) {
508 super.visitLiteralExpression(expression
);
509 if (myHolder
.hasErrorResults()) return;
510 myHolder
.add(HighlightUtil
.checkLiteralExpressionParsingError(expression
));
513 @Override public void visitMethod(PsiMethod method
) {
514 super.visitMethod(method
);
515 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkUnreachableStatement(method
.getBody()));
516 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkConstructorHandleSuperClassExceptions(method
));
517 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkRecursiveConstructorInvocation(method
));
518 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkOverrideAnnotation(method
));
519 if (!myHolder
.hasErrorResults() && method
.isConstructor()) {
520 myHolder
.add(HighlightClassUtil
.checkThingNotAllowedInInterface(method
, method
.getContainingClass()));
522 myHolder
.add(HighlightNamesUtil
.highlightMethodName(method
, method
.getNameIdentifier(), true));
525 private void highlightMethodOrClassName(PsiJavaCodeReferenceElement element
) {
526 PsiElement parent
= element
.getParent();
527 if (parent
instanceof PsiReferenceExpression
|| parent
instanceof PsiJavaCodeReferenceElement
) {
530 if (parent
instanceof PsiMethodCallExpression
) {
531 PsiMethod method
= ((PsiMethodCallExpression
)parent
).resolveMethod();
532 PsiElement methodNameElement
= element
.getReferenceNameElement();
533 if (method
!= null && methodNameElement
!= null) {
534 myHolder
.add(HighlightNamesUtil
.highlightMethodName(method
, methodNameElement
, false));
535 myHolder
.add(HighlightNamesUtil
.highlightClassNameInQualifier(element
));
538 else if (parent
instanceof PsiConstructorCall
) {
540 PsiMethod method
= ((PsiConstructorCall
)parent
).resolveConstructor();
541 if (method
== null) {
542 PsiElement resolved
= element
.resolve();
543 if (resolved
instanceof PsiClass
) {
544 myHolder
.add(HighlightNamesUtil
.highlightClassName((PsiClass
)resolved
, element
));
548 myHolder
.add(HighlightNamesUtil
.highlightMethodName(method
, element
, false));
551 catch (IndexNotReadyException e
) {
554 else if (parent
instanceof PsiImportStatement
&& ((PsiImportStatement
)parent
).isOnDemand()) {
555 // highlight on demand import as class
556 myHolder
.add(HighlightNamesUtil
.highlightClassName(null, element
));
559 PsiElement resolved
= element
.resolve();
560 if (resolved
instanceof PsiClass
) {
561 myHolder
.add(HighlightNamesUtil
.highlightClassName((PsiClass
)resolved
, element
));
566 @Override public void visitMethodCallExpression(PsiMethodCallExpression expression
) {
567 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkEnumSuperConstructorCall(expression
));
568 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkSuperQualifierType(expression
));
570 if (!myHolder
.hasErrorResults()) visitExpression(expression
);
573 @Override public void visitModifierList(PsiModifierList list
) {
574 super.visitModifierList(list
);
575 PsiElement parent
= list
.getParent();
576 if (!myHolder
.hasErrorResults() && parent
instanceof PsiMethod
) {
577 myHolder
.add(HighlightMethodUtil
.checkMethodCanHaveBody((PsiMethod
)parent
));
579 if (parent
instanceof PsiMethod
) {
580 PsiMethod method
= (PsiMethod
)parent
;
581 MethodSignatureBackedByPsiMethod methodSignature
= MethodSignatureBackedByPsiMethod
.create(method
, PsiSubstitutor
.EMPTY
);
582 if (!method
.isConstructor()) {
583 List
<HierarchicalMethodSignature
> superMethodSignatures
= method
.getHierarchicalMethodSignature().getSuperSignatures();
584 if (!superMethodSignatures
.isEmpty()) {
585 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkMethodIncompatibleReturnType(methodSignature
, superMethodSignatures
, true));
586 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkMethodIncompatibleThrows(methodSignature
, superMethodSignatures
, true, method
.getContainingClass()));
587 if (!method
.hasModifierProperty(PsiModifier
.STATIC
)) {
588 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkMethodWeakerPrivileges(methodSignature
, superMethodSignatures
, true));
589 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkUncheckedOverriding(method
, superMethodSignatures
));
590 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkMethodOverridesFinal(methodSignature
, superMethodSignatures
));
594 PsiClass aClass
= method
.getContainingClass();
595 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkMethodMustHaveBody(method
, aClass
));
596 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkDuplicateMethod(aClass
, method
));
597 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkConstructorCallsBaseClassConstructor(method
, myRefCountHolder
, myResolveHelper
));
598 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkStaticMethodOverride(method
));
600 else if (parent
instanceof PsiClass
) {
601 PsiClass aClass
= (PsiClass
)parent
;
602 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkDuplicateNestedClass(aClass
));
603 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkClassMustBeAbstract(aClass
));
604 if (!myHolder
.hasErrorResults()) {
605 myHolder
.add(HighlightClassUtil
.checkClassDoesNotCallSuperConstructorOrHandleExceptions(aClass
, myRefCountHolder
, myResolveHelper
));
607 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkOverrideEquivalentInheritedMethods(aClass
));
608 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkOverrideEquivalentMethods(aClass
));
609 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkCyclicInheritance(aClass
));
611 else if (parent
instanceof PsiEnumConstant
) {
612 if (!myHolder
.hasErrorResults()) myHolder
.addAll(GenericsHighlightUtil
.checkEnumConstantModifierList(list
));
616 @Override public void visitNameValuePair(PsiNameValuePair pair
) {
617 myHolder
.add(AnnotationsHighlightUtil
.checkNameValuePair(pair
));
618 if (!myHolder
.hasErrorResults()) {
619 PsiIdentifier nameId
= pair
.getNameIdentifier();
620 if (nameId
!= null) myHolder
.add(HighlightInfo
.createHighlightInfo(HighlightInfoType
.ANNOTATION_ATTRIBUTE_NAME
, nameId
, null));
624 @Override public void visitNewExpression(PsiNewExpression expression
) {
625 myHolder
.add(HighlightUtil
.checkUnhandledExceptions(expression
, null));
626 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkAnonymousInheritFinal(expression
));
627 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkQualifiedNewOfStaticClass(expression
));
628 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkCreateInnerClassFromStaticContext(expression
));
629 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkTypeParameterInstantiation(expression
));
630 if (!myHolder
.hasErrorResults()) HighlightMethodUtil
.checkNewExpression(expression
, myHolder
);
631 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkEnumInstantiation(expression
));
632 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkGenericArrayCreation(expression
, expression
.getType()));
633 if (!myHolder
.hasErrorResults()) registerConstructorCall(expression
);
635 if (!myHolder
.hasErrorResults()) visitExpression(expression
);
638 @Override public void visitOuterLanguageElement(OuterLanguageElement element
) {
639 XmlHighlightVisitor
.visitJspElement(element
);
640 super.visitOuterLanguageElement(element
);
643 @Override public void visitPackageStatement(PsiPackageStatement statement
) {
644 super.visitPackageStatement(statement
);
645 myHolder
.add(AnnotationsHighlightUtil
.checkPackageAnnotationContainingFile(statement
));
648 @Override public void visitParameter(PsiParameter parameter
) {
649 super.visitParameter(parameter
);
650 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkVarArgParameterIsLast(parameter
));
651 if (!myHolder
.hasErrorResults() && parameter
.getParent() instanceof PsiForeachStatement
) {
652 myHolder
.add(GenericsHighlightUtil
.checkForeachLoopParameterType((PsiForeachStatement
)parameter
.getParent()));
656 @Override public void visitParameterList(PsiParameterList list
) {
657 PsiElement parent
= list
.getParent();
658 if (parent
instanceof PsiAnnotationMethod
&& list
.getParametersCount() > 0) {
659 myHolder
.add(HighlightInfo
.createHighlightInfo(HighlightInfoType
.ERROR
,
661 JavaErrorMessages
.message("annotation.interface.members.may.not.have.parameters")));
665 @Override public void visitPostfixExpression(PsiPostfixExpression expression
) {
666 super.visitPostfixExpression(expression
);
667 if (!myHolder
.hasErrorResults()) {
668 myHolder
.add(HighlightUtil
.checkUnaryOperatorApplicable(expression
.getOperationSign(), expression
.getOperand()));
672 @Override public void visitPrefixExpression(PsiPrefixExpression expression
) {
673 super.visitPrefixExpression(expression
);
674 if (!myHolder
.hasErrorResults()) {
675 myHolder
.add(HighlightUtil
.checkUnaryOperatorApplicable(expression
.getOperationSign(), expression
.getOperand()));
679 private void registerConstructorCall(PsiConstructorCall constructorCall
) {
680 if (myRefCountHolder
!= null) {
681 JavaResolveResult resolveResult
= constructorCall
.resolveMethodGenerics();
682 final PsiElement resolved
= resolveResult
.getElement();
683 if (resolved
instanceof PsiNamedElement
) {
684 myRefCountHolder
.registerLocallyReferenced((PsiNamedElement
)resolved
);
689 @Override public void visitReferenceElement(PsiJavaCodeReferenceElement ref
) {
690 JavaResolveResult result
= null;
692 result
= ref
.advancedResolve(true);
694 catch (IndexNotReadyException e
) {
697 PsiElement resolved
= result
.getElement();
698 PsiElement parent
= ref
.getParent();
699 if (myRefCountHolder
!= null) {
700 myRefCountHolder
.registerReference(ref
, result
);
703 myHolder
.add(HighlightUtil
.checkReference(ref
, result
, resolved
));
704 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkAbstractInstantiation(ref
));
705 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkExtendsDuplicate(ref
, resolved
));
706 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkExceptionAlreadyCaught(ref
, resolved
));
707 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkClassExtendsForeignInnerClass(ref
, resolved
));
708 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkSelectStaticClassFromParameterizedType(resolved
, ref
));
709 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkParameterizedReferenceTypeArguments(resolved
, ref
, result
.getSubstitutor()));
711 if (resolved
!= null && parent
instanceof PsiReferenceList
) {
712 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkElementInReferenceList(ref
, (PsiReferenceList
)parent
, result
));
715 if (parent
instanceof PsiAnonymousClass
&& ref
.equals(((PsiAnonymousClass
)parent
).getBaseClassReference())) {
716 myHolder
.add(GenericsHighlightUtil
.checkOverrideEquivalentMethods((PsiClass
)parent
));
719 if (resolved
instanceof PsiVariable
) {
720 PsiVariable variable
= (PsiVariable
)resolved
;
722 final PsiClass containingClass
= PsiTreeUtil
.getParentOfType(ref
, PsiClass
.class);
723 if (containingClass
instanceof PsiAnonymousClass
&& !PsiTreeUtil
.isAncestor(containingClass
, variable
, false) && !(variable
instanceof PsiField
)) {
724 if (!PsiTreeUtil
.isAncestor(((PsiAnonymousClass
) containingClass
).getArgumentList(), ref
, false)) {
725 myHolder
.add(HighlightInfo
.createHighlightInfo(HighlightInfoType
.IMPLICIT_ANONYMOUS_CLASS_PARAMETER
, ref
, null));
729 if (!variable
.hasModifierProperty(PsiModifier
.FINAL
) && isReassigned(variable
)) {
730 myHolder
.add(HighlightNamesUtil
.highlightReassignedVariable(variable
, ref
));
733 myHolder
.add(HighlightNamesUtil
.highlightVariable(variable
, ref
.getReferenceNameElement()));
735 myHolder
.add(HighlightNamesUtil
.highlightClassNameInQualifier(ref
));
738 highlightMethodOrClassName(ref
);
742 @Override public void visitReferenceExpression(PsiReferenceExpression expression
) {
743 visitReferenceElement(expression
);
744 if (!myHolder
.hasErrorResults()) {
745 visitExpression(expression
);
746 if (myHolder
.hasErrorResults()) return;
748 JavaResolveResult result
;
750 result
= expression
.advancedResolve(false);
752 catch (IndexNotReadyException e
) {
755 PsiElement resolved
= result
.getElement();
756 if (resolved
instanceof PsiVariable
&& resolved
.getContainingFile() == expression
.getContainingFile()) {
757 if (!myHolder
.hasErrorResults()) {
758 myHolder
.add(HighlightControlFlowUtil
.checkVariableInitializedBeforeUsage(expression
, (PsiVariable
)resolved
, myUninitializedVarProblems
));
760 PsiVariable variable
= (PsiVariable
)resolved
;
761 boolean isFinal
= variable
.hasModifierProperty(PsiModifier
.FINAL
);
762 if (isFinal
&& !variable
.hasInitializer()) {
763 if (!myHolder
.hasErrorResults()) {
764 myHolder
.add(HighlightControlFlowUtil
.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable
, expression
, myFinalVarProblems
));
766 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightControlFlowUtil
.checkFinalVariableInitalizedInLoop(expression
, resolved
));
770 PsiElement parent
= expression
.getParent();
771 if (parent
instanceof PsiMethodCallExpression
&& ((PsiMethodCallExpression
)parent
).getMethodExpression() == expression
) {
772 myHolder
.addAll(HighlightMethodUtil
.checkMethodCall((PsiMethodCallExpression
)parent
, myResolveHelper
));
776 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkExpressionRequired(expression
));
777 if (!myHolder
.hasErrorResults() && resolved
instanceof PsiField
) {
778 myHolder
.add(HighlightUtil
.checkIllegalForwardReferenceToField(expression
, (PsiField
)resolved
));
780 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkConstructorCallMustBeFirstStatement(expression
));
781 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkAccessStaticFieldFromEnumConstructor(expression
, result
));
782 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkClassReferenceAfterQualifier(expression
, resolved
));
785 @Override public void visitReferenceList(PsiReferenceList list
) {
786 if (list
.getFirstChild() == null) return;
787 PsiElement parent
= list
.getParent();
788 if (!(parent
instanceof PsiTypeParameter
)) {
789 myHolder
.add(AnnotationsHighlightUtil
.checkAnnotationDeclaration(parent
, list
));
790 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkImplementsAllowed(list
));
791 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightClassUtil
.checkClassExtendsOnlyOneClass(list
));
792 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkGenericCannotExtendException(list
));
796 @Override public void visitReferenceParameterList(PsiReferenceParameterList list
) {
797 myHolder
.add(GenericsHighlightUtil
.checkParametersOnRaw(list
));
800 @Override public void visitReturnStatement(PsiReturnStatement statement
) {
801 myHolder
.add(HighlightUtil
.checkReturnStatementType(statement
));
804 @Override public void visitStatement(PsiStatement statement
) {
805 super.visitStatement(statement
);
806 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkNotAStatement(statement
));
807 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkStatementPrependedWithCaseInsideSwitch(statement
));
810 @Override public void visitSuperExpression(PsiSuperExpression expr
) {
811 myHolder
.add(HighlightUtil
.checkThisOrSuperExpressionInIllegalContext(expr
, expr
.getQualifier()));
812 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightMethodUtil
.checkAbstractMethodDirectCall(expr
));
813 if (!myHolder
.hasErrorResults()) visitExpression(expr
);
816 @Override public void visitSwitchLabelStatement(PsiSwitchLabelStatement statement
) {
817 super.visitSwitchLabelStatement(statement
);
818 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkCaseStatement(statement
));
821 @Override public void visitSwitchStatement(PsiSwitchStatement statement
) {
822 super.visitSwitchStatement(statement
);
823 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkSwitchSelectorType(statement
));
826 @Override public void visitThisExpression(PsiThisExpression expr
) {
827 myHolder
.add(HighlightUtil
.checkThisOrSuperExpressionInIllegalContext(expr
, expr
.getQualifier()));
828 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkMemberReferencedBeforeConstructorCalled(expr
));
829 if (!myHolder
.hasErrorResults()) {
830 visitExpression(expr
);
834 @Override public void visitThrowStatement(PsiThrowStatement statement
) {
835 myHolder
.add(HighlightUtil
.checkUnhandledExceptions(statement
, null));
836 if (!myHolder
.hasErrorResults()) visitStatement(statement
);
839 @Override public void visitTryStatement(PsiTryStatement statement
) {
840 super.visitTryStatement(statement
);
841 if (!myHolder
.hasErrorResults()) {
842 PsiParameter
[] parameters
= statement
.getCatchBlockParameters();
843 for (PsiParameter parameter
: parameters
) {
844 myHolder
.add(HighlightUtil
.checkExceptionThrownInTry(parameter
));
845 myHolder
.add(HighlightUtil
.checkCatchParameterIsThrowable(parameter
));
846 myHolder
.add(GenericsHighlightUtil
.checkCatchParameterIsClass(parameter
));
851 @Override public void visitTypeElement(PsiTypeElement type
) {
852 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkIllegalType(type
));
853 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkReferenceTypeUsedAsTypeArgument(type
));
854 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkWildcardUsage(type
));
857 @Override public void visitTypeCastExpression(PsiTypeCastExpression typeCast
) {
858 super.visitTypeCastExpression(typeCast
);
859 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkInconvertibleTypeCast(typeCast
));
860 if (!myHolder
.hasErrorResults()) myHolder
.add(GenericsHighlightUtil
.checkUncheckedTypeCast(typeCast
));
863 @Override public void visitTypeParameterList(PsiTypeParameterList list
) {
864 myHolder
.add(GenericsHighlightUtil
.checkTypeParametersList(list
));
867 @Override public void visitVariable(PsiVariable variable
) {
868 super.visitVariable(variable
);
869 if (!myHolder
.hasErrorResults()) myHolder
.add(HighlightUtil
.checkVariableInitializerType(variable
));
871 if (isReassigned(variable
)) {
872 myHolder
.add(HighlightNamesUtil
.highlightReassignedVariable(variable
, variable
.getNameIdentifier()));
875 if (variable
.getInitializer() == null) {
876 final PsiElement child
= variable
.getLastChild();
877 if (child
instanceof PsiErrorElement
&& child
.getPrevSibling() == variable
.getNameIdentifier()) return;
879 myHolder
.add(HighlightNamesUtil
.highlightVariable(variable
, variable
.getNameIdentifier()));
883 private boolean isReassigned(PsiVariable variable
) {
885 return HighlightControlFlowUtil
.isReassigned(variable
, myFinalVarProblems
, myParameterIsReassigned
);
887 catch (IndexNotReadyException e
) {