Java Code Examples for org.eclipse.xtext.xbase.XConstructorCall#getConstructor()

The following examples show how to use org.eclipse.xtext.xbase.XConstructorCall#getConstructor() . 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: ScopeProviderAccess.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IConstructorLinkingCandidate getKnownConstructor(XConstructorCall constructorCall, AbstractTypeComputationState state,
		ResolvedTypes resolvedTypes) {
	IConstructorLinkingCandidate result = resolvedTypes.getConstructor(constructorCall);
	if (result != null) {
		return result;
	}
	EObject proxyOrResolved = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
	if (proxyOrResolved == null) {
		result = new NullConstructorLinkingCandidate(constructorCall, state);
		return result;
	}
	if (!proxyOrResolved.eIsProxy()) {
		result = state.createResolvedLink(constructorCall, (JvmConstructor) proxyOrResolved);
		return result;
	}
	if (!encoder.isCrossLinkFragment(constructorCall.eResource(), EcoreUtil.getURI(proxyOrResolved).fragment())) {
		JvmConstructor constructor = constructorCall.getConstructor();
		if (!constructor.eIsProxy()) {
			return state.createResolvedLink(constructorCall, constructor);
		}
	}
	return null;
}
 
Example 2
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected Object _doEvaluate(XConstructorCall constructorCall, IEvaluationContext context, CancelIndicator indicator) {
	JvmConstructor jvmConstructor = constructorCall.getConstructor();
	List<Object> arguments = evaluateArgumentExpressions(jvmConstructor, constructorCall.getArguments(), context, indicator);
	Constructor<?> constructor = javaReflectAccess.getConstructor(jvmConstructor);
	try {
		if (constructor == null)
			throw new NoSuchMethodException("Could not find constructor " + jvmConstructor.getIdentifier());
		constructor.setAccessible(true);
		Object result = constructor.newInstance(arguments.toArray(new Object[arguments.size()]));
		return result;
	} catch (InvocationTargetException targetException) {
		throw new EvaluationException(targetException.getTargetException());
	} catch (Exception e) {
		throw new IllegalStateException("Could not invoke constructor: " + jvmConstructor.getIdentifier(), e);
	}
}
 
Example 3
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**  Generate a constructor call.
 *
 * @param expr the call expression.
 */
public void generate(XConstructorCall expr) {
	final List<Object> leftOperand = new ArrayList<>();
	final List<Object> receiver = new ArrayList<>();
	final JvmConstructor feature = expr.getConstructor();
	final List<XExpression> args = getActualArguments(expr);
	final JvmType type = expr.getConstructor().getDeclaringType();
	this.codeReceiver.getImportManager().addImportFor(type);
	internalAppendCall(feature, leftOperand, receiver, type.getSimpleName(), args, null);
}
 
Example 4
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkDeprecated(XConstructorCall expression) {
	if (!isIgnored(DEPRECATED_MEMBER_REFERENCE)) {
		JvmConstructor constructor = expression.getConstructor();
		checkDeprecated(
				constructor,
				expression,
				XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR);
	}
}
 
Example 5
Source File: SARLHoverSignatureProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected String _signature(XConstructorCall featureCall, boolean typeAtEnd) {
	final JvmIdentifiableElement feature = featureCall.getConstructor();
	if (feature != null) {
		return internalGetSignature(feature, typeAtEnd);
	}
	return ""; //$NON-NLS-1$
}
 
Example 6
Source File: XbaseUIValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkRestrictedType(XConstructorCall constructorCall) {
	if (isRestrictionCheckIgnored())
		return;
	JvmConstructor constructor = constructorCall.getConstructor();
	if (constructor == null)
		return;
	JvmDeclaredType declaringType = constructor.getDeclaringType();
	checkRestrictedType(constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, declaringType);
}
 
Example 7
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_09() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<Object>(strings, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example 8
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_08() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<Object>(chars, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example 9
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_07() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<? extends Object> objects = null\n" +
			"    new testdata.OverloadedMethods<Object>(objects, objects)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example 10
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_06() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    new testdata.OverloadedMethods<Object>(chars, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example 11
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_05() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<String>(strings, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.List,java.util.List)", constructor.getIdentifier());
}
 
Example 12
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_04() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(chars, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(1);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.List,java.util.List)", constructor.getIdentifier());
}
 
Example 13
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_03() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(strings, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.util.Collection)", constructor.getIdentifier());
}
 
Example 14
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_02() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(chars, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.util.Collection,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example 15
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_01() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    new testdata.OverloadedMethods<Object>()\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(0);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods()", constructor.getIdentifier());
}
 
Example 16
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void highlightConstructorCall(XConstructorCall constructorCall, IHighlightedPositionAcceptor acceptor) {
	if (constructorCall.getConstructor() != null && !constructorCall.getConstructor().eIsProxy()) {
		EObject declaringType = constructorCall.getConstructor().getDeclaringType();
		if (declaringType instanceof JvmGenericType) {
			highlightFeature(acceptor, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, getStyle((JvmGenericType) declaringType));
		}
	}
}
 
Example 17
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IScope createConstructorCallSerializationScope(EObject context) {
	if (!(context instanceof XConstructorCall)) {
		return IScope.NULLSCOPE;
	}
	XConstructorCall constructorCall = (XConstructorCall) context;
	JvmConstructor constructor = constructorCall.getConstructor();
	if (constructor.eIsProxy()) {
		return IScope.NULLSCOPE;
	}
	return doCreateConstructorCallSerializationScope(constructorCall);
}
 
Example 18
Source File: ThrownExceptionSwitch.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Boolean caseXConstructorCall(XConstructorCall object) {
	JvmConstructor constructor = object.getConstructor();
	accept(constructor);
	return Boolean.TRUE;
}