Search in sources :

Example 6 with PsiClass

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

the class ParcelableAction method update.

@Override
public void update(AnActionEvent e) {
    PsiClass psiClass = getPsiClassFromContext(e);
    e.getPresentation().setEnabled(psiClass != null && !psiClass.isEnum() && !psiClass.isInterface());
}
Also used : PsiClass(com.intellij.psi.PsiClass)

Example 7 with PsiClass

use of com.intellij.psi.PsiClass in project Main by SpartanRefactoring.

the class SpartanizerAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    PsiClass psiClass = getPsiClassFromContext(e);
    if (psiClass == null)
        logger.warn("Spartanization action retrieved null PSI class");
    else {
        logger.info("Spartanization action on\nPSI class '" + psiClass.getQualifiedName() + "'");
        Spartanizer.spartanizeFileOnePass(psiClass.getContainingFile());
    }
}
Also used : PsiClass(com.intellij.psi.PsiClass)

Example 8 with PsiClass

use of com.intellij.psi.PsiClass in project Main by SpartanRefactoring.

the class Class method replaceByRange.

@Override
public List<PsiElement> replaceByRange(List<PsiElement> elements, Map<Integer, List<PsiElement>> map, PsiRewrite r) {
    PsiClass psiClass = az.classDeclaration(elements.get(0));
    PsiClass innerAsClass = az.classDeclaration(inner);
    innerAsClass.setName(psiClass.getName());
    List<Encapsulator> methods = Arrays.stream(innerAsClass.getMethods()).map(m -> Pruning.prune(Encapsulator.buildTreeFromPsi(m), null)).collect(Collectors.toList());
    List<Encapsulator> fields = Arrays.stream(innerAsClass.getFields()).map(f -> Pruning.prune(Encapsulator.buildTreeFromPsi(f), null)).collect(Collectors.toList());
    List<Encapsulator> innerClasses = Arrays.stream(innerAsClass.getInnerClasses()).map(m -> Pruning.prune(Encapsulator.buildTreeFromPsi(m), null)).collect(Collectors.toList());
    List<Encapsulator> prunedChildren = new LinkedList<>();
    prunedChildren.addAll(methods);
    prunedChildren.addAll(fields);
    prunedChildren.addAll(innerClasses);
    prunedChildren.forEach(c -> c.accept(n -> {
        if (!n.isGeneric())
            return;
        GenericEncapsulator ge = az.generic(n);
        ge.replaceByRange(map.get(ge.getId()), map, r);
    }));
    return Utils.wrapWithList(inner);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) PsiMethod(com.intellij.psi.PsiMethod) Pruning(il.org.spartan.Leonidas.plugin.leonidas.Pruning) Collectors(java.util.stream.Collectors) Leonidas.auxilary_layer(il.org.spartan.Leonidas.auxilary_layer) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) Matcher(il.org.spartan.Leonidas.plugin.leonidas.Matcher) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) PsiField(com.intellij.psi.PsiField) MatchingResult(il.org.spartan.Leonidas.plugin.leonidas.MatchingResult) LinkedList(java.util.LinkedList) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList)

Example 9 with PsiClass

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

the class GroovyEditorTextProvider method getEditorText.

@Override
public TextWithImports getEditorText(PsiElement elementAtCaret) {
    String result = "";
    PsiElement element = findExpressionInner(elementAtCaret, true);
    if (element != null) {
        if (element instanceof GrReferenceExpression) {
            final GrReferenceExpression reference = (GrReferenceExpression) element;
            if (reference.getQualifier() == null) {
                final PsiElement resolved = reference.resolve();
                if (resolved instanceof PsiEnumConstant) {
                    final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
                    final PsiClass enumClass = enumConstant.getContainingClass();
                    if (enumClass != null) {
                        result = enumClass.getName() + "." + enumConstant.getName();
                    }
                }
            }
        }
        if (result.isEmpty()) {
            result = element.getText();
        }
    }
    return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, result);
}
Also used : PsiEnumConstant(com.intellij.psi.PsiEnumConstant) PsiClass(com.intellij.psi.PsiClass) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 10 with PsiClass

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

the class GroovyScriptClassSearcher method findClass.

@Nullable
@Override
public PsiClass findClass(@NotNull PsiElement place) {
    if (place.getLanguage() == GroovyLanguage.INSTANCE) {
        PsiClass containingClass = PsiTreeUtil.getParentOfType(place, PsiClass.class, false);
        while (containingClass instanceof PsiTypeParameter) {
            containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
        }
        if (containingClass != null)
            return containingClass;
        PsiFile file = place.getContainingFile();
        if (file instanceof GroovyFile && ((GroovyFile) file).isScript()) {
            return ((GroovyFile) file).getScriptClass();
        }
    }
    return null;
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiClass (com.intellij.psi.PsiClass)594 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