Search in sources :

Example 96 with PsiFile

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);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) ASTNode(com.intellij.lang.ASTNode) PsiFile(com.intellij.psi.PsiFile) StubElement(com.intellij.psi.stubs.StubElement) StubBuilder(com.intellij.psi.StubBuilder)

Example 97 with PsiFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with PsiFile

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");
                }
            }
        }
    }
}
Also used : GrCommandArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiFile(com.intellij.psi.PsiFile) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 99 with PsiFile

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) DomFileElement(com.intellij.util.xml.DomFileElement) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with PsiFile

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));
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

PsiFile (com.intellij.psi.PsiFile)1776 VirtualFile (com.intellij.openapi.vfs.VirtualFile)490 PsiElement (com.intellij.psi.PsiElement)466 Nullable (org.jetbrains.annotations.Nullable)267 Project (com.intellij.openapi.project.Project)266 NotNull (org.jetbrains.annotations.NotNull)248 Document (com.intellij.openapi.editor.Document)181 Editor (com.intellij.openapi.editor.Editor)166 XmlFile (com.intellij.psi.xml.XmlFile)126 PsiDirectory (com.intellij.psi.PsiDirectory)114 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)109 Module (com.intellij.openapi.module.Module)106 TextRange (com.intellij.openapi.util.TextRange)88 ArrayList (java.util.ArrayList)81 XmlTag (com.intellij.psi.xml.XmlTag)68 File (java.io.File)58 PsiManager (com.intellij.psi.PsiManager)56 PsiClass (com.intellij.psi.PsiClass)50 List (java.util.List)46 Language (com.intellij.lang.Language)45