Cleanup (optimization)

This commit is contained in:
Roman Shevchenko
2014-05-27 12:04:17 +04:00
parent 298bf22f80
commit 08c14cb030
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,18 +39,16 @@ import java.util.List;
@SuppressWarnings({"HardCodedStringLiteral"})
public class SignatureParsing {
private SignatureParsing() {
}
private SignatureParsing() { }
public static PsiTypeParameterListStub parseTypeParametersDeclaration(CharacterIterator signatureIterator, StubElement parentStub)
throws ClsFormatException {
public static PsiTypeParameterListStub parseTypeParametersDeclaration(CharacterIterator iterator, StubElement parentStub) throws ClsFormatException {
PsiTypeParameterListStub list = new PsiTypeParameterListStubImpl(parentStub);
if (signatureIterator.current() == '<') {
signatureIterator.next();
while (signatureIterator.current() != '>') {
parseTypeParameter(signatureIterator, list);
if (iterator.current() == '<') {
iterator.next();
while (iterator.current() != '>') {
parseTypeParameter(iterator, list);
}
signatureIterator.next();
iterator.next();
}
return list;
@@ -69,18 +67,22 @@ public class SignatureParsing {
//todo parse annotations on type param
PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString()));
List<String> bounds = ContainerUtil.newSmartList();
// 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) {
bounds.add(bound);
if (bound == null) continue;
if (bounds == null) {
if (CommonClassNames.JAVA_LANG_OBJECT.equals(bound)) {
jlo = true;
continue;
}
}
}
int size = bounds.size();
if (size > 0 && CommonClassNames.JAVA_LANG_OBJECT.equals(bounds.get(size - 1))) {
bounds.remove(size - 1);
bounds = ContainerUtil.newSmartList();
if (jlo) bounds.add(CommonClassNames.JAVA_LANG_OBJECT);
bounds.add(bound);
}
StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds));