org.eclipse.xtext.util.PolymorphicDispatcher Java Examples

The following examples show how to use org.eclipse.xtext.util.PolymorphicDispatcher. 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: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Construct the generator.
 */
public AbstractExtraLanguageGenerator() {
	this.beforeDispatcher = new PolymorphicDispatcher<Void>(
			"_before", 2, 2, //$NON-NLS-1$
			Collections.singletonList(this)) {
		@Override
		protected Void handleNoSuchMethod(Object... params) {
			return null;
		}
	};
	this.generateDispatcher = new PolymorphicDispatcher<>(
			"_generate", 2, 2, //$NON-NLS-1$
			Collections.singletonList(this));
	this.generateDispatcher2 = new PolymorphicDispatcher<>(
			"_generate", 3, 3, //$NON-NLS-1$
			Collections.singletonList(this));
	this.afterDispatcher = new PolymorphicDispatcher<Void>(
			"_after", 2, 2, //$NON-NLS-1$
			Collections.singletonList(this)) {
		@Override
		protected Void handleNoSuchMethod(Object... params) {
			return null;
		}
	};
}
 
Example #2
Source File: AbstractDeclarativeScopeProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope polymorphicFindScopeForReferenceName(EObject context, EReference reference) {
	Predicate<Method> predicate = getPredicate(context, reference);
	PolymorphicDispatcher<IScope> dispatcher = new PolymorphicDispatcher<IScope>(Collections
			.singletonList(this), predicate, errorHandler) {
		@Override
		protected IScope handleNoSuchMethod(Object... params) {
			if (PolymorphicDispatcher.NullErrorHandler.class.equals(errorHandler.getClass()))
				return null;
			return super.handleNoSuchMethod(params);
		}
	};
	EObject current = context;
	IScope scope = null;
	while (scope == null && current != null) {
		scope = dispatcher.invoke(current, reference);
		current = current.eContainer();
	}
	return scope;
}
 
Example #3
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected String internalGetSignature(EObject object, boolean typeAtEnd) {
	PolymorphicDispatcher<String> polymorphicDispatcher = new PolymorphicDispatcher<String>("_signature", 2, 2,
			Collections.singletonList(this), new ErrorHandler<String>() {
				@Override
				public String handle(Object[] params, Throwable throwable) {
					return null;
				}
			});
	String result = polymorphicDispatcher.invoke(object, typeAtEnd);
	if (result != null)
		return result;
	if (object instanceof JvmIdentifiableElement) {
		return getLabel(object);
	}
	return getLabelForNonXbaseElement(object);
}
 
Example #4
Source File: AbstractJavaBasedContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void invokeMethod(String methodName, ICompletionProposalAcceptor acceptor, Object... params) {
	PolymorphicDispatcher<Void> dispatcher = dispatchers.get(methodName);
	if (dispatcher == null) {
		ErrorHandler<Void> errorHandler = WarningErrorHandler.get(log);
		dispatcher = new PolymorphicDispatcher<Void>(methodName, params.length + 1, params.length + 1,
				Collections.singletonList(this), errorHandler) {
			@Override
			public Class<?> getDefaultClass(int paramIndex) {
				if (paramIndex == 0)
					return EObject.class;
				return super.getDefaultClass(paramIndex);
			}
		};
		dispatchers.put(methodName, dispatcher);
	}
	Object[] paramAsArray = new Object[params.length + 1];
	System.arraycopy(params, 0, paramAsArray, 0, params.length);
	paramAsArray[params.length] = acceptor;
	if (announceProcessing(Lists.asList(methodName, paramAsArray))) {
		dispatcher.invoke(paramAsArray);
	}
}
 
Example #5
Source File: JavaOperationMockup.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public Object execute(ArgumentExpression expression, ExecutionContext context) {
	Operation definition = getOperation(expression);
	List<Object> targets = callbacks;
	if (definition.eContainer() instanceof InterfaceScope) {
		String className = ((InterfaceScope) definition.eContainer()).getName();
		if (className != null) {
			targets = callbacks.stream().filter(c -> className.equals(c.getClass().getSimpleName()))
					.collect(Collectors.toList());
		}
	}
	PolymorphicDispatcher<Object> dispatcher = new PolymorphicDispatcher<Object>(definition.getName(),
			definition.getParameters().size(), definition.getParameters().size(),
			targets.size() > 0 ? targets : callbacks);
	try {
		return dispatcher.invoke(executeArguments(expression.getArguments(), context, definition));
	} catch (Exception ex) {
		throw new WrappedException("Error during invocation of operation '" + definition.getName()
				+ "' with params " + definition.getParameters() + " '", ex);
	}
}
 
Example #6
Source File: AbstractTypeSystemInferrer.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void initDispatcher(List<ITypeSystemInferrer> targets) {
	dispatcher = new PolymorphicDispatcher<Object>(METHOD_NAME, 1, 1, targets,
			new PolymorphicDispatcher.ErrorHandler<Object>() {
				@Override
				public Object handle(Object[] params, Throwable throwable) {
					if (throwable instanceof NoSuchMethodError) {
						warning(String.format(NO_INFER_METHOD, Arrays.toString(params)), NO_INFER_METHOD_CODE);
					} else {
						error(throwable.getMessage(), EXCEPTION_CODE);
					}
					return null;
				}
			});
}
 
