Search in sources :

Example 16 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationProducerTest method testSameRunApplicationConfigurationOnPackage.

public void testSameRunApplicationConfigurationOnPackage() {
    PsiFile file = myFixture.configureByText("a.go", "package main; <caret>\nfunc main() {}");
    PsiElement at = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(at);
    ConfigurationContext configurationContext = new ConfigurationContext(at);
    GoApplicationRunConfigurationProducer producer = new GoApplicationRunConfigurationProducer();
    GoApplicationConfiguration runConfiguration = createRunAppFileConfiguration(file.getVirtualFile().getPath());
    assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createRunAppFileConfiguration(file.getVirtualFile().getPath() + "_vl");
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) GoApplicationRunConfigurationProducer(com.goide.runconfig.application.GoApplicationRunConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) GoApplicationConfiguration(com.goide.runconfig.application.GoApplicationConfiguration) PsiElement(com.intellij.psi.PsiElement)

Example 17 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationProducerTest method testSameRunApplicationConfigurationOnFile.

public void testSameRunApplicationConfigurationOnFile() {
    PsiFile file = myFixture.configureByText("a.go", "package main; <caret>\nfunc main() {}");
    PsiElement at = file.findElementAt(myFixture.getCaretOffset());
    assertNotNull(at);
    ConfigurationContext configurationContext = new ConfigurationContext(at);
    GoRunFileConfigurationProducer producer = new GoRunFileConfigurationProducer();
    GoRunFileConfiguration runConfiguration = createFileConfiguration(file.getVirtualFile().getPath());
    assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createFileConfiguration(file.getVirtualFile().getPath() + "_vl");
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) GoRunFileConfigurationProducer(com.goide.runconfig.file.GoRunFileConfigurationProducer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) GoRunFileConfiguration(com.goide.runconfig.file.GoRunFileConfiguration)

Example 18 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStructLiteralCompletion method allowedVariants.

@NotNull
static Variants allowedVariants(@Nullable GoReferenceExpression structFieldReference) {
    GoValue value = parent(structFieldReference, GoValue.class);
    GoElement element = parent(value, GoElement.class);
    if (element != null && element.getKey() != null) {
        return Variants.NONE;
    }
    GoType type = GoPsiImplUtil.getLiteralType(element, true);
    if (!(type instanceof GoStructType)) {
        return Variants.NONE;
    }
    boolean hasValueInitializers = false;
    boolean hasFieldValueInitializers = false;
    GoLiteralValue literalValue = parent(element, GoLiteralValue.class);
    List<GoElement> fieldInitializers = literalValue != null ? literalValue.getElementList() : Collections.emptyList();
    for (GoElement initializer : fieldInitializers) {
        if (initializer == element) {
            continue;
        }
        PsiElement colon = initializer.getColon();
        hasFieldValueInitializers |= colon != null;
        hasValueInitializers |= colon == null;
    }
    return hasFieldValueInitializers && !hasValueInitializers ? Variants.FIELD_NAME_ONLY : !hasFieldValueInitializers && hasValueInitializers ? Variants.VALUE_ONLY : Variants.BOTH;
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoStructLiteralCompletion method alreadyAssignedFields.

@NotNull
static Set<String> alreadyAssignedFields(@Nullable GoLiteralValue literal) {
    if (literal == null) {
        return Collections.emptySet();
    }
    return ContainerUtil.map2SetNotNull(literal.getElementList(), element -> {
        GoKey key = element.getKey();
        GoFieldName fieldName = key != null ? key.getFieldName() : null;
        PsiElement identifier = fieldName != null ? fieldName.getIdentifier() : null;
        return identifier != null ? identifier.getText() : null;
    });
}
Also used : PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with PsiElement

use of com.intellij.psi.PsiElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoExcludePathLookupActionProvider method fillActions.

@Override
public void fillActions(LookupElement element, Lookup lookup, Consumer<LookupElementAction> consumer) {
    PsiElement psiElement = element.getPsiElement();
    PsiFile file = psiElement != null && psiElement.isValid() ? psiElement.getContainingFile() : null;
    String importPath = file instanceof GoFile ? ((GoFile) file).getImportPath(false) : null;
    if (importPath != null) {
        Project project = psiElement.getProject();
        for (String path : getPaths(importPath)) {
            consumer.consume(new ExcludePathAction(project, path));
        }
        consumer.consume(new EditExcludedAction(project));
    }
}
Also used : GoFile(com.goide.psi.GoFile) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3163 Nullable (org.jetbrains.annotations.Nullable)493 PsiFile (com.intellij.psi.PsiFile)471 NotNull (org.jetbrains.annotations.NotNull)442 TextRange (com.intellij.openapi.util.TextRange)237 PsiReference (com.intellij.psi.PsiReference)226 Project (com.intellij.openapi.project.Project)222 VirtualFile (com.intellij.openapi.vfs.VirtualFile)206 ArrayList (java.util.ArrayList)192 ASTNode (com.intellij.lang.ASTNode)142 XmlTag (com.intellij.psi.xml.XmlTag)134 PsiClass (com.intellij.psi.PsiClass)115 Editor (com.intellij.openapi.editor.Editor)111 Document (com.intellij.openapi.editor.Document)109 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)85 PsiDirectory (com.intellij.psi.PsiDirectory)80 IElementType (com.intellij.psi.tree.IElementType)78 Module (com.intellij.openapi.module.Module)73 PsiMethod (com.intellij.psi.PsiMethod)73 UsageInfo (com.intellij.usageView.UsageInfo)70