@Override public int getIndex() { final PsiTypeParameterStub stub = getStub(); if (stub != null) { final PsiTypeParameterListStub parentStub = (PsiTypeParameterListStub)stub.getParentStub(); return parentStub.getChildrenStubs().indexOf(stub); } int ret = 0; PsiElement element = getPrevSibling(); while (element != null) { if (element instanceof PsiTypeParameter) { ret++; } element = element.getPrevSibling(); } return ret; }
private static PsiTypeParameterStub parseTypeParameter(CharacterIterator iterator, PsiTypeParameterListStub parent) throws ClsFormatException { StringBuilder name = new StringBuilder(); while (iterator.current() != ':' && iterator.current() != CharacterIterator.DONE) { name.append(iterator.current()); iterator.next(); } if (iterator.current() == CharacterIterator.DONE) { throw new ClsFormatException(); } //todo parse annotations on type param PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString())); // postpone list allocation till a second bound is seen; ignore sole Object bound List<String> bounds = null; boolean jlo = false; while (iterator.current() == ':') { iterator.next(); String bound = parseTopLevelClassRefSignature(iterator); if (bound == null) continue; if (bounds == null) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(bound)) { jlo = true; continue; } bounds = ContainerUtil.newSmartList(); if (jlo) { bounds.add(CommonClassNames.JAVA_LANG_OBJECT); } } bounds.add(bound); } StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds)); return parameterStub; }
@Override public String getName() { final PsiTypeParameterStub stub = getStub(); if (stub != null) { return stub.getName(); } return getNameIdentifier().getText(); }
private static PsiTypeParameterStub parseTypeParameter(CharacterIterator signatureIterator, PsiTypeParameterListStub parent) throws ClsFormatException { StringBuilder name = new StringBuilder(); while (signatureIterator.current() != ':' && signatureIterator.current() != CharacterIterator.DONE) { name.append(signatureIterator.current()); signatureIterator.next(); } if (signatureIterator.current() == CharacterIterator.DONE) { throw new ClsFormatException(); } //todo parse annotations on type param PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString())); ArrayList<String> bounds = null; while (signatureIterator.current() == ':') { signatureIterator.next(); String bound = parseTopLevelClassRefSignature(signatureIterator); if (bound != null && !bound.equals(CommonClassNames.JAVA_LANG_OBJECT)) { if (bounds == null) bounds = new ArrayList<String>(); bounds.add(bound); } } StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds)); return parameterStub; }
public ClsTypeParameterImpl(@NotNull PsiTypeParameterStub stub) { super(stub); myLightEmptyImplementsList = new LightEmptyImplementsList(getManager()); }
@Override public int getIndex() { final PsiTypeParameterStub stub = getStub(); return stub.getParentStub().getChildrenStubs().indexOf(stub); }
public PsiTypeParameterImpl(final PsiTypeParameterStub stub) { super(stub, JavaStubElementTypes.TYPE_PARAMETER); }
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { myInternalName = name; String parentName = myParent instanceof PsiClassStub ? ((PsiClassStub) myParent).getQualifiedName() : myParent instanceof PsiJavaFileStub ? ((PsiJavaFileStub) myParent).getPackageName() : null; String fqn = getFqn(name, myShortName, parentName); String shortName = myShortName != null && name.endsWith(myShortName) ? myShortName : PsiNameHelper.getShortClassName(fqn); int flags = myAccess | access; boolean isDeprecated = isSet(flags, Opcodes.ACC_DEPRECATED); boolean isInterface = isSet(flags, Opcodes.ACC_INTERFACE); boolean isEnum = isSet(flags, Opcodes.ACC_ENUM); boolean isAnnotationType = isSet(flags, Opcodes.ACC_ANNOTATION); byte stubFlags = PsiClassStubImpl.packFlags(isDeprecated, isInterface, isEnum, false, false, isAnnotationType, false, false); myResult = new PsiClassStubImpl(JavaStubElementTypes.CLASS, myParent, fqn, shortName, null, stubFlags); myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags)); ClassInfo info = null; if(signature != null) { try { info = parseClassSignature(signature); } catch(ClsFormatException e) { if(LOG.isDebugEnabled()) { LOG.debug("source=" + mySource + " signature=" + signature, e); } } } if(info == null) { info = parseClassDescription(superName, interfaces); } PsiTypeParameterListStub typeParameterList = new PsiTypeParameterListStubImpl(myResult); for(Pair<String, String[]> parameter : info.typeParameters) { PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(typeParameterList, StringRef.fromString(parameter.first)); newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, parameter.second); } if(myResult.isInterface()) { if(info.interfaceNames != null && myResult.isAnnotationType()) { info.interfaceNames.remove(CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION); } newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, ArrayUtil.toStringArray(info.interfaceNames)); newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.EMPTY_STRING_ARRAY); } else { if(info.superName == null || "java/lang/Object".equals(superName) || myResult.isEnum() && "java/lang/Enum".equals(superName)) { newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, ArrayUtil.EMPTY_STRING_ARRAY); } else { newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, new String[]{info.superName}); } newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.toStringArray(info.interfaceNames)); } }