[java] implementation of light psi class that doesn't depend on some delegate
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 6 Jul 2015 16:09:46 +0000 (19:09 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 6 Jul 2015 16:24:38 +0000 (19:24 +0300)
java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBase.java [new file with mode: 0644]
java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBuilder.java [new file with mode: 0644]

diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBase.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBase.java
new file mode 100644 (file)
index 0000000..5d5e958
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2000-2015 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.psi.impl.light;
+
+import com.intellij.lang.Language;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.*;
+import com.intellij.psi.impl.InheritanceImplUtil;
+import com.intellij.psi.impl.PsiClassImplUtil;
+import com.intellij.psi.impl.PsiImplUtil;
+import com.intellij.psi.impl.PsiSuperMethodImplUtil;
+import com.intellij.psi.javadoc.PsiDocComment;
+import com.intellij.psi.scope.PsiScopeProcessor;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.List;
+
+public abstract class LightPsiClassBase extends LightElement implements PsiClass, SyntheticElement {
+
+  private final @NotNull String myName;
+
+  public LightPsiClassBase(@NotNull PsiElement context, @NotNull String name) {
+    this(context.getManager(), context.getLanguage(), name);
+  }
+
+  public LightPsiClassBase(@NotNull PsiManager manager, @NotNull Language language, @NotNull String name) {
+    super(manager, language);
+    myName = name;
+  }
+
+  @NotNull
+  @Override
+  public String getName() {
+    return myName;
+  }
+
+  @Nullable
+  @Override
+  public String getQualifiedName() {
+    PsiElement parent = getParent();
+    if (parent instanceof PsiJavaFile) {
+      return StringUtil.getQualifiedName(((PsiJavaFile)parent).getPackageName(), getName());
+    }
+    if (parent instanceof PsiClass) {
+      String parentQName = ((PsiClass)parent).getQualifiedName();
+      if (parentQName == null) return null;
+      return StringUtil.getQualifiedName(parentQName, getName());
+    }
+    return null;
+  }
+
+  @Override
+  public String toString() {
+    return "Light PSI class: " + getName();
+  }
+
+  @Override
+  public boolean isInterface() {
+    return false;
+  }
+
+  @Override
+  public boolean isAnnotationType() {
+    return false;
+  }
+
+  @Override
+  public boolean isEnum() {
+    return false;
+  }
+
+  @Override
+  @NotNull
+  public PsiClassType[] getExtendsListTypes() {
+    return PsiClassImplUtil.getExtendsListTypes(this);
+  }
+
+  @Override
+  @NotNull
+  public PsiClassType[] getImplementsListTypes() {
+    return PsiClassImplUtil.getImplementsListTypes(this);
+  }
+
+  @Nullable
+  @Override
+  public PsiClass getSuperClass() {
+    return PsiClassImplUtil.getSuperClass(this);
+  }
+
+  @Override
+  public PsiClass[] getInterfaces() {
+    return PsiClassImplUtil.getInterfaces(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiClass[] getSupers() {
+    return PsiClassImplUtil.getSupers(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiClassType[] getSuperTypes() {
+    return PsiClassImplUtil.getSuperTypes(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiMethod[] getConstructors() {
+    return PsiImplUtil.getConstructors(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiField[] getAllFields() {
+    return PsiClassImplUtil.getAllFields(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiMethod[] getAllMethods() {
+    return PsiClassImplUtil.getAllMethods(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiClass[] getAllInnerClasses() {
+    return PsiClassImplUtil.getAllInnerClasses(this);
+  }
+
+  @Nullable
+  @Override
+  public PsiField findFieldByName(@NonNls String name, boolean checkBases) {
+    return PsiClassImplUtil.findFieldByName(this, name, checkBases);
+  }
+
+  @Nullable
+  @Override
+  public PsiMethod findMethodBySignature(PsiMethod patternMethod, boolean checkBases) {
+    return PsiClassImplUtil.findMethodBySignature(this, patternMethod, checkBases);
+  }
+
+  @NotNull
+  @Override
+  public PsiMethod[] findMethodsBySignature(PsiMethod patternMethod, boolean checkBases) {
+    return PsiClassImplUtil.findMethodsBySignature(this, patternMethod, checkBases);
+  }
+
+  @NotNull
+  @Override
+  public PsiMethod[] findMethodsByName(@NonNls String name, boolean checkBases) {
+    return PsiClassImplUtil.findMethodsByName(this, name, checkBases);
+  }
+
+  @NotNull
+  @Override
+  public List<Pair<PsiMethod, PsiSubstitutor>> findMethodsAndTheirSubstitutorsByName(@NonNls String name, boolean checkBases) {
+    return PsiClassImplUtil.findMethodsAndTheirSubstitutorsByName(this, name, checkBases);
+  }
+
+  @NotNull
+  @Override
+  public List<Pair<PsiMethod, PsiSubstitutor>> getAllMethodsAndTheirSubstitutors() {
+    return PsiClassImplUtil.getAllWithSubstitutorsByMap(this, PsiClassImplUtil.MemberType.METHOD);
+  }
+
+  @Nullable
+  @Override
+  public PsiClass findInnerClassByName(@NonNls String name, boolean checkBases) {
+    // TODO
+    return null;
+  }
+
+  @Nullable
+  @Override
+  public PsiElement getLBrace() {
+    return null;
+  }
+
+  @Nullable
+  @Override
+  public PsiElement getRBrace() {
+    return null;
+  }
+
+  @Nullable
+  @Override
+  public PsiIdentifier getNameIdentifier() {
+    return null;
+  }
+
+  @Override
+  public boolean isInheritor(@NotNull PsiClass baseClass, boolean checkDeep) {
+    return InheritanceImplUtil.isInheritor(this, baseClass, checkDeep);
+  }
+
+  @Override
+  public boolean isInheritorDeep(PsiClass baseClass, @Nullable PsiClass classToByPass) {
+    return InheritanceImplUtil.isInheritorDeep(this, baseClass, classToByPass);
+  }
+
+  @NotNull
+  @Override
+  public Collection<HierarchicalMethodSignature> getVisibleSignatures() {
+    return PsiSuperMethodImplUtil.getVisibleSignatures(this);
+  }
+
+  @Override
+  public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
+    throw new IncorrectOperationException("Cannot rename light class");
+  }
+
+  @Nullable
+  @Override
+  public PsiDocComment getDocComment() {
+    return null;
+  }
+
+  @Override
+  public boolean isDeprecated() {
+    return false;
+  }
+
+  @Override
+  public boolean hasTypeParameters() {
+    return PsiImplUtil.hasTypeParameters(this);
+  }
+
+  @NotNull
+  @Override
+  public PsiTypeParameter[] getTypeParameters() {
+    return PsiImplUtil.getTypeParameters(this);
+  }
+
+  @NotNull
+  @Override
+  public abstract PsiModifierList getModifierList();
+
+  @Override
+  public boolean hasModifierProperty(@PsiModifier.ModifierConstant @NonNls @NotNull String name) {
+    return getModifierList().hasModifierProperty(name);
+  }
+
+  @Override
+  public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
+    return PsiClassImplUtil.processDeclarationsInClass(
+      this, processor, state, null, lastParent, place, PsiUtil.getLanguageLevel(place), false
+    );
+  }
+}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBuilder.java b/java/java-psi-impl/src/com/intellij/psi/impl/light/LightPsiClassBuilder.java
new file mode 100644 (file)
index 0000000..06939dd
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2000-2015 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.psi.impl.light;
+
+import com.intellij.psi.*;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+
+public class LightPsiClassBuilder extends LightPsiClassBase implements OriginInfoAwareElement {
+
+  private final LightModifierList myModifierList = new LightModifierList(getManager());
+  private final LightReferenceListBuilder myImplementsList = new LightReferenceListBuilder(getManager(), PsiReferenceList.Role.EXTENDS_LIST);
+  private final LightReferenceListBuilder myExtendsList = new LightReferenceListBuilder(getManager(), PsiReferenceList.Role.EXTENDS_LIST);
+  private final LightTypeParameterListBuilder myTypeParametersList = new LightTypeParameterListBuilder(getManager(), getLanguage());
+  private final Collection<PsiMethod> myMethods = ContainerUtil.newArrayList();
+  private PsiElement myScope;
+  private PsiClass myContainingClass;
+  private String myOriginInfo;
+
+  public LightPsiClassBuilder(@NotNull PsiElement context, @NotNull String name) {
+    super(context, name);
+  }
+
+  @Nullable
+  @Override
+  public String getOriginInfo() {
+    return myOriginInfo;
+  }
+
+  @NotNull
+  @Override
+  public LightModifierList getModifierList() {
+    return myModifierList;
+  }
+
+  @NotNull
+  @Override
+  public LightReferenceListBuilder getExtendsList() {
+    return myExtendsList;
+  }
+
+  @NotNull
+  @Override
+  public LightReferenceListBuilder getImplementsList() {
+    return myImplementsList;
+  }
+
+  @NotNull
+  @Override
+  public PsiField[] getFields() {
+    // TODO
+    return PsiField.EMPTY_ARRAY;
+  }
+
+  @NotNull
+  @Override
+  public PsiMethod[] getMethods() {
+    return myMethods.toArray(new PsiMethod[myMethods.size()]);
+  }
+
+  @NotNull
+  @Override
+  public PsiClass[] getInnerClasses() {
+    // TODO
+    return PsiClass.EMPTY_ARRAY;
+  }
+
+  @NotNull
+  @Override
+  public PsiClassInitializer[] getInitializers() {
+    return PsiClassInitializer.EMPTY_ARRAY;
+  }
+
+  @Override
+  public PsiElement getScope() {
+    return myScope;
+  }
+
+  @Nullable
+  @Override
+  public PsiClass getContainingClass() {
+    return myContainingClass;
+  }
+
+  @NotNull
+  @Override
+  public LightTypeParameterListBuilder getTypeParameterList() {
+    return myTypeParametersList;
+  }
+
+  public LightPsiClassBuilder setOriginInfo(String originInfo) {
+    myOriginInfo = originInfo;
+    return this;
+  }
+
+  public LightPsiClassBuilder setScope(PsiElement scope) {
+    myScope = scope;
+    return this;
+  }
+
+  public LightPsiClassBuilder setContainingClass(PsiClass containingClass) {
+    myContainingClass = containingClass;
+    return this;
+  }
+
+  public LightPsiClassBuilder addMethod(PsiMethod method) {
+    if (method instanceof LightMethodBuilder) {
+      ((LightMethodBuilder)method).setContainingClass(this);
+    }
+    myMethods.add(method);
+    return this;
+  }
+}