diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/naming/N4JSImportedNamesAdapter.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/naming/N4JSImportedNamesAdapter.java index e9c128984c..d0bbcafa0a 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/naming/N4JSImportedNamesAdapter.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/naming/N4JSImportedNamesAdapter.java @@ -10,10 +10,10 @@ */ package org.eclipse.n4js.naming; -import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.TreeSet; import org.eclipse.xtext.linking.impl.ImportedNamesAdapter; import org.eclipse.xtext.naming.QualifiedName; @@ -21,6 +21,7 @@ import org.eclipse.xtext.scoping.IScope; import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; /** * Adapts default implementation to not normalize qualified names to be all lower case. @@ -72,18 +73,18 @@ public IScope wrap(IScope scope) { } @Override - public Set getImportedNames() { - return Collections.unmodifiableSet(nonNullImportedNames); + synchronized public TreeSet getImportedNames() { + return Sets.newTreeSet(nonNullImportedNames); } /** Adds given element to set of imported names. */ - public void addImportedName(QualifiedName name) { + synchronized public void addImportedName(QualifiedName name) { Preconditions.checkNotNull(name); nonNullImportedNames.add(name); } @Override - public void clear() { + synchronized public void clear() { nonNullImportedNames.clear(); } } diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/resource/N4JSResourceDescription.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/resource/N4JSResourceDescription.java index c2aabae30b..fc2a1102cd 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/resource/N4JSResourceDescription.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/resource/N4JSResourceDescription.java @@ -22,6 +22,7 @@ import org.apache.log4j.Logger; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.n4js.naming.N4JSImportedNamesAdapter; import org.eclipse.n4js.ts.typeRefs.TypeRef; import org.eclipse.n4js.ts.types.ContainerType; import org.eclipse.n4js.ts.types.TEnum; @@ -145,18 +146,15 @@ public Iterable getImportedNames() { // also all names are collected that cannot be resolved EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl); - ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource()); - Iterable superImportedNames = Collections.emptySet(); - if (adapter != null) { - superImportedNames = adapter.getImportedNames(); - } + N4JSImportedNamesAdapter adapter = (N4JSImportedNamesAdapter) ImportedNamesAdapter + .find(getResource()); // use sorted set to ensure order of items final SortedSet importedNames; - if (superImportedNames != null) { - importedNames = Sets.newTreeSet(superImportedNames); - } else { + if (adapter == null) { importedNames = Sets. newTreeSet(); + } else { + importedNames = adapter.getImportedNames(); } // import our own module name to get a proper change notification Resource resource = getResource();