Search in sources :

Example 1 with PsiTypeParameter

use of com.intellij.psi.PsiTypeParameter 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)

Example 2 with PsiTypeParameter

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

the class ReturnValueBeanBuilder method buildBeanClass.

public String buildBeanClass() throws IOException {
    final StringBuilder out = new StringBuilder(1024);
    if (myPackageName.length() > 0) {
        out.append("package ").append(myPackageName).append(";\n\n");
    }
    out.append("public ");
    if (myStatic)
        out.append("static ");
    out.append("class ").append(myClassName);
    if (!myTypeParams.isEmpty()) {
        out.append('<');
        boolean first = true;
        for (PsiTypeParameter typeParam : myTypeParams) {
            if (!first) {
                out.append(',');
            }
            final String parameterText = typeParam.getText();
            out.append(parameterText);
            first = false;
        }
        out.append('>');
    }
    out.append(" {\n");
    outputField(out);
    out.append("\n\n");
    outputConstructor(out);
    out.append("\n\n");
    outputGetter(out);
    out.append("\n}\n");
    return out.toString();
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter)

Example 3 with PsiTypeParameter

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

the class MissingClassBodyFixer method apply.

@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
    if (!(psiElement instanceof PsiClass) || psiElement instanceof PsiTypeParameter)
        return;
    PsiClass psiClass = (PsiClass) psiElement;
    if (psiClass.getLBrace() == null) {
        int offset = psiClass.getTextRange().getEndOffset();
        editor.getDocument().insertString(offset, "{\n}");
        editor.getCaretModel().moveToOffset(offset);
    }
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) PsiClass(com.intellij.psi.PsiClass)

Example 4 with PsiTypeParameter

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

the class PsiUtilTest method testTypeParameterIterator1.

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

Example 5 with PsiTypeParameter

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

the class PsiUtilTest method compareIterator.

private static void compareIterator(String[] expected, Iterator<PsiTypeParameter> it) {
    final ArrayList<String> actual = new ArrayList<>();
    while (it.hasNext()) {
        PsiTypeParameter typeParameter = it.next();
        actual.add(typeParameter.getName());
    }
    assertEquals(Arrays.asList(expected).toString(), actual.toString());
}
Also used : PsiTypeParameter(com.intellij.psi.PsiTypeParameter) ArrayList(java.util.ArrayList)

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