@NotNull @Override public PsiTypeParameter createTypeParameter(String name, PsiClassType[] superTypes) { @NonNls StringBuilder builder = new StringBuilder(); builder.append("public <").append(name); 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.delete(builder.length() - 1, builder.length()); } builder.append("> void foo(){}"); try { return createMethodFromText(builder.toString(), null).getTypeParameters()[0]; } catch (RuntimeException e) { throw new IncorrectOperationException("type parameter text: " + builder.toString()); } }
@Override public void endElement(String uri, String localName, String qName) throws SAXException { if ("item".equals(qName)) { externalName = null; } else if ("annotation".equals(qName)) { if (externalName != null && annotationFQN != null) { String argumentsString = arguments.length() == 0 ? "" : intern(arguments.toString()); for (AnnotationData existingData : data.get(externalName)) { if (existingData.annotationClassFqName.equals(annotationFQN)) { duplicateError(file, externalName, "Duplicate annotation '" + annotationFQN + "' "); } } AnnotationData annData = internAnnotationData(new AnnotationData(annotationFQN, argumentsString)); data.add(externalName, annData); annotationFQN = null; arguments = null; } } }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if ("item".equals(qName)) { externalName = attributes.getValue("name"); } else if ("annotation".equals(qName)) { annotationFQN = attributes.getValue("name"); arguments = new StringBuilder(); } else if ("val".equals(qName)) { if (arguments.length() != 0) { arguments.append(","); } String name = attributes.getValue("name"); if (name != null) { arguments.append(name); arguments.append("="); } arguments.append(attributes.getValue("val")); } }