Search in sources :

Example 26 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)

Example 27 with PsiClass

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

the class GroovyTestFramework method findOrCreateSetUpMethod.

@Override
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
    LOG.assertTrue(clazz.getLanguage() == GroovyLanguage.INSTANCE);
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(clazz.getProject());
    final PsiMethod patternMethod = createSetUpPatternMethod(factory);
    final PsiClass baseClass = clazz.getSuperClass();
    if (baseClass != null) {
        final PsiMethod baseMethod = baseClass.findMethodBySignature(patternMethod, false);
        if (baseMethod != null && baseMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
            PsiUtil.setModifierProperty(patternMethod, PsiModifier.PROTECTED, false);
            PsiUtil.setModifierProperty(patternMethod, PsiModifier.PUBLIC, true);
        }
    }
    PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
    if (inClass == null) {
        PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
        if (testMethod != null) {
            return (PsiMethod) clazz.addBefore(patternMethod, testMethod);
        }
        return (PsiMethod) clazz.add(patternMethod);
    } else if (inClass.getBody() == null) {
        return (PsiMethod) inClass.replace(patternMethod);
    }
    return inClass;
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Example 28 with PsiClass

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

the class MavenPluginCustomParameterValueConverter method getConverter.

@Override
public Converter getConverter(@NotNull GenericDomValue domElement) {
    Project project = domElement.getManager().getProject();
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
    PsiClass psiClass = psiFacade.findClass(myType, GlobalSearchScope.allScope(project));
    if (psiClass != null) {
        GenericDomValueConvertersRegistry convertersRegistry = MavenDomConvertersRegistry.getInstance().getConvertersRegistry();
        return convertersRegistry.getConverter(domElement, psiFacade.getElementFactory().createType(psiClass));
    }
    return null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) GenericDomValueConvertersRegistry(com.intellij.util.xml.converters.values.GenericDomValueConvertersRegistry) PsiClass(com.intellij.psi.PsiClass)

Example 29 with PsiClass

use of com.intellij.psi.PsiClass in project kotlin by JetBrains.

the class JavaClassFinderImpl method findClass.

@Nullable
@Override
public JavaClass findClass(@NotNull ClassId classId) {
    PsiClass psiClass = javaFacade.findClass(classId, javaSearchScope);
    if (psiClass == null)
        return null;
    JavaClassImpl javaClass = new JavaClassImpl(psiClass);
    FqName fqName = classId.asSingleFqName();
    if (!fqName.equals(javaClass.getFqName())) {
        throw new IllegalStateException("Requested " + fqName + ", got " + javaClass.getFqName());
    }
    if (psiClass instanceof KtLightClassMarker) {
        throw new IllegalStateException("Kotlin light classes should not be found by JavaPsiFacade, resolving: " + fqName);
    }
    return javaClass;
}
Also used : JavaClassImpl(org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl) KtLightClassMarker(org.jetbrains.kotlin.asJava.KtLightClassMarker) FqName(org.jetbrains.kotlin.name.FqName) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with PsiClass

use of com.intellij.psi.PsiClass in project kotlin by JetBrains.

the class JavaAnnotationImpl method computeClassId.

@Nullable
private static ClassId computeClassId(@NotNull PsiClass psiClass) {
    PsiClass container = psiClass.getContainingClass();
    if (container != null) {
        ClassId parentClassId = computeClassId(container);
        String name = psiClass.getName();
        return parentClassId == null || name == null ? null : parentClassId.createNestedClassId(Name.identifier(name));
    }
    String fqName = psiClass.getQualifiedName();
    return fqName == null ? null : ClassId.topLevel(new FqName(fqName));
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) PsiClass(com.intellij.psi.PsiClass) ClassId(org.jetbrains.kotlin.name.ClassId) 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