Don't repeat full qualified name in error messages for field annotations

This commit is contained in:
Nikolay Krasko
2012-10-08 20:47:51 +04:00
parent d0b41ff153
commit a145e93ebb
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.resolve.java.kotlinSignature; package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.util.containers.ComparatorUtil; import com.intellij.util.containers.ComparatorUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
@@ -70,47 +69,25 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
} }
private static void checkFieldAnnotation(JetProperty altProperty, PsiFieldWrapper fieldWrapper, boolean isVar) { private static void checkFieldAnnotation(JetProperty altProperty, PsiFieldWrapper fieldWrapper, boolean isVar) {
String fieldLink = getFieldQualifiedName(fieldWrapper);
if (!ComparatorUtil.equalsNullable(fieldWrapper.getName(), altProperty.getName())) { if (!ComparatorUtil.equalsNullable(fieldWrapper.getName(), altProperty.getName())) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException("Field name mismatch, original: %s, alternative: %s",
"Field name mismatch, original: %s, alternative: %s", fieldWrapper.getName(), altProperty.getName());
fieldLink, altProperty.getName());
} }
if (altProperty.getTypeRef() == null) { if (altProperty.getTypeRef() == null) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have type reference");
"Field annotation for '%s' shouldn't have type reference",
fieldLink);
} }
if (altProperty.getGetter() != null || altProperty.getSetter() != null) { if (altProperty.getGetter() != null || altProperty.getSetter() != null) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have getters and setters");
"Field annotation for '%s' shouldn't have getters and setters",
fieldLink);
} }
if (altProperty.isVar() != isVar) { if (altProperty.isVar() != isVar) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException("Wrong mutability in annotation for field");
"Wrong mutability in annotation for field '%s'",
fieldLink);
} }
if (altProperty.getInitializer() != null) { if (altProperty.getInitializer() != null) {
throw new AlternativeSignatureMismatchException( throw new AlternativeSignatureMismatchException("Default value is not expected in annotation for field");
"Default value is not expected in annotation for field '%s'",
fieldLink);
} }
} }
@NotNull
private static String getFieldQualifiedName(PsiFieldWrapper fieldWrapper) {
PsiClass containingClass = fieldWrapper.getPsiField().getContainingClass();
String fieldLink = containingClass != null ?
String.format("%s.%s", containingClass.getQualifiedName(), fieldWrapper.getName()) :
fieldWrapper.getName();
assert (fieldLink != null);
return fieldLink;
}
} }