Search in sources :

Example 6 with PsiTypeParameter

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

the class PsiUtilTest method testTypeParameterIterator3.

public void testTypeParameterIterator3() throws Exception {
    final PsiClass classA = createClass("class A<T> { class B<X, Y> {}}");
    final Iterator<PsiTypeParameter> iterator = PsiUtil.typeParametersIterator(classA.getInnerClasses()[0]);
    compareIterator(new String[] { "Y", "X", "T" }, iterator);
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass)

Example 7 with PsiTypeParameter

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

the class PsiUtilTest method testTypeParameterIterator2.

public void testTypeParameterIterator2() throws Exception {
    final PsiClass classA = createClass("class A<T> { static class B<X> {}}");
    final Iterator<PsiTypeParameter> iterator = PsiUtil.typeParametersIterator(classA.getInnerClasses()[0]);
    compareIterator(new String[] { "X" }, iterator);
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass)

Example 8 with PsiTypeParameter

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

the class InheritanceUtil method existsMutualSubclass.

public static boolean existsMutualSubclass(PsiClass class1, final PsiClass class2, final boolean avoidExpensiveProcessing) {
    if (class1 instanceof PsiTypeParameter) {
        final PsiClass[] superClasses = class1.getSupers();
        for (PsiClass superClass : superClasses) {
            if (!existsMutualSubclass(superClass, class2, avoidExpensiveProcessing)) {
                return false;
            }
        }
        return true;
    }
    if (class2 instanceof PsiTypeParameter) {
        return existsMutualSubclass(class2, class1, avoidExpensiveProcessing);
    }
    final String className = class1.getQualifiedName();
    if (CommonClassNames.JAVA_LANG_OBJECT.equals(className)) {
        return true;
    }
    final String class2Name = class2.getQualifiedName();
    if (CommonClassNames.JAVA_LANG_OBJECT.equals(class2Name)) {
        return true;
    }
    if (class1.isInheritor(class2, true) || class2.isInheritor(class1, true)) {
        return true;
    }
    final SearchScope scope = GlobalSearchScope.allScope(class1.getProject());
    final Query<PsiClass> search = ClassInheritorsSearch.search(class1, scope, true);
    final boolean[] result = new boolean[1];
    search.forEach(new Processor<PsiClass>() {

        AtomicInteger count = new AtomicInteger(0);

        @Override
        public boolean process(PsiClass inheritor) {
            if (inheritor.equals(class2) || inheritor.isInheritor(class2, true) || avoidExpensiveProcessing && count.incrementAndGet() > 20) {
                result[0] = true;
                return false;
            }
            return true;
        }
    });
    return result[0];
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PsiClass(com.intellij.psi.PsiClass) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 9 with PsiTypeParameter

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

the class PsiUtilTest method testTypeParameterIterator.

public void testTypeParameterIterator() throws Exception {
    PsiClass classA = createClass("class A<T> {}");
    final Iterator<PsiTypeParameter> iterator = PsiUtil.typeParametersIterator(classA);
    compareIterator(new String[] { "T" }, iterator);
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass)

Example 10 with PsiTypeParameter

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

the class GroovyTypeParameterInfoHandler method findElementForParameterInfo.

@Nullable
@Override
public GrTypeArgumentList findElementForParameterInfo(@NotNull CreateParameterInfoContext context) {
    final GrTypeArgumentList parameterList = ParameterInfoUtils.findParentOfType(context.getFile(), context.getOffset(), GrTypeArgumentList.class);
    if (parameterList != null) {
        if (!(parameterList.getParent() instanceof GrCodeReferenceElement))
            return null;
        final GrCodeReferenceElement ref = ((GrCodeReferenceElement) parameterList.getParent());
        final PsiElement resolved = ref.resolve();
        if (!(resolved instanceof PsiTypeParameterListOwner))
            return null;
        final PsiTypeParameter[] typeParams = ((PsiTypeParameterListOwner) resolved).getTypeParameters();
        if (typeParams.length == 0)
            return null;
        context.setItemsToShow(typeParams);
        return parameterList;
    }
    return null;
}
Also used : PsiTypeParameterListOwner(com.intellij.psi.PsiTypeParameterListOwner) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiTypeParameter(com.intellij.psi.PsiTypeParameter) GrTypeArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiTypeParameter (com.intellij.psi.PsiTypeParameter)11 PsiClass (com.intellij.psi.PsiClass)7 Nullable (org.jetbrains.annotations.Nullable)2 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiTypeParameterListOwner (com.intellij.psi.PsiTypeParameterListOwner)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1 GrTypeArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList)1