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