[groovy] store hasBlock flag for method in stubs

This commit is contained in:
Daniil Ovchinnikov
2017-08-14 16:54:16 +03:00
parent b4bd7ca65d
commit 7b2cdc1976
6 changed files with 37 additions and 8 deletions
@@ -49,6 +49,8 @@ public interface GrMethod extends GrMembersDeclaration, GrNamedElement, PsiMetho
@Nullable
GrOpenBlock getBlock();
default boolean hasBlock() { return getBlock() != null; }
void setBlock(GrCodeBlock newBlock);
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -116,6 +116,12 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase<GrMethodStub> i
return findChildByClass(GrOpenBlock.class);
}
@Override
public boolean hasBlock() {
GrMethodStub stub = getStub();
return stub != null ? stub.hasBlock() : GrMethod.super.hasBlock();
}
@Override
public void setBlock(GrCodeBlock newBlock) {
ASTNode newNode = newBlock.getNode().copyElement();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -29,7 +29,8 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrMethodElementType;
* @author ilyas
*/
public class GrMethodStub extends StubBase<GrMethod> implements NamedStub<GrMethod> {
public static final byte IS_DEPRECATED_BY_DOC_TAG = 0x01;
public static final byte IS_DEPRECATED_BY_DOC_TAG = 0b1;
public static final byte HAS_BLOCK = 0b10;
private final StringRef myName;
private final String[] myAnnotations;
@@ -75,11 +76,19 @@ public class GrMethodStub extends StubBase<GrMethod> implements NamedStub<GrMeth
return (myFlags & IS_DEPRECATED_BY_DOC_TAG) != 0;
}
public boolean hasBlock() {
return (myFlags & HAS_BLOCK) != 0;
}
public static byte buildFlags(GrMethod method) {
byte f = 0;
if (PsiImplUtil.isDeprecatedByDocTag(method)) {
f|= IS_DEPRECATED_BY_DOC_TAG;
f |= IS_DEPRECATED_BY_DOC_TAG;
}
if (method.hasBlock()) {
f |= HAS_BLOCK;
}
return f;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -40,7 +40,7 @@ import java.io.IOException;
* @author ilyas
*/
public class GrStubFileElementType extends IStubFileElementType<GrFileStub> {
public static final int STUB_VERSION = 35;
public static final int STUB_VERSION = 36;
public GrStubFileElementType(Language language) {
super(language);
@@ -155,7 +155,7 @@ public class ConvertMethodToClosureIntention extends Intention {
}
return !method.isConstructor() &&
isJavaIdentifier(method.getName()) &&
method.getBlock() != null &&
method.hasBlock() &&
method.getParent() instanceof GrTypeDefinitionBody;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 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.
@@ -20,6 +20,7 @@ import com.intellij.psi.impl.source.PsiFileImpl
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.util.InheritanceUtil
import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl
import groovy.transform.CompileStatic
import org.jetbrains.plugins.groovy.LightGroovyTestCase
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition
@@ -283,4 +284,15 @@ class A {
assert psiFile.stub
assert !psiFile.contentsLoaded
}
void 'test do not load contents in highlighting'() {
def file = fixture.tempDirFixture.createFile('classes.groovy', '''\
class C {
static void staticVoidMethod() {}
}
''')
((JavaCodeInsightTestFixtureImpl)fixture).virtualFileFilter = { it == file }
fixture.configureByText '_.groovy', 'C.staticVoidMethod()'
fixture.checkHighlighting()
}
}