Skip to content

Commit 93c47f9

Browse files
committed
use computeIfAbsent and Arrays.asList instead of creating a new Array
1 parent db67361 commit 93c47f9

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/scoping/AbstractScopeNameProvider.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ public abstract class AbstractScopeNameProvider implements IScopeNameProvider {
4646
*/
4747
@Override
4848
public Iterable<INameFunction> getNameFunctions(final EClass type) {
49-
Iterable<INameFunction> result = nameFunctionCache.get(type);
50-
if (result == null) {
51-
result = internalGetNameFunctions(type);
49+
return nameFunctionCache.computeIfAbsent(type, eClass -> {
50+
Iterable<INameFunction> result = internalGetNameFunctions(eClass);
5251
if (result == null) {
53-
result = getDefaultNames(type);
52+
result = getDefaultNames(eClass);
5453
}
55-
nameFunctionCache.put(type, result);
56-
}
57-
return result;
54+
return result;
55+
});
5856
}
5957

6058
/**

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/scoping/NameFunctions.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
package com.avaloq.tools.ddk.xtext.scoping;
1212

1313
import java.text.MessageFormat;
14+
import java.util.Arrays;
1415

15-
import org.apache.logging.log4j.Logger;
1616
import org.apache.logging.log4j.LogManager;
17+
import org.apache.logging.log4j.Logger;
1718
import org.eclipse.emf.ecore.EObject;
1819
import org.eclipse.emf.ecore.EStructuralFeature;
1920
import org.eclipse.xtext.naming.QualifiedName;
2021
import org.eclipse.xtext.resource.IEObjectDescription;
2122

2223
import com.avaloq.tools.ddk.xtext.naming.QualifiedNames;
23-
import com.google.common.base.Function;
2424
import com.google.common.collect.Iterables;
2525
import com.google.common.collect.Lists;
2626

@@ -109,12 +109,7 @@ public QualifiedName apply(final EObject from) {
109109
* @return The name functions
110110
*/
111111
public static Iterable<INameFunction> fromFeatures(final EStructuralFeature... nameFeatures) {
112-
return Iterables.transform(Lists.newArrayList(nameFeatures), new Function<EStructuralFeature, INameFunction>() {
113-
@Override
114-
public INameFunction apply(final EStructuralFeature from) {
115-
return fromFeature(from);
116-
}
117-
});
112+
return Iterables.transform(Arrays.asList(nameFeatures), NameFunctions::fromFeature);
118113
}
119114

120115
/**

0 commit comments

Comments
 (0)