Pull down getPsi() method from JavaElement

This commit is contained in:
Alexander Udalov
2013-08-20 15:42:26 +04:00
parent 714dbe2df3
commit 4cd238ddde
41 changed files with 125 additions and 175 deletions
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaFieldImpl;
import org.jetbrains.jet.lang.types.JetType;
import java.util.HashMap;
@@ -34,7 +34,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
public AlternativeFieldSignatureData(
@NotNull JavaAnnotationResolver annotationResolver,
@NotNull JavaField field,
@NotNull JavaFieldImpl field,
@NotNull JetType originalReturnType,
boolean isVar
) {
@@ -66,7 +66,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
return altReturnType;
}
private static void checkFieldAnnotation(@NotNull JetProperty altProperty, @NotNull JavaField field, boolean isVar) {
private static void checkFieldAnnotation(@NotNull JetProperty altProperty, @NotNull JavaFieldImpl field, boolean isVar) {
if (!ComparatorUtil.equalsNullable(field.getName().asString(), altProperty.getName())) {
throw new AlternativeSignatureMismatchException("Field name mismatch, original: %s, alternative: %s",
field.getName().asString(), altProperty.getName());
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -54,7 +55,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
public AlternativeMethodSignatureData(
@NotNull JavaAnnotationResolver annotationResolver,
@NotNull JavaMethod method,
@NotNull JavaMethodImpl method,
@Nullable JetType receiverType,
@NotNull List<ValueParameterDescriptor> valueParameters,
@Nullable JetType originalReturnType,
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.Visibilities;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSupertypeResolver;
import org.jetbrains.jet.lang.resolve.java.structure.*;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaTypeSubstitutorImpl;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -123,9 +124,10 @@ class PropagationHeuristics {
return null;
}
@SuppressWarnings("unchecked")
@NotNull
static List<JavaMethod> getSuperMethods(@NotNull JavaMethod method) {
return new SuperMethodCollector(method).collect();
static List<JavaMethodImpl> getSuperMethods(@NotNull JavaMethod method) {
return (List) new SuperMethodCollector(method).collect();
}
private PropagationHeuristics() {
@@ -72,7 +72,7 @@ public class SignaturesPropagationData {
@Nullable JetType receiverType,
@NotNull List<ValueParameterDescriptor> autoValueParameters, // descriptors built by parameters resolver
@NotNull List<TypeParameterDescriptor> autoTypeParameters, // descriptors built by signature resolver
@NotNull JavaMethod method,
@NotNull JavaMethodImpl method,
@NotNull BindingTrace trace
) {
this.containingClass = containingClass;
@@ -215,7 +215,7 @@ public class SignaturesPropagationData {
}
private static List<FunctionDescriptor> getSuperFunctionsForMethod(
@NotNull JavaMethod method,
@NotNull JavaMethodImpl method,
@NotNull BindingTrace trace,
@NotNull ClassDescriptor containingClass
) {
@@ -223,10 +223,10 @@ public class SignaturesPropagationData {
Map<ClassDescriptor, JetType> superclassToSupertype = getSuperclassToSupertypeMap(containingClass);
Multimap<FqName, Pair<FunctionDescriptor, JavaMethod>> superclassToFunctions =
Multimap<FqName, Pair<FunctionDescriptor, JavaMethodImpl>> superclassToFunctions =
getSuperclassToFunctionsMultimap(method, trace.getBindingContext(), containingClass);
for (JavaMethod superMethod : PropagationHeuristics.getSuperMethods(method)) {
for (JavaMethodImpl superMethod : PropagationHeuristics.getSuperMethods(method)) {
JavaClass javaClass = superMethod.getContainingClass();
FqName classFqName = javaClass.getFqName();
assert classFqName != null : "Class FQ name should not be null: " + javaClass;
@@ -268,12 +268,12 @@ public class SignaturesPropagationData {
}
@NotNull
private static Multimap<FqName, Pair<FunctionDescriptor, JavaMethod>> getSuperclassToFunctionsMultimap(
private static Multimap<FqName, Pair<FunctionDescriptor, JavaMethodImpl>> getSuperclassToFunctionsMultimap(
@NotNull JavaMethod method,
@NotNull BindingContext bindingContext,
@NotNull ClassDescriptor containingClass
) {
Multimap<FqName, Pair<FunctionDescriptor, JavaMethod>> result = HashMultimap.create();
Multimap<FqName, Pair<FunctionDescriptor, JavaMethodImpl>> result = HashMultimap.create();
Name functionName = method.getName();
int parameterCount = method.getValueParameters().size();
@@ -289,7 +289,7 @@ public class SignaturesPropagationData {
fun.getValueParameters().size() + (fun.getReceiverParameter() != null ? 1 : 0) == parameterCount) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, fun);
if (declaration instanceof PsiMethod) {
result.put(fqName, Pair.<FunctionDescriptor, JavaMethod>create(fun, new JavaMethodImpl((PsiMethod) declaration)));
result.put(fqName, Pair.create(fun, new JavaMethodImpl((PsiMethod) declaration)));
} // else declaration is null or JetNamedFunction: both cases are processed later
}
}
@@ -299,11 +299,11 @@ public class SignaturesPropagationData {
@Nullable
private static DeclarationDescriptor findSuperFunction(
@NotNull Collection<Pair<FunctionDescriptor, JavaMethod>> superFunctionCandidates,
@NotNull JavaMethod superMethod
@NotNull Collection<Pair<FunctionDescriptor, JavaMethodImpl>> superFunctionCandidates,
@NotNull JavaMethodImpl superMethod
) {
PsiManager psiManager = PsiManager.getInstance(superMethod.getPsi().getProject());
for (Pair<FunctionDescriptor, JavaMethod> candidate : superFunctionCandidates) {
for (Pair<FunctionDescriptor, JavaMethodImpl> candidate : superFunctionCandidates) {
if (psiManager.areElementsEquivalent(candidate.second.getPsi(), superMethod.getPsi())) {
return candidate.first;
}
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaAnnotationImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaAnnotationOwnerImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -36,14 +37,14 @@ public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationRes
@Nullable
@Override
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
PsiAnnotation psiAnnotation = findExternalAnnotation(owner.getPsi(), fqName);
PsiAnnotation psiAnnotation = findExternalAnnotation(((JavaAnnotationOwnerImpl) owner).getPsi(), fqName);
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
}
@NotNull
@Override
public Collection<JavaAnnotation> findExternalAnnotations(@NotNull JavaAnnotationOwner owner) {
PsiModifierListOwner psiOwner = owner.getPsi();
PsiModifierListOwner psiOwner = ((JavaAnnotationOwnerImpl) owner).getPsi();
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
return annotations == null
? Collections.<JavaAnnotation>emptyList()
@@ -107,7 +107,7 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
}
// Originally from com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil
private static boolean isMethodReturnTypeCompatible(@NotNull JavaMethod method) {
private static boolean isMethodReturnTypeCompatible(@NotNull JavaMethodImpl method) {
if (method.isStatic()) return true;
HierarchicalMethodSignature methodSignature = method.getPsi().getHierarchicalMethodSignature();
@@ -167,8 +167,9 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
@NotNull List<String> signatureErrors,
@NotNull List<FunctionDescriptor> superFunctions
) {
if (!RawTypesCheck.hasRawTypesInHierarchicalSignature(method) &&
isMethodReturnTypeCompatible(method) &&
JavaMethodImpl methodWithPsi = (JavaMethodImpl) method;
if (!RawTypesCheck.hasRawTypesInHierarchicalSignature(methodWithPsi) &&
isMethodReturnTypeCompatible(methodWithPsi) &&
!containsErrorType(superFunctions, descriptor)) {
if (signatureErrors.isEmpty()) {
for (FunctionDescriptor superFunction : superFunctions) {
@@ -236,7 +237,7 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
return false;
}
public static boolean hasRawTypesInHierarchicalSignature(@NotNull JavaMethod method) {
public static boolean hasRawTypesInHierarchicalSignature(@NotNull JavaMethodImpl method) {
// This is a very important optimization: package-classes are big and full of static methods
// building method hierarchies for such classes takes a very long time
if (method.isStatic()) return false;
@@ -29,6 +29,8 @@ import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSign
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesPropagationData;
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaFieldImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
import org.jetbrains.jet.lang.types.JetType;
import javax.inject.Inject;
@@ -60,7 +62,8 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
@NotNull List<TypeParameterDescriptor> typeParameters
) {
SignaturesPropagationData data =
new SignaturesPropagationData(owner, returnType, receiverType, valueParameters, typeParameters, method, trace);
new SignaturesPropagationData(owner, returnType, receiverType, valueParameters, typeParameters, (JavaMethodImpl) method,
trace);
return new PropagatedMethodSignature(data.getModifiedReturnType(), data.getModifiedReceiverType(),
data.getModifiedValueParameters(), data.getModifiedTypeParameters(), data.getSignatureErrors(),
data.getSuperFunctions());
@@ -77,8 +80,8 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
@NotNull List<TypeParameterDescriptor> typeParameters
) {
AlternativeMethodSignatureData data =
new AlternativeMethodSignatureData(annotationResolver, method, receiverType, valueParameters, returnType, typeParameters,
hasSuperMethods);
new AlternativeMethodSignatureData(annotationResolver, (JavaMethodImpl) method, receiverType, valueParameters, returnType,
typeParameters, hasSuperMethods);
if (data.isAnnotated() && !data.hasErrors()) {
return new AlternativeMethodSignature(data.getReturnType(), receiverType, data.getValueParameters(), data.getTypeParameters(),
@@ -96,7 +99,8 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
@NotNull JetType returnType,
boolean isVar
) {
AlternativeFieldSignatureData data = new AlternativeFieldSignatureData(annotationResolver, field, returnType, isVar);
AlternativeFieldSignatureData data =
new AlternativeFieldSignatureData(annotationResolver, (JavaFieldImpl) field, returnType, isVar);
if (data.isAnnotated() && !data.hasErrors()) {
return new AlternativeFieldSignature(data.getReturnType(), null);
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.resolve.java.resolver;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiLiteralExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,6 +32,10 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
import org.jetbrains.jet.lang.resolve.java.structure.JavaElement;
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaClassImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaFieldImpl;
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
import org.jetbrains.jet.lang.resolve.name.FqName;
import javax.inject.Inject;
@@ -65,37 +70,38 @@ public class TraceBasedJavaResolverCache implements JavaResolverCache {
@Nullable
@Override
public SimpleFunctionDescriptor getMethod(@NotNull JavaMethod method) {
return trace.get(FUNCTION, method.getPsi());
return trace.get(FUNCTION, ((JavaMethodImpl) method).getPsi());
}
@Nullable
@Override
public ConstructorDescriptor getConstructor(@NotNull JavaElement constructor) {
return trace.get(CONSTRUCTOR, constructor.getPsi());
return trace.get(CONSTRUCTOR, ((JavaElementImpl) constructor).getPsi());
}
@Nullable
@Override
public ClassDescriptor getClass(@NotNull JavaClass javaClass) {
return trace.get(CLASS, javaClass.getPsi());
return trace.get(CLASS, ((JavaClassImpl) javaClass).getPsi());
}
@Override
public void recordMethod(@NotNull JavaMethod method, @NotNull SimpleFunctionDescriptor descriptor) {
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, method.getPsi(), descriptor);
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, ((JavaMethodImpl) method).getPsi(), descriptor);
}
@Override
public void recordConstructor(@NotNull JavaElement element, @NotNull ConstructorDescriptor descriptor) {
trace.record(CONSTRUCTOR, element.getPsi(), descriptor);
trace.record(CONSTRUCTOR, ((JavaElementImpl) element).getPsi(), descriptor);
}
@Override
public void recordField(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor) {
trace.record(VARIABLE, field.getPsi(), descriptor);
PsiField psiField = ((JavaFieldImpl) field).getPsi();
trace.record(VARIABLE, psiField, descriptor);
if (AnnotationUtils.isPropertyAcceptableAsAnnotationParameter(descriptor)) {
PsiExpression initializer = field.getPsi().getInitializer();
PsiExpression initializer = psiField.getInitializer();
if (initializer instanceof PsiLiteralExpression) {
CompileTimeConstant<?> constant = JavaAnnotationArgumentResolver
.resolveCompileTimeConstantValue(((PsiLiteralExpression) initializer).getValue(), descriptor.getType());
@@ -108,7 +114,7 @@ public class TraceBasedJavaResolverCache implements JavaResolverCache {
@Override
public void recordClass(@NotNull JavaClass javaClass, @NotNull ClassDescriptor descriptor) {
trace.record(CLASS, javaClass.getPsi(), descriptor);
trace.record(CLASS, ((JavaClassImpl) javaClass).getPsi(), descriptor);
}
@Override
@@ -123,6 +129,6 @@ public class TraceBasedJavaResolverCache implements JavaResolverCache {
@Override
public void recordPackage(@NotNull JavaElement element, @NotNull NamespaceDescriptor descriptor) {
trace.record(NAMESPACE, element.getPsi(), descriptor);
trace.record(NAMESPACE, ((JavaElementImpl) element).getPsi(), descriptor);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -25,10 +24,6 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
public interface JavaAnnotation extends JavaElement {
@NotNull
@Override
PsiAnnotation getPsi();
@Nullable
JavaAnnotationArgument findArgument(@NotNull Name name);
@@ -16,16 +16,10 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiAnnotationMemberValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface JavaAnnotationArgument extends JavaElement {
@NotNull
@Override
PsiAnnotationMemberValue getPsi();
@Nullable
Name getName();
}
@@ -16,14 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
public interface JavaAnnotationAsAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
PsiAnnotation getPsi();
@NotNull
JavaAnnotation getAnnotation();
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -24,10 +23,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection;
public interface JavaAnnotationOwner extends JavaElement {
@NotNull
@Override
PsiModifierListOwner getPsi();
@NotNull
Collection<JavaAnnotation> getAnnotations();
@@ -16,16 +16,11 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiArrayInitializerMemberValue;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public interface JavaArrayAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
PsiArrayInitializerMemberValue getPsi();
@NotNull
Collection<JavaAnnotationArgument> getElements();
}
@@ -16,14 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiArrayType;
import org.jetbrains.annotations.NotNull;
public interface JavaArrayType extends JavaType {
@NotNull
@Override
PsiArrayType getPsi();
@NotNull
JavaType getComponentType();
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassKind;
@@ -27,10 +26,6 @@ import java.util.Collection;
public interface JavaClass
extends JavaClassifier, JavaNamedElement, JavaTypeParameterListOwner, JavaModifierListOwner, JavaAnnotationOwner {
@NotNull
@Override
PsiClass getPsi();
@NotNull
Collection<JavaClass> getInnerClasses();
@@ -16,11 +16,5 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
public interface JavaClassifier extends JavaElement {
@NotNull
@Override
PsiClass getPsi();
}
@@ -16,17 +16,12 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiClassType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface JavaClassifierType extends JavaType {
@NotNull
@Override
PsiClassType getPsi();
@Nullable
JavaClassifier getClassifier();
@@ -16,10 +16,5 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
public interface JavaElement {
@NotNull
PsiElement getPsi();
}
@@ -16,14 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiField;
import org.jetbrains.annotations.NotNull;
public interface JavaField extends JavaMember {
@NotNull
@Override
PsiField getPsi();
boolean isEnumEntry();
@NotNull
@@ -16,15 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiLiteralExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface JavaLiteralAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
PsiLiteralExpression getPsi();
@Nullable
Object getValue();
}
@@ -16,15 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiMember;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface JavaMember extends JavaModifierListOwner, JavaAnnotationOwner, JavaNamedElement {
@NotNull
@Override
PsiMember getPsi();
@NotNull
JavaClass getContainingClass();
}
@@ -16,17 +16,12 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface JavaMethod extends JavaMember, JavaTypeParameterListOwner {
@NotNull
@Override
PsiMethod getPsi();
@NotNull
Collection<JavaValueParameter> getValueParameters();
@@ -16,15 +16,10 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.Visibility;
public interface JavaModifierListOwner extends JavaElement {
@NotNull
@Override
PsiModifierListOwner getPsi();
boolean isAbstract();
boolean isStatic();
@@ -16,17 +16,12 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection;
public interface JavaPackage extends JavaElement {
@NotNull
@Override
PsiPackage getPsi();
@NotNull
Collection<JavaClass> getClasses();
@@ -16,14 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiPrimitiveType;
import org.jetbrains.annotations.NotNull;
public interface JavaPrimitiveType extends JavaType {
@NotNull
@Override
PsiPrimitiveType getPsi();
@NotNull
String getCanonicalText();
}
@@ -16,15 +16,9 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiReferenceExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface JavaReferenceAnnotationArgument extends JavaAnnotationArgument {
@NotNull
@Override
PsiReferenceExpression getPsi();
@Nullable
JavaElement resolve();
}
@@ -16,10 +16,5 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
public interface JavaType {
@NotNull
PsiType getPsi();
}
@@ -16,17 +16,12 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiTypeParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface JavaTypeParameter extends JavaClassifier, JavaNamedElement {
@NotNull
@Override
PsiTypeParameter getPsi();
int getIndex();
@NotNull
@@ -16,16 +16,11 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface JavaValueParameter extends JavaAnnotationOwner {
@NotNull
@Override
PsiParameter getPsi();
@Nullable
Name getName();
@@ -16,15 +16,10 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiWildcardType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface JavaWildcardType extends JavaType {
@NotNull
@Override
PsiWildcardType getPsi();
@Nullable
JavaType getBound();
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2013 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 org.jetbrains.jet.lang.resolve.java.structure.impl;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner;
public interface JavaAnnotationOwnerImpl extends JavaAnnotationOwner {
@NotNull
PsiModifierListOwner getPsi();
}
@@ -35,7 +35,7 @@ import java.util.Collection;
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.*;
public class JavaClassImpl extends JavaClassifierImpl implements JavaClass {
public class JavaClassImpl extends JavaClassifierImpl implements JavaClass, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
public JavaClassImpl(@NotNull PsiClass psiClass) {
super(psiClass);
assert !(psiClass instanceof PsiTypeParameter)
@@ -25,6 +25,6 @@ public class JavaElementFactoryImpl extends JavaElementFactory {
@NotNull
@Override
public JavaArrayType createArrayType(@NotNull JavaType elementType) {
return new JavaArrayTypeImpl(elementType.getPsi().createArrayType());
return new JavaArrayTypeImpl(((JavaTypeImpl) elementType).getPsi().createArrayType());
}
}
@@ -28,7 +28,6 @@ public abstract class JavaElementImpl implements JavaElement {
}
@NotNull
@Override
public PsiElement getPsi() {
return psiElement;
}
@@ -40,7 +39,7 @@ public abstract class JavaElementImpl implements JavaElement {
@Override
public boolean equals(Object obj) {
return obj instanceof JavaElement && getPsi().equals(((JavaElement) obj).getPsi());
return obj instanceof JavaElementImpl && getPsi().equals(((JavaElementImpl) obj).getPsi());
}
@Override
@@ -19,14 +19,13 @@ package org.jetbrains.jet.lang.resolve.java.structure.impl;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Visibilities;
import org.jetbrains.jet.lang.descriptors.Visibility;
import org.jetbrains.jet.lang.resolve.java.JavaVisibilities;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation;
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner;
import org.jetbrains.jet.lang.resolve.java.structure.JavaModifierListOwner;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Collection;
@@ -38,34 +37,35 @@ import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementColl
private JavaElementUtil() {
}
public static boolean isAbstract(@NotNull JavaModifierListOwner owner) {
public static boolean isAbstract(@NotNull JavaModifierListOwnerImpl owner) {
return owner.getPsi().hasModifierProperty(PsiModifier.ABSTRACT);
}
public static boolean isStatic(@NotNull JavaModifierListOwner owner) {
public static boolean isStatic(@NotNull JavaModifierListOwnerImpl owner) {
return owner.getPsi().hasModifierProperty(PsiModifier.STATIC);
}
public static boolean isFinal(@NotNull JavaModifierListOwner owner) {
public static boolean isFinal(@NotNull JavaModifierListOwnerImpl owner) {
return owner.getPsi().hasModifierProperty(PsiModifier.FINAL);
}
@NotNull
public static Visibility getVisibility(@NotNull JavaModifierListOwner owner) {
if (owner.getPsi().hasModifierProperty(PsiModifier.PUBLIC)) {
public static Visibility getVisibility(@NotNull JavaModifierListOwnerImpl owner) {
PsiModifierListOwner psiOwner = owner.getPsi();
if (psiOwner.hasModifierProperty(PsiModifier.PUBLIC)) {
return Visibilities.PUBLIC;
}
if (owner.getPsi().hasModifierProperty(PsiModifier.PRIVATE)) {
if (psiOwner.hasModifierProperty(PsiModifier.PRIVATE)) {
return Visibilities.PRIVATE;
}
if (owner.getPsi().hasModifierProperty(PsiModifier.PROTECTED)) {
if (psiOwner.hasModifierProperty(PsiModifier.PROTECTED)) {
return owner.isStatic() ? JavaVisibilities.PROTECTED_STATIC_VISIBILITY : JavaVisibilities.PROTECTED_AND_PACKAGE;
}
return JavaVisibilities.PACKAGE_VISIBILITY;
}
@NotNull
public static Collection<JavaAnnotation> getAnnotations(@NotNull JavaAnnotationOwner owner) {
public static Collection<JavaAnnotation> getAnnotations(@NotNull JavaAnnotationOwnerImpl owner) {
PsiModifierList modifierList = owner.getPsi().getModifierList();
if (modifierList != null) {
return annotations(modifierList.getAnnotations());
@@ -74,7 +74,7 @@ import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementColl
}
@Nullable
public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwnerImpl owner, @NotNull FqName fqName) {
PsiModifierList modifierList = owner.getPsi().getModifierList();
if (modifierList != null) {
PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqName.asString());
@@ -29,7 +29,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
public abstract class JavaMemberImpl extends JavaElementImpl implements JavaMember {
public abstract class JavaMemberImpl extends JavaElementImpl implements JavaMember, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
protected JavaMemberImpl(@NotNull PsiMember psiMember) {
super(psiMember);
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2013 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 org.jetbrains.jet.lang.resolve.java.structure.impl;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.structure.JavaModifierListOwner;
public interface JavaModifierListOwnerImpl extends JavaModifierListOwner {
@NotNull
PsiModifierListOwner getPsi();
}
@@ -28,14 +28,14 @@ public class JavaSignatureFormatterImpl extends JavaSignatureFormatter {
@NotNull
@Override
public String formatMethod(@NotNull JavaMethod method) {
return PsiFormatUtil.formatMethod(method.getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
return PsiFormatUtil.formatMethod(((JavaMethodImpl) method).getPsi(), PsiSubstitutor.EMPTY, SHOW_NAME | SHOW_PARAMETERS,
SHOW_TYPE | SHOW_FQ_CLASS_NAMES);
}
@NotNull
@Override
public String getExternalName(@NotNull JavaMethod method) {
String result = PsiFormatUtil.getExternalName(method.getPsi());
String result = PsiFormatUtil.getExternalName(((JavaMethodImpl) method).getPsi());
return result == null ? "null" : result;
}
}
@@ -28,7 +28,6 @@ public abstract class JavaTypeImpl implements JavaType {
this.psiType = psiType;
}
@Override
@NotNull
public PsiType getPsi() {
return psiType;
@@ -76,7 +75,7 @@ public abstract class JavaTypeImpl implements JavaType {
@Override
public boolean equals(Object obj) {
return obj instanceof JavaTypeImpl && getPsi().equals(((JavaType) obj).getPsi());
return obj instanceof JavaTypeImpl && getPsi().equals(((JavaTypeImpl) obj).getPsi());
}
@Override
@@ -46,8 +46,8 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
public static JavaTypeSubstitutor create(@NotNull Map<JavaTypeParameter, JavaType> substitutionMap) {
Map<PsiTypeParameter, PsiType> psiMap = new HashMap<PsiTypeParameter, PsiType>();
for (Map.Entry<JavaTypeParameter, JavaType> entry : substitutionMap.entrySet()) {
JavaType value = entry.getValue();
psiMap.put(entry.getKey().getPsi(), value == null ? null : value.getPsi());
JavaTypeImpl value = ((JavaTypeImpl) entry.getValue());
psiMap.put(((JavaTypeParameterImpl) entry.getKey()).getPsi(), value == null ? null : value.getPsi());
}
PsiSubstitutor psiSubstitutor = PsiSubstitutorImpl.createSubstitutor(psiMap);
return new JavaTypeSubstitutorImpl(psiSubstitutor, substitutionMap);
@@ -56,13 +56,13 @@ public class JavaTypeSubstitutorImpl implements JavaTypeSubstitutor {
@Override
@NotNull
public JavaType substitute(@NotNull JavaType type) {
return JavaTypeImpl.create(psiSubstitutor.substitute(type.getPsi()));
return JavaTypeImpl.create(psiSubstitutor.substitute(((JavaTypeImpl) type).getPsi()));
}
@Override
@Nullable
public JavaType substitute(@NotNull JavaTypeParameter typeParameter) {
PsiType psiType = psiSubstitutor.substitute(typeParameter.getPsi());
PsiType psiType = psiSubstitutor.substitute(((JavaTypeParameterImpl) typeParameter).getPsi());
return psiType == null ? null : JavaTypeImpl.create(psiType);
}
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
public class JavaValueParameterImpl extends JavaElementImpl implements JavaValueParameter {
public class JavaValueParameterImpl extends JavaElementImpl implements JavaValueParameter, JavaAnnotationOwnerImpl {
public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) {
super(psiParameter);
}