private static String parseMethodViaGenericSignature( final String signature, final PsiMethodStubImpl stub, final List<String> args, final List<String> throwables) throws ClsFormatException { StringCharacterIterator iterator = new StringCharacterIterator(signature); SignatureParsing.parseTypeParametersDeclaration(iterator, stub); if (iterator.current() != '(') { throw new ClsFormatException(); } iterator.next(); while (iterator.current() != ')' && iterator.current() != CharacterIterator.DONE) { args.add(SignatureParsing.parseTypeString(iterator)); } if (iterator.current() != ')') { throw new ClsFormatException(); } iterator.next(); String returnType = SignatureParsing.parseTypeString(iterator); while (iterator.current() == '^') { iterator.next(); throwables.add(SignatureParsing.parseTypeString(iterator)); } return returnType; }
@Nullable private static String parseClassSignature( final CharacterIterator signatureIterator, final List<String> convertedInterfaces) throws ClsFormatException { final String convertedSuper = SignatureParsing.parseTopLevelClassRefSignature(signatureIterator); while (signatureIterator.current() != CharacterIterator.DONE) { final String ifs = SignatureParsing.parseTopLevelClassRefSignature(signatureIterator); if (ifs == null) throw new ClsFormatException(); convertedInterfaces.add(ifs); } return convertedSuper; }
@NotNull private static TypeInfo fieldType(String desc, String signature) { if (signature != null) { try { return TypeInfo.fromString( SignatureParsing.parseTypeString(new StringCharacterIterator(signature, 0))); } catch (ClsFormatException e) { return fieldTypeViaDescription(desc); } } else { return fieldTypeViaDescription(desc); } }
@Override public void visit( int version, int access, String name, String signature, String superName, String[] interfaces) { String fqn = getClassName(name); String shortName = myShortName != null ? myShortName : PsiNameHelper.getShortClassName(fqn); int flags = myAccess == 0 ? access : myAccess; boolean isDeprecated = (flags & Opcodes.ACC_DEPRECATED) != 0; boolean isInterface = (flags & Opcodes.ACC_INTERFACE) != 0; boolean isEnum = (flags & Opcodes.ACC_ENUM) != 0; boolean isAnnotationType = (flags & Opcodes.ACC_ANNOTATION) != 0; byte stubFlags = PsiClassStubImpl.packFlags( isDeprecated, isInterface, isEnum, false, false, isAnnotationType, false, false); myResult = new PsiClassStubImpl(JavaStubElementTypes.CLASS, myParent, fqn, shortName, null, stubFlags); LanguageLevel languageLevel = convertFromVersion(version); ((PsiClassStubImpl) myResult).setLanguageLevel(languageLevel); myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags)); CharacterIterator signatureIterator = signature != null ? new StringCharacterIterator(signature) : null; if (signatureIterator != null) { try { SignatureParsing.parseTypeParametersDeclaration(signatureIterator, myResult); } catch (ClsFormatException e) { signatureIterator = null; } } else { new PsiTypeParameterListStubImpl(myResult); } String convertedSuper; List<String> convertedInterfaces = new ArrayList<String>(); if (signatureIterator == null) { convertedSuper = parseClassDescription(superName, interfaces, convertedInterfaces); } else { try { convertedSuper = parseClassSignature(signatureIterator, convertedInterfaces); } catch (ClsFormatException e) { new PsiTypeParameterListStubImpl(myResult); convertedSuper = parseClassDescription(superName, interfaces, convertedInterfaces); } } if (isInterface) { if (isAnnotationType) { convertedInterfaces.remove(JAVA_LANG_ANNOTATION_ANNOTATION); } newReferenceList( JavaStubElementTypes.EXTENDS_LIST, myResult, ArrayUtil.toStringArray(convertedInterfaces)); newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult); } else { if (convertedSuper == null || JAVA_LANG_OBJECT.equals(convertedSuper) || isEnum && (JAVA_LANG_ENUM.equals(convertedSuper) || (JAVA_LANG_ENUM + "<" + fqn + ">").equals(convertedSuper))) { newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult); } else { newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, convertedSuper); } newReferenceList( JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.toStringArray(convertedInterfaces)); } }