Search in sources :

Example 11 with PsiElement

use of com.intellij.psi.PsiElement in project qi4j-sdk by Qi4j.

the class CreateConcernOfInPackageAction method isAvailable.

@Override
protected final boolean isAvailable(DataContext dataContext) {
    boolean isAvailable = super.isAvailable(dataContext);
    if (!isAvailable) {
        return false;
    }
    PsiElement psiElement = PSI_ELEMENT.getData(dataContext);
    if (psiElement == null) {
        return false;
    }
    GlobalSearchScope searchScope = determineSearchScope(psiElement);
    if (searchScope == null) {
        return false;
    }
    Project project = PROJECT.getData(dataContext);
    PsiClass psiClass = getConcernOfClass(project, searchScope);
    return psiClass != null;
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement)

Example 12 with PsiElement

use of com.intellij.psi.PsiElement in project android-parcelable-intellij-plugin by mcharmas.

the class ParcelableAction method getPsiClassFromContext.

private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (psiFile == null || editor == null) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);
    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
Also used : PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 13 with PsiElement

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

the class GoExpectedTypesTest method doTopLevelTest.

private void doTopLevelTest(@NotNull String text, @NotNull String expectedTypeText) {
    myFixture.configureByText("a.go", "package a;" + text);
    PsiElement elementAt = findElementAtCaretOrInSelection();
    GoExpression typeOwner = PsiTreeUtil.getNonStrictParentOfType(elementAt, GoExpression.class);
    assertNotNull("Cannot find type owner. Context element: " + elementAt.getText(), typeOwner);
    assertEquals(expectedTypeText, StringUtil.join(GoTypeUtil.getExpectedTypes(typeOwner), PsiElement::getText, "; "));
}
Also used : GoExpression(com.goide.psi.GoExpression) PsiElement(com.intellij.psi.PsiElement)

Example 14 with PsiElement

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

the class GoUnderlyingTypeTest method doTest.

private void doTest(@NotNull String text, String expected) {
    myFixture.configureByText("a.go", "package a\n" + text);
    PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    GoType type = PsiTreeUtil.getParentOfType(element, GoType.class);
    assertNotNull(type);
    assertEquals(expected, type.getUnderlyingType().getText());
}
Also used : PsiElement(com.intellij.psi.PsiElement) GoType(com.goide.psi.GoType)

Example 15 with PsiElement

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

the class GoRunConfigurationTestCase method doTestProducedConfigurations.

protected void doTestProducedConfigurations(@Nullable PsiElement context) {
    assertNotNull(context);
    ConfigurationContext configurationContext = new ConfigurationContext(context);
    List<ConfigurationFromContext> configurationAndSettings = configurationContext.getConfigurationsFromContext();
    Element configurationsElement = new Element("configurations");
    if (configurationAndSettings != null) {
        for (ConfigurationFromContext setting : configurationAndSettings) {
            try {
                RunConfiguration configuration = setting.getConfiguration();
                Element configurationElement = new Element("configurations");
                configurationElement.setAttribute("name", configuration.getName());
                configurationElement.setAttribute("class", configuration.getClass().getSimpleName());
                configuration.writeExternal(configurationElement);
                configurationsElement.addContent(configurationElement);
            } catch (WriteExternalException e) {
                throw new RuntimeException(e);
            }
        }
    }
    assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".xml", JDOMUtil.writeElement(configurationsElement));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

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