Unnecessary TLinkedList replaced to LinkedList and rename FinalListItem to OpenClassInfo.
This commit is contained in:
+16
-17
@@ -20,8 +20,6 @@ import com.google.dart.compiler.backend.js.ast.*;
|
|||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import gnu.trove.THashMap;
|
import gnu.trove.THashMap;
|
||||||
import gnu.trove.TLinkableAdaptor;
|
|
||||||
import gnu.trove.TLinkedList;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -50,9 +48,9 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
private final LabelGenerator localLabelGenerator = new LabelGenerator('c');
|
private final LabelGenerator localLabelGenerator = new LabelGenerator('c');
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final THashMap<ClassDescriptor, FinalListItem> openClassDescriptorToItem = new THashMap<ClassDescriptor, FinalListItem>();
|
private final THashMap<ClassDescriptor, OpenClassInfo> openClassDescriptorToItem = new THashMap<ClassDescriptor, OpenClassInfo>();
|
||||||
|
|
||||||
private final TLinkedList<FinalListItem> openList = new TLinkedList<FinalListItem>();
|
private final LinkedList<OpenClassInfo> openList = new LinkedList<OpenClassInfo>();
|
||||||
private final List<Pair<JetClassOrObject, JsInvocation>> finalList = new ArrayList<Pair<JetClassOrObject, JsInvocation>>();
|
private final List<Pair<JetClassOrObject, JsInvocation>> finalList = new ArrayList<Pair<JetClassOrObject, JsInvocation>>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -77,7 +75,7 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
|
public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
|
||||||
FinalListItem item = openClassDescriptorToItem.get(descriptor);
|
OpenClassInfo item = openClassDescriptorToItem.get(descriptor);
|
||||||
// class declared in library
|
// class declared in library
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -87,12 +85,12 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FinalListItem extends TLinkableAdaptor {
|
private static class OpenClassInfo {
|
||||||
private final JetClass declaration;
|
private final JetClass declaration;
|
||||||
private final JsNameRef label;
|
private final JsNameRef label;
|
||||||
private final JsNameRef qualifiedLabel;
|
private final JsNameRef qualifiedLabel;
|
||||||
|
|
||||||
private FinalListItem(JetClass declaration, JsNameRef label, JsNameRef qualifiedLabel) {
|
private OpenClassInfo(JetClass declaration, JsNameRef label, JsNameRef qualifiedLabel) {
|
||||||
this.declaration = declaration;
|
this.declaration = declaration;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.qualifiedLabel = qualifiedLabel;
|
this.qualifiedLabel = qualifiedLabel;
|
||||||
@@ -124,18 +122,18 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
private void generateOpenClassDeclarations(@NotNull List<JsVar> vars, @NotNull List<JsPropertyInitializer> propertyInitializers) {
|
private void generateOpenClassDeclarations(@NotNull List<JsVar> vars, @NotNull List<JsPropertyInitializer> propertyInitializers) {
|
||||||
// first pass: set up list order
|
// first pass: set up list order
|
||||||
LinkedList<FinalListItem> sortedOpenClasses =
|
LinkedList<OpenClassInfo> sortedOpenClasses =
|
||||||
(LinkedList<FinalListItem>) DFS.topologicalOrder(openList, new DFS.Neighbors<FinalListItem>() {
|
(LinkedList<OpenClassInfo>) DFS.topologicalOrder(openList, new DFS.Neighbors<OpenClassInfo>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FinalListItem> getNeighbors(FinalListItem current) {
|
public Iterable<OpenClassInfo> getNeighbors(OpenClassInfo current) {
|
||||||
LinkedList<FinalListItem> parents = new LinkedList<FinalListItem>();
|
LinkedList<OpenClassInfo> parents = new LinkedList<OpenClassInfo>();
|
||||||
ClassDescriptor classDescriptor = getClassDescriptor(context().bindingContext(), current.declaration);
|
ClassDescriptor classDescriptor = getClassDescriptor(context().bindingContext(), current.declaration);
|
||||||
Collection<JetType> superTypes = classDescriptor.getTypeConstructor().getSupertypes();
|
Collection<JetType> superTypes = classDescriptor.getTypeConstructor().getSupertypes();
|
||||||
|
|
||||||
for (JetType type : superTypes) {
|
for (JetType type : superTypes) {
|
||||||
ClassDescriptor descriptor = getClassDescriptorForType(type);
|
ClassDescriptor descriptor = getClassDescriptorForType(type);
|
||||||
FinalListItem item = openClassDescriptorToItem.get(descriptor);
|
OpenClassInfo item = openClassDescriptorToItem.get(descriptor);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -150,9 +148,9 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
assert sortedOpenClasses.size() == openList.size();
|
assert sortedOpenClasses.size() == openList.size();
|
||||||
|
|
||||||
// second pass: generate
|
// second pass: generate
|
||||||
Iterator<FinalListItem> it = sortedOpenClasses.descendingIterator();
|
Iterator<OpenClassInfo> it = sortedOpenClasses.descendingIterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
FinalListItem item = it.next();
|
OpenClassInfo item = it.next();
|
||||||
JsExpression translatedDeclaration = translateClassDeclaration(item.declaration, classDescriptorToLabel, context());
|
JsExpression translatedDeclaration = translateClassDeclaration(item.declaration, classDescriptorToLabel, context());
|
||||||
generate(item, propertyInitializers, translatedDeclaration, vars);
|
generate(item, propertyInitializers, translatedDeclaration, vars);
|
||||||
}
|
}
|
||||||
@@ -162,7 +160,7 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
ClassAliasingMap aliasingMap = new ClassAliasingMap() {
|
ClassAliasingMap aliasingMap = new ClassAliasingMap() {
|
||||||
@Override
|
@Override
|
||||||
public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
|
public JsNameRef get(ClassDescriptor descriptor, ClassDescriptor referencedDescriptor) {
|
||||||
FinalListItem item = openClassDescriptorToItem.get(descriptor);
|
OpenClassInfo item = openClassDescriptorToItem.get(descriptor);
|
||||||
return item == null ? null : item.qualifiedLabel;
|
return item == null ? null : item.qualifiedLabel;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -172,7 +170,7 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generate(@NotNull FinalListItem item,
|
private static void generate(@NotNull OpenClassInfo item,
|
||||||
@NotNull List<JsPropertyInitializer> propertyInitializers,
|
@NotNull List<JsPropertyInitializer> propertyInitializers,
|
||||||
@NotNull JsExpression definition,
|
@NotNull JsExpression definition,
|
||||||
@NotNull List<JsVar> vars) {
|
@NotNull List<JsVar> vars) {
|
||||||
@@ -201,7 +199,8 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
|||||||
else {
|
else {
|
||||||
String label = localLabelGenerator.generate();
|
String label = localLabelGenerator.generate();
|
||||||
JsNameRef labelRef = dummyFunction.getScope().declareName(label).makeRef();
|
JsNameRef labelRef = dummyFunction.getScope().declareName(label).makeRef();
|
||||||
FinalListItem item = new FinalListItem((JetClass) declaration, labelRef, new JsNameRef(labelRef.getIdent(), declarationsObjectRef));
|
OpenClassInfo
|
||||||
|
item = new OpenClassInfo((JetClass) declaration, labelRef, new JsNameRef(labelRef.getIdent(), declarationsObjectRef));
|
||||||
openList.add(item);
|
openList.add(item);
|
||||||
openClassDescriptorToItem.put(descriptor, item);
|
openClassDescriptorToItem.put(descriptor, item);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user