Merge remote-tracking branch 'origin/master'

This commit is contained in:
Konstantin Kolosovsky
2014-02-10 20:12:45 +04:00
71 changed files with 997 additions and 398 deletions
@@ -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();
@@ -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<HierarchicalMethodSignature> signaturesWithSupers = aClass.getVisibleSignatures();
PsiManager manager = aClass.getManager();
Map<MethodSignature, MethodSignatureBackedByPsiMethod> 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<HierarchicalMethodSignature> 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<HierarchicalMethodSignature> signaturesWithSupers,
PsiIdentifier classIdentifier) {
static HighlightInfo checkUnrelatedDefaultMethods(@NotNull PsiClass aClass,
@NotNull Collection<HierarchicalMethodSignature> 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;
}
@@ -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);
}
@@ -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);
@@ -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<HierarchicalMethodSignature> superMethodSignatures,
static HighlightInfo checkMethodIncompatibleReturnType(@NotNull MethodSignatureBackedByPsiMethod methodSignature,
@NotNull List<HierarchicalMethodSignature> 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<MethodCandidateInfo> candidateList = new ArrayList<MethodCandidateInfo>(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();
@@ -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<HighlightInfo> checkExceptionThrownInTry(@NotNull final PsiParameter parameter, @NotNull final Set<PsiClassType> thrownTypes) {
static List<HighlightInfo> checkExceptionThrownInTry(@NotNull final PsiParameter parameter, @NotNull final Set<PsiClassType> 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.<HighlightInfo>singletonList(info);
}
if (caughtType instanceof PsiDisjunctionType) {
return checkMultiCatchParameter(parameter, thrownTypes);
@@ -1182,7 +1183,7 @@ public class HighlightUtil extends HighlightUtilBase {
}
@Nullable
private static Collection<HighlightInfo> checkSimpleCatchParameter(@NotNull final PsiParameter parameter,
private static HighlightInfo checkSimpleCatchParameter(@NotNull final PsiParameter parameter,
@NotNull final Collection<PsiClassType> 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<HighlightInfo> checkMultiCatchParameter(@NotNull final PsiParameter parameter,
@NotNull final Collection<PsiClassType> thrownTypes) {
private static List<HighlightInfo> checkMultiCatchParameter(@NotNull final PsiParameter parameter,
@NotNull final Collection<PsiClassType> thrownTypes) {
final List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter);
final Collection<HighlightInfo> highlights = ContainerUtil.newArrayListWithCapacity(typeElements.size());
final List<HighlightInfo> highlights = new ArrayList<HighlightInfo>(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
@@ -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<PsiClass, MostlySingularMultiMap<MethodSignature, PsiMethod>> myDuplicateMethods = new THashMap<PsiClass, MostlySingularMultiMap<MethodSignature, PsiMethod>>();
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<MethodSignature, PsiMethod> getDuplicateMethods(PsiClass aClass) {
private MostlySingularMultiMap<MethodSignature, PsiMethod> getDuplicateMethods(@NotNull PsiClass aClass) {
MostlySingularMultiMap<MethodSignature, PsiMethod> signatures = myDuplicateMethods.get(aClass);
if (signatures == null) {
signatures = new MostlySingularMultiMap<MethodSignature, PsiMethod>();
@@ -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<PsiLanguageInjectionHost.Shred> 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));
@@ -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<LookupElement> consumer) {
@@ -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 <T extends PsiPolyVariantReference> JavaResolveResult[] resolveWithContainingFile(@NotNull T ref,
@NotNull ResolveCache.PolyVariantResolver<T> resolver,
boolean needToPreventRecursion,
boolean incompleteCode,
@NotNull PsiFile containingFile) {
@NotNull ResolveCache.PolyVariantResolver<T> resolver,
boolean needToPreventRecursion,
boolean incompleteCode,
@NotNull PsiFile containingFile) {
boolean valid = containingFile.isValid();
if (!valid) {
return JavaResolveResult.EMPTY_ARRAY;
@@ -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=\
<html><body><table border=0>\
<tr><td colspan={0}>Ambiguous method call. Both</td></tr>\
<tr>{1}<td>in <b>{2}</b>\\&nbsp;and</td></tr>\
<tr>{3}<td>in <b>{4}</b>\\&nbsp;match.</td></tr>\
<tr>{3}<td>in <b>{4}</b>\\&nbsp;match</td></tr>\
</table></body></html>
@@ -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'
@@ -1,6 +1,6 @@
public class a {
<error descr="'f(int)' is already defined in 'a'">void f(int i)</error> { }
<error descr="'f(int)' is already defined in 'a'">void f(int i)</error> {
void f(int i) {
new c1() {
<error descr="'f1()' is already defined in 'Anonymous class derived from c1'">public void f1()</error> {}
@@ -28,6 +28,7 @@ public class a {
}
abstract class c1 {
abstract public void f1(int i);
Object o = new c1[0];
}
interface ii {
@@ -4,7 +4,7 @@ class m {
int r = 0;
new Runnable() {
public void run() {
int k = <error descr="Variable 'r' is accessed from within inner class. Needs to be declared final.">r</error>;
int k = <error descr="Variable 'r' is accessed from within inner class, needs to be declared final">r</error>;
int ii = i;
}
};
@@ -27,9 +27,9 @@ class UnsupportedFeatures {
<error descr="For-each loops are not supported at this language level">for (String s : args) { System.out.println(s); }</error>
List<error descr="Generics are not supported at this language level"><String></error> list =
new ArrayList<error descr="Diamond types are not supported at this language level"><></error>();
new ArrayList<error descr="Generics are not supported at this language level"><></error>();
for (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String s : list</error>) {}
<error descr="For-each loops are not supported at this language level">for (String s : list) {}</error>
Arrays.asList<error descr="'asList(java.lang.String...)' in 'java.util.Arrays' cannot be applied to '(java.lang.String)'">("")</error>;
<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Boolean'">Boolean b = true;</error>
<error descr="Incompatible types. Found: 'java.lang.Boolean', required: 'boolean'">boolean b1 = Boolean.TRUE;</error>
@@ -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<String> list =
new ArrayList<>();
for (String s : list) {}
Arrays.asList("");
Boolean b = true;
boolean b1 = Boolean.TRUE;
try { Reader r = new FileReader("/dev/null"); }
catch (<error descr="Multi-catches are not supported at this language level">FileNotFoundException | IOException e</error>) { e.printStackTrace(); }
try <error descr="Try-with-resources are not supported at this language level">(Reader r = new FileReader("/dev/null"))</error> { }
I i1 = <error descr="Method references are not supported at this language level">UnsupportedFeatures::m</error>;
I i2 = <error descr="Lambda expressions are not supported at this language level">() -> { }</error>;
}
interface I {
<error descr="Extension methods are not supported at this language level">default void m() { }</error>
}
}
@@ -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<error descr="Cannot resolve method 'm(?)'">(<error descr="Reference to 'IF' is ambiguous, both 'I1.IF' and 'I2.IF' match">IF</error>)</error>;
m(<error descr="Reference to 'IF' is ambiguous, both 'I1.IF' and 'I2.IF' match">IF</error>);
}
}
@@ -22,7 +22,10 @@ enum E {
}
interface I {
@<error descr="Duplicate annotation">Anno</error> public @<error descr="Duplicate annotation">Anno</error> Collection<<error descr="Type annotations are not supported at this language level">@Anno</error> String> method(@<error descr="Duplicate annotation">Anno</error> @<error descr="Duplicate annotation">Anno</error> Object o);
@<error descr="Duplicate annotation">Anno</error>
public @<error descr="Duplicate annotation">Anno</error>
Collection<<error descr="Type annotations are not supported at this language level">@Anno</error> String>
method(@<error descr="Duplicate annotation">Anno</error> @<error descr="Duplicate annotation">Anno</error> Object o);
}
@interface Caller {
@@ -22,8 +22,12 @@ class a {
for (Object oi: (Iterable)o) {}
for (<error descr="Incompatible types. Found: 'double', required: 'int'">int i:db</error>) {
// error descr="Incompatible types. Found: 'double', required: 'int'" was not shown because there is an error in nested for
for (int i : db) {
for (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">int p: list</error>) {}
}
for (int gjkh : <error descr="foreach not applicable to type 'int'">222</error>) {
}
}
}
@@ -22,7 +22,7 @@ class a {
for (Object oi: (Iterable)o) {}
for (<error descr="Incompatible types. Found: 'double', required: 'int'">int i:db</error>) {
for (int i:db) {
for (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">int p: list</error>) {}
}
}
@@ -1,6 +1,6 @@
public interface IDEA99969 {
default IntStream distinct(Stream s) {
return s.map<error descr="Ambiguous method call: both 'Stream.map(Function)' and 'Stream.map(IntFunction)' match">(i -> <error descr="Inconvertible types; cannot cast '<lambda parameter>' to 'int'">(int) i</error>)</error>;
return s.map(i -> <error descr="Inconvertible types; cannot cast '<lambda parameter>' to 'int'">(int) i</error>);
}
}
interface Stream<T> {
@@ -8,8 +8,8 @@ class Test {
IntStream mi = sp.map(Inner::foo);
Stream<Integer> mI = sp.map(Inner::fooBoxed);
IntStream li = sp.map<error descr="Ambiguous method call: both 'Stream.map(Function<? super Inner,?>)' and 'Stream.map(IntFunction<? super Inner>)' match">(inner->inner.<error descr="Cannot resolve method 'foo()'">foo</error>())</error>;
Stream<Integer> lI = sp.map<error descr="Ambiguous method call: both 'Stream.map(Function<? super Inner,? extends Integer>)' and 'Stream.map(IntFunction<? super Inner>)' match">(inner -> inner.<error descr="Cannot resolve method 'fooBoxed()'">fooBoxed</error>())</error>;
IntStream li = sp.map(inner->inner.<error descr="Cannot resolve method 'foo()'">foo</error>());
Stream<Integer> lI = sp.map(inner -> inner.<error descr="Cannot resolve method 'fooBoxed()'">fooBoxed</error>());
}
interface Stream<T> {
@@ -108,7 +108,7 @@ class ParameterIsEffectivelyFinal {
new Runnable() {
@Override
public void run() {
System.out.println(<error descr="Variable 'o' is accessed from within inner class. Needs to be declared final.">o</error>);
System.out.println(<error descr="Variable 'o' is accessed from within inner class, needs to be declared final">o</error>);
}
}.run();
return 0;
@@ -21,9 +21,9 @@ class Test {
}
void foo(Foo<String> as, final Foo<Character> ac) {
boolean b1 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> false)</error>)</error>;
String s1 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>)</error>;
boolean b2 = as.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<String,Boolean>)' and 'Foo.forAll(II<String,String>)' match">(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>)</error>;
boolean b1 = as.forAll(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> false)</error>);
String s1 = as.forAll(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>);
boolean b2 = as.forAll(s -> ac.forAll<error descr="Ambiguous method call: both 'Foo.forAll(I<Character,Boolean>)' and 'Foo.forAll(II<Character,String>)' match">(c -> "")</error>);
String s2 = as.forAll2(s -> ac.forAll2(<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
boolean b3 = as.forAll((I<String, Boolean>)s -> ac.forAll((I<Character, Boolean>)<error descr="Incompatible return type String in lambda expression">c -> ""</error>));
String s3 = as.forAll((II<String, String>)s -> ac.forAll((II<Character, String>)<error descr="Incompatible return type boolean in lambda expression">c -> false</error>));
@@ -1,5 +1,5 @@
interface A {
default String <error descr="Default method toString overrides a member of java.lang.Object">toString</error>() {
default String <error descr="Default method 'toString' overrides a member of 'java.lang.Object'">toString</error>() {
return "";
}
}
@@ -23,10 +23,10 @@ class C {
interface II extends I {
default void m() {
I.super.m();
<error descr="Unqualified super reference is not allowed in extension method">super.m</error>();
<error descr="Unqualified super reference is not allowed in extension method">super.<error descr="Cannot resolve method 'm()'">m</error></error>();
System.out.println(I.super.i);
System.out.println<error descr="Cannot resolve method 'println(?)'">(<error descr="Unqualified super reference is not allowed in extension method">super.i</error>)</error>;
System.out.println(<error descr="Unqualified super reference is not allowed in extension method">super.<error descr="Cannot resolve symbol 'i'">i</error></error>);
}
void ma();
@@ -14,9 +14,9 @@ class Foo {
void foo(K k){}
void bar() {
foo<error descr="Ambiguous method call: both 'Foo.foo(I)' and 'Foo.foo(K)' match">((p) -> {
foo((p) -> {
System.out.println<error descr="Cannot resolve method 'println(<lambda parameter>)'">(p)</error>;
})</error>;
});
foo((p, k) -> {
System.out.println(p);
@@ -1,9 +0,0 @@
// "Implement Methods" "true"
class c {
void foo() {
new I<String>(<caret>
}
}
interface I<T> {
foo(T t);
}
@@ -1,4 +1,6 @@
// "Make 'victim' return 'boolean'" "true"
import java.util.*;
public class External {
void m1() {
if (new Out().victim(null)) {
@@ -1,4 +1,6 @@
// "Make 'victim' return 'boolean'" "true"
import java.util.*;
public class External {
void m1() {
if (new Out().<caret>victim(null)) {
@@ -63,7 +63,7 @@ PsiJavaFile:RefParamsAfterError.java
PsiJavaToken:LT('<')
PsiErrorElement:Identifier expected
<empty list>
PsiErrorElement:'>' or ',' expected.
PsiErrorElement:'>' or ',' expected
<empty list>
PsiErrorElement:Identifier expected
<empty list>
@@ -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); }
}
@@ -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() {
Ma<caret>p<> l;
Ma<caret>p l;
}
}
'''
@@ -34,7 +34,7 @@ public class Foo {
public class Foo {
void foo() {
Ma<caret>p<> l;
Ma<caret>p l;
}
}
'''
@@ -45,7 +45,7 @@ public class Foo {
myFixture.configureByText 'a.java', '''\
public class Foo {
void foo() {
Ma<caret>p<> l;
Ma<caret>p l;
}
}
'''
@@ -54,7 +54,7 @@ public class Foo {
public class Foo {
void foo() {
Ma<caret>p<> l;
Ma<caret>p l;
}
}
'''
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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);
}
}
}
}
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -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/";
@@ -41,4 +41,35 @@
<item name='java.nio.channels.Channels java.nio.channels.WritableByteChannel newChannel(java.io.OutputStream) 0'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='java.nio.channels.SelectableChannel int validOps()'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
<item name='java.nio.channels.SelectableChannel java.nio.channels.SelectionKey register(java.nio.channels.Selector, int) 1'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
<item
name='java.nio.channels.SelectableChannel java.nio.channels.SelectionKey register(java.nio.channels.Selector, int, java.lang.Object) 1'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
<item name='java.nio.channels.SelectionKey int interestOps()'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
<item name='java.nio.channels.SelectionKey java.nio.channels.SelectionKey interestOps(int) 0'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
<item name='java.nio.channels.SelectionKey int readyOps()'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="flagsFromClass" val="java.nio.channels.SelectionKey.class" />
</annotation>
</item>
</root>
@@ -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<VirtualFile, EditorInfo> editorInfos;
Map<VirtualFile, EditorInfo> 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<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(String testDataFromDir,
final VirtualFile toDir,
final String... relativePaths) throws IOException {
@NotNull
protected Map<VirtualFile, EditorInfo> 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<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(final VirtualFile fromDir, final VirtualFile toDir, final String... relativePaths) throws IOException {
LinkedHashMap<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
@NotNull
protected Map<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(@NotNull VirtualFile fromDir,
@NotNull VirtualFile toDir,
@NotNull String... relativePaths) throws IOException {
Map<VirtualFile, EditorInfo> editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
List<OutputStream> streamsToClose = new ArrayList<OutputStream>();
@@ -356,28 +356,30 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
}
}*/
private EditorInfo copyContent(final VirtualFile from, final VirtualFile to, final List<OutputStream> streamsToClose) throws IOException {
private EditorInfo copyContent(@NotNull VirtualFile from, @NotNull VirtualFile to, @NotNull List<OutputStream> 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<Editor> openEditorsAndActivateLast(final LinkedHashMap<VirtualFile, EditorInfo> editorInfos) {
@NotNull
protected List<Editor> openEditorsAndActivateLast(@NotNull Map<VirtualFile, EditorInfo> editorInfos) {
final List<Editor> list = openEditors(editorInfos);
setActiveEditor(list.get(list.size() - 1));
return list;
}
protected final List<Editor> openEditors(final LinkedHashMap<VirtualFile, EditorInfo> editorInfos) {
@NotNull
protected final List<Editor> openEditors(@NotNull final Map<VirtualFile, EditorInfo> editorInfos) {
return ContainerUtil.map(editorInfos.keySet(), new Function<VirtualFile, Editor>() {
@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<OutputStream> streamsToClose) throws IOException {
if (newFileText != null) {
VfsUtil.saveText(newVFile, newFileText);
} else {
private void doWrite(final String newFileText,
@NotNull VirtualFile newVFile,
byte[] content,
@NotNull List<OutputStream> 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<Document>(getProject()) {
@Override
protected void run(@NotNull Result<Document> 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() {
@@ -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();
@@ -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);
@@ -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<? extends HighlightInfo> 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;
}
}
@@ -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;
}
@@ -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) {
@@ -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<Class, JCheckBox> myCheckBoxes = new HashMap<Class, JCheckBox>();
private List<JCheckBox> myAutoClicked = new ArrayList<JCheckBox>();
private final PsiElement myInitialPsiElement;
private final Map<Class, JCheckBox> myCheckBoxes = new HashMap<Class, JCheckBox>();
private final List<JCheckBox> myAutoClicked = new ArrayList<JCheckBox>();
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<Object> myVisibleParents = new HashSet<Object>();
private final Set<Object> myVisibleParents = new HashSet<Object>();
private final boolean isUnitTest = ApplicationManager.getApplication().isUnitTestMode();
@Override
@@ -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<String> classNameList = new ArrayList<String>();
@@ -61,7 +61,7 @@ public class ClassFinder {
}
}
else {
addIfNotNull(classNameList, computeClassName(current));
ContainerUtil.addIfNotNull(classNameList, computeClassName(current));
}
}
@@ -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/";
@@ -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/";