use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GrIntroduceFieldHandlerBase method findPossibleScopes.
@NotNull
@Override
protected PsiClass[] findPossibleScopes(GrExpression expression, GrVariable variable, StringPartInfo partInfo, Editor editor) {
PsiElement place = getCurrentPlace(expression, variable, partInfo);
PsiClass aClass = PsiUtil.getContextClass(place);
if (aClass instanceof GroovyScriptClass) {
return new PsiClass[] { aClass };
} else {
List<PsiClass> result = ContainerUtil.newArrayList(aClass);
while (aClass != null) {
aClass = PsiTreeUtil.getParentOfType(aClass, PsiClass.class);
ContainerUtil.addIfNotNull(result, aClass);
}
return result.toArray(new PsiClass[result.size()]);
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class DataBindingWizardAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final Project project;
final VirtualFile formFile;
GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext());
if (editor == null) {
return;
}
project = editor.getProject();
formFile = editor.getFile();
try {
final WizardData wizardData = new WizardData(project, formFile);
final Module module = ModuleUtilCore.findModuleForFile(formFile, wizardData.myProject);
LOG.assertTrue(module != null);
final LwRootContainer[] rootContainer = new LwRootContainer[1];
Generator.exposeForm(wizardData.myProject, formFile, rootContainer);
final String classToBind = rootContainer[0].getClassToBind();
if (classToBind == null) {
Messages.showInfoMessage(project, UIDesignerBundle.message("info.form.not.bound"), UIDesignerBundle.message("title.data.binding.wizard"));
return;
}
final PsiClass boundClass = FormEditingUtil.findClassToBind(module, classToBind);
if (boundClass == null) {
Messages.showErrorDialog(project, UIDesignerBundle.message("error.bound.to.not.found.class", classToBind), UIDesignerBundle.message("title.data.binding.wizard"));
return;
}
Generator.prepareWizardData(wizardData, boundClass);
if (!hasBinding(rootContainer[0])) {
Messages.showInfoMessage(project, UIDesignerBundle.message("info.no.bound.components"), UIDesignerBundle.message("title.data.binding.wizard"));
return;
}
if (!wizardData.myBindToNewBean) {
final String[] variants = new String[] { UIDesignerBundle.message("action.alter.data.binding"), UIDesignerBundle.message("action.bind.to.another.bean"), CommonBundle.getCancelButtonText() };
final int result = Messages.showYesNoCancelDialog(project, UIDesignerBundle.message("info.data.binding.regenerate", wizardData.myBeanClass.getQualifiedName()), UIDesignerBundle.message("title.data.binding"), variants[0], variants[1], variants[2], Messages.getQuestionIcon());
if (result == Messages.YES) {
// do nothing here
} else if (result == Messages.NO) {
wizardData.myBindToNewBean = true;
} else {
return;
}
}
final DataBindingWizard wizard = new DataBindingWizard(project, wizardData);
wizard.show();
} catch (Generator.MyException exc) {
Messages.showErrorDialog(project, exc.getMessage(), CommonBundle.getErrorTitle());
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class FormRelatedFilesProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
if (psiClass != null) {
while (psiClass != null) {
List<PsiFile> forms = FormClassIndex.findFormsBoundToClass(psiClass.getProject(), psiClass);
if (!forms.isEmpty()) {
return GotoRelatedItem.createItems(forms, "UI Forms");
}
psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
}
} else {
PsiFile file = context.getContainingFile();
if (file != null && file.getFileType() == GuiFormFileType.INSTANCE) {
try {
String className = Utils.getBoundClassName(file.getText());
if (className != null) {
Project project = file.getProject();
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
if (aClass != null) {
return Collections.singletonList(new GotoRelatedItem(aClass, "Java"));
}
}
} catch (Exception ignore) {
}
}
}
return Collections.emptyList();
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GroovyStubNotificationProvider method decorateStubFile.
private static EditorNotificationPanel decorateStubFile(final VirtualFile file, final Project project) {
final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText("This stub is generated for Groovy class to make Groovy-Java cross-compilation possible");
panel.createActionLabel("Go to the Groovy class", () -> DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
final PsiClass original = findClassByStub(project, file);
if (original != null) {
original.navigate(true);
}
}));
panel.createActionLabel("Exclude from stub generation", () -> DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
final PsiClass psiClass = findClassByStub(project, file);
if (psiClass != null) {
ExcludeFromStubGenerationAction.doExcludeFromStubGeneration(psiClass.getContainingFile());
}
}));
return panel;
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class SpringLoadedPositionManager method getOuterClassName.
@Nullable
private static String getOuterClassName(final SourcePosition position) {
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
PsiElement element = findElementAt(position);
if (element == null)
return null;
PsiElement sourceImage = PsiTreeUtil.getParentOfType(element, GrClosableBlock.class, GrTypeDefinition.class, PsiClassImpl.class);
if (sourceImage instanceof PsiClass) {
return getClassNameForJvm((PsiClass) sourceImage);
}
return null;
} finally {
accessToken.finish();
}
}
Aggregations