org.eclipse.xtext.common.types.JvmOperation Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmOperation.
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: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethods_publicAbstractMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "publicAbstractMethod()"); assertSame(type, method.getDeclaringType()); assertTrue(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PUBLIC, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
Example #2
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testImplicitFirstArgument_03() throws Exception { XtendClass clazz = clazz( "import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + " def testExtensionMethods(CharSequence it) {\n" + " toLowerCase\n" + " }\n" + " extension String" + "}"); XtendFunction func= (XtendFunction) clazz.getMembers().get(0); XFeatureCall third = (XFeatureCall) ((XBlockExpression)func.getExpression()).getExpressions().get(0); JvmOperation thirdFeature = (JvmOperation) third.getFeature(); assertEquals("java.lang.String.toLowerCase()", thirdFeature.getIdentifier()); assertNull(third.getImplicitFirstArgument()); XMemberFeatureCall thirdReceiver = (XMemberFeatureCall) third.getImplicitReceiver(); assertTrue(thirdReceiver.getFeature() instanceof JvmField); assertNull(third.getInvalidFeatureIssueCode(), third.getInvalidFeatureIssueCode()); }
Example #3
Source File: Utils.java From sarl with Apache License 2.0 | 6 votes |
/** Analyzing the type hierarchy of the given interface and * extract hierarchy information. * * @param jvmElement - the element to analyze * @param operations - filled with the operations inside and inherited by the element. * @param fields - filled with the fields inside and inherited by the element. * @param sarlSignatureProvider - provider of tools related to action signatures. * @see OverrideHelper */ public static void populateInterfaceElements( JvmDeclaredType jvmElement, Map<ActionPrototype, JvmOperation> operations, Map<String, JvmField> fields, IActionPrototypeProvider sarlSignatureProvider) { for (final JvmFeature feature : jvmElement.getAllFeatures()) { if (!"java.lang.Object".equals(feature.getDeclaringType().getQualifiedName())) { //$NON-NLS-1$ if (operations != null && feature instanceof JvmOperation) { final JvmOperation operation = (JvmOperation) feature; final ActionParameterTypes sig = sarlSignatureProvider.createParameterTypesFromJvmModel( operation.isVarArgs(), operation.getParameters()); final ActionPrototype actionKey = sarlSignatureProvider.createActionPrototype( operation.getSimpleName(), sig); operations.put(actionKey, operation); } else if (fields != null && feature instanceof JvmField) { fields.put(feature.getSimpleName(), (JvmField) feature); } } } }
Example #4
Source File: JvmModelGeneratorTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testAnnotation_1() { try { final XExpression expression = this.expression("42", false); final Procedure1<JvmAnnotationType> _function = (JvmAnnotationType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "theTruth", this.references.getTypeForName(int.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmAnnotationType clazz = this.builder.toAnnotationType(expression, "my.test.Foo", _function); final Class<?> compiledClass = this.compile(expression.eResource(), clazz); Assert.assertTrue(compiledClass.isAnnotation()); final Method method = IterableExtensions.<Method>head(((Iterable<Method>)Conversions.doWrapArray(compiledClass.getMethods()))); Assert.assertEquals("theTruth", method.getName()); Assert.assertEquals(Integer.valueOf(42), method.getDefaultValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #5
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_07() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_01()"); JvmTypeReference listZ = methodV.getReturnType(); assertEquals("java.util.List<Z[][]>", listZ.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmType argumentType = typeArgument.getType(); assertTrue(argumentType instanceof JvmArrayType); assertTrue(((JvmArrayType) argumentType).getComponentType() instanceof JvmArrayType); JvmComponentType componentType = ((JvmArrayType) ((JvmArrayType) argumentType).getComponentType()) .getComponentType(); JvmTypeParameter z = type.getTypeParameters().get(2); assertSame(z, componentType); }
Example #6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testFindTypeByName_javaLangNumber_02() { String typeName = Number[][].class.getName(); JvmArrayType type = (JvmArrayType) getTypeProvider().findTypeByName(typeName); JvmOperation longValue = (JvmOperation) type.eResource().getEObject("java.lang.Number.longValue()"); assertNotNull(longValue); JvmDeclaredType number = longValue.getDeclaringType(); assertNotNull(number.getArrayType()); assertSame(type, number.getArrayType().getArrayType()); assertNull(type.eGet(TypesPackage.Literals.JVM_COMPONENT_TYPE__ARRAY_TYPE)); // array will created on the fly assertNotNull(type.getArrayType()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
Example #7
Source File: JvmModelGenerator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmConstructor) { return _generateModifier((JvmConstructor)it, appendable, config); } else if (it instanceof JvmOperation) { return _generateModifier((JvmOperation)it, appendable, config); } else if (it instanceof JvmField) { return _generateModifier((JvmField)it, appendable, config); } else if (it instanceof JvmGenericType) { return _generateModifier((JvmGenericType)it, appendable, config); } else if (it instanceof JvmDeclaredType) { return _generateModifier((JvmDeclaredType)it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
Example #8
Source File: XtendHoverDocumentationProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected void handleSuperMethodReferences(EObject context) { if (context instanceof XtendFunction) { XtendFunction function = (XtendFunction) context; if (function.isOverride()) { JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function); if (inferredOperation != null) { JvmOperation overridden = overrideHelper.findOverriddenOperation(inferredOperation); if (overridden != null) { buffer.append("<div>"); //$NON-NLS-1$ buffer.append("<b>"); //$NON-NLS-1$ buffer.append("Overrides:"); //$NON-NLS-1$ buffer.append("</b> "); //$NON-NLS-1$ buffer.append(createMethodInTypeLinks(overridden)); buffer.append("</div>"); //$NON-NLS-1$ } } } } }
Example #9
Source File: DispatchHelper.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public JvmOperation getDispatcherOperation(JvmOperation dispatchCase) { EObject sourceElement = associations.getPrimarySourceElement(dispatchCase); if (sourceElement instanceof XtendFunction) { XtendFunction function = (XtendFunction) sourceElement; if (function.isDispatch()) { Iterable<JvmOperation> operations = filter(associations.getJvmElements(sourceElement), JvmOperation.class); for(JvmOperation operation: operations) { if (Strings.equal(operation.getSimpleName(), function.getName())) { return operation; } } } } else { DispatchSignature signature = new DispatchSignature(dispatchCase.getSimpleName().substring(1), dispatchCase.getParameters().size()); JvmOperation result = getDispatcherOperation(dispatchCase.getDeclaringType(), signature); return result; } return null; }
Example #10
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsListResult_03() { JvmOperation twoListWildcardsListResult = getMethodFromParameterizedMethods( "twoListWildcardsListResult(java.util.List,java.util.List)"); JvmTypeReference returnType = twoListWildcardsListResult.getReturnType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
Example #11
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation methodS = getMethodFromType(type, ParameterizedTypes.class, "methodS(S)"); JvmTypeReference listS = methodS.getReturnType(); assertFalse(listS.toString(), listS.eIsProxy()); assertEquals("java.util.List<? extends S>", listS.getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listS; assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertTrue(typeArgument instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument; assertEquals("? extends S", wildcardTypeArgument.getIdentifier()); assertEquals(1, wildcardTypeArgument.getConstraints().size()); JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, upperBound.getTypeReference().getType()); }
Example #12
Source File: Utils.java From sarl with Apache License 2.0 | 6 votes |
/** Analyzing the type hierarchy of the given element, and * extract any type-related information. * * @param jvmElement - the element to analyze * @param finalOperations - filled with the final operations inherited by the element. * @param overridableOperations - filled with the oervrideable operations inherited by the element. * @param inheritedFields - filled with the fields inherited by the element. * @param operationsToImplement - filled with the abstract operations inherited by the element. * @param superConstructors - filled with the construstors of the super type. * @param sarlSignatureProvider - provider of tools related to action signatures. * @see OverrideHelper */ public static void populateInheritanceContext( JvmDeclaredType jvmElement, Map<ActionPrototype, JvmOperation> finalOperations, Map<ActionPrototype, JvmOperation> overridableOperations, Map<String, JvmField> inheritedFields, Map<ActionPrototype, JvmOperation> operationsToImplement, Map<ActionParameterTypes, JvmConstructor> superConstructors, IActionPrototypeProvider sarlSignatureProvider) { populateInheritanceContext( jvmElement, jvmElement.getExtendedClass(), jvmElement.getExtendedInterfaces(), finalOperations, overridableOperations, inheritedFields, operationsToImplement, superConstructors, sarlSignatureProvider); }
Example #13
Source File: SarlJvmModelAssociations.java From sarl with Apache License 2.0 | 6 votes |
@Override public XtendFunction getXtendFunction(JvmOperation jvmOperation) { XtendFunction fct = null; try { fct = super.getXtendFunction(jvmOperation); } catch (Throwable exception) { fct = null; } if (fct == null) { for (final EObject obj : getSourceElements(jvmOperation)) { if (obj instanceof XtendFunction) { fct = (XtendFunction) obj; break; } } } return fct; }
Example #14
Source File: JvmAnnotationReferenceImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Expression getExpression(final String property) { final JvmOperation op = this.findOperation(property); final Function1<JvmAnnotationValue, Boolean> _function = (JvmAnnotationValue it) -> { return Boolean.valueOf((Objects.equal(it.getOperation(), op) || ((it.getOperation() == null) && Objects.equal(op.getSimpleName(), "value")))); }; final JvmAnnotationValue annotationValue = IterableExtensions.<JvmAnnotationValue>findFirst(this.getDelegate().getValues(), _function); boolean _matched = false; if (annotationValue instanceof JvmCustomAnnotationValue) { _matched=true; EObject _head = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue)annotationValue).getValues()); final XExpression expression = ((XExpression) _head); if (((expression != null) && this.getCompilationUnit().isBelongedToCompilationUnit(expression))) { return this.getCompilationUnit().toExpression(expression); } } return null; }
Example #15
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListParamsNoResult_03() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsNoResult, typeVar.getDeclarator()); }
Example #16
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethods_defaultStaticMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "defaultStaticMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertTrue(method.isStatic()); assertFalse(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.DEFAULT, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
Example #17
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
Example #18
Source File: ReferencedInvalidTypeFinder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected LightweightTypeReference internalFindReferencedInvalidType(final JvmIdentifiableElement operation) { if (operation instanceof JvmOperation) { return _internalFindReferencedInvalidType((JvmOperation)operation); } else if (operation instanceof JvmExecutable) { return _internalFindReferencedInvalidType((JvmExecutable)operation); } else if (operation instanceof JvmField) { return _internalFindReferencedInvalidType((JvmField)operation); } else if (operation != null) { return _internalFindReferencedInvalidType(operation); } else if (operation == null) { return _internalFindReferencedInvalidType((Void)null); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(operation).toString()); } }
Example #19
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void _toJavaExpression(final XClosure closure, final ITreeAppendable b) { if (b.hasName(closure)) { b.trace(closure, false).append(getVarName(closure, b)); } else { LightweightTypeReference type = getLightweightType(closure); JvmOperation operation = findImplementingOperation(type); if (operation != null) { GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA8) && canCompileToJavaLambda(closure, type, operation)) { toLambda(closure, b.trace(closure, false), type, operation, true); } else { toAnonymousClass(closure, b.trace(closure, false), type, operation); } } } }
Example #20
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testInferredFunction_04() throws Exception { XtendFile xtendFile = file("class Foo { def Iterable<CharSequence> create result: newArrayList(s) newList(String s) {} }"); JvmGenericType inferredType = getInferredType(xtendFile); XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0); EList<JvmMember> jvmMembers = inferredType.getMembers(); assertEquals(4, jvmMembers.size()); JvmMember jvmMember = jvmMembers.get(1); assertTrue(jvmMember instanceof JvmOperation); XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0); assertEquals(xtendFunction.getName(), jvmMember.getSimpleName()); assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility()); assertEquals("java.lang.Iterable<java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier()); JvmField cacheVar = (JvmField) jvmMembers.get(2); assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility()); assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<java.lang.CharSequence>>", cacheVar.getType().getIdentifier()); JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3); assertEquals("_init_"+xtendFunction.getName(), privateInitializer.getSimpleName()); assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility()); // This used to be a bogus assertion since Iterable<CharSequence> is not assignable from ArrayList<String> // assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier()); assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier()); assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier()); }
Example #21
Source File: XtendHoverSignatureProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected String getSimpleSignature(EObject container) { if(container instanceof XtendFunction){ XtendFunction function = (XtendFunction) container; JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function); if (inferredOperation != null) { return function.getName() + uiStrings.parameters(inferredOperation); } } else if (container instanceof XtendConstructor){ XtendConstructor constructor = (XtendConstructor) container; XtendClass xtendClazz = EcoreUtil2.getContainerOfType(constructor, XtendClass.class); JvmConstructor inferredConstructor = associations.getInferredConstructor(constructor); return xtendClazz.getName() + " " + uiStrings.parameters(inferredConstructor); } return super.getSimpleSignature(container); }
Example #22
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testMethods_privateSynchronizedMethod_01() { String typeName = Methods.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, Methods.class, "privateSynchronizedMethod()"); assertSame(type, method.getDeclaringType()); assertFalse(method.isAbstract()); assertFalse(method.isFinal()); assertFalse(method.isStatic()); assertTrue(method.isSynchronized()); assertFalse(method.isStrictFloatingPoint()); assertFalse(method.isNative()); assertEquals(JvmVisibility.PRIVATE, method.getVisibility()); JvmType methodType = method.getReturnType().getType(); assertEquals("void", methodType.getIdentifier()); }
Example #23
Source File: ResolvedOperationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testListToArrayHasTwoOrThreeCandidates() { final IResolvedOperation operation = this.toOperation("(null as java.util.List<String>).toArray(null)"); final List<JvmOperation> candidates = operation.getOverriddenAndImplementedMethodCandidates(); final Function1<JvmOperation, String> _function = (JvmOperation it) -> { return it.getIdentifier(); }; final String message = IterableExtensions.join(ListExtensions.<JvmOperation, String>map(candidates, _function), ", "); try { Assert.assertEquals(message, 2, candidates.size()); } catch (final Throwable _t) { if (_t instanceof AssertionError) { Assert.assertEquals(message, 3, candidates.size()); } else { throw Exceptions.sneakyThrow(_t); } } }
Example #24
Source File: FunctionTypes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> getFunctionTypeParameterMapping( LightweightTypeReference functionType, JvmOperation operation, ActualTypeArgumentCollector typeArgumentCollector, ITypeReferenceOwner owner) { /* * The mapping is populated by means of the function type to declarator mapping, though a method * * m(Zonk zonk) { .. } * * with * * interface Foo<X> { * void bar(X x); * } * interface Zonk extends Foo<CharSequence> {} * * infers the parameter type CharSequence for the lamba param */ LightweightTypeReference lightweightTypeReference = owner.toLightweightTypeReference(operation.getDeclaringType()); typeArgumentCollector.populateTypeParameterMapping(lightweightTypeReference, functionType); Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> typeParameterMapping = typeArgumentCollector.rawGetTypeParameterMapping(); return typeParameterMapping; }
Example #25
Source File: AbstractNewSarlElementWizardPage.java From sarl with Apache License 2.0 | 6 votes |
private static void createInfoCall(IExpressionBuilder builder, String message) { final JvmParameterizedTypeReference capacity = builder.newTypeRef(null, LOGGING_CAPACITY_NAME); final String objectType = Object.class.getName(); final String objectArrayType = objectType + "[]"; //$NON-NLS-1$ final JvmOperation infoMethod = Iterables.find( ((JvmDeclaredType) capacity.getType()).getDeclaredOperations(), it -> { if (Objects.equals(it.getSimpleName(), "info") //$NON-NLS-1$ && it.getParameters().size() == 2) { final String type1 = it.getParameters().get(0).getParameterType().getIdentifier(); final String type2 = it.getParameters().get(1).getParameterType().getIdentifier(); return Objects.equals(objectType, type1) && Objects.equals(objectArrayType, type2); } return false; }, null); if (infoMethod != null) { builder.setExpression("info(\"" + message + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ ((XFeatureCall) builder.getXExpression()).setFeature(infoMethod); } }
Example #26
Source File: EntitiesValidator.java From xtext-web with Eclipse Public License 2.0 | 6 votes |
@Check public void checkOperationNamesAreUnique(Entity entity) { JvmGenericType inferredJavaClass = IterableExtensions .head(Iterables.filter(jvmModelAssociations.getJvmElements(entity), JvmGenericType.class)); Multimap<String, JvmOperation> signature2Declarations = HashMultimap.create(); overrideHelper.getResolvedFeatures(inferredJavaClass).getDeclaredOperations().forEach((it) -> { signature2Declarations.put(it.getResolvedErasureSignature(), it.getDeclaration()); }); signature2Declarations.asMap().values().forEach((jvmOperations) -> { if (jvmOperations.size() > 1) { Iterables .filter(IterableExtensions.map(jvmOperations, (op) -> jvmModelAssociations.getPrimarySourceElement(op)), Operation.class) .forEach((op) -> { error("Duplicate operation " + op.getName(), op, DomainmodelPackage.Literals.FEATURE__NAME, IssueCodes.DUPLICATE_OPERATION); }); } }); }
Example #27
Source File: FeatureKinds.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public static String getTypeName(JvmIdentifiableElement feature) { if (feature instanceof JvmFormalParameter) { return "parameter"; } if (feature instanceof XVariableDeclaration) { return "local variable"; } if (feature instanceof JvmEnumerationLiteral) { return "enum literal"; } if (feature instanceof JvmField) { return "field"; } if (feature instanceof JvmOperation) { return "method"; } if (feature instanceof JvmConstructor) { return "constructor"; } if (feature instanceof JvmType) { return "type"; } throw new IllegalStateException(); }
Example #28
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testFeatureCall_5() throws Exception { XBlockExpression block = (XBlockExpression) expression( "{\n" + " val list = newArrayList\n" + " list.addAll(null as java.util.ArrayList<String>)\n" + " list\n" + "}"); XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) block.getExpressions().get(1); assertEquals("java.util.ArrayList.addAll(java.util.Collection)", ((JvmOperation)memberFeatureCall.getFeature()).getIdentifier()); }
Example #29
Source File: DispatchHelperTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testSort_01() throws Exception { XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Integer i) {null}" + " def dispatch foo(Boolean i) {null}" + " def dispatch foo(String i) {null}" + "}"); JvmGenericType type = associations.getInferredType(clazz); ListMultimap<DispatchSignature,JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type); List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1)); Iterator<JvmOperation> i = list.iterator(); assertEquals(Integer.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier()); assertEquals(Boolean.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier()); assertEquals(String.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier()); }
Example #30
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void test_ParameterizedTypes_inner_return_02() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = getMethodFromType(type, ParameterizedTypes.class, "concreteInner()"); JvmTypeReference returnType = operation.getReturnType(); assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference); assertEquals( "ParameterizedTypes<String, String, List<String>, V, String>$Inner<String, List<String>, List<String>>", returnType.getSimpleName()); }