Example #7
Source File: PartialPartialSerializationTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #8
Source File: PartialXtextContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #9
Source File: PartialFileAwareTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #10
Source File: PartialXtextGrammarTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #11
Source File: PartialNoJdtTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #12
Source File: PartialNestedRefsTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #13
Source File: PartialHelloWorldContentAssistParser.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #14
Source File: PartialTestLanguageContentAssistParser.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #15
Source File: PartialCheckContentAssistParser.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #16
Source File: PartialCheckCfgContentAssistParser.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #17
Source File: PartialIndentationAwareUiTestLanguageContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #18
Source File: AbstractTypeSystemInterpreter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initDispatcher() {
	dispatcher = new PolymorphicDispatcher<Object>(METHOD_NAME, 1, 1, Collections.singletonList(this),
			new PolymorphicDispatcher.ErrorHandler<Object>() {
				@Override
				public Object handle(Object[] params, Throwable throwable) {
					if (throwable instanceof NoSuchMethodError) {
						warning("No infer method for type " + Arrays.toString(params));
					} else {
						error(throwable.getMessage());
					}
					return null;
				}
			});
}
 
Example #19
Source File: PartialGamlContentAssistParser.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #20
Source File: PartialYangContentAssistParser.java    From yang-design-studio with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #21
Source File: PartialSARLContentAssistParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #22
Source File: SARLLabelProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Constructor.
 * @param delegate the original provider.
 */
@Inject
public SARLLabelProvider(AdapterFactoryLabelProvider delegate) {
	super(delegate);
	this.imageDescriptorDispatcher = new PolymorphicDispatcher<>(
			"imageDescriptor", //$NON-NLS-1$
			1, 1,
			Collections.singletonList(this),
			new ErrorHandler<ImageDescriptor>() {
				@Override
				public ImageDescriptor handle(Object[] params, Throwable exception) {
					return handleImageDescriptorError(params, exception);
				}
			});
}
 
Example #23
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Constructor.
 */
public SARLOperationHelper() {
	this.hasSideEffectsDispatcher = new PolymorphicDispatcher<Boolean>(
			"_hasSideEffects", 2, 2, //$NON-NLS-1$
			Collections.singletonList(this)) {
		@Override
		protected Boolean handleNoSuchMethod(Object... params) {
			return Boolean.FALSE;
		}
	};
}
 
Example #24
Source File: JavaInlineExpressionCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Constructor.
 */
@SuppressWarnings("checkstyle:magicnumber")
public JavaInlineExpressionCompiler() {
	this.generateDispatcher = new PolymorphicDispatcher<Boolean>(
			"_generate", 4, 4, //$NON-NLS-1$
			Collections.singletonList(this)) {
		@Override
		protected Boolean handleNoSuchMethod(Object... params) {
			return Boolean.FALSE;
		}
	};
}
 
Example #25
Source File: XsemanticsRuntimeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected <T> PolymorphicDispatcher<T> buildPolymorphicDispatcher(
		final String methodName, int numOfArgs) {
	return new PatchedPolymorphicDispatcher<T>(
			Collections.singletonList(this), getPredicate(methodName,
					numOfArgs)) {
		@Override
		protected T handleNoSuchMethod(Object... params) {
			throw noSuchMethodException(methodName, params);
		}
	};
}
 
Example #26
Source File: XsemanticsRuntimeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected <T> PolymorphicDispatcher<Result<T>> buildPolymorphicDispatcher1(
		String methodName, int numOfArgs, final String judgmentSymbol,
		final String... relationSymbols) {
	return new PatchedPolymorphicDispatcher<Result<T>>(
			Collections.singletonList(this), getPredicate(methodName,
					numOfArgs)) {
		@Override
		protected Result<T> handleNoSuchMethod(Object... params) {
			throw noSuchMethodException(
					judgmentSymbol, Arrays.asList(relationSymbols),
					params);
		}
	};
}
 
Example #27
Source File: XsemanticsRuntimeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected <F, S> PolymorphicDispatcher<Result2<F, S>> buildPolymorphicDispatcher2(
		String methodName, int numOfArgs, final String judgmentSymbol,
		final String... relationSymbols) {
	return new PatchedPolymorphicDispatcher<Result2<F, S>>(
			Collections.singletonList(this), getPredicate(methodName,
					numOfArgs)) {
		@Override
		protected Result2<F, S> handleNoSuchMethod(
				Object... params) {
			throw noSuchMethodException(
					judgmentSymbol, Arrays.asList(relationSymbols),
					params);
		}
	};
}
 
Example #28
Source File: XsemanticsRuntimeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected <F, S, T> PolymorphicDispatcher<Result3<F, S, T>> buildPolymorphicDispatcher3(
		String methodName, int numOfArgs, final String judgmentSymbol,
		final String... relationSymbols) {
	return new PatchedPolymorphicDispatcher<Result3<F, S, T>>(
			Collections.singletonList(this), getPredicate(methodName,
					numOfArgs)) {
		@Override
		protected Result3<F, S, T> handleNoSuchMethod(
				Object... params) {
			throw noSuchMethodException(
					judgmentSymbol, Arrays.asList(relationSymbols),
					params);
		}
	};
}
 
Example #29
Source File: PartialConditionModelContentAssistParser.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}
 
Example #30
Source File: PartialBuilderTestLanguageContentAssistParser.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
	if (rule == null || rule.eIsProxy())
		return Collections.emptyList();
	String methodName = "entryRule" + rule.getName();
	PolymorphicDispatcher<Collection<FollowElement>> dispatcher = 
		new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
	dispatcher.invoke();
	return parser.getFollowElements();
}