Search in sources :

Example 46 with PsiClass

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()]);
    }
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with PsiClass

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClass(com.intellij.psi.PsiClass) WizardData(com.intellij.uiDesigner.wizard.WizardData) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) Project(com.intellij.openapi.project.Project) DataBindingWizard(com.intellij.uiDesigner.wizard.DataBindingWizard) Module(com.intellij.openapi.module.Module) Generator(com.intellij.uiDesigner.wizard.Generator)

Example 48 with PsiClass

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();
}
Also used : Project(com.intellij.openapi.project.Project) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with PsiClass

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;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiClass(com.intellij.psi.PsiClass)

Example 50 with PsiClass

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();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiClass (com.intellij.psi.PsiClass)598 PsiElement (com.intellij.psi.PsiElement)113 PsiMethod (com.intellij.psi.PsiMethod)97 Nullable (org.jetbrains.annotations.Nullable)75 NotNull (org.jetbrains.annotations.NotNull)60 Project (com.intellij.openapi.project.Project)59 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)57 Module (com.intellij.openapi.module.Module)55 PsiFile (com.intellij.psi.PsiFile)49 VirtualFile (com.intellij.openapi.vfs.VirtualFile)47 ArrayList (java.util.ArrayList)37 PsiField (com.intellij.psi.PsiField)36 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)25 Location (com.intellij.execution.Location)20 File (java.io.File)16 HashSet (java.util.HashSet)16 PsiClassType (com.intellij.psi.PsiClassType)15 PsiPackage (com.intellij.psi.PsiPackage)15 List (java.util.List)15 PsiType (com.intellij.psi.PsiType)13