use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class StubsTest method doTest.
public void doTest() throws Exception {
final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
String fileText = data.get(0);
PsiFile psiFile = TestUtils.createPseudoPhysicalGroovyFile(getProject(), fileText);
ASTNode node = psiFile.getNode();
Assert.assertNotNull(node);
IElementType type = node.getElementType();
Assert.assertTrue(type instanceof IStubFileElementType);
IStubFileElementType stubFileType = (IStubFileElementType) type;
StubBuilder builder = stubFileType.getBuilder();
StubElement element = builder.buildStubTree(psiFile);
StringBuffer buffer = new StringBuffer();
getStubsTreeImpl(element, buffer, "");
String stubTree = buffer.toString().trim();
assertEquals(data.get(1), stubTree);
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class GroovyScriptRunConfiguration method getPathByElement.
@SuppressWarnings("Duplicates")
@Nullable
private static String getPathByElement(@NotNull PsiElement element) {
PsiFile file = element.getContainingFile();
if (file == null)
return null;
VirtualFile vfile = file.getVirtualFile();
if (vfile == null)
return null;
return vfile.getPath();
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class GroovyShellCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
if (!(file instanceof GroovyShellCodeFragment))
return;
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (!(parent instanceof GrReferenceExpression && !((GrReferenceExpression) parent).isQualified()))
return;
if (PsiUtil.isExpressionStatement(parent)) {
addAllCommands(result);
} else if (parent.getParent() instanceof GrCommandArgumentList) {
PsiElement ppparent = parent.getParent().getParent();
if (ppparent instanceof GrMethodCall && isFirstArg((GrMethodCall) ppparent, parent)) {
GrExpression invokedExpression = ((GrMethodCall) ppparent).getInvokedExpression();
if (invokedExpression instanceof GrReferenceExpression && !((GrReferenceExpression) invokedExpression).isQualified()) {
String name = ((GrReferenceExpression) invokedExpression).getReferenceName();
if ("help".equals(name)) {
addAllCommands(result);
} else if ("show".equals(name)) {
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("purge".equals(name)) {
add(result, "variables");
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("record".equals(name)) {
add(result, "start");
add(result, "stop");
add(result, "status");
} else if ("history".equals(name)) {
add(result, "show");
add(result, "recall");
add(result, "flush");
add(result, "clear");
}
}
}
}
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class MavenModulePsiReference method getVariants.
@NotNull
public Object[] getVariants() {
List<DomFileElement<MavenDomProjectModel>> files = MavenDomUtil.collectProjectModels(getProject());
List<Object> result = new ArrayList<>();
for (DomFileElement<MavenDomProjectModel> eachDomFile : files) {
VirtualFile eachVFile = eachDomFile.getOriginalFile().getVirtualFile();
if (Comparing.equal(eachVFile, myVirtualFile))
continue;
PsiFile psiFile = eachDomFile.getFile();
String modulePath = calcRelativeModulePath(myVirtualFile, eachVFile);
result.add(LookupElementBuilder.create(psiFile, modulePath).withPresentableText(modulePath));
}
return result.toArray();
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class MavenPropertyCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile psiFile = parameters.getOriginalFile();
Project project = psiFile.getProject();
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
if (!manager.isMavenizedProject())
return;
MavenProject projectFile = MavenDomUtil.findContainingProject(psiFile);
if (projectFile == null)
return;
if (!MavenDomUtil.isMavenFile(psiFile) && !MavenDomUtil.isFilteredResourceFile(psiFile))
return;
String text = psiFile.getText();
int offset = parameters.getOffset();
int braceOffset = findOpenBrace(text, offset);
if (braceOffset == -1)
return;
TextRange range = TextRange.create(braceOffset, offset);
String prefix = range.substring(text);
MavenFilteredPropertyPsiReference ref = new MavenFilteredPropertyPsiReference(projectFile, psiFile, prefix, range);
addVariants(Arrays.asList(ref.getVariants()), result.withPrefixMatcher(prefix));
}
Aggregations