diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java index a2100e7e7ce3..c445ceccb35a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/AnnotationsHighlightUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -160,8 +160,7 @@ public class AnnotationsHighlightUtil { return null; } - @Nullable - public static HighlightInfo checkDuplicateAnnotations(PsiAnnotation annotationToCheck) { + static HighlightInfo checkDuplicateAnnotations(@NotNull PsiAnnotation annotationToCheck) { PsiAnnotationOwner owner = annotationToCheck.getOwner(); if (owner == null) return null; @@ -170,20 +169,26 @@ public class AnnotationsHighlightUtil { PsiElement resolved = element.resolve(); if (!(resolved instanceof PsiClass)) return null; - for (PsiAnnotation annotation : owner.getAnnotations()) { - if (annotation == annotationToCheck) continue; - PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); - if (nameRef == null) continue; - PsiElement aClass = nameRef.resolve(); - if (!resolved.equals(aClass)) continue; + PsiClass annotationType = (PsiClass)resolved; + PsiClass contained = contained(annotationType); + String containedElementFQN = contained == null ? null : contained.getQualifiedName(); + + if (containedElementFQN != null) { + PsiClass container = annotationType; + String containerName = container.getQualifiedName(); + if (isAnnotationRepeatedTwice(owner, containedElementFQN)) { + String description = JavaErrorMessages.message("annotation.container.wrong.place", containerName); + return annotationError(annotationToCheck, description); + } + } + else if (isAnnotationRepeatedTwice(owner, annotationType.getQualifiedName())) { if (!PsiUtil.isLanguageLevel8OrHigher(annotationToCheck)) { String description = JavaErrorMessages.message("annotation.duplicate.annotation"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create(); } - - PsiClass annotationType = (PsiClass)resolved; PsiAnnotation metaAnno = PsiImplUtil.findAnnotation(annotationType.getModifierList(), CommonClassNames.JAVA_LANG_ANNOTATION_REPEATABLE); + if (metaAnno == null) { String explanation = JavaErrorMessages.message("annotation.non.repeatable", annotationType.getQualifiedName()); String description = JavaErrorMessages.message("annotation.duplicate.explained", explanation); @@ -198,28 +203,58 @@ public class AnnotationsHighlightUtil { PsiClass container = getRepeatableContainer(metaAnno); if (container != null) { - String containerName = container.getQualifiedName(); - if (containerName != null) { - PsiAnnotation containerAnno = owner.findAnnotation(containerName); - if (containerAnno != null) { - String description = JavaErrorMessages.message("annotation.container.wrong.place", containerName); - return annotationError(containerAnno, description); - } - } - PsiAnnotation.TargetType[] targets = PsiImplUtil.getTargetsForLocation(owner); PsiAnnotation.TargetType applicable = PsiImplUtil.findApplicableTarget(container, targets); if (applicable == null) { String target = JavaErrorMessages.message("annotation.target." + targets[0]); - String message = JavaErrorMessages.message("annotation.container.not.applicable", containerName, target); - return annotationError(annotation, message); + String message = JavaErrorMessages.message("annotation.container.not.applicable", container.getName(), target); + return annotationError(annotationToCheck, message); } } } + for (PsiAnnotation annotation : owner.getAnnotations()) { + if (annotation == annotationToCheck) continue; + PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); + if (nameRef == null) continue; + PsiElement aClass = nameRef.resolve(); + if (!resolved.equals(aClass)) continue; + + } + return null; } + // returns contained element + private static PsiClass contained(PsiClass annotationType) { + if (!annotationType.isAnnotationType()) return null; + PsiMethod[] values = annotationType.findMethodsByName("value", false); + if (values.length != 1) return null; + PsiMethod value = values[0]; + PsiType returnType = value.getReturnType(); + if (!(returnType instanceof PsiArrayType)) return null; + PsiType type = ((PsiArrayType)returnType).getComponentType(); + if (!(type instanceof PsiClassType)) return null; + PsiClass contained = ((PsiClassType)type).resolve(); + if (contained == null || !contained.isAnnotationType()) return null; + if (PsiImplUtil.findAnnotation(contained.getModifierList(), CommonClassNames.JAVA_LANG_ANNOTATION_REPEATABLE) == null) return null; + + return contained; + } + + private static boolean isAnnotationRepeatedTwice(@NotNull PsiAnnotationOwner owner, @NotNull String qualifiedName) { + int count = 0; + for (PsiAnnotation annotation : owner.getAnnotations()) { + PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); + if (nameRef == null) continue; + PsiElement resolved = nameRef.resolve(); + if (!(resolved instanceof PsiClass) || !qualifiedName.equals(((PsiClass)resolved).getQualifiedName())) continue; + count++; + if (count == 2) return true; + } + return false; + } + @Nullable public static HighlightInfo checkMissingAttributes(PsiAnnotation annotation) { PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement(); @@ -601,7 +636,7 @@ public class AnnotationsHighlightUtil { } @Nullable - private static String doCheckRepeatableAnnotation(PsiAnnotation annotation) { + private static String doCheckRepeatableAnnotation(@NotNull PsiAnnotation annotation) { PsiAnnotationOwner owner = annotation.getOwner(); if (!(owner instanceof PsiModifierList)) return null; PsiElement target = ((PsiModifierList)owner).getParent(); @@ -642,7 +677,7 @@ public class AnnotationsHighlightUtil { } @Nullable - private static PsiClass getRepeatableContainer(PsiAnnotation annotation) { + private static PsiClass getRepeatableContainer(@NotNull PsiAnnotation annotation) { PsiAnnotationMemberValue containerRef = PsiImplUtil.findAttributeValue(annotation, null); if (!(containerRef instanceof PsiClassObjectAccessExpression)) return null; PsiType containerType = ((PsiClassObjectAccessExpression)containerRef).getOperand().getType(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index 05208e889727..4273334e03cf 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -326,7 +326,7 @@ public class GenericsHighlightUtil { if (errorResult == null && languageLevel.isAtLeast(LanguageLevel.JDK_1_7) && referenceElements.length > 1) { //todo suppress erased methods which come from the same class - return checkOverrideEquivalentMethods(aClass); + return checkOverrideEquivalentMethods(languageLevel, aClass); } return errorResult; } @@ -380,7 +380,8 @@ public class GenericsHighlightUtil { return null; } - public static HighlightInfo checkOverrideEquivalentMethods(@NotNull PsiClass aClass) { + public static HighlightInfo checkOverrideEquivalentMethods(@NotNull LanguageLevel languageLevel, + @NotNull PsiClass aClass) { final Collection signaturesWithSupers = aClass.getVisibleSignatures(); PsiManager manager = aClass.getManager(); Map sameErasureMethods = @@ -395,43 +396,31 @@ public class GenericsHighlightUtil { } } - final PsiIdentifier classIdentifier = aClass.getNameIdentifier(); - if (PsiUtil.isLanguageLevel8OrHigher(aClass) && classIdentifier != null) { - HighlightInfo info = checkUnrelatedDefaultMethods(aClass, signaturesWithSupers, classIdentifier); - if (info != null) return info; - info = checkDefaultMethodOverrideEquivalentToObjectNonPrivate(aClass, signaturesWithSupers); - if (info != null) return info; - } - return null; } - private static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(PsiClass aClass, - Collection withSupers) { - if (aClass.isInterface()) { - for (HierarchicalMethodSignature sig : withSupers) { - final PsiMethod method = sig.getMethod(); - if (method.hasModifierProperty(PsiModifier.DEFAULT)) { - for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) { - final PsiClass containingClass = methodSignature.getMethod().getContainingClass(); - if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { - final PsiIdentifier identifier = method.getNameIdentifier(); - LOG.assertTrue(identifier != null); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) - .descriptionAndTooltip("Default method " + sig.getName() + " overrides a member of java.lang.Object") - .range(identifier) - .create(); - } - } + static HighlightInfo checkDefaultMethodOverrideEquivalentToObjectNonPrivate(@NotNull LanguageLevel languageLevel, + @NotNull PsiClass aClass, + @NotNull PsiMethod method, + @NotNull PsiElement methodIdentifier) { + if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && aClass.isInterface() && method.hasModifierProperty(PsiModifier.DEFAULT)) { + HierarchicalMethodSignature sig = method.getHierarchicalMethodSignature(); + for (HierarchicalMethodSignature methodSignature : sig.getSuperSignatures()) { + final PsiClass containingClass = methodSignature.getMethod().getContainingClass(); + if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) { + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) + .descriptionAndTooltip("Default method '" + sig.getName() + "' overrides a member of 'java.lang.Object'") + .range(methodIdentifier) + .create(); } } } return null; } - private static HighlightInfo checkUnrelatedDefaultMethods(PsiClass aClass, - Collection signaturesWithSupers, - PsiIdentifier classIdentifier) { + static HighlightInfo checkUnrelatedDefaultMethods(@NotNull PsiClass aClass, + @NotNull Collection signaturesWithSupers, + @NotNull PsiIdentifier classIdentifier) { for (HierarchicalMethodSignature methodSignature : signaturesWithSupers) { final PsiMethod method = methodSignature.getMethod(); if (method.hasModifierProperty(PsiModifier.DEFAULT)) { @@ -725,14 +714,10 @@ public class GenericsHighlightUtil { } @Nullable - public static HighlightInfo checkEnumInstantiation(PsiNewExpression expression) { - final PsiType type = expression.getType(); - if (type instanceof PsiClassType) { - final PsiClass aClass = ((PsiClassType)type).resolve(); - if (aClass != null && aClass.isEnum()) { - String description = JavaErrorMessages.message("enum.types.cannot.be.instantiated"); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create(); - } + public static HighlightInfo checkEnumInstantiation(PsiNewExpression expression, PsiClass aClass) { + if (aClass != null && aClass.isEnum()) { + String description = JavaErrorMessages.message("enum.types.cannot.be.instantiated"); + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create(); } return null; } @@ -979,8 +964,8 @@ public class GenericsHighlightUtil { } } - static void checkEnumConstantForConstructorProblems(PsiEnumConstant enumConstant, - final HighlightInfoHolder holder, + static void checkEnumConstantForConstructorProblems(@NotNull PsiEnumConstant enumConstant, + @NotNull HighlightInfoHolder holder, @NotNull JavaSdkVersion javaSdkVersion) { PsiClass containingClass = enumConstant.getContainingClass(); if (enumConstant.getInitializingClass() == null) { @@ -1208,23 +1193,17 @@ public class GenericsHighlightUtil { /** * http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.8 */ - @Nullable - public static HighlightInfo checkRawOnParameterizedType(PsiReferenceParameterList list) { - if (list.getTypeArguments().length > 0) return null; - final PsiElement parent = list.getParent(); - if (parent instanceof PsiJavaCodeReferenceElement) { - final PsiElement qualifier = ((PsiJavaCodeReferenceElement)parent).getQualifier(); - if (qualifier instanceof PsiJavaCodeReferenceElement) { - if (((PsiJavaCodeReferenceElement)qualifier).getTypeParameters().length > 0) { - final PsiElement resolve = ((PsiJavaCodeReferenceElement)parent).resolve(); - if (resolve instanceof PsiTypeParameterListOwner - && ((PsiTypeParameterListOwner)resolve).hasTypeParameters() - && !((PsiTypeParameterListOwner)resolve).hasModifierProperty(PsiModifier.STATIC)) { - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip( - "Improper formed type; some type parameters are missing").create(); - } - } - } + static HighlightInfo checkRawOnParameterizedType(@NotNull PsiJavaCodeReferenceElement parent, PsiElement resolved) { + PsiReferenceParameterList list = parent.getParameterList(); + if (list == null || list.getTypeArguments().length > 0) return null; + final PsiElement qualifier = parent.getQualifier(); + if (qualifier instanceof PsiJavaCodeReferenceElement && + ((PsiJavaCodeReferenceElement)qualifier).getTypeParameters().length > 0 && + resolved instanceof PsiTypeParameterListOwner && + ((PsiTypeParameterListOwner)resolved).hasTypeParameters() && + !((PsiTypeParameterListOwner)resolved).hasModifierProperty(PsiModifier.STATIC)) { + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip( + "Improper formed type; some type parameters are missing").create(); } return null; } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java index f16fc5b3682d..052a1176dfdd 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightClassUtil.java @@ -57,16 +57,10 @@ public class HighlightClassUtil { * new ref(...) or new ref(..) { ... } where ref is abstract class */ @Nullable - static HighlightInfo checkAbstractInstantiation(PsiJavaCodeReferenceElement ref, PsiElement resolved) { + static HighlightInfo checkAbstractInstantiation(@NotNull PsiJavaCodeReferenceElement ref, PsiElement resolved) { PsiElement parent = ref.getParent(); HighlightInfo highlightInfo = null; - if (parent instanceof PsiNewExpression && !PsiUtilCore.hasErrorElementChild(parent)) { - if (((PsiNewExpression)parent).getType() instanceof PsiArrayType) return null; - if (resolved instanceof PsiClass) { - highlightInfo = checkInstantiationOfAbstractClass((PsiClass)resolved, ref); - } - } - else if (parent instanceof PsiAnonymousClass + if (parent instanceof PsiAnonymousClass && parent.getParent() instanceof PsiNewExpression && !PsiUtilCore.hasErrorElementChild(parent.getParent())) { PsiAnonymousClass aClass = (PsiAnonymousClass)parent; @@ -127,26 +121,21 @@ public class HighlightClassUtil { } @Nullable - public static HighlightInfo checkInstantiationOfAbstractClass(PsiClass aClass, PsiElement highlightElement) { + public static HighlightInfo checkInstantiationOfAbstractClass(PsiClass aClass, @NotNull PsiElement highlightElement) { HighlightInfo errorResult = null; - if (aClass.hasModifierProperty(PsiModifier.ABSTRACT)) { + if (aClass != null && aClass.hasModifierProperty(PsiModifier.ABSTRACT) + && (!(highlightElement instanceof PsiNewExpression) || !(((PsiNewExpression)highlightElement).getType() instanceof PsiArrayType))) { String baseClassName = aClass.getName(); String message = JavaErrorMessages.message("abstract.cannot.be.instantiated", baseClassName); - PsiElement parent = highlightElement.getParent(); - if (parent instanceof PsiNewExpression) { - errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip(message).create(); - } else { - errorResult = - HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(highlightElement).descriptionAndTooltip(message).create(); - } + errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(highlightElement).descriptionAndTooltip(message).create(); final PsiMethod anyAbstractMethod = ClassUtil.getAnyAbstractMethod(aClass); if (!aClass.isInterface() && anyAbstractMethod == null) { // suggest to make not abstract only if possible QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.ABSTRACT, false, false)); } - if (anyAbstractMethod != null && parent instanceof PsiNewExpression && ((PsiNewExpression)parent).getClassReference() != null) { - QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementAbstractClassMethodsFix(parent)); + if (anyAbstractMethod != null && highlightElement instanceof PsiNewExpression && ((PsiNewExpression)highlightElement).getClassReference() != null) { + QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementAbstractClassMethodsFix(highlightElement)); } } return errorResult; @@ -688,10 +677,9 @@ public class HighlightClassUtil { } @Nullable - public static HighlightInfo checkQualifiedNew(PsiNewExpression expression) { + public static HighlightInfo checkQualifiedNew(PsiNewExpression expression, PsiType type, PsiClass aClass) { PsiExpression qualifier = expression.getQualifier(); if (qualifier == null) return null; - PsiType type = expression.getType(); if (type instanceof PsiArrayType) { String description = JavaErrorMessages.message("invalid.qualified.new"); HighlightInfo info = @@ -699,7 +687,6 @@ public class HighlightClassUtil { QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createRemoveNewQualifierFix(expression, null)); return info; } - PsiClass aClass = PsiUtil.resolveClassInType(type); HighlightInfo info = null; if (aClass != null) { if (aClass.hasModifierProperty(PsiModifier.STATIC)) { @@ -820,17 +807,15 @@ public class HighlightClassUtil { } @Nullable - public static HighlightInfo checkCreateInnerClassFromStaticContext(PsiNewExpression expression) { - PsiType type = expression.getType(); - PsiExpression qualifier = expression.getQualifier(); + public static HighlightInfo checkCreateInnerClassFromStaticContext(PsiNewExpression expression, PsiType type, PsiClass aClass) { if (type == null || type instanceof PsiArrayType || type instanceof PsiPrimitiveType) return null; - PsiClass aClass = PsiUtil.resolveClassInType(type); if (aClass == null) return null; if (aClass instanceof PsiAnonymousClass) { aClass = ((PsiAnonymousClass)aClass).getBaseClassType().resolve(); if (aClass == null) return null; } + PsiExpression qualifier = expression.getQualifier(); return checkCreateInnerClassFromStaticContext(expression, qualifier, aClass); } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java index 357c934f8f2d..35f9416d2d8c 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -638,8 +638,8 @@ public class HighlightControlFlowUtil { @Nullable - static HighlightInfo checkVariableMustBeFinal(PsiVariable variable, - PsiJavaCodeReferenceElement context, + static HighlightInfo checkVariableMustBeFinal(@NotNull PsiVariable variable, + @NotNull PsiJavaCodeReferenceElement context, @NotNull LanguageLevel languageLevel) { if (variable.hasModifierProperty(PsiModifier.FINAL)) return null; final PsiClass innerClass = getInnerClassVariableReferencedFrom(variable, context); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 6f6673f5005c..ac211ff387ba 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,8 +121,8 @@ public class HighlightMethodUtil { } - static HighlightInfo checkMethodIncompatibleReturnType(MethodSignatureBackedByPsiMethod methodSignature, - List superMethodSignatures, + static HighlightInfo checkMethodIncompatibleReturnType(@NotNull MethodSignatureBackedByPsiMethod methodSignature, + @NotNull List superMethodSignatures, boolean includeRealPositionInfo) { return checkMethodIncompatibleReturnType(methodSignature, superMethodSignatures, includeRealPositionInfo, null); } @@ -143,10 +143,11 @@ public class HighlightMethodUtil { if (returnType == null || superReturnType == null || method == superMethod) continue; PsiClass superClass = superMethod.getContainingClass(); if (superClass == null) continue; + TextRange toHighlight = textRange != null ? textRange + : includeRealPositionInfo ? method.getReturnTypeElement().getTextRange() : TextRange.EMPTY_RANGE; HighlightInfo highlightInfo = checkSuperMethodSignature(superMethod, superMethodSignature, superReturnType, method, methodSignature, returnType, JavaErrorMessages.message("incompatible.return.type"), - textRange != null ? textRange - : includeRealPositionInfo ? method.getReturnTypeElement().getTextRange() : TextRange.EMPTY_RANGE); + toHighlight); if (highlightInfo != null) return highlightInfo; } @@ -154,12 +155,13 @@ public class HighlightMethodUtil { } private static HighlightInfo checkSuperMethodSignature(@NotNull PsiMethod superMethod, - MethodSignatureBackedByPsiMethod superMethodSignature, + @NotNull MethodSignatureBackedByPsiMethod superMethodSignature, PsiType superReturnType, - PsiMethod method, - MethodSignatureBackedByPsiMethod methodSignature, - PsiType returnType, - String detailMessage, final TextRange range) { + @NotNull PsiMethod method, + @NotNull MethodSignatureBackedByPsiMethod methodSignature, + @NotNull PsiType returnType, + @NotNull String detailMessage, + @NotNull TextRange range) { if (superReturnType == null) return null; if ("clone".equals(method.getName())) { final PsiClass containingClass = method.getContainingClass(); @@ -189,16 +191,15 @@ public class HighlightMethodUtil { } } - return createIncompatibleReturnTypeMessage(method, superMethod, - substitutedSuperReturnType, returnType, detailMessage, - range); + return createIncompatibleReturnTypeMessage(method, superMethod, substitutedSuperReturnType, returnType, detailMessage, range); } - private static HighlightInfo createIncompatibleReturnTypeMessage(PsiMethod method, + private static HighlightInfo createIncompatibleReturnTypeMessage(@NotNull PsiMethod method, @NotNull PsiMethod superMethod, - PsiType substitutedSuperReturnType, + @NotNull PsiType substitutedSuperReturnType, @NotNull PsiType returnType, - String detailMessage, final TextRange textRange) { + @NotNull String detailMessage, + @NotNull TextRange textRange) { String description = MessageFormat.format("{0}; {1}", createClashMethodMessage(method, superMethod, true), detailMessage); HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create(); QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMethodReturnFix(method, substitutedSuperReturnType, false)); @@ -421,7 +422,81 @@ public class HighlightMethodUtil { } @Nullable - static HighlightInfo checkAmbiguousMethodCall(@NotNull PsiReferenceExpression referenceToMethod, + static HighlightInfo checkAmbiguousMethodCallIdentifier(@NotNull PsiReferenceExpression referenceToMethod, + @NotNull JavaResolveResult[] resolveResults, + @NotNull PsiExpressionList list, + final PsiElement element, + @NotNull JavaResolveResult resolveResult, + @NotNull PsiMethodCallExpression methodCall, + @NotNull PsiResolveHelper resolveHelper) { + MethodCandidateInfo methodCandidate1 = null; + MethodCandidateInfo methodCandidate2 = null; + for (JavaResolveResult result : resolveResults) { + if (!(result instanceof MethodCandidateInfo)) continue; + MethodCandidateInfo candidate = (MethodCandidateInfo)result; + if (candidate.isApplicable() && !candidate.getElement().isConstructor()) { + if (methodCandidate1 == null) { + methodCandidate1 = candidate; + } + else { + methodCandidate2 = candidate; + break; + } + } + } + MethodCandidateInfo[] candidates = toMethodCandidates(resolveResults); + + String description; + String toolTip; + PsiElement elementToHighlight; + HighlightInfoType highlightInfoType = HighlightInfoType.ERROR; + if (methodCandidate2 != null) { + return null; + } + else { + if (element != null && !resolveResult.isAccessible()) { + description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult); + elementToHighlight = referenceToMethod.getReferenceNameElement(); + } + else if (element != null && !resolveResult.isStaticsScopeCorrect()) { + description = HighlightUtil.buildProblemWithStaticDescription(element); + elementToHighlight = referenceToMethod.getReferenceNameElement(); + } + else { + String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list); + description = JavaErrorMessages.message("cannot.resolve.method", methodName); + if (candidates.length == 0) { + elementToHighlight = referenceToMethod.getReferenceNameElement(); + highlightInfoType = HighlightInfoType.WRONG_REF; + } + else { + return null; + } + } + toolTip = XmlStringUtil.escapeString(description); + } + HighlightInfo info = + HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight).description(description).escapedToolTip(toolTip).create(); + if (methodCandidate2 == null) { + registerMethodCallIntentions(info, methodCall, list, resolveHelper); + } + if (!resolveResult.isAccessible() && resolveResult.isStaticsScopeCorrect() && methodCandidate2 != null) { + HighlightUtil.registerAccessQuickFixAction((PsiMember)element, referenceToMethod, info, resolveResult.getCurrentFileResolveScope()); + } + if (element != null && !resolveResult.isStaticsScopeCorrect()) { + HighlightUtil.registerStaticProblemQuickFixAction(element, info, referenceToMethod); + } + + TextRange fixRange = getFixRange(elementToHighlight); + CastMethodArgumentFix.REGISTRAR.registerCastActions(candidates, methodCall, info, fixRange); + PermuteArgumentsFix.registerFix(info, methodCall, candidates, fixRange); + WrapExpressionFix.registerWrapAction(candidates, list.getExpressions(), info); + registerChangeParameterClassFix(methodCall, list, info); + return info; + } + + @Nullable + static HighlightInfo checkAmbiguousMethodCallArguments(@NotNull PsiReferenceExpression referenceToMethod, @NotNull JavaResolveResult[] resolveResults, @NotNull PsiExpressionList list, final PsiElement element, @@ -474,19 +549,16 @@ public class HighlightMethodUtil { } else { if (element != null && !resolveResult.isAccessible()) { - description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult); - elementToHighlight = referenceToMethod.getReferenceNameElement(); + return null; } else if (element != null && !resolveResult.isStaticsScopeCorrect()) { - description = HighlightUtil.buildProblemWithStaticDescription(element); - elementToHighlight = referenceToMethod.getReferenceNameElement(); + return null; } else { String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list); description = JavaErrorMessages.message("cannot.resolve.method", methodName); if (candidates.length == 0) { - elementToHighlight = referenceToMethod.getReferenceNameElement(); - highlightInfoType = HighlightInfoType.WRONG_REF; + return null; } else { elementToHighlight = list; @@ -514,7 +586,8 @@ public class HighlightMethodUtil { return info; } - private static MethodCandidateInfo[] toMethodCandidates(JavaResolveResult[] resolveResults) { + @NotNull + private static MethodCandidateInfo[] toMethodCandidates(@NotNull JavaResolveResult[] resolveResults) { List candidateList = new ArrayList(resolveResults.length); for (JavaResolveResult result : resolveResults) { @@ -911,9 +984,6 @@ public class HighlightMethodUtil { additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, true, false)); } } - else if (isExtension) { - return HighlightUtil.checkExtensionMethodsFeature(method, languageLevel,containingFile); - } } else if (isExtension) { description = JavaErrorMessages.message("extension.method.in.class"); @@ -941,8 +1011,7 @@ public class HighlightMethodUtil { } @Nullable - static HighlightInfo checkConstructorCallMustBeFirstStatement(PsiReferenceExpression expression) { - PsiElement methodCall = expression.getParent(); + static HighlightInfo checkConstructorCallMustBeFirstStatement(@NotNull PsiMethodCallExpression methodCall) { if (!RefactoringChangeUtil.isSuperOrThisMethodCall(methodCall)) return null; PsiElement codeBlock = methodCall.getParent().getParent(); if (codeBlock instanceof PsiCodeBlock @@ -955,21 +1024,19 @@ public class HighlightMethodUtil { prevSibling = prevSibling.getPrevSibling(); } } + PsiReferenceExpression expression = methodCall.getMethodExpression(); String message = JavaErrorMessages.message("constructor.call.must.be.first.statement", expression.getText() + "()"); - PsiElement element = expression.getParent(); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(message).create(); + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(methodCall).descriptionAndTooltip(message).create(); } - static HighlightInfo checkAbstractMethodDirectCall(PsiSuperExpression expr) { - if (expr.getParent() instanceof PsiReferenceExpression - && expr.getParent().getParent() instanceof PsiMethodCallExpression) { - PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expr.getParent().getParent(); - PsiMethod method = methodCallExpression.resolveMethod(); - if (method != null && method.hasModifierProperty(PsiModifier.ABSTRACT)) { - String message = JavaErrorMessages.message("direct.abstract.method.access", JavaHighlightUtil.formatMethod(method)); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(methodCallExpression).descriptionAndTooltip(message).create(); - } + static HighlightInfo checkSuperAbstractMethodDirectCall(@NotNull PsiMethodCallExpression methodCallExpression) { + PsiReferenceExpression expression = methodCallExpression.getMethodExpression(); + if (!(expression.getQualifierExpression() instanceof PsiSuperExpression)) return null; + PsiMethod method = methodCallExpression.resolveMethod(); + if (method != null && method.hasModifierProperty(PsiModifier.ABSTRACT)) { + String message = JavaErrorMessages.message("direct.abstract.method.access", JavaHighlightUtil.formatMethod(method)); + return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(methodCallExpression).descriptionAndTooltip(message).create(); } return null; } @@ -1231,8 +1298,10 @@ public class HighlightMethodUtil { } - static void checkNewExpression(@NotNull PsiNewExpression expression, @NotNull HighlightInfoHolder holder, @NotNull JavaSdkVersion javaSdkVersion) { - PsiType type = expression.getType(); + static void checkNewExpression(@NotNull PsiNewExpression expression, + PsiType type, + @NotNull HighlightInfoHolder holder, + @NotNull JavaSdkVersion javaSdkVersion) { if (!(type instanceof PsiClassType)) return; PsiClassType.ClassResolveResult typeResult = ((PsiClassType)type).resolveGenerics(); PsiClass aClass = typeResult.getElement(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index e52e62b435e5..7c4e8fa112cc 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1166,13 +1166,14 @@ public class HighlightUtil extends HighlightUtilBase { } @Nullable - static Collection checkExceptionThrownInTry(@NotNull final PsiParameter parameter, @NotNull final Set thrownTypes) { + static List checkExceptionThrownInTry(@NotNull final PsiParameter parameter, @NotNull final Set thrownTypes) { final PsiElement declarationScope = parameter.getDeclarationScope(); if (!(declarationScope instanceof PsiCatchSection)) return null; final PsiType caughtType = parameter.getType(); if (caughtType instanceof PsiClassType) { - return checkSimpleCatchParameter(parameter, thrownTypes, (PsiClassType)caughtType); + HighlightInfo info = checkSimpleCatchParameter(parameter, thrownTypes, (PsiClassType)caughtType); + return info == null ? null : Collections.singletonList(info); } if (caughtType instanceof PsiDisjunctionType) { return checkMultiCatchParameter(parameter, thrownTypes); @@ -1182,7 +1183,7 @@ public class HighlightUtil extends HighlightUtilBase { } @Nullable - private static Collection checkSimpleCatchParameter(@NotNull final PsiParameter parameter, + private static HighlightInfo checkSimpleCatchParameter(@NotNull final PsiParameter parameter, @NotNull final Collection thrownTypes, @NotNull final PsiClassType caughtType) { if (ExceptionUtil.isUncheckedExceptionOrSuperclass(caughtType)) return null; @@ -1195,14 +1196,14 @@ public class HighlightUtil extends HighlightUtilBase { final HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parameter).descriptionAndTooltip(description).create(); QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createDeleteCatchFix(parameter)); - return Collections.singleton(errorResult); + return errorResult; } @Nullable - private static Collection checkMultiCatchParameter(@NotNull final PsiParameter parameter, - @NotNull final Collection thrownTypes) { + private static List checkMultiCatchParameter(@NotNull final PsiParameter parameter, + @NotNull final Collection thrownTypes) { final List typeElements = PsiUtil.getParameterTypeElements(parameter); - final Collection highlights = ContainerUtil.newArrayListWithCapacity(typeElements.size()); + final List highlights = new ArrayList(typeElements.size()); for (final PsiTypeElement typeElement : typeElements) { final PsiType catchType = typeElement.getType(); @@ -1400,17 +1401,6 @@ public class HighlightUtil extends HighlightUtilBase { String description = JavaErrorMessages.message("dot.expected.after.super.or.this"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(o, o + 1).descriptionAndTooltip(description).create(); } - - if (PsiUtil.isLanguageLevel8OrHigher(expr)) { - final PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class); - if (method != null && method.hasModifierProperty(PsiModifier.DEFAULT) && qualifier == null) { - final String description = JavaErrorMessages.message("unqualified.super.disallowed"); - final HighlightInfo highlightInfo = - HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip(description).create(); - QualifySuperArgumentFix.registerQuickFixAction((PsiSuperExpression)expr, highlightInfo); - return highlightInfo; - } - } } PsiClass aClass; @@ -1450,6 +1440,21 @@ public class HighlightUtil extends HighlightUtilBase { return null; } + static HighlightInfo checkUnqualifiedSuperInDefaultMethod(@NotNull LanguageLevel languageLevel, + @NotNull PsiReferenceExpression expr, + PsiExpression qualifier) { + if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && qualifier instanceof PsiSuperExpression) { + final PsiMethod method = PsiTreeUtil.getParentOfType(expr, PsiMethod.class); + if (method != null && method.hasModifierProperty(PsiModifier.DEFAULT) && ((PsiSuperExpression)qualifier).getQualifier() == null) { + String description = JavaErrorMessages.message("unqualified.super.disallowed"); + HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expr).descriptionAndTooltip(description).create(); + QualifySuperArgumentFix.registerQuickFixAction((PsiSuperExpression)qualifier, info); + return info; + } + } + return null; + } + private static boolean isInsideDefaultMethod(PsiMethod method, PsiClass aClass) { while (method != null && method.getContainingClass() != aClass) { method = PsiTreeUtil.getParentOfType(method, PsiMethod.class, true); @@ -2534,8 +2539,7 @@ public class HighlightUtil extends HighlightUtilBase { } } if ((resolved instanceof PsiLocalVariable || resolved instanceof PsiParameter) && !(resolved instanceof ImplicitVariable)) { - highlightInfo = HighlightControlFlowUtil.checkVariableMustBeFinal((PsiVariable)resolved, ref, - languageLevel); + highlightInfo = HighlightControlFlowUtil.checkVariableMustBeFinal((PsiVariable)resolved, ref, languageLevel); } else if (resolved instanceof PsiClass) { if (Comparing.strEqual(((PsiClass)resolved).getQualifiedName(), ((PsiClass)resolved).getName())) { @@ -2813,9 +2817,14 @@ public class HighlightUtil extends HighlightUtilBase { } @Nullable - public static HighlightInfo checkDiamondFeature(@NotNull PsiTypeElement typeElement, @NotNull LanguageLevel languageLevel,@NotNull PsiFile containingFile) { - return typeElement.getType() instanceof PsiDiamondType ? checkFeature(typeElement.getParent(), Feature.DIAMOND_TYPES, - languageLevel, containingFile) : null; + public static HighlightInfo checkDiamondFeature(@NotNull PsiType type, + @NotNull PsiElement toHighlight, + @NotNull LanguageLevel languageLevel, + @NotNull PsiFile containingFile) { + if (type instanceof PsiDiamondType) { + return checkFeature(toHighlight, Feature.DIAMOND_TYPES, languageLevel, containingFile); + } + return null; } @Nullable @@ -2825,8 +2834,8 @@ public class HighlightUtil extends HighlightUtilBase { } @Nullable - public static HighlightInfo checkTryWithResourcesFeature(@NotNull PsiResourceVariable resourceVariable, @NotNull LanguageLevel languageLevel,@NotNull PsiFile containingFile) { - return checkFeature(resourceVariable.getParent(), Feature.TRY_WITH_RESOURCES, languageLevel, containingFile); + public static HighlightInfo checkTryWithResourcesFeature(@NotNull PsiElement toHighlight, @NotNull LanguageLevel languageLevel,@NotNull PsiFile containingFile) { + return checkFeature(toHighlight, Feature.TRY_WITH_RESOURCES, languageLevel, containingFile); } @Nullable diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index f0e982ead75a..c6282959300d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.codeInsight.daemon.impl.*; import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.colors.TextAttributesScheme; import com.intellij.openapi.progress.ProgressIndicator; @@ -85,13 +86,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh private final Map> myDuplicateMethods = new THashMap>(); private LanguageLevel myLanguageLevel; private JavaSdkVersion myJavaSdkVersion; + private static final boolean CHECK_ELEMENT_LEVEL = ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isInternal(); public HighlightVisitorImpl(@NotNull PsiResolveHelper resolveHelper) { myResolveHelper = resolveHelper; } @NotNull - private MostlySingularMultiMap getDuplicateMethods(PsiClass aClass) { + private MostlySingularMultiMap getDuplicateMethods(@NotNull PsiClass aClass) { MostlySingularMultiMap signatures = myDuplicateMethods.get(aClass); if (signatures == null) { signatures = new MostlySingularMultiMap(); @@ -124,7 +126,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visit(@NotNull PsiElement element) { - element.accept(this); + if (CHECK_ELEMENT_LEVEL) { + ((CheckLevelHighlightInfoHolder)myHolder).enterLevel(element); + element.accept(this); + ((CheckLevelHighlightInfoHolder)myHolder).enterLevel(null); + } + else { + element.accept(this); + } } private void registerReferencesFromInjectedFragments(@NotNull PsiElement element) { @@ -135,16 +144,17 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @NotNull final List places) { injectedPsi.accept(REGISTER_REFERENCES_VISITOR); } - }); + } + ); } @Override public boolean analyze(@NotNull final PsiFile file, final boolean updateWholeFile, - @NotNull HighlightInfoHolder holder, + @NotNull final HighlightInfoHolder holder, @NotNull final Runnable action) { myFile = file; - myHolder = holder; + myHolder = CHECK_ELEMENT_LEVEL ? new CheckLevelHighlightInfoHolder(file, holder) : holder; boolean success = true; try { myLanguageLevel = PsiUtil.getLanguageLevel(file); @@ -260,7 +270,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitAssignmentExpression(PsiAssignmentExpression assignment) { if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkAssignmentCompatibleTypes(assignment)); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkAssignmentOperatorApplicable(assignment,myFile)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkAssignmentOperatorApplicable(assignment, myFile)); if (!myHolder.hasErrorResults()) visitExpression(assignment); } @@ -272,7 +282,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitLambdaExpression(PsiLambdaExpression expression) { - myHolder.add(HighlightUtil.checkLambdaFeature(expression, myLanguageLevel,myFile)); + myHolder.add(HighlightUtil.checkLambdaFeature(expression, myLanguageLevel, myFile)); if (!myHolder.hasErrorResults()) { if (LambdaUtil.isValidLambdaContext(expression.getParent())) { final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType(); @@ -372,6 +382,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) { myHolder.add(HighlightUtil.checkLabelDefined(statement.getLabelIdentifier(), statement.findExitedStatement())); } + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkBreakOutsideLoop(statement)); } @Override @@ -414,6 +425,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) { myHolder.add(HighlightUtil.checkLabelDefined(statement.getLabelIdentifier(), statement.findContinuedStatement())); } + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkContinueOutsideLoop(statement)); } @Override @@ -517,6 +529,37 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } + @Override + public void visitExpressionList(PsiExpressionList list) { + super.visitExpressionList(list); + PsiElement parent = list.getParent(); + if (parent instanceof PsiMethodCallExpression) { + PsiMethodCallExpression expression = (PsiMethodCallExpression)parent; + if (expression.getArgumentList() == list) { + PsiReferenceExpression referenceExpression = expression.getMethodExpression(); + JavaResolveResult result; + JavaResolveResult[] results; + try { + results = resolveOptimised(referenceExpression); + result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY; + } + catch (IndexNotReadyException e) { + return; + } + PsiElement resolved = result.getElement(); + + if ((!result.isAccessible() || !result.isStaticsScopeCorrect()) && + !HighlightMethodUtil.isDummyConstructorCall(expression, myResolveHelper, list, referenceExpression)) { + try { + myHolder.add(HighlightMethodUtil.checkAmbiguousMethodCallArguments(referenceExpression, results, list, resolved, result, expression, myResolveHelper)); + } + catch (IndexNotReadyException ignored) { + } + } + } + } + } + @Override public void visitField(PsiField field) { super.visitField(field); @@ -531,6 +574,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitForeachStatement(final PsiForeachStatement statement) { myHolder.add(HighlightUtil.checkForEachFeature(statement, myLanguageLevel, myFile)); + if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkForeachLoopParameterType(statement)); } @Override @@ -553,7 +597,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } boolean isMethodParameter = variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiMethod; - if (!isMethodParameter) { // method params are highlighted in visitMethod since we should make sure the method body was visited before + if (isMethodParameter) { + myReassignedParameters.put((PsiParameter)variable, 1); // mark param as present in current file + } + else { + // method params are highlighted in visitMethod since we should make sure the method body was visited before if (HighlightControlFlowUtil.isReassigned(variable, myFinalVarProblems)) { myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, identifier)); } @@ -561,9 +609,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme)); } } - else { - myReassignedParameters.put((PsiParameter)variable, 1); // mark param as present in current file - } myHolder.add(HighlightUtil.checkUnderscore(identifier, variable)); } @@ -577,6 +622,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!(parent instanceof PsiAnonymousClass) && aClass.getNameIdentifier() == identifier) { myHolder.add(HighlightNamesUtil.highlightClassName(aClass, identifier, colorsScheme)); } + if (!myHolder.hasErrorResults() && myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { + myHolder.add(GenericsHighlightUtil.checkUnrelatedDefaultMethods(aClass, aClass.getVisibleSignatures(), identifier)); + } } else if (parent instanceof PsiMethod) { PsiMethod method = (PsiMethod)parent; @@ -584,32 +632,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(HighlightMethodUtil.checkConstructorName(method)); } myHolder.add(HighlightNamesUtil.highlightMethodName(method, identifier, true, colorsScheme)); - } - else { - visitParentReference(parent); + myHolder.add(GenericsHighlightUtil.checkDefaultMethodOverrideEquivalentToObjectNonPrivate(myLanguageLevel, + method.getContainingClass(), method, + identifier)); } super.visitIdentifier(identifier); } - private void visitParentReference(PsiElement parent) { - if (parent instanceof PsiJavaCodeReferenceElement && !(parent.getParent() instanceof PsiJavaCodeReferenceElement) && - !((PsiJavaCodeReferenceElement)parent).isQualified()) { - PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)parent; - JavaResolveResult result; - try { - result = ref.advancedResolve(true); - } - catch (IndexNotReadyException e) { - return; - } - myHolder.add(HighlightUtil.checkReference(ref, result, myFile, myLanguageLevel)); - if (myRefCountHolder != null) { - myRefCountHolder.registerReference(ref, result); - } - } - } - @Override public void visitImportStatement(final PsiImportStatement statement) { if (!myHolder.hasErrorResults()) { @@ -690,20 +720,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } } - else if (PsiKeyword.CONTINUE.equals(text) && parent instanceof PsiContinueStatement) { - PsiContinueStatement statement = (PsiContinueStatement)parent; - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkContinueOutsideLoop(statement)); - } - else if (PsiKeyword.BREAK.equals(text) && parent instanceof PsiBreakStatement) { - PsiBreakStatement statement = (PsiBreakStatement)parent; - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkBreakOutsideLoop(statement)); - } else if (PsiKeyword.INTERFACE.equals(text) && parent instanceof PsiClass) { if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkInterfaceCannotBeLocal((PsiClass)parent)); } - else { - visitParentReference(parent); - } if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkStaticDeclarationInInnerClass(keyword)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIllegalVoidType(keyword)); @@ -736,9 +755,15 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkRecursiveConstructorInvocation(method)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideAnnotation(method, myLanguageLevel)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method)); + PsiClass aClass = method.getContainingClass(); if (!myHolder.hasErrorResults() && method.isConstructor()) { - myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, method.getContainingClass())); + myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, aClass)); } + if (!myHolder.hasErrorResults() && method.hasModifierProperty(PsiModifier.DEFAULT)) { + myHolder.add(HighlightUtil.checkExtensionMethodsFeature(method, myLanguageLevel, myFile)); + } + + if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkDuplicateMethod(aClass, method, getDuplicateMethods(aClass))); // method params are highlighted in visitMethod since we should make sure the method body was visited before PsiParameter[] parameters = method.getParameterList().getParameters(); @@ -812,6 +837,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } + if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorCallMustBeFirstStatement(expression)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkSuperAbstractMethodDirectCall(expression)); + if (!myHolder.hasErrorResults()) visitExpression(expression); } @@ -840,7 +868,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } PsiClass aClass = method.getContainingClass(); if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodMustHaveBody(method, aClass)); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkDuplicateMethod(aClass, method, getDuplicateMethods(aClass))); if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorCallsBaseClassConstructor(method, myRefCountHolder, myResolveHelper)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkStaticMethodOverride(method,myFile)); } @@ -856,7 +883,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myHolder.add(HighlightClassUtil.checkClassDoesNotCallSuperConstructorOrHandleExceptions(aClass, myRefCountHolder, myResolveHelper)); } if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkOverrideEquivalentInheritedMethods(aClass, myFile)); - if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(aClass)); + if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass + )); if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCyclicInheritance(aClass)); } catch (IndexNotReadyException ignored) { @@ -881,18 +909,21 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitNewExpression(PsiNewExpression expression) { + final PsiType type = expression.getType(); + final PsiClass aClass = PsiUtil.resolveClassInType(type); myHolder.add(HighlightUtil.checkUnhandledExceptions(expression, null)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkAnonymousInheritFinal(expression)); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkQualifiedNew(expression)); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCreateInnerClassFromStaticContext(expression)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkQualifiedNew(expression, type, aClass)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkCreateInnerClassFromStaticContext(expression, type, aClass)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkTypeParameterInstantiation(expression)); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkInstantiationOfAbstractClass(aClass, expression)); try { - if (!myHolder.hasErrorResults()) HighlightMethodUtil.checkNewExpression(expression, myHolder, myJavaSdkVersion); + if (!myHolder.hasErrorResults()) HighlightMethodUtil.checkNewExpression(expression, type, myHolder, myJavaSdkVersion); } catch (IndexNotReadyException ignored) { } - if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkEnumInstantiation(expression)); - if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkGenericArrayCreation(expression, expression.getType())); + if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkEnumInstantiation(expression, aClass)); + if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkGenericArrayCreation(expression, type)); if (!myHolder.hasErrorResults()) registerConstructorCall(expression); if (!myHolder.hasErrorResults()) visitExpression(expression); @@ -913,9 +944,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkVarArgParameterIsLast(parameter, myLanguageLevel,myFile)); } - else if (parent instanceof PsiForeachStatement) { - if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkForeachLoopParameterType((PsiForeachStatement)parent)); - } else if (parent instanceof PsiCatchSection) { if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkMultiCatchFeature(parameter, myLanguageLevel,myFile)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkCatchParameterIsThrowable(parameter)); @@ -946,7 +974,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } - private void registerConstructorCall(PsiConstructorCall constructorCall) { + private void registerConstructorCall(@NotNull PsiConstructorCall constructorCall) { if (myRefCountHolder != null) { JavaResolveResult resolveResult = constructorCall.resolveMethodGenerics(); final PsiElement resolved = resolveResult.getElement(); @@ -958,23 +986,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitReferenceElement(PsiJavaCodeReferenceElement ref) { - doVisitReferenceElement(ref); + JavaResolveResult resolveResult = doVisitReferenceElement(ref); + if (resolveResult != null && !myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkRawOnParameterizedType(ref, resolveResult.getElement())); } private JavaResolveResult doVisitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) { JavaResolveResult result; try { - if (ref instanceof PsiReferenceExpressionImpl) { - PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)ref; - JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(referenceExpression, - PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, - true, true, - myFile); - result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY; - } - else { - result = ref.advancedResolve(true); - } + result = resolveOptimised(ref); } catch (IndexNotReadyException e) { return null; @@ -982,11 +1001,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh PsiElement resolved = result.getElement(); PsiElement parent = ref.getParent(); + if (myRefCountHolder != null) { + myRefCountHolder.registerReference(ref, result); + } + myHolder.add(HighlightUtil.checkReference(ref, result, myFile, myLanguageLevel)); if (parent instanceof PsiJavaCodeReferenceElement || ref.isQualified()) { - if (myRefCountHolder != null) { - myRefCountHolder.registerReference(ref, result); - } - myHolder.add(HighlightUtil.checkReference(ref, result, myFile, myLanguageLevel)); if (!myHolder.hasErrorResults() && resolved instanceof PsiTypeParameter) { boolean cannotSelectFromTypeParameter = !myJavaSdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7); if (!cannotSelectFromTypeParameter) { @@ -1020,7 +1039,8 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } if (parent instanceof PsiAnonymousClass && ref.equals(((PsiAnonymousClass)parent).getBaseClassReference())) { - myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods((PsiClass)parent)); + PsiClass aClass = (PsiClass)parent; + myHolder.add(GenericsHighlightUtil.checkOverrideEquivalentMethods(myLanguageLevel, aClass)); } if (resolved instanceof PsiVariable) { @@ -1093,6 +1113,38 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh return result; } + @NotNull + private JavaResolveResult resolveOptimised(@NotNull PsiJavaCodeReferenceElement ref) { + JavaResolveResult result; + if (ref instanceof PsiReferenceExpressionImpl) { + PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)ref; + JavaResolveResult[] results = JavaResolveUtil.resolveWithContainingFile(referenceExpression, + PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, + true, true, + myFile); + result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY; + } + else { + result = ref.advancedResolve(true); + } + return result; + } + + @NotNull + private JavaResolveResult[] resolveOptimised(@NotNull PsiReferenceExpression expression) { + JavaResolveResult[] results; + if (expression instanceof PsiReferenceExpressionImpl) { + PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)expression; + results = JavaResolveUtil.resolveWithContainingFile(referenceExpression, + PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, true, true, + myFile); + } + else { + results = expression.multiResolve(true); + } + return results; + } + @Override public void visitReferenceExpression(PsiReferenceExpression expression) { JavaResolveResult resultForIncompleteCode = doVisitReferenceElement(expression); @@ -1103,15 +1155,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh JavaResolveResult result; JavaResolveResult[] results; try { - if (expression instanceof PsiReferenceExpressionImpl) { - PsiReferenceExpressionImpl referenceExpression = (PsiReferenceExpressionImpl)expression; - results = JavaResolveUtil.resolveWithContainingFile(referenceExpression, - PsiReferenceExpressionImpl.OurGenericsResolver.INSTANCE, true, true, - myFile); - } - else { - results = expression.multiResolve(true); - } + results = resolveOptimised(expression); result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY; } catch (IndexNotReadyException e) { @@ -1142,13 +1186,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh PsiExpressionList list = methodCallExpression.getArgumentList(); if (!HighlightMethodUtil.isDummyConstructorCall(methodCallExpression, myResolveHelper, list, expression)) { try { - HighlightInfo info = HighlightMethodUtil.checkAmbiguousMethodCall(expression, results, list, resolved, result, methodCallExpression, myResolveHelper); - myHolder.add(info); + myHolder.add(HighlightMethodUtil.checkAmbiguousMethodCallIdentifier(expression, results, list, resolved, result, + methodCallExpression, myResolveHelper)); } catch (IndexNotReadyException ignored) { } } } + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkExpressionRequired(expression, resultForIncompleteCode)); if (!myHolder.hasErrorResults() && resolved instanceof PsiField) { try { @@ -1157,9 +1202,9 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh catch (IndexNotReadyException ignored) { } } - if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorCallMustBeFirstStatement(expression)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkAccessStaticFieldFromEnumConstructor(expression, result)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkClassReferenceAfterQualifier(expression, resolved)); + myHolder.add(HighlightUtil.checkUnqualifiedSuperInDefaultMethod(myLanguageLevel, expression, expression.getQualifierExpression())); } @Override @@ -1278,7 +1323,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh public void visitReferenceParameterList(PsiReferenceParameterList list) { myHolder.add(GenericsHighlightUtil.checkParametersAllowed(list, myLanguageLevel,myFile)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkParametersOnRaw(list)); - if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkRawOnParameterizedType(list)); + if (!myHolder.hasErrorResults()) { + for (PsiType type : list.getTypeArguments()) { + myHolder.add(HighlightUtil.checkDiamondFeature(type, list, myLanguageLevel,myFile)); + } + } } @Override @@ -1300,7 +1349,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitSuperExpression(PsiSuperExpression expr) { myHolder.add(HighlightUtil.checkThisOrSuperExpressionInIllegalContext(expr, expr.getQualifier())); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkAbstractMethodDirectCall(expr)); if (!myHolder.hasErrorResults()) visitExpression(expr); } @@ -1353,14 +1401,18 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitResourceVariable(final PsiResourceVariable resourceVariable) { visitVariable(resourceVariable); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkTryWithResourcesFeature(resourceVariable, myLanguageLevel,myFile)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkTryResourceIsAutoCloseable(resourceVariable)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkUnhandledCloserExceptions(resourceVariable)); } + @Override + public void visitResourceList(PsiResourceList resourceList) { + super.visitResourceList(resourceList); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkTryWithResourcesFeature(resourceList, myLanguageLevel, myFile)); + } + @Override public void visitTypeElement(final PsiTypeElement type) { - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkDiamondFeature(type, myLanguageLevel,myFile)); if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkIllegalType(type)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkReferenceTypeUsedAsTypeArgument(type)); if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkWildcardUsage(type)); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/StaticMemberProcessor.java b/java/java-impl/src/com/intellij/codeInsight/completion/StaticMemberProcessor.java index 9a91e8f10f9d..e79fe27ac5c2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/StaticMemberProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/StaticMemberProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -import static com.intellij.util.containers.ContainerUtil.addIfNotNull; - /** * @author peter */ @@ -53,7 +51,7 @@ public abstract class StaticMemberProcessor { } public void importMembersOf(@Nullable PsiClass psiClass) { - addIfNotNull(myStaticImportedClasses, psiClass); + ContainerUtil.addIfNotNull(myStaticImportedClasses, psiClass); } public void processStaticMethodsGlobally(final PrefixMatcher matcher, Consumer consumer) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java index eb058f9aa580..5b76439ef406 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -241,10 +241,10 @@ public class JavaResolveUtil { @NotNull public static JavaResolveResult[] resolveWithContainingFile(@NotNull T ref, - @NotNull ResolveCache.PolyVariantResolver resolver, - boolean needToPreventRecursion, - boolean incompleteCode, - @NotNull PsiFile containingFile) { + @NotNull ResolveCache.PolyVariantResolver resolver, + boolean needToPreventRecursion, + boolean incompleteCode, + @NotNull PsiFile containingFile) { boolean valid = containingFile.isValid(); if (!valid) { return JavaResolveResult.EMPTY_ARRAY; diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index 08aa5781f9c6..d9feb5cbd34b 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -78,7 +78,7 @@ generics.unchecked.cast=Unchecked cast: ''{0}'' to ''{1}'' generics.unchecked.call.to.member.of.raw.type=Unchecked call to ''{0}'' as a member of raw type ''{1}'' generics.diamond.not.applicable=Diamond operator is not applicable for non-parameterized types generics.reference.parameters.not.allowed=Reference parameters are not allowed here -foreach.not.applicable=foreach not applicable to type ''{0}''. +foreach.not.applicable=foreach not applicable to type ''{0}'' illegal.to.access.static.member.from.enum.constructor.or.instance.initializer=It is illegal to access static member ''{0}'' from enum constructor or instance initializer enum.types.cannot.be.instantiated=Enum types cannot be instantiated generic.array.creation=Generic array creation @@ -133,7 +133,7 @@ variable.not.initialized=Variable ''{0}'' might not have been initialized variable.already.assigned=Variable ''{0}'' might already have been assigned to variable.assigned.in.loop=Variable ''{0}'' might be assigned in loop assignment.to.final.variable=Cannot assign a value to final variable ''{0}'' -variable.must.be.final=Variable ''{0}'' is accessed from within inner class. Needs to be declared final. +variable.must.be.final=Variable ''{0}'' is accessed from within inner class, needs to be declared final initializer.must.be.able.to.complete.normally=Initializer must be able to complete normally weaker.privileges={0}; attempting to assign weaker access privileges (''{1}''); was ''{2}'' incompatible.return.type=attempting to use incompatible return type @@ -170,7 +170,7 @@ ambiguous.method.html.tooltip=\ \ \ {1}\ - {3}\ + {3}\
Ambiguous method call. Both
in {2}\\ and
in {4}\\ match.
in {4}\\ match
@@ -339,7 +339,7 @@ expected.lbracket='[' expected expected.lparen.or.lbracket='(' or '[' expected expected.array.initializer=Array initializer expected unexpected.tokens=Unexpected tokens -expected.gt.or.comma='>' or ',' expected. +expected.gt.or.comma='>' or ',' expected string.expected=String literal expected else.without.if='else' without 'if' catch.without.try='catch' without 'try' diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java index a5d74ebe3c55..15b61dffcd77 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java @@ -1,6 +1,6 @@ public class a { void f(int i) { } - void f(int i) { + void f(int i) { new c1() { public void f1() {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java index 9bf1beba3c1e..455f86be4fe7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java @@ -28,6 +28,7 @@ public class a { } abstract class c1 { abstract public void f1(int i); + Object o = new c1[0]; } interface ii { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java index f2a914b6ff60..f05342d5dfe6 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java @@ -4,7 +4,7 @@ class m { int r = 0; new Runnable() { public void run() { - int k = r; + int k = r; int ii = i; } }; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java index b3bdd17d9a7b..326c24bbbbf5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnsupportedFeatures.java @@ -27,9 +27,9 @@ class UnsupportedFeatures { for (String s : args) { System.out.println(s); } List list = - new ArrayList<>(); + new ArrayList<>(); - for (String s : list) {} + for (String s : list) {} Arrays.asList(""); Boolean b = true; boolean b1 = Boolean.TRUE; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/UnsupportedFeatures7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/UnsupportedFeatures7.java new file mode 100644 index 000000000000..506accd112c3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/UnsupportedFeatures7.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.*; +import java.util.*; + +import static java.lang.Math.*; + +@interface Anno { } + +@Anno +class UnsupportedFeatures { + void m(String... args) throws Exception { + for (String s : args) { System.out.println(s); } + + List list = + new ArrayList<>(); + + for (String s : list) {} + Arrays.asList(""); + Boolean b = true; + boolean b1 = Boolean.TRUE; + + try { Reader r = new FileReader("/dev/null"); } + catch (FileNotFoundException | IOException e) { e.printStackTrace(); } + + try (Reader r = new FileReader("/dev/null")) { } + + I i1 = UnsupportedFeatures::m; + I i2 = () -> { }; + } + + interface I { + default void m() { } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/Usage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/Usage.java index dcbc8ccd43a0..eccbc76e062a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/Usage.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/staticImportConflict/Usage.java @@ -24,6 +24,6 @@ class Usage { m(Base1.F); //Base1.m(int) m(F); //Base2.m(float), float Base2.F F.class.getName(); // class Base2.F - m(IF); + m(IF); } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/annotations/wrongPlace.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/annotations/wrongPlace.java index 581948e6ed2b..ffb0435f7b9a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/annotations/wrongPlace.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/annotations/wrongPlace.java @@ -22,7 +22,10 @@ enum E { } interface I { - @Anno public @Anno Collection<@Anno String> method(@Anno @Anno Object o); + @Anno + public @Anno + Collection<@Anno String> + method(@Anno @Anno Object o); } @interface Caller { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java index c9fc821243f8..2f3f516231d1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java @@ -22,8 +22,12 @@ class a { for (Object oi: (Iterable)o) {} - for (int i:db) { + // error descr="Incompatible types. Found: 'double', required: 'int'" was not shown because there is an error in nested for + for (int i : db) { for (int p: list) {} } + + for (int gjkh : 222) { + } } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ForeachTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ForeachTypes.java index bd06d92a3b5b..47c44fe95c8d 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ForeachTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ForeachTypes.java @@ -22,7 +22,7 @@ class a { for (Object oi: (Iterable)o) {} - for (int i:db) { + for (int i:db) { for (int p: list) {} } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java index 57f194dcab48..1512dd0abc43 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java @@ -1,6 +1,6 @@ public interface IDEA99969 { default IntStream distinct(Stream s) { - return s.map(i -> (int) i); + return s.map(i -> (int) i); } } interface Stream { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution3.java index 6f7e6d061350..ca4938fb569b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution3.java @@ -8,8 +8,8 @@ class Test { IntStream mi = sp.map(Inner::foo); Stream mI = sp.map(Inner::fooBoxed); - IntStream li = sp.map(inner->inner.foo()); - Stream lI = sp.map(inner -> inner.fooBoxed()); + IntStream li = sp.map(inner->inner.foo()); + Stream lI = sp.map(inner -> inner.fooBoxed()); } interface Stream { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java index 1d3bab8d8243..254ec7191a47 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/EffectiveFinal.java @@ -108,7 +108,7 @@ class ParameterIsEffectivelyFinal { new Runnable() { @Override public void run() { - System.out.println(o); + System.out.println(o); } }.run(); return 0; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility1.java index 8daa44f040a7..84e929697a92 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility1.java @@ -21,9 +21,9 @@ class Test { } void foo(Foo as, final Foo ac) { - boolean b1 = as.forAll(s -> ac.forAll(c -> false)); - String s1 = as.forAll(s -> ac.forAll(c -> "")); - boolean b2 = as.forAll(s -> ac.forAll(c -> "")); + boolean b1 = as.forAll(s -> ac.forAll(c -> false)); + String s1 = as.forAll(s -> ac.forAll(c -> "")); + boolean b2 = as.forAll(s -> ac.forAll(c -> "")); String s2 = as.forAll2(s -> ac.forAll2(c -> false)); boolean b3 = as.forAll((I)s -> ac.forAll((I)c -> "")); String s3 = as.forAll((II)s -> ac.forAll((II)c -> false)); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java index ea14af2900ce..cb671b7cd6c0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/DefaultMethodOverrideEquivalentObject.java @@ -1,5 +1,5 @@ interface A { - default String toString() { + default String toString() { return ""; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java index 8c6bc7e3815d..cc358d64f1ee 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java @@ -23,10 +23,10 @@ class C { interface II extends I { default void m() { I.super.m(); - super.m(); + super.m(); System.out.println(I.super.i); - System.out.println(super.i); + System.out.println(super.i); } void ma(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java index cd82c711775f..81c52a8cb7e6 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java @@ -14,9 +14,9 @@ class Foo { void foo(K k){} void bar() { - foo((p) -> { + foo((p) -> { System.out.println(p); - }); + }); foo((p, k) -> { System.out.println(p); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/implementAbstractFromNew/beforeImplementInterfaceIncomplete.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/implementAbstractFromNew/beforeImplementInterfaceIncomplete.java deleted file mode 100644 index 62792362cadd..000000000000 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/implementAbstractFromNew/beforeImplementInterfaceIncomplete.java +++ /dev/null @@ -1,9 +0,0 @@ -// "Implement Methods" "true" -class c { - void foo() { - new I( - } -} -interface I { - foo(T t); -} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/after5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/after5.java index 93bc3136e1b1..6bf0da8b390e 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/after5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/after5.java @@ -1,4 +1,6 @@ // "Make 'victim' return 'boolean'" "true" +import java.util.*; + public class External { void m1() { if (new Out().victim(null)) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/before5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/before5.java index 3c7bc2f4025a..fb2bb3b6d61b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/before5.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/before5.java @@ -1,4 +1,6 @@ // "Make 'victim' return 'boolean'" "true" +import java.util.*; + public class External { void m1() { if (new Out().victim(null)) { diff --git a/java/java-tests/testData/psi/parser-full/commonParsing/RefParamsAfterError.txt b/java/java-tests/testData/psi/parser-full/commonParsing/RefParamsAfterError.txt index fd394aa1ad24..38e287efd51c 100644 --- a/java/java-tests/testData/psi/parser-full/commonParsing/RefParamsAfterError.txt +++ b/java/java-tests/testData/psi/parser-full/commonParsing/RefParamsAfterError.txt @@ -63,7 +63,7 @@ PsiJavaFile:RefParamsAfterError.java PsiJavaToken:LT('<') PsiErrorElement:Identifier expected - PsiErrorElement:'>' or ',' expected. + PsiErrorElement:'>' or ',' expected PsiErrorElement:Identifier expected diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java index b6c42325c325..0a83f8edac12 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,4 +60,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase { public void testJava5CastConventions() { setLanguageLevel(LanguageLevel.JDK_1_5); doTest(true, false); } public void testUnhandledExceptions() { doTest(true, false); } public void testUnhandledExceptionsValueOf() { doTest(true, false); } + public void testUnsupportedFeatures7() { doTest(false, false); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy index b2a4447dbb73..662762ba2a69 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/AddImportActionTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ public class AddImportActionTest extends LightCodeInsightFixtureTestCase { myFixture.configureByText 'a.java', '''\ public class Foo { void foo() { - Map<> l; + Map l; } } ''' @@ -34,7 +34,7 @@ public class Foo { public class Foo { void foo() { - Map<> l; + Map l; } } ''' @@ -45,7 +45,7 @@ public class Foo { myFixture.configureByText 'a.java', '''\ public class Foo { void foo() { - Map<> l; + Map l; } } ''' @@ -54,7 +54,7 @@ public class Foo { public class Foo { void foo() { - Map<> l; + Map l; } } ''' diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/CreateSubclassTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/CreateSubclassTest.java index b76e7ce63788..b7be4420395b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/CreateSubclassTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/CreateSubclassTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.intention; import com.intellij.codeInsight.intention.impl.CreateSubclassAction; @@ -6,6 +21,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDirectory; import com.intellij.psi.search.ProjectScope; import com.intellij.refactoring.MultiFileTestCase; +import org.jetbrains.annotations.NotNull; /** * @author yole @@ -47,6 +63,7 @@ public class CreateSubclassTest extends MultiFileTestCase { }); } + @NotNull @Override protected String getTestRoot() { return "/codeInsight/createSubclass/"; diff --git a/java/java-tests/testSrc/com/intellij/lang/spi/SPIRenameTest.java b/java/java-tests/testSrc/com/intellij/lang/spi/SPIRenameTest.java index bb4bd50d6330..9ed424b02330 100644 --- a/java/java-tests/testSrc/com/intellij/lang/spi/SPIRenameTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/spi/SPIRenameTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement; import com.intellij.refactoring.MultiFileTestCase; import com.intellij.refactoring.rename.RenameProcessor; import com.intellij.refactoring.rename.RenamePsiElementProcessor; +import org.jetbrains.annotations.NotNull; /** * User: anna @@ -53,6 +54,7 @@ public class SPIRenameTest extends MultiFileTestCase { }); } + @NotNull @Override protected String getTestRoot() { return "/spi/"; diff --git a/java/java-tests/testSrc/com/intellij/project/convertors/Convertor34Test.java b/java/java-tests/testSrc/com/intellij/project/convertors/Convertor34Test.java index 92170d1c6635..93858dbd1fc1 100644 --- a/java/java-tests/testSrc/com/intellij/project/convertors/Convertor34Test.java +++ b/java/java-tests/testSrc/com/intellij/project/convertors/Convertor34Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.intellij.refactoring.MultiFileTestCase; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.List; @@ -43,6 +44,7 @@ public class Convertor34Test extends MultiFileTestCase { super.setUp(); } + @NotNull @Override protected String getTestRoot() { return "/moduleRootManager/convertor34/"; diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java index 7d0aaa65f947..12c94d2a4299 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/smartPointers/SmartPsiElementPointersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -416,4 +416,22 @@ public class SmartPsiElementPointersTest extends CodeInsightTestCase { Assert.assertNotNull(pointer1.getRange()); } } + + public void testSmartPointerCreationDoesNotLoadDocument() { + PsiPackage aPackage = myJavaFacade.findPackage("java.io"); + SmartPointerManagerImpl smartPointerManager = (SmartPointerManagerImpl)SmartPointerManager.getInstance(myProject); + for (PsiClass aClass : aPackage.getClasses()) { + PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); + PsiFile file = aClass.getContainingFile(); + Document document = documentManager.getCachedDocument(file); + if (document == null) { //ignore already loaded documents + SmartPsiElementPointer pointer = smartPointerManager.createSmartPsiElementPointer(aClass); + assertNull(documentManager.getCachedDocument(file)); + //System.out.println("file = " + file); + } + else { + System.out.println("already loaded file = " + file); + } + } + } } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java b/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java index 51a5acfbfa63..ee971c4e42e2 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/DndMoveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.refactoring.move.MoveHandler; import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -28,6 +29,7 @@ import org.jetbrains.annotations.Nullable; * @since Aug 31, 2010 */ public class DndMoveTest extends CodeInsightTestCase { + @NotNull @Override protected String getTestRoot() { return "/refactoring/dndMove/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/EncapsulateFieldsTest.java b/java/java-tests/testSrc/com/intellij/refactoring/EncapsulateFieldsTest.java index 666168ba9b43..a24ffb056003 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/EncapsulateFieldsTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/EncapsulateFieldsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import com.intellij.refactoring.encapsulateFields.FieldDescriptor; import com.intellij.refactoring.encapsulateFields.FieldDescriptorImpl; import com.intellij.refactoring.util.DocCommentPolicy; import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; public class EncapsulateFieldsTest extends MultiFileTestCase{ public void testAlreadyExist() throws Exception { @@ -76,6 +77,7 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{ return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/encapsulateFields/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractClassTest.java index 1e287b22f90c..812b2ab0646f 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractClassTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * User: anna * Date: 20-Aug-2008 @@ -17,6 +33,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.extractclass.ExtractClassProcessor; import com.intellij.refactoring.util.classMembers.MemberInfo; import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -24,6 +41,7 @@ import java.util.Collections; import java.util.TreeSet; public class ExtractClassTest extends MultiFileTestCase{ + @NotNull @Override protected String getTestRoot() { return "/refactoring/extractClass/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractEnumTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractEnumTest.java index 48d711b9593e..c6b811c693ba 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractEnumTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractEnumTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.extractclass.ExtractClassProcessor; import com.intellij.refactoring.util.classMembers.MemberInfo; import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -36,6 +37,7 @@ import java.util.TreeSet; public class ExtractEnumTest extends MultiFileTestCase { + @NotNull @Override protected String getTestRoot() { return "/refactoring/extractEnum/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java index 5b728986593b..01068325c9ee 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InheritanceToDelegationTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.JavaTestUtil; @@ -8,6 +23,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.inheritanceToDelegation.InheritanceToDelegationProcessor; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -21,6 +37,7 @@ public class InheritanceToDelegationTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/inheritanceToDelegation/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java index 2aecb284e522..690f7ac7ba0e 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InlineSuperClassTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * User: anna * Date: 20-Aug-2008 @@ -10,8 +26,10 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.inlineSuperClass.InlineSuperClassRefactoringProcessor; import com.intellij.refactoring.util.DocCommentPolicy; +import org.jetbrains.annotations.NotNull; public class InlineSuperClassTest extends MultiFileTestCase { + @NotNull @Override protected String getTestRoot() { return "/refactoring/inlineSuperClass/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java index 905f87eb7615..387424a4ffd3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterObjectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,10 @@ import com.intellij.refactoring.introduceparameterobject.IntroduceParameterObjec import com.intellij.refactoring.util.VariableData; import com.intellij.util.Function; import com.intellij.util.VisibilityUtil; +import org.jetbrains.annotations.NotNull; public class IntroduceParameterObjectTest extends MultiFileTestCase{ + @NotNull @Override protected String getTestRoot() { return "/refactoring/introduceParameterObject/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableMultifileTest.java index f70fdadd7581..b200906a58ef 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableMultifileTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableMultifileTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.introduceVariable.IntroduceVariableBase; import com.intellij.testFramework.PlatformTestCase; +import org.jetbrains.annotations.NotNull; /** * @author dsl @@ -39,6 +40,7 @@ public class IntroduceVariableMultifileTest extends MultiFileTestCase { LanguageLevelProjectExtension.getInstance(myJavaFacade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/introduceVariable/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveInnerTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveInnerTest.java index bbc75763774a..2e6865bfc5f8 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MoveInnerTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveInnerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import com.intellij.refactoring.move.moveInner.MoveInnerDialog; import com.intellij.refactoring.move.moveInner.MoveInnerImpl; import com.intellij.refactoring.move.moveInner.MoveInnerProcessor; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -36,6 +37,7 @@ public class MoveInnerTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/moveInner/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java index 2f384c9e3b5b..83e8fa10aed9 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MoveMembersTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.JavaTestUtil; @@ -13,6 +28,7 @@ import com.intellij.psi.search.ProjectScope; import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions; import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor; import com.intellij.util.VisibilityUtil; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -171,6 +187,7 @@ public class MoveMembersTest extends MultiFileTestCase { doTest("Outer.Inner", "Outer", true, VisibilityUtil.ESCALATE_VISIBILITY, 0); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/moveMembers/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageAsDirectoryTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageAsDirectoryTest.java index 70cb10ab1cac..d4fb33559020 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageAsDirectoryTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageAsDirectoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.move.moveClassesOrPackages.MoveDirectoryWithClassesProcessor; import com.intellij.testFramework.PsiTestUtil; import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Comparator; @@ -39,6 +40,7 @@ public class MovePackageAsDirectoryTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/movePackageAsDir/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageMultirootTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageMultirootTest.java index 4dd238104286..1ae0af9a8016 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageMultirootTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageMultirootTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackages import com.intellij.refactoring.move.moveClassesOrPackages.MultipleRootsMoveDestination; import com.intellij.JavaTestUtil; import com.intellij.testFramework.PsiTestUtil; +import org.jetbrains.annotations.NotNull; /** * @author dsl @@ -39,6 +40,7 @@ public class MovePackageMultirootTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/movePackageMultiroot/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageTest.java b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageTest.java index 1c35bd29f02d..19296b0152d9 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MovePackageTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MovePackageTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -8,6 +23,7 @@ import com.intellij.psi.PsiPackage; import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor; import com.intellij.refactoring.move.moveClassesOrPackages.SingleSourceRootMoveDestination; import com.intellij.JavaTestUtil; +import org.jetbrains.annotations.NotNull; public class MovePackageTest extends MultiFileTestCase { @@ -33,6 +49,7 @@ public class MovePackageTest extends MultiFileTestCase { doTest(new String[]{"a"}, "a.b"); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/movePackage/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PullUpMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PullUpMultifileTest.java index 2d3864b664f3..a1df6dba3b81 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PullUpMultifileTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PullUpMultifileTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,12 +30,14 @@ import com.intellij.refactoring.util.DocCommentPolicy; import com.intellij.refactoring.util.classMembers.InterfaceContainmentVerifier; import com.intellij.refactoring.util.classMembers.MemberInfo; import com.intellij.util.containers.MultiMap; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.HashSet; //pull first method from class a.A to class b.B public class PullUpMultifileTest extends MultiFileTestCase { + @NotNull @Override protected String getTestRoot() { return "/refactoring/pullUp/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java index c10a6cdc09b8..1119144e887b 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PushDownMultifileTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,11 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.memberPushDown.PushDownProcessor; import com.intellij.refactoring.util.DocCommentPolicy; import com.intellij.refactoring.util.classMembers.MemberInfo; +import org.jetbrains.annotations.NotNull; //push first method from class a.A to class b.B public class PushDownMultifileTest extends MultiFileTestCase { + @NotNull @Override protected String getTestRoot() { return "/refactoring/pushDown/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RemoveMiddleManTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RemoveMiddleManTest.java index fa025c8767fb..8966302e9898 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RemoveMiddleManTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RemoveMiddleManTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * User: anna * Date: 20-Aug-2008 @@ -15,6 +31,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.removemiddleman.DelegationUtils; import com.intellij.refactoring.removemiddleman.RemoveMiddlemanProcessor; import com.intellij.refactoring.util.classMembers.MemberInfo; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -26,6 +43,7 @@ public class RemoveMiddleManTest extends MultiFileTestCase{ return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/removemiddleman/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java index c3c4de33788e..6bf0f408214a 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameClassTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.JavaTestUtil; @@ -10,6 +25,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.rename.RenameProcessor; import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; public class RenameClassTest extends MultiFileTestCase { @Override @@ -101,6 +117,7 @@ public class RenameClassTest extends MultiFileTestCase { FileDocumentManager.getInstance().saveAllDocuments(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/renameClass/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java index 6da0cdf162c0..cb354a6c0b7f 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameMethodMultiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiMethod; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.rename.RenameProcessor; +import org.jetbrains.annotations.NotNull; import org.junit.Assert; /** @@ -34,6 +35,7 @@ public class RenameMethodMultiTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/renameMethod/multi/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithBuilderTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithBuilderTest.java index 7d18135056f3..a727714f85fa 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithBuilderTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * User: anna * Date: 06-May-2008 @@ -14,6 +30,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.replaceConstructorWithBuilder.ParameterData; import com.intellij.refactoring.replaceConstructorWithBuilder.ReplaceConstructorWithBuilderProcessor; import com.intellij.util.containers.HashMap; +import org.jetbrains.annotations.NotNull; import java.util.LinkedHashMap; import java.util.Map; @@ -122,6 +139,7 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase { } + @NotNull @Override protected String getTestRoot() { return "/refactoring/replaceConstructorWithBuilder/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java b/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java index 5a9b17611d11..a6768c98d0f3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/SafeDeleteTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.JavaTestUtil; @@ -11,6 +26,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.safeDelete.SafeDeleteHandler; import com.intellij.testFramework.PsiTestUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.java.JavaSourceRootType; import org.jetbrains.jps.model.java.JpsJavaExtensionService; @@ -20,6 +36,7 @@ public class SafeDeleteTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/safeDelete/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java b/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java index 44defbea3ef3..a2ab68458b40 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/TurnRefsToSuperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.turnRefsToSuper.TurnRefsToSuperProcessor; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; public class TurnRefsToSuperTest extends MultiFileTestCase { public void testSuperClass() throws Exception { doTest("AClass", "ASuper", true); } @@ -73,6 +74,7 @@ public class TurnRefsToSuperTest extends MultiFileTestCase { }, true); } + @NotNull @Override public String getTestRoot() { return "/refactoring/turnRefsToSuper/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java b/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java index 076280dafb95..5cfefaa3a065 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/TypeCookTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.intellij.refactoring.typeCook.deductive.builder.ReductionSystem; import com.intellij.refactoring.typeCook.deductive.builder.SystemBuilder; import com.intellij.refactoring.typeCook.deductive.resolver.Binding; import com.intellij.refactoring.typeCook.deductive.resolver.ResolverTree; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileNotFoundException; @@ -47,6 +48,7 @@ public class TypeCookTest extends MultiFileTestCase { return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override public String getTestRoot() { return "/refactoring/typeCook/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java b/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java index ddd3803fe854..1b0d7f1072fd 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/WrapReturnValueTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * User: anna * Date: 20-Aug-2008 @@ -12,6 +28,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.refactoring.wrapreturnvalue.WrapReturnValueProcessor; import com.intellij.JavaTestUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; public class WrapReturnValueTest extends MultiFileTestCase{ @Override @@ -19,6 +36,7 @@ public class WrapReturnValueTest extends MultiFileTestCase{ return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected String getTestRoot() { return "/refactoring/wrapReturnValue/"; diff --git a/java/java-tests/testSrc/com/intellij/refactoring/migration/MigrationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/migration/MigrationTest.java index f66f695c8697..91349d6f3fec 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/migration/MigrationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/migration/MigrationTest.java @@ -1,9 +1,25 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring.migration; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.refactoring.MultiFileTestCase; import com.intellij.JavaTestUtil; +import org.jetbrains.annotations.NotNull; /** * @author dsl @@ -50,6 +66,7 @@ public class MigrationTest extends MultiFileTestCase { }; } + @NotNull @Override protected String getTestRoot() { return "/refactoring/migration/"; diff --git a/java/jdkAnnotations/java/nio/channels/annotations.xml b/java/jdkAnnotations/java/nio/channels/annotations.xml index b82a6fe0a0f1..d0ecca816f3d 100644 --- a/java/jdkAnnotations/java/nio/channels/annotations.xml +++ b/java/jdkAnnotations/java/nio/channels/annotations.xml @@ -41,4 +41,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index 71f24d8e5fed..f523af0a5b39 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; -import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.undo.UndoManager; @@ -44,6 +43,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiDocumentManager; @@ -68,6 +68,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; /** * @author Mike @@ -75,7 +76,7 @@ import java.util.List; public abstract class CodeInsightTestCase extends PsiTestCase { protected Editor myEditor; - protected Editor createEditor(VirtualFile file) { + protected Editor createEditor(@NotNull VirtualFile file) { final FileEditorManager instance = FileEditorManager.getInstance(myProject); if (file.getFileType().isBinary()) return null; @@ -112,7 +113,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { /** * @param files the first file will be loaded in editor */ - protected VirtualFile configureByFiles(@Nullable String projectRoot,String... files) throws Exception { + protected VirtualFile configureByFiles(@Nullable String projectRoot, @NotNull String... files) throws Exception { if (files.length == 0) return null; final VirtualFile[] vFiles = new VirtualFile[files.length]; for (int i = 0; i < files.length; i++) { @@ -128,7 +129,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return configureByFiles(projectFile, vFiles); } - protected VirtualFile configureByFile(@NonNls String filePath, String projectRoot) throws Exception { + protected VirtualFile configureByFile(@NonNls String filePath, @Nullable String projectRoot) throws Exception { String fullPath = getTestDataPath() + filePath; final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/')); @@ -139,11 +140,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return configureByFile(vFile, projectFile); } - protected PsiFile configureByText(@NotNull FileType fileType, @NonNls final String text) { + protected PsiFile configureByText(@NotNull FileType fileType, @NonNls @NotNull final String text) { return configureByText(fileType, text, null); } - protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls final String text, @Nullable String _extension) { + protected PsiFile configureByText(@NotNull final FileType fileType, @NonNls @NotNull String text, @Nullable String _extension) { try { final String extension = _extension == null ? fileType.getDefaultExtension():_extension; @@ -177,16 +178,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } - @Override - protected String getTestDataPath() { - return PathManagerEx.getTestDataPath(); - } - - protected void configureByFile(final VirtualFile vFile) throws IOException { + protected void configureByFile(@NotNull VirtualFile vFile) throws IOException { configureByFile(vFile, null); } - protected void configureByExistingFile(final VirtualFile virtualFile) { + protected void configureByExistingFile(@NotNull final VirtualFile virtualFile) { myFile = null; myEditor = null; @@ -216,7 +212,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); } - protected VirtualFile configureByFiles(@Nullable final File rawProjectRoot, final VirtualFile... vFiles) throws IOException { + protected VirtualFile configureByFiles(@Nullable final File rawProjectRoot, @NotNull final VirtualFile... vFiles) throws IOException { myFile = null; myEditor = null; @@ -235,7 +231,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { // auxiliary files should be copied first VirtualFile[] reversed = ArrayUtil.reverseArray(vFiles); - final LinkedHashMap editorInfos; + Map editorInfos; if (rawProjectRoot != null) { final File projectRoot = rawProjectRoot.getCanonicalFile(); FileUtil.copyDir(projectRoot, toDirIO); @@ -288,22 +284,26 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return false; } - protected void doCommitModel(final ModifiableRootModel rootModel) { + protected void doCommitModel(@NotNull ModifiableRootModel rootModel) { rootModel.commit(); } protected void sourceRootAdded(final VirtualFile dir) { } - protected LinkedHashMap copyFilesFillingEditorInfos(String testDataFromDir, - final VirtualFile toDir, - final String... relativePaths) throws IOException { + @NotNull + protected Map copyFilesFillingEditorInfos(@NotNull String testDataFromDir, + @NotNull VirtualFile toDir, + @NotNull String... relativePaths) throws IOException { if (!testDataFromDir.startsWith("/")) testDataFromDir = "/" + testDataFromDir; return copyFilesFillingEditorInfos(LocalFileSystem.getInstance().refreshAndFindFileByPath(getTestDataPath() + testDataFromDir), toDir, relativePaths); } - protected LinkedHashMap copyFilesFillingEditorInfos(final VirtualFile fromDir, final VirtualFile toDir, final String... relativePaths) throws IOException { - LinkedHashMap editorInfos = new LinkedHashMap(); + @NotNull + protected Map copyFilesFillingEditorInfos(@NotNull VirtualFile fromDir, + @NotNull VirtualFile toDir, + @NotNull String... relativePaths) throws IOException { + Map editorInfos = new LinkedHashMap(); List streamsToClose = new ArrayList(); @@ -356,28 +356,30 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } }*/ - private EditorInfo copyContent(final VirtualFile from, final VirtualFile to, final List streamsToClose) throws IOException { + private EditorInfo copyContent(@NotNull VirtualFile from, @NotNull VirtualFile to, @NotNull List streamsToClose) throws IOException { byte[] content = from.getFileType().isBinary() ? from.contentsToByteArray(): null; - final String fileText = from.getFileType().isBinary() ? null : StringUtil.convertLineSeparators(VfsUtil.loadText(from)); + final String fileText = from.getFileType().isBinary() ? null : StringUtil.convertLineSeparators(VfsUtilCore.loadText(from)); - EditorInfo editorInfo = fileText != null ? new EditorInfo(fileText) : null; - String newFileText = fileText != null ? editorInfo.getNewFileText() : null; + EditorInfo editorInfo = fileText == null ? null : new EditorInfo(fileText); + String newFileText = fileText == null ? null : editorInfo.getNewFileText(); doWrite(newFileText, to, content, streamsToClose); return editorInfo; } - protected final void setActiveEditor(Editor editor) { + protected final void setActiveEditor(@NotNull Editor editor) { myEditor = editor; myFile = getPsiFile(editor.getDocument()); } - protected List openEditorsAndActivateLast(final LinkedHashMap editorInfos) { + @NotNull + protected List openEditorsAndActivateLast(@NotNull Map editorInfos) { final List list = openEditors(editorInfos); setActiveEditor(list.get(list.size() - 1)); return list; } - protected final List openEditors(final LinkedHashMap editorInfos) { + @NotNull + protected final List openEditors(@NotNull final Map editorInfos) { return ContainerUtil.map(editorInfos.keySet(), new Function() { @Override public Editor fun(final VirtualFile newVFile) { @@ -396,14 +398,18 @@ public abstract class CodeInsightTestCase extends PsiTestCase { }); } - private void doWrite(final String newFileText, final VirtualFile newVFile, final byte[] content, final List streamsToClose) throws IOException { - if (newFileText != null) { - VfsUtil.saveText(newVFile, newFileText); - } else { + private void doWrite(final String newFileText, + @NotNull VirtualFile newVFile, + byte[] content, + @NotNull List streamsToClose) throws IOException { + if (newFileText == null) { final OutputStream outputStream = newVFile.getOutputStream(this, -1, -1); outputStream.write(content); streamsToClose.add(outputStream); } + else { + VfsUtil.saveText(newVFile, newFileText); + } } protected boolean isAddDirToContentRoot() { @@ -414,7 +420,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return true; } - protected VirtualFile configureByFile(final VirtualFile vFile, final File projectRoot) throws IOException { + protected VirtualFile configureByFile(@NotNull VirtualFile vFile, File projectRoot) throws IOException { return configureByFiles(projectRoot, vFile); } @@ -422,7 +428,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return false; } - protected void setupCursorAndSelection(final Editor editor) { + protected void setupCursorAndSelection(@NotNull final Editor editor) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { @@ -466,7 +472,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } @Override - protected void configure(String path, String dataName) throws Exception { + protected void configure(@NotNull String path, String dataName) throws Exception { super.configure(path, dataName); myEditor = createEditor(myFile.getVirtualFile()); @@ -487,11 +493,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase { myEditor.getSelectionModel().setSelection(selectionStart, selectionEnd); } - protected void checkResultByFile(@NonNls String filePath) throws Exception { + protected void checkResultByFile(@NonNls @NotNull String filePath) throws Exception { checkResultByFile(filePath, false); } - protected void checkResultByFile(@NonNls final String filePath, final boolean stripTrailingSpaces) throws Exception { + protected void checkResultByFile(@NonNls @NotNull final String filePath, final boolean stripTrailingSpaces) throws Exception { new WriteCommandAction(getProject()) { @Override protected void run(@NotNull Result result) throws Throwable { @@ -508,7 +514,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { assertNotNull("Cannot find file " + fullPath, vFile); String ft = null; try { - ft = VfsUtil.loadText(vFile); + ft = VfsUtilCore.loadText(vFile); } catch (IOException e) { throw new RuntimeException(e); @@ -626,7 +632,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return CommonDataKeys.EDITOR.is(dataId) ? myEditor : super.getData(dataId); } - protected VirtualFile getVirtualFile(@NonNls String filePath) { + protected VirtualFile getVirtualFile(@NonNls @NotNull String filePath) { String fullPath = getTestDataPath() + filePath; final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/')); @@ -634,6 +640,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return vFile; } + @NotNull protected String getTestRoot(){ return FileUtil.toSystemIndependentName(getTestDataPath()); } @@ -673,7 +680,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { action.execute(getEditor(), DataManager.getInstance().getDataContext()); } - protected void type(@NonNls String s) { + protected void type(@NonNls @NotNull String s) { for (char c : s.toCharArray()) { type(c); } @@ -688,7 +695,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { protected void backspace() { backspace(getEditor()); } - protected void backspace(final Editor editor) { + protected void backspace(@NotNull final Editor editor) { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { diff --git a/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java b/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java index d66ff0368ba3..cadc61af8dbd 100644 --- a/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java +++ b/java/testFramework/src/com/intellij/refactoring/MultiFileTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.PsiTestUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.io.File; @@ -71,6 +72,7 @@ public abstract class MultiFileTestCase extends CodeInsightTestCase { PsiTestUtil.addSourceContentToRoots(myModule, rootDir); } + @NotNull @Override @NonNls protected abstract String getTestRoot(); diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java index 63bbdb23f6a0..c2c5b4157793 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import com.intellij.util.IncorrectOperationException; import org.jdom.Document; import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -122,7 +123,7 @@ public abstract class PsiTestCase extends ModuleTestCase { return myFile.findElementAt(offset); } - protected void configure(String path, String dataName) throws Exception { + protected void configure(@NotNull String path, String dataName) throws Exception { myDataRoot = getTestDataPath() + path; myTestDataBefore = loadData(dataName); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CheckLevelHighlightInfoHolder.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CheckLevelHighlightInfoHolder.java new file mode 100644 index 000000000000..67e54ab812fb --- /dev/null +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/CheckLevelHighlightInfoHolder.java @@ -0,0 +1,100 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon.impl; + +import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder; +import com.intellij.lang.annotation.AnnotationSession; +import com.intellij.openapi.editor.colors.TextAttributesScheme; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +public class CheckLevelHighlightInfoHolder extends HighlightInfoHolder { + private final HighlightInfoHolder myHolder; + private PsiElement myLevel; + + public CheckLevelHighlightInfoHolder(PsiFile file, HighlightInfoHolder holder) { + super(file); + myHolder = holder; + } + + @NotNull + @Override + public TextAttributesScheme getColorsScheme() { + return myHolder.getColorsScheme(); + } + + @Override + public PsiFile getContextFile() { + return myHolder.getContextFile(); + } + + @NotNull + @Override + public Project getProject() { + return myHolder.getProject(); + } + + @Override + public boolean hasErrorResults() { + return myHolder.hasErrorResults(); + } + + @Override + public boolean add(@Nullable HighlightInfo info) { + if (info == null) return false; + PsiElement psiElement = info.psiElement; + if (psiElement != null && !PsiTreeUtil.isAncestor(myLevel, psiElement,false)) { + throw new RuntimeException("Info: '" + info + "' reported for the element '" + psiElement + "'; but it was at the level " + myLevel); + } + return myHolder.add(info); + } + + @Override + public void clear() { + myHolder.clear(); + } + + @Override + public boolean addAll(Collection highlightInfos) { + return myHolder.addAll(highlightInfos); + } + + @Override + public int size() { + return myHolder.size(); + } + + @Override + public HighlightInfo get(int i) { + return myHolder.get(i); + } + + @NotNull + @Override + public AnnotationSession getAnnotationSession() { + return myHolder.getAnnotationSession(); + } + + public void enterLevel(PsiElement element) { + myLevel = element; + } +} diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index f8b71697461d..4cff679c1d2b 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,6 +98,7 @@ public class HighlightInfo implements Segment { private static final int AFTER_END_OF_LINE_FLAG = 3; private static final int FILE_LEVEL_ANNOTATION_FLAG = 4; private static final int NEEDS_UPDATE_ON_TYPING_FLAG = 5; + PsiElement psiElement; @NotNull ProperTextRange getFixTextRange() { @@ -432,6 +433,7 @@ public class HighlightInfo implements Segment { return false; } } + info.psiElement = psiElement; return true; } diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java index 01124e1c6ecb..5ea2cdbf8ee9 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,14 +62,14 @@ public class SelfElementInfo implements SmartPointerElementInfo { myProject = project; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); - Document document = documentManager.getDocument(containingFile); - if (document == null || documentManager.isUncommited(document)) { + Document document = documentManager.getCachedDocument(containingFile); + if (document != null && documentManager.isUncommited(document)) { mySyncMarkerIsValid = false; - return; } - - mySyncMarkerIsValid = true; - setRange(range); + else { + mySyncMarkerIsValid = true; + setRange(range); + } } protected void setRange(@NotNull Segment range) { diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 9151f46f0c89..176e1b7c7a22 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,16 +100,16 @@ public class FileStructurePopup implements Disposable { @NonNls private static final String narrowDownPropertyKey = "FileStructurePopup.narrowDown"; private boolean myShouldNarrowDown = true; - private FileStructureTree myTree; + private final FileStructureTree myTree; private final FilteringTreeBuilder myAbstractTreeBuilder; private String myTitle; - private TreeSpeedSearch mySpeedSearch; - private SmartTreeStructure myTreeStructure; + private final TreeSpeedSearch mySpeedSearch; + private final SmartTreeStructure myTreeStructure; private int myPreferredWidth; private final FilteringTreeStructure myFilteringStructure; - private PsiElement myInitialPsiElement; - private Map myCheckBoxes = new HashMap(); - private List myAutoClicked = new ArrayList(); + private final PsiElement myInitialPsiElement; + private final Map myCheckBoxes = new HashMap(); + private final List myAutoClicked = new ArrayList(); private String myTestSearchFilter; private final ActionCallback myTreeHasBuilt = new ActionCallback(); private boolean myInitialNodeIsLeaf; @@ -877,7 +877,7 @@ public class FileStructurePopup implements Disposable { private class FileStructurePopupFilter implements ElementFilter { private String myLastFilter = null; - private HashSet myVisibleParents = new HashSet(); + private final Set myVisibleParents = new HashSet(); private final boolean isUnitTest = ApplicationManager.getApplication().isUnitTestMode(); @Override diff --git a/platform/testFramework/src/com/intellij/ClassFinder.java b/platform/testFramework/src/com/intellij/ClassFinder.java index b4a8f7d40064..e69c9b667b11 100644 --- a/platform/testFramework/src/com/intellij/ClassFinder.java +++ b/platform/testFramework/src/com/intellij/ClassFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ package com.intellij; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -33,7 +34,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static com.intellij.util.containers.ContainerUtil.addIfNotNull; public class ClassFinder { private final List classNameList = new ArrayList(); @@ -61,7 +61,7 @@ public class ClassFinder { } } else { - addIfNotNull(classNameList, computeClassName(current)); + ContainerUtil.addIfNotNull(classNameList, computeClassName(current)); } } diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java index 7a8f9ffd870b..f91457e29eb4 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/binding/RenameUIRelatedTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,13 @@ import com.intellij.psi.search.ProjectScope; import com.intellij.refactoring.MultiFileTestCase; import com.intellij.refactoring.rename.RenameProcessor; import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; /** * @author ven */ public class RenameUIRelatedTest extends MultiFileTestCase { + @NotNull @Override protected String getTestRoot() { return "/renameUIRelated/"; diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/refactoring/MoveFileTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/refactoring/MoveFileTest.java index e2f900324d76..24f63e7349b8 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/refactoring/MoveFileTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/refactoring/MoveFileTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.uiDesigner.refactoring; import com.intellij.openapi.application.PluginPathManager; @@ -10,6 +25,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.refactoring.MultiFileTestCase; import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor; +import org.jetbrains.annotations.NotNull; public class MoveFileTest extends MultiFileTestCase { @Override @@ -17,6 +33,7 @@ public class MoveFileTest extends MultiFileTestCase { return PluginPathManager.getPluginHomePath("ui-designer") + "/testData"; } + @NotNull @Override protected String getTestRoot() { return "/move/";