From f6b43bb7b20596a3fc8fb336cb35421ba37175cf Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 19 Aug 2013 17:51:26 +0400 Subject: [PATCH] Extract interfaces out of Java*Type --- .../resolve/java/structure/JavaArrayType.java | 14 +-- .../java/structure/JavaArrayTypeImpl.java | 38 ++++++ .../resolve/java/structure/JavaClass.java | 2 +- .../java/structure/JavaClassifierType.java | 75 ++---------- .../structure/JavaClassifierTypeImpl.java | 111 ++++++++++++++++++ ...JavaElementCollectionFromPsiArrayUtil.java | 2 +- .../structure/JavaElementFactoryImpl.java | 2 +- .../java/structure/JavaPrimitiveType.java | 14 +-- .../java/structure/JavaPrimitiveTypeImpl.java | 38 ++++++ .../resolve/java/structure/JavaTypeImpl.java | 8 +- .../java/structure/JavaWildcardType.java | 24 +--- .../java/structure/JavaWildcardTypeImpl.java | 52 ++++++++ 12 files changed, 265 insertions(+), 115 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayTypeImpl.java create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierTypeImpl.java create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveTypeImpl.java create mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardTypeImpl.java diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayType.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayType.java index b25d7b5df07..ffafca8e1d8 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayType.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayType.java @@ -19,19 +19,11 @@ package org.jetbrains.jet.lang.resolve.java.structure; import com.intellij.psi.PsiArrayType; import org.jetbrains.annotations.NotNull; -public class JavaArrayType extends JavaTypeImpl { - public JavaArrayType(@NotNull PsiArrayType psiArrayType) { - super(psiArrayType); - } - +public interface JavaArrayType extends JavaType { @NotNull @Override - public PsiArrayType getPsi() { - return (PsiArrayType) super.getPsi(); - } + PsiArrayType getPsi(); @NotNull - public JavaType getComponentType() { - return JavaTypeImpl.create(getPsi().getComponentType()); - } + JavaType getComponentType(); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayTypeImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayTypeImpl.java new file mode 100644 index 00000000000..1d2d6e88dc1 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaArrayTypeImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import com.intellij.psi.PsiArrayType; +import org.jetbrains.annotations.NotNull; + +public class JavaArrayTypeImpl extends JavaTypeImpl implements JavaArrayType { + public JavaArrayTypeImpl(@NotNull PsiArrayType psiArrayType) { + super(psiArrayType); + } + + @NotNull + @Override + public PsiArrayType getPsi() { + return (PsiArrayType) super.getPsi(); + } + + @Override + @NotNull + public JavaType getComponentType() { + return JavaTypeImpl.create(getPsi().getComponentType()); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java index f9fbeb132ef..501dcc13a8e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClass.java @@ -171,7 +171,7 @@ public class JavaClass extends JavaClassifierImpl @NotNull public JavaClassifierType getDefaultType() { - return new JavaClassifierType(JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi())); + return new JavaClassifierTypeImpl(JavaPsiFacade.getElementFactory(getPsi().getProject()).createType(getPsi())); } @NotNull diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierType.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierType.java index 06d4ac661c4..ba1c4c31f2b 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierType.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierType.java @@ -16,90 +16,31 @@ package org.jetbrains.jet.lang.resolve.java.structure; -import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClassType; -import com.intellij.psi.PsiType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.types; - -public class JavaClassifierType extends JavaTypeImpl { - private static class ResolutionResult { - private final JavaClassifier classifier; - private final JavaTypeSubstitutor substitutor; - - private ResolutionResult(@Nullable JavaClassifier classifier, @NotNull JavaTypeSubstitutor substitutor) { - this.classifier = classifier; - this.substitutor = substitutor; - } - } - - private ResolutionResult resolutionResult; - - public JavaClassifierType(@NotNull PsiClassType psiClassType) { - super(psiClassType); - } +public interface JavaClassifierType extends JavaType { @NotNull @Override - public PsiClassType getPsi() { - return (PsiClassType) super.getPsi(); - } + PsiClassType getPsi(); @Nullable - public JavaClassifier getClassifier() { - resolve(); - return resolutionResult.classifier; - } + JavaClassifier getClassifier(); @NotNull - public JavaTypeSubstitutor getSubstitutor() { - resolve(); - return resolutionResult.substitutor; - } - - private void resolve() { - if (resolutionResult == null) { - PsiClassType.ClassResolveResult result = getPsi().resolveGenerics(); - PsiClass psiClass = result.getElement(); - resolutionResult = new ResolutionResult( - psiClass == null ? null : JavaClassifierImpl.create(psiClass), - new JavaTypeSubstitutor(result.getSubstitutor()) - ); - } - } + JavaTypeSubstitutor getSubstitutor(); @NotNull - public Collection getSupertypes() { - PsiType[] psiTypes = getPsi().getSuperTypes(); - if (psiTypes.length == 0) return Collections.emptyList(); - List result = new ArrayList(psiTypes.length); - for (PsiType psiType : psiTypes) { - if (!(psiType instanceof PsiClassType)) { - throw new IllegalStateException("Supertype should be a class: " + psiType + ", type: " + getPsi()); - } - result.add(new JavaClassifierType((PsiClassType) psiType)); - } - return result; - } + Collection getSupertypes(); @NotNull - public String getPresentableText() { - return getPsi().getPresentableText(); - } + String getPresentableText(); - public boolean isRaw() { - return getPsi().isRaw(); - } + boolean isRaw(); @NotNull - public Collection getTypeArguments() { - return types(getPsi().getParameters()); - } + Collection getTypeArguments(); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierTypeImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierTypeImpl.java new file mode 100644 index 00000000000..8da3a300346 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaClassifierTypeImpl.java @@ -0,0 +1,111 @@ +/* + * 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; + +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiClassType; +import com.intellij.psi.PsiType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.types; + +public class JavaClassifierTypeImpl extends JavaTypeImpl implements JavaClassifierType { + private static class ResolutionResult { + private final JavaClassifier classifier; + private final JavaTypeSubstitutor substitutor; + + private ResolutionResult(@Nullable JavaClassifier classifier, @NotNull JavaTypeSubstitutor substitutor) { + this.classifier = classifier; + this.substitutor = substitutor; + } + } + + private ResolutionResult resolutionResult; + + public JavaClassifierTypeImpl(@NotNull PsiClassType psiClassType) { + super(psiClassType); + } + + @NotNull + @Override + public PsiClassType getPsi() { + return (PsiClassType) super.getPsi(); + } + + @Override + @Nullable + public JavaClassifier getClassifier() { + resolve(); + return resolutionResult.classifier; + } + + @Override + @NotNull + public JavaTypeSubstitutor getSubstitutor() { + resolve(); + return resolutionResult.substitutor; + } + + private void resolve() { + if (resolutionResult == null) { + PsiClassType.ClassResolveResult result = getPsi().resolveGenerics(); + PsiClass psiClass = result.getElement(); + resolutionResult = new ResolutionResult( + psiClass == null ? null : JavaClassifierImpl.create(psiClass), + new JavaTypeSubstitutor(result.getSubstitutor()) + ); + } + } + + @Override + @NotNull + public Collection getSupertypes() { + PsiType[] psiTypes = getPsi().getSuperTypes(); + if (psiTypes.length == 0) return Collections.emptyList(); + List result = new ArrayList(psiTypes.length); + for (PsiType psiType : psiTypes) { + if (!(psiType instanceof PsiClassType)) { + throw new IllegalStateException("Supertype should be a class: " + psiType + ", type: " + getPsi()); + } + result.add(new JavaClassifierTypeImpl((PsiClassType) psiType)); + } + return result; + } + + @Override + @NotNull + public String getPresentableText() { + return getPsi().getPresentableText(); + } + + @Override + public boolean isRaw() { + return getPsi().isRaw(); + } + + @Override + @NotNull + public Collection getTypeArguments() { + return types(getPsi().getParameters()); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java index a694b5c2dfc..4ac5bb53156 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementCollectionFromPsiArrayUtil.java @@ -104,7 +104,7 @@ public class JavaElementCollectionFromPsiArrayUtil { if (classTypes.length == 0) return Collections.emptyList(); List result = new ArrayList(classTypes.length); for (PsiClassType psiClassType : classTypes) { - result.add(new JavaClassifierType(psiClassType)); + result.add(new JavaClassifierTypeImpl(psiClassType)); } return result; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementFactoryImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementFactoryImpl.java index 0bf84b1f274..40a9c92c2c1 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementFactoryImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaElementFactoryImpl.java @@ -22,6 +22,6 @@ public class JavaElementFactoryImpl extends JavaElementFactory { @NotNull @Override public JavaArrayType createArrayType(@NotNull JavaType elementType) { - return new JavaArrayType(elementType.getPsi().createArrayType()); + return new JavaArrayTypeImpl(elementType.getPsi().createArrayType()); } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveType.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveType.java index 9a3e738f127..251484e631e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveType.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveType.java @@ -19,19 +19,11 @@ package org.jetbrains.jet.lang.resolve.java.structure; import com.intellij.psi.PsiPrimitiveType; import org.jetbrains.annotations.NotNull; -public class JavaPrimitiveType extends JavaTypeImpl { - public JavaPrimitiveType(@NotNull PsiPrimitiveType psiPrimitiveType) { - super(psiPrimitiveType); - } - +public interface JavaPrimitiveType extends JavaType { @NotNull @Override - public PsiPrimitiveType getPsi() { - return (PsiPrimitiveType) super.getPsi(); - } + PsiPrimitiveType getPsi(); @NotNull - public String getCanonicalText() { - return getPsi().getCanonicalText(); - } + String getCanonicalText(); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveTypeImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveTypeImpl.java new file mode 100644 index 00000000000..bd4bbe0e7c9 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaPrimitiveTypeImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import com.intellij.psi.PsiPrimitiveType; +import org.jetbrains.annotations.NotNull; + +public class JavaPrimitiveTypeImpl extends JavaTypeImpl implements JavaPrimitiveType { + public JavaPrimitiveTypeImpl(@NotNull PsiPrimitiveType psiPrimitiveType) { + super(psiPrimitiveType); + } + + @NotNull + @Override + public PsiPrimitiveType getPsi() { + return (PsiPrimitiveType) super.getPsi(); + } + + @Override + @NotNull + public String getCanonicalText() { + return getPsi().getCanonicalText(); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaTypeImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaTypeImpl.java index 0bd334ca693..788b41f5414 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaTypeImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaTypeImpl.java @@ -45,25 +45,25 @@ public abstract class JavaTypeImpl implements JavaType { @Nullable @Override public JavaType visitPrimitiveType(PsiPrimitiveType primitiveType) { - return new JavaPrimitiveType(primitiveType); + return new JavaPrimitiveTypeImpl(primitiveType); } @Nullable @Override public JavaType visitArrayType(PsiArrayType arrayType) { - return new JavaArrayType(arrayType); + return new JavaArrayTypeImpl(arrayType); } @Nullable @Override public JavaType visitClassType(PsiClassType classType) { - return new JavaClassifierType(classType); + return new JavaClassifierTypeImpl(classType); } @Nullable @Override public JavaType visitWildcardType(PsiWildcardType wildcardType) { - return new JavaWildcardType(wildcardType); + return new JavaWildcardTypeImpl(wildcardType); } }); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardType.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardType.java index c43ad485690..5c5945cf8ab 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardType.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardType.java @@ -16,34 +16,20 @@ package org.jetbrains.jet.lang.resolve.java.structure; -import com.intellij.psi.PsiType; import com.intellij.psi.PsiWildcardType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class JavaWildcardType extends JavaTypeImpl { - public JavaWildcardType(@NotNull PsiWildcardType psiWildcardType) { - super(psiWildcardType); - } - +public interface JavaWildcardType extends JavaType { @NotNull @Override - public PsiWildcardType getPsi() { - return (PsiWildcardType) super.getPsi(); - } + PsiWildcardType getPsi(); @Nullable - public JavaType getBound() { - PsiType bound = getPsi().getBound(); - return bound == null ? null : JavaTypeImpl.create(bound); - } + JavaType getBound(); - public boolean isExtends() { - return getPsi().isExtends(); - } + boolean isExtends(); @NotNull - public JavaTypeProvider getTypeProvider() { - return new JavaTypeProvider(getPsi().getManager()); - } + JavaTypeProvider getTypeProvider(); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardTypeImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardTypeImpl.java new file mode 100644 index 00000000000..e160f4372f7 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/structure/JavaWildcardTypeImpl.java @@ -0,0 +1,52 @@ +/* + * 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; + +import com.intellij.psi.PsiType; +import com.intellij.psi.PsiWildcardType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class JavaWildcardTypeImpl extends JavaTypeImpl implements JavaWildcardType { + public JavaWildcardTypeImpl(@NotNull PsiWildcardType psiWildcardType) { + super(psiWildcardType); + } + + @NotNull + @Override + public PsiWildcardType getPsi() { + return (PsiWildcardType) super.getPsi(); + } + + @Override + @Nullable + public JavaType getBound() { + PsiType bound = getPsi().getBound(); + return bound == null ? null : JavaTypeImpl.create(bound); + } + + @Override + public boolean isExtends() { + return getPsi().isExtends(); + } + + @Override + @NotNull + public JavaTypeProvider getTypeProvider() { + return new JavaTypeProvider(getPsi().getManager()); + } +}