Java Code Examples for org.eclipse.xtext.common.types.JvmFormalParameter#getParameterType()
The following examples show how to use
org.eclipse.xtext.common.types.JvmFormalParameter#getParameterType() .
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-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 2
Source File: AbstractTypeProviderTest.java From xtext-extras 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 3
Source File: XtypeProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void appendParameters(StyledString result, JvmExecutable executable, int insignificantParameters, LightweightTypeReferenceFactory ownedConverter) { List<JvmFormalParameter> declaredParameters = executable.getParameters(); List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size()); for(int i = 0; i < relevantParameters.size(); i++) { JvmFormalParameter parameter = relevantParameters.get(i); if (i != 0) result.append(", "); if (i == relevantParameters.size() - 1 && executable.isVarArgs() && parameter.getParameterType() instanceof JvmGenericArrayTypeReference) { JvmGenericArrayTypeReference parameterType = (JvmGenericArrayTypeReference) parameter.getParameterType(); result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName()); result.append("..."); } else { if (parameter.getParameterType()!= null) { String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName(); if (simpleName != null) // is null if the file is not on the class path result.append(simpleName); } } result.append(' '); result.append(notNull(parameter.getName())); } }
Example 4
Source File: UIStrings.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected String parametersToString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs, boolean includeName) { StringBuilder result = new StringBuilder(); boolean needsSeparator = false; Iterator<? extends JvmFormalParameter> iterator = elements.iterator(); while (iterator.hasNext()) { JvmFormalParameter parameter = iterator.next(); if (needsSeparator) result.append(", "); needsSeparator = true; JvmTypeReference typeRef = parameter.getParameterType(); if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) { typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType(); result.append(referenceToString(typeRef, "[null]")); result.append("..."); } else { result.append(referenceToString(typeRef, "[null]")); } if (includeName) { result.append(" " + parameter.getName()); } } return result.toString(); }
Example 5
Source File: AbstractTypeProviderTest.java From xtext-extras 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 6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void test_twoListWildcardsNoResult_02() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); assertNotNull(paramType); assertEquals("java.util.List<? extends java.lang.Object>", paramType.getIdentifier()); assertTrue(paramType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
Example 7
Source File: SARLOperationHelper.java From sarl with Apache License 2.0 | 5 votes |
private boolean hasPrimitiveParameters(JvmOperation op) { for (final JvmFormalParameter parameter : op.getParameters()) { final JvmTypeReference type = parameter.getParameterType(); if (type == null || !Utils.toLightweightTypeReference(type, this.services).isPrimitive()) { return false; } } return true; }
Example 8
Source File: SARLExpressionHelper.java From sarl with Apache License 2.0 | 5 votes |
private boolean hasPrimitiveParameters(JvmOperation op) { for (final JvmFormalParameter parameter : op.getParameters()) { final JvmTypeReference type = parameter.getParameterType(); if (type == null || !Utils.toLightweightTypeReference(type, this.services).isPrimitive()) { return false; } } return true; }
Example 9
Source File: ExpressionScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getParameterType(JvmFormalParameter p) { JvmTypeReference parameterType = p.getParameterType(); if (parameterType == null) { return null; } JvmType type = parameterType.getType(); if (type == null) return null; return owner.toPlainTypeReference(type).getRawTypeReference(); }
Example 10
Source File: OverrideHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isMatchesSignature(JvmFormalParameter parameter, JvmFormalParameter candidateParameter, TypeParameterSubstitutor<?> substitutor, ITypeReferenceOwner owner) { JvmTypeReference parameterType = parameter.getParameterType(); if (parameterType == null || parameterType.getType() == null) { return false; } String identifier = parameterType.getIdentifier(); LightweightTypeReference candidateParameterType = substitutor.substitute(owner.toLightweightTypeReference(candidateParameter.getParameterType())); return identifier.equals(candidateParameterType.getJavaIdentifier()); }
Example 11
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void test_twoListParamsNoResult_02() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); assertNotNull(paramType); assertFalse(paramType.getType().eIsProxy()); assertEquals("java.util.List<T>", paramType.getIdentifier()); assertTrue(paramType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
Example 12
Source File: BucketedEObjectDescription.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void computeShadowingKey(JvmIdentifiableElement identifiable, StringBuilder result) { if (identifiable instanceof JvmExecutable) { JvmExecutable executable = (JvmExecutable) identifiable; result.append('('); boolean first = true; for(JvmFormalParameter parameter: executable.getParameters()) { if (!first) { result.append(','); } else { first = false; } if (parameter.getParameterType() != null && parameter.getParameterType().getType() != null) result.append(parameter.getParameterType().getType().getIdentifier()); else result.append("null"); } result.append(')'); } if (getImplicitFirstArgument() != null) { result.append(":implicitFirstArgument"); } if (getImplicitReceiver() != null) { result.append(":implicitReceiver"); } if (isTypeLiteral()) { result.append(":typeLiteral"); } if (isVisible()) { result.append('+'); } else { result.append('-'); } }
Example 13
Source File: ExtensionScopeHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isMatchingFirstParameter(JvmOperation feature) { List<JvmFormalParameter> parameters = feature.getParameters(); JvmFormalParameter firstParameter = parameters.get(0); JvmTypeReference type = firstParameter.getParameterType(); if (type == null) return false; JvmType rawParameterType = type.getType(); if (rawParameterType == null || rawParameterType.eIsProxy()) return false; if (!(rawParameterType instanceof JvmTypeParameter)) { if (rawArgumentType.isResolved()) { // short circuit - limit extension scope entries to real candidates LightweightTypeReference parameterTypeReference = rawArgumentType.getOwner().toPlainTypeReference(rawParameterType); if (parameterTypeReference.isResolved() && !parameterTypeReference.isAssignableFrom(rawArgumentType)) { if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && rawArgumentType.isSubtypeOf(Iterable.class)) { return true; } return false; } if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && !rawArgumentType.isSubtypeOf(Iterable.class)) { return false; } } else if (isArrayTypeMismatch(rawArgumentType, rawParameterType)) { return false; } } return true; }
Example 14
Source File: JavaElementFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private String getQualifiedParameterType(JvmFormalParameter formalParameter) { JvmTypeReference parameterType = formalParameter.getParameterType(); if (parameterType == null) return null; JvmType type = parameterType.getType(); if (type == null) return null; return type.getQualifiedName('.'); }
Example 15
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override protected void _format(JvmFormalParameter expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getExtensionExtensionKeyword()), ONE_SPACE); final JvmTypeReference parameterType = expr.getParameterType(); if (parameterType != null) { document.surround(regionFor.keyword(this.keywords.getColonKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getAsKeyword()), ONE_SPACE); } document.format(parameterType); }
Example 16
Source File: DefaultActionPrototypeProvider.java From sarl with Apache License 2.0 | 5 votes |
@Override public ActionParameterTypes createParameterTypesFromJvmModel(boolean isVarargs, List<JvmFormalParameter> parameters) { final ActionParameterTypes sig = new ActionParameterTypes(isVarargs, parameters.size()); for (final JvmFormalParameter p : parameters) { final JvmTypeReference paramType = p.getParameterType(); if (paramType != null) { sig.add(paramType.getIdentifier()); } } return sig; }
Example 17
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected LightweightTypeReference getDeclaredParameterType(JvmFormalParameter declaredParam, final ITypeComputationState state) { JvmTypeReference parameterType = declaredParam.getParameterType(); if (parameterType == null) return null; return state.getReferenceOwner().toLightweightTypeReference(parameterType); }
Example 18
Source File: XbaseInterpreter.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected Object _doEvaluate(XTryCatchFinallyExpression tryCatchFinally, IEvaluationContext context, CancelIndicator indicator) { Object result = null; ReturnValue returnValue = null; Map<String, Boolean> resIsInit = new HashMap<String, Boolean>(); List<XVariableDeclaration> resources = tryCatchFinally.getResources(); List<EvaluationException> caughtExceptions = newArrayList(); // Resources try { for (XVariableDeclaration res : resources) { resIsInit.put(res.getName(), false); result = internalEvaluate(res, context, indicator); // Remember for automatic close which resources are initialized resIsInit.put(res.getName(), true); } // Expression Body result = internalEvaluate(tryCatchFinally.getExpression(), context, indicator); } catch (ReturnValue value) { // Keep thrown return value in mind until resources are closed returnValue = value; } catch (EvaluationException evaluationException) { Throwable cause = evaluationException.getCause(); boolean caught = false; // Catch Clauses for (XCatchClause catchClause : tryCatchFinally.getCatchClauses()) { JvmFormalParameter exception = catchClause.getDeclaredParam(); JvmTypeReference catchParameterType = exception.getParameterType(); if (!isInstanceoOf(cause, catchParameterType)) { continue; } IEvaluationContext forked = context.fork(); forked.newValue(QualifiedName.create(exception.getName()), cause); result = internalEvaluate(catchClause.getExpression(), forked, indicator); caught = true; break; } // Save uncaught exception if(!caught) caughtExceptions.add(evaluationException); } // finally expressions ... // ... given if (tryCatchFinally.getFinallyExpression() != null) { try { internalEvaluate(tryCatchFinally.getFinallyExpression(), context, indicator); } catch (EvaluationException e) { throw new EvaluationException(new FinallyDidNotCompleteException(e)); } } // ... prompted by try with resources (automatic close) if (!resources.isEmpty()) { for (int i = resources.size() - 1; i >= 0; i--) { XVariableDeclaration resource = resources.get(i); // Only close resources that are instantiated (= avoid // NullPointerException) if (resIsInit.get(resource.getName())) { // Find close method for resource JvmOperation close = findCloseMethod(resource); // Invoke close on resource if (close != null) { // Invoking the close method might throw // a EvaluationException. Hence, we collect those thrown // EvaluationExceptions and propagate them later on. try { invokeOperation(close, context.getValue(QualifiedName.create(resource.getSimpleName())), Collections.emptyList()); } catch (EvaluationException t) { caughtExceptions.add(t); } } } } } // Throw caught exceptions if there are any if (!caughtExceptions.isEmpty()) throw caughtExceptions.get(0); // throw return value from expression block after resources are closed if (returnValue != null) throw returnValue; return result; }
Example 19
Source File: XsemanticsTypeSystemGen.java From xsemantics with Eclipse Public License 1.0 | 4 votes |
private JvmTypeReference _applyRuleInputParameterType_1(final RuleEnvironment G, final InputParameter p) throws RuleFailedException { JvmFormalParameter _parameter = p.getParameter(); JvmTypeReference _parameterType = _parameter.getParameterType(); return _parameterType; }
Example 20
Source File: XsemanticsTypeSystemGen.java From xsemantics with Eclipse Public License 1.0 | 4 votes |
private JvmTypeReference _applyRuleJvmFormalParameterType_1(final RuleEnvironment G, final JvmFormalParameter p) throws RuleFailedException { JvmTypeReference _parameterType = p.getParameterType(); return _parameterType; }