Minor cleanup in Java model: fix warnings, remove unused

This commit is contained in:
Alexander Udalov
2016-03-17 20:39:12 +03:00
parent 0a54464420
commit 0d74fc2290
10 changed files with 23 additions and 63 deletions
@@ -24,40 +24,19 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
import org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl;
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil;
import org.jetbrains.kotlin.load.java.structure.impl.JavaModifierListOwnerImpl;
import org.jetbrains.kotlin.name.FqName;
import java.util.Collection;
import java.util.Collections;
public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationResolver {
@Nullable
@Override
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
if (owner instanceof JavaModifierListOwnerImpl) {
JavaModifierListOwnerImpl modifierListOwner = (JavaModifierListOwnerImpl) owner;
PsiAnnotation psiAnnotation = findExternalAnnotation(modifierListOwner.getPsi(), fqName);
PsiModifierListOwner psiOwner = ((JavaModifierListOwnerImpl) owner).getPsi();
PsiAnnotation psiAnnotation =
ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotation(psiOwner, fqName.asString());
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
}
return null;
}
@NotNull
@Override
public Collection<JavaAnnotation> findExternalAnnotations(@NotNull JavaAnnotationOwner owner) {
if (owner instanceof JavaModifierListOwnerImpl) {
PsiModifierListOwner psiOwner = ((JavaModifierListOwnerImpl) owner).getPsi();
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
return annotations == null
? Collections.<JavaAnnotation>emptyList()
: JavaElementCollectionFromPsiArrayUtil.annotations(annotations);
}
return Collections.emptyList();
}
@Nullable
public static PsiAnnotation findExternalAnnotation(@NotNull PsiModifierListOwner owner, @NotNull FqName fqName) {
return ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotation(owner, fqName.asString());
}
}
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.load.java.structure.impl;
import com.intellij.psi.*;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
@@ -35,13 +38,6 @@ public class JavaAnnotationImpl extends JavaElementImpl<PsiAnnotation> implement
super(psiAnnotation);
}
@Override
@Nullable
public JavaAnnotationArgument findArgument(@NotNull Name name) {
PsiAnnotationMemberValue attribute = getPsi().findAttributeValue(name.asString());
return attribute == null ? null : JavaAnnotationArgumentImpl.Factory.create(attribute, name);
}
@Override
@NotNull
public Collection<JavaAnnotationArgument> getArguments() {
@@ -74,7 +70,8 @@ public class JavaAnnotationImpl extends JavaElementImpl<PsiAnnotation> implement
PsiClass container = psiClass.getContainingClass();
if (container != null) {
ClassId parentClassId = computeClassId(container);
return parentClassId == null ? null : parentClassId.createNestedClassId(Name.identifier(psiClass.getName()));
String name = psiClass.getName();
return parentClassId == null || name == null ? null : parentClassId.createNestedClassId(Name.identifier(name));
}
String fqName = psiClass.getQualifiedName();
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.Visibility;
import org.jetbrains.kotlin.load.java.structure.*;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.name.SpecialNames;
import java.util.Collection;
import java.util.List;
@@ -55,7 +56,7 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
@NotNull
@Override
public Name getName() {
return Name.identifier(getPsi().getName());
return SpecialNames.safeIdentifier(getPsi().getName());
}
@Override
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiAnnotationMethod;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.java.structure.JavaMethod;
import org.jetbrains.kotlin.load.java.structure.JavaType;
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType;
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.name.SpecialNames;
import java.util.Collection;
@@ -36,7 +37,7 @@ public class JavaTypeParameterImpl extends JavaClassifierImpl<PsiTypeParameter>
@NotNull
@Override
public Name getName() {
return Name.identifier(getPsi().getName());
return SpecialNames.safeIdentifier(getPsi().getName());
}
@Override