Filter creating stub elements
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ import java.io.IOException;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
public static final int STUB_VERSION = 10;
|
||||
public static final int STUB_VERSION = 12;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
+21
@@ -20,8 +20,10 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
/**
|
||||
@@ -39,4 +41,23 @@ public abstract class JetStubElementType<StubT extends StubElement, PsiT extends
|
||||
public String getExternalId() {
|
||||
return "jet." + toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateStub(ASTNode node) {
|
||||
PsiElement psi = node.getPsi();
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(psi, JetFunctionLiteral.class) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JetBlockExpression blockExpression = PsiTreeUtil.getParentOfType(psi, JetBlockExpression.class);
|
||||
@SuppressWarnings("unchecked") JetDeclarationWithBody stubStopElement =
|
||||
PsiTreeUtil.getParentOfType(blockExpression, JetFunction.class, JetPropertyAccessor.class);
|
||||
|
||||
if (stubStopElement != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.shouldCreateStub(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,13 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
" VALUE_PARAMETER:PsiJetParameterStubImpl[val name=other typeText=String defaultValue=\"hello\"]\n");
|
||||
}
|
||||
|
||||
public void testNotStoreInFunction() {
|
||||
doBuildTest("fun some() { val test = 12;\n fun fake() {}\n class FakeClass\n }",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" FUN:PsiJetFunctionStubImpl[top name=some]\n" +
|
||||
" VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
private void doBuildTest(@NonNls final String source, @NonNls @NotNull final String tree) {
|
||||
final JetFile file = (JetFile) createLightFile(JetFileType.INSTANCE, source);
|
||||
final FileASTNode fileNode = file.getNode();
|
||||
|
||||
Reference in New Issue
Block a user