Java Code Examples for org.eclipse.xtext.xbase.lib.Functions.Function0#apply()

The following examples show how to use org.eclipse.xtext.xbase.lib.Functions.Function0#apply() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpSessionWrapper.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T> T get(Object key, Function0<? extends T> factory) {
	synchronized (session) {
		T sessionValue = get(key);
		if (sessionValue != null) {
			return sessionValue;
		} else {
			T factoryValue = factory.apply();
			put(key, factoryValue);
			return factoryValue;
		}
	}
}
 
Example 2
Source File: HashMapSession.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends Object> T get(Object key, Function0<? extends T> factory) {
	synchronized (this.map) {
		T sessionValue = this.<T>get(key);
		if (sessionValue != null) {
			return sessionValue;
		} else {
			T factoryValue = factory.apply();
			put(key, factoryValue);
			return factoryValue;
		}
	}
}
 
Example 3
Source File: HashMapSession.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends Object> T get(Object key, Function0<? extends T> factory) {
	synchronized (this.map) {
		T sessionValue = this.<T>get(key);
		if (sessionValue != null) {
			return sessionValue;
		} else {
			T factoryValue = factory.apply();
			put(key, factoryValue);
			return factoryValue;
		}
	}
}
 
Example 4
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Compute the simple name for the called feature.
 *
 * @param featureCall the feature call.
 * @param logicalContainerProvider the provider of logicial container.
 * @param featureNameProvider the provider of feature name.
 * @param nullKeyword the null-equivalent keyword.
 * @param thisKeyword the this-equivalent keyword.
 * @param superKeyword the super-equivalent keyword.
 * @param referenceNameLambda replies the reference name or {@code null} if none.
 * @return the simple name.
 */
public static String getCallSimpleName(XAbstractFeatureCall featureCall,
		ILogicalContainerProvider logicalContainerProvider,
		IdentifiableSimpleNameProvider featureNameProvider,
		Function0<? extends String> nullKeyword,
		Function0<? extends String> thisKeyword,
		Function0<? extends String> superKeyword,
		Function1<? super JvmIdentifiableElement, ? extends String> referenceNameLambda) {
	String name = null;
	final JvmIdentifiableElement calledFeature = featureCall.getFeature();
	if (calledFeature instanceof JvmConstructor) {
		final JvmDeclaredType constructorContainer = ((JvmConstructor) calledFeature).getDeclaringType();
		final JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(featureCall);
		final JvmDeclaredType contextType = ((JvmMember) logicalContainer).getDeclaringType();
		if (contextType == constructorContainer) {
			name = thisKeyword.apply();
		} else {
			name = superKeyword.apply();
		}
	} else if (calledFeature != null) {
		final String referenceName = referenceNameLambda.apply(calledFeature);
		if (referenceName != null) {
			name = referenceName;
		} else if (calledFeature instanceof JvmOperation) {
			name = featureNameProvider.getSimpleName(calledFeature);
		} else {
			name = featureCall.getConcreteSyntaxFeatureName();
		}
	}
	if (name == null) {
		return nullKeyword.apply();
	}
	return name;
}
 
Example 5
Source File: ISession.java    From xtext-web with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public <T extends Object> T get(Object key, Function0<? extends T> factory) {
  return factory.apply();
}