Filter enum synthetic methods for stub based classes

Fixed #KT-36095
This commit is contained in:
Igor Yakovlev
2020-03-26 23:36:31 +03:00
parent 172a45a637
commit 43468c6d55
3 changed files with 45 additions and 25 deletions
@@ -1,34 +1,23 @@
/*
* Copyright 2010-2016 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.
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.asJava.builder;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.psi.*;
import com.intellij.psi.impl.compiled.ClsClassImpl;
import com.intellij.psi.impl.compiled.ClsEnumConstantImpl;
import com.intellij.psi.impl.compiled.ClsFieldImpl;
import com.intellij.psi.impl.compiled.ClsRepositoryPsiElement;
import com.intellij.psi.impl.java.stubs.*;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static org.jetbrains.kotlin.asJava.SyntheticElementUtilsKt.isSyntheticValuesOrValueOfMethod;
public class ClsWrapperStubPsiFactory extends StubPsiFactory {
public static final Key<LightElementOrigin> ORIGIN = Key.create("ORIGIN");
public static final ClsWrapperStubPsiFactory INSTANCE = new ClsWrapperStubPsiFactory();
@@ -54,6 +43,30 @@ public class ClsWrapperStubPsiFactory extends StubPsiFactory {
public PsiClass getSourceMirrorClass() {
return null;
}
@NotNull
@Override
public PsiMethod[] getMethods() {
PsiMethod[] baseMethods = super.getMethods();
if (!isEnum()) return baseMethods;
int filteredArraySize = 0;
for (PsiMethod method : baseMethods) {
if (!isSyntheticValuesOrValueOfMethod(method)) filteredArraySize++;
}
if (filteredArraySize == baseMethods.length) return baseMethods;
PsiMethod[] filteredMethods = new PsiMethod[filteredArraySize];
int index = 0;
for (PsiMethod method : baseMethods) {
if (!isSyntheticValuesOrValueOfMethod(method)) {
filteredMethods[index] = method;
index++;
}
}
return filteredMethods;
}
};
}