private boolean isPsiMethodCamelLanguage(PsiMethod method) { PsiType type = method.getReturnType(); if (type != null && type instanceof PsiClassReferenceType) { PsiClassReferenceType clazz = (PsiClassReferenceType) type; PsiClass resolved = clazz.resolve(); if (resolved != null) { boolean language = getCamelIdeaUtils().isCamelExpressionOrLanguage(resolved); // try parent using some weird/nasty stub stuff which is how complex IDEA AST // is when its parsing the Camel route builder if (!language) { PsiElement elem = resolved.getParent(); if (elem instanceof PsiTypeParameterList) { elem = elem.getParent(); } if (elem instanceof PsiClass) { language = getCamelIdeaUtils().isCamelExpressionOrLanguage((PsiClass) elem); } } return language; } } return false; }
public LombokLightClassBuilder withParameterTypes(@Nullable PsiTypeParameterList parameterList) { if (parameterList != null) { for (PsiTypeParameter typeParameter : parameterList.getTypeParameters()) { getTypeParameterList().addParameter(typeParameter); } } return this; }
@Nullable public static PsiTypeParameterList createTypeParameterList(@NotNull PsiTypeParameterList psiTypeParameterList) { PsiTypeParameter[] psiTypeParameters = psiTypeParameterList.getTypeParameters(); if (psiTypeParameters.length > 0) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiTypeParameterList.getProject()); final StringBuilder builder = new StringBuilder("public <"); for (PsiTypeParameter psiTypeParameter : psiTypeParameters) { builder.append(psiTypeParameter.getName()); PsiClassType[] superTypes = psiTypeParameter.getExtendsListTypes(); if (superTypes.length > 1 || superTypes.length == 1 && !superTypes[0].equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { builder.append(" extends "); for (PsiClassType type : superTypes) { if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { continue; } builder.append(type.getCanonicalText()).append('&'); } builder.deleteCharAt(builder.length() - 1); } builder.append(','); } builder.deleteCharAt(builder.length() - 1); builder.append("> void foo(){}"); PsiMethod methodFromText = elementFactory.createMethodFromText(builder.toString(), null); return methodFromText.getTypeParameterList(); } return null; }
private void rebuildTypeParameter(@NotNull PsiTypeParameterListOwner listOwner, @NotNull PsiTypeParameterListOwner resultOwner) { final PsiTypeParameterList fromMethodTypeParameterList = listOwner.getTypeParameterList(); if (listOwner.hasTypeParameters() && null != fromMethodTypeParameterList) { PsiTypeParameterList typeParameterList = PsiMethodUtil.createTypeParameterList(fromMethodTypeParameterList); if (null != typeParameterList) { final PsiTypeParameterList resultOwnerTypeParameterList = resultOwner.getTypeParameterList(); if (null != resultOwnerTypeParameterList) { resultOwnerTypeParameterList.replace(typeParameterList); } } } }
private static Collection<TextRange> selectWithTypeParameters(@NotNull PsiClass psiClass) { final PsiIdentifier identifier = psiClass.getNameIdentifier(); final PsiTypeParameterList list = psiClass.getTypeParameterList(); if (identifier != null && list != null) { return Collections.singletonList(new TextRange(identifier.getTextRange().getStartOffset(), list.getTextRange().getEndOffset())); } return Collections.emptyList(); }
@Override public void visitTypeParameterList(PsiTypeParameterList list) { mVisitor.report("PsiTypeParameterList", list.getText(), list); super.visitElement(list); }
@Override public PsiTypeParameterList createPsi(@NotNull final PsiTypeParameterListStub stub) { return getPsiFactory(stub).createTypeParameterList(stub); }
@Override public PsiTypeParameterList createPsi(@NotNull final ASTNode node) { return new PsiTypeParameterListImpl(node); }
@Override @Nullable PsiTypeParameterList getTypeParameterList();
@Nullable PsiTypeParameterList getTypeParameterList();