Search in sources :

Example 91 with PsiClass

use of com.intellij.psi.PsiClass in project GsonFormat by zzz40500.

the class DataWriter method run.

@Override
protected void run() {
    if (targetClass == null) {
        return;
    }
    generateClassList.clear();
    new ClassProcessor(factory, cls).generate(targetClass, new IProcessor() {

        @Override
        public void onStarProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
            generateClassList.add(cls.getQualifiedName());
        }

        @Override
        public void onEndProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
        }

        @Override
        public void onStartGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass) {
        }

        @Override
        public void onEndGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass, PsiClass generateClass) {
            generateClassList.add(generateClass.getQualifiedName());
        }
    });
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) ClassProcessor(org.gsonformat.intellij.process.ClassProcessor) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass) IProcessor(org.gsonformat.intellij.process.IProcessor)

Example 92 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class GutterIconTooltipHelper method composeText.

public static String composeText(@NotNull Iterable<? extends PsiElement> elements, @NotNull String start, @NotNull String pattern, @NotNull String postfix) {
    @NonNls StringBuilder result = new StringBuilder();
    result.append("<html><body>");
    result.append(start);
    Set<String> names = new LinkedHashSet<>();
    for (PsiElement element : elements) {
        String descr = "";
        if (element instanceof PsiClass) {
            String className = ClassPresentationUtil.getNameForClass((PsiClass) element, true);
            descr = MessageFormat.format(pattern, className);
        } else if (element instanceof PsiMethod) {
            String methodName = ((PsiMethod) element).getName();
            PsiClass aClass = ((PsiMethod) element).getContainingClass();
            String className = aClass == null ? "" : ClassPresentationUtil.getNameForClass(aClass, true);
            descr = MessageFormat.format(pattern, methodName, className);
        } else if (element instanceof PsiFile) {
            descr = MessageFormat.format(pattern, ((PsiFile) element).getName());
        }
        names.add(descr);
    }
    @NonNls String sep = "";
    for (String name : names) {
        result.append(sep);
        sep = "<br>";
        result.append(name);
    }
    result.append(postfix);
    result.append("</body></html>");
    return result.toString();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NonNls(org.jetbrains.annotations.NonNls) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 93 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class FQNameCellRenderer method getListCellRendererComponent.

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    clear();
    if (value instanceof PsiClass) {
        PsiClass aClass = (PsiClass) value;
        setIcon(aClass.getIcon(0));
        if (aClass.getQualifiedName() != null) {
            SimpleTextAttributes attributes;
            if (aClass.isDeprecated()) {
                attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_STRIKEOUT, null);
            } else {
                attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
            }
            append(aClass.getQualifiedName(), attributes);
        }
    } else {
        LOG.assertTrue(value instanceof String);
        String qName = (String) value;
        append(qName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
        setIcon(AllIcons.Nodes.Static);
    }
    setFont(FONT);
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiClass(com.intellij.psi.PsiClass)

Example 94 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class SuperMethodWarningUtil method checkSuperMethod.

public static void checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString, @NotNull final PsiElementProcessor<PsiMethod> processor, @NotNull Editor editor) {
    PsiClass aClass = method.getContainingClass();
    if (aClass == null) {
        processor.execute(method);
        return;
    }
    PsiMethod superMethod = method.findDeepestSuperMethod();
    if (superMethod == null) {
        processor.execute(method);
        return;
    }
    final PsiClass containingClass = superMethod.getContainingClass();
    if (containingClass == null) {
        processor.execute(method);
        return;
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        processor.execute(superMethod);
        return;
    }
    final PsiMethod[] methods = { superMethod, method };
    final String renameBase = actionString + " base method";
    final String renameCurrent = actionString + " only current method";
    final JBList list = new JBList(renameBase, renameCurrent);
    JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(method.getName() + (containingClass.isInterface() && !aClass.isInterface() ? " implements" : " overrides") + " method of " + SymbolPresentationUtil.getSymbolPresentableText(containingClass)).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
        final Object value = list.getSelectedValue();
        if (value instanceof String) {
            processor.execute(methods[value.equals(renameBase) ? 0 : 1]);
        }
    }).createPopup().showInBestPositionFor(editor);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) JBList(com.intellij.ui.components.JBList)

Example 95 with PsiClass

use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.

the class SuperMethodWarningUtil method checkSuperMethods.

@NotNull
public static PsiMethod[] checkSuperMethods(@NotNull PsiMethod method, @NotNull String actionString, @NotNull Collection<PsiElement> ignore) {
    PsiClass aClass = method.getContainingClass();
    if (aClass == null)
        return new PsiMethod[] { method };
    final Collection<PsiMethod> superMethods = getSuperMethods(method, aClass, ignore);
    if (superMethods.isEmpty())
        return new PsiMethod[] { method };
    Set<String> superClasses = new HashSet<>();
    boolean superAbstract = false;
    boolean parentInterface = false;
    for (final PsiMethod superMethod : superMethods) {
        final PsiClass containingClass = superMethod.getContainingClass();
        superClasses.add(containingClass.getQualifiedName());
        final boolean isInterface = containingClass.isInterface();
        superAbstract |= isInterface || superMethod.hasModifierProperty(PsiModifier.ABSTRACT);
        parentInterface |= isInterface;
    }
    SuperMethodWarningDialog dialog = new SuperMethodWarningDialog(method.getProject(), DescriptiveNameUtil.getDescriptiveName(method), actionString, superAbstract, parentInterface, aClass.isInterface(), ArrayUtil.toStringArray(superClasses));
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        return superMethods.toArray(new PsiMethod[superMethods.size()]);
    }
    if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) {
        return new PsiMethod[] { method };
    }
    return PsiMethod.EMPTY_ARRAY;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

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