Skip to content

Commit

Permalink
fix concurrent exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Mar 26, 2024
1 parent c02fbda commit 1753923
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
*/
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;
import org.eclipse.xtext.resource.IEObjectDescription;
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.
Expand Down Expand Up @@ -72,18 +73,18 @@ public IScope wrap(IScope scope) {
}

@Override
public Set<QualifiedName> getImportedNames() {
return Collections.unmodifiableSet(nonNullImportedNames);
synchronized public TreeSet<QualifiedName> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,18 +146,15 @@ public Iterable<QualifiedName> getImportedNames() {
// also all names are collected that cannot be resolved

EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl);
ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource());
Iterable<QualifiedName> 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<QualifiedName> importedNames;
if (superImportedNames != null) {
importedNames = Sets.newTreeSet(superImportedNames);
} else {
if (adapter == null) {
importedNames = Sets.<QualifiedName> newTreeSet();
} else {
importedNames = adapter.getImportedNames();
}
// import our own module name to get a proper change notification
Resource resource = getResource();
Expand Down

0 comments on commit 1753923

Please sign in to comment.