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));
}
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));
}
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;
}
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;
});
}
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));
}
}
Aggregations