Search in sources :

Example 1 with GoFileStub

use of com.goide.stubs.GoFileStub in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFile method getBuildFlags.

@Nullable
public String getBuildFlags() {
    GoFileStub stub = getStub();
    if (stub != null) {
        return stub.getBuildFlags();
    }
    // https://code.google.com/p/go/source/browse/src/pkg/go/build/build.go?r=2449e85a115014c3d9251f86d499e5808141e6bc#790
    Collection<String> buildFlags = ContainerUtil.newArrayList();
    int buildFlagLength = GoConstants.BUILD_FLAG.length();
    for (PsiComment comment : getCommentsToConsider(this)) {
        String commentText = StringUtil.trimStart(comment.getText(), "//").trim();
        if (commentText.startsWith(GoConstants.BUILD_FLAG) && commentText.length() > buildFlagLength && StringUtil.isWhiteSpace(commentText.charAt(buildFlagLength))) {
            ContainerUtil.addIfNotNull(buildFlags, StringUtil.nullize(commentText.substring(buildFlagLength).trim(), true));
        }
    }
    return !buildFlags.isEmpty() ? StringUtil.join(buildFlags, "|") : null;
}
Also used : GoFileStub(com.goide.stubs.GoFileStub) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GoFileStub

use of com.goide.stubs.GoFileStub in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFile method getPackageName.

@Nullable
public String getPackageName() {
    return CachedValuesManager.getCachedValue(this, () -> {
        GoFileStub stub = getStub();
        if (stub != null) {
            return CachedValueProvider.Result.create(stub.getPackageName(), this);
        }
        GoPackageClause packageClause = getPackage();
        return CachedValueProvider.Result.create(packageClause != null ? packageClause.getName() : null, this);
    });
}
Also used : GoFileStub(com.goide.stubs.GoFileStub) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GoFileStub

use of com.goide.stubs.GoFileStub in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoMethodDeclarationStubElementType method indexStub.

@Override
public void indexStub(@NotNull GoMethodDeclarationStub stub, @NotNull IndexSink sink) {
    super.indexStub(stub, sink);
    String typeName = stub.getTypeName();
    if (!StringUtil.isEmpty(typeName)) {
        StubElement parent = stub.getParentStub();
        if (parent instanceof GoFileStub) {
            String packageName = ((GoFileStub) parent).getPackageName();
            if (!StringUtil.isEmpty(typeName)) {
                sink.occurrence(GoMethodIndex.KEY, packageName + "." + typeName);
            }
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) GoFileStub(com.goide.stubs.GoFileStub)

Example 4 with GoFileStub

use of com.goide.stubs.GoFileStub in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoNamedStubElementType method indexStub.

@Override
public void indexStub(@NotNull S stub, @NotNull IndexSink sink) {
    String name = stub.getName();
    if (shouldIndex() && StringUtil.isNotEmpty(name)) {
        String packageName = null;
        StubElement parent = stub.getParentStub();
        while (parent != null) {
            if (parent instanceof GoFileStub) {
                packageName = ((GoFileStub) parent).getPackageName();
                break;
            }
            parent = parent.getParentStub();
        }
        String indexingName = StringUtil.isNotEmpty(packageName) ? packageName + "." + name : name;
        if (stub.isPublic()) {
            sink.occurrence(GoAllPublicNamesIndex.ALL_PUBLIC_NAMES, indexingName);
        } else {
            sink.occurrence(GoAllPrivateNamesIndex.ALL_PRIVATE_NAMES, indexingName);
        }
        for (StubIndexKey<String, ? extends GoNamedElement> key : getExtraIndexKeys()) {
            sink.occurrence(key, name);
        }
    }
}
Also used : StubElement(com.intellij.psi.stubs.StubElement) GoFileStub(com.goide.stubs.GoFileStub)

Example 5 with GoFileStub

use of com.goide.stubs.GoFileStub in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoFile method getFunctions.

@NotNull
public List<GoFunctionDeclaration> getFunctions() {
    return CachedValuesManager.getCachedValue(this, () -> {
        GoFileStub stub = getStub();
        List<GoFunctionDeclaration> functions = stub != null ? getChildrenByType(stub, GoTypes.FUNCTION_DECLARATION, GoFunctionDeclarationStubElementType.ARRAY_FACTORY) : GoPsiImplUtil.goTraverser().children(this).filter(GoFunctionDeclaration.class).toList();
        return CachedValueProvider.Result.create(functions, this);
    });
}
Also used : GoFileStub(com.goide.stubs.GoFileStub) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoFileStub (com.goide.stubs.GoFileStub)5 StubElement (com.intellij.psi.stubs.StubElement)2 Nullable (org.jetbrains.annotations.Nullable)2 NotNull (org.jetbrains.annotations.NotNull)1