Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getSimpleName()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#getSimpleName() .
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: RootResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected AbstractDiagnostic createTypeDiagnostic(XExpression expression, LightweightTypeReference actualType, LightweightTypeReference expectedType) { if (!expectedType.isAny()) { String actualName = actualType.getSimpleName(); String expectedName = expectedType.getSimpleName(); if (actualName.equals(expectedName)) { if (expectedType.isAssignableFrom(actualType)) { return null; } } if (expression.eContainingFeature() == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_FIRST_ARGUMENT) { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert implicit first argument from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: type %s is not applicable at this location", actualType.getHumanReadableName()), expression, null, -1, null); } }
Example 2
Source File: AbstractClosureTypeTest2.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public String getEquivalent(final ParameterizedTypeReference type) { boolean _isEmpty = type.getTypeArguments().isEmpty(); if (_isEmpty) { return type.getType().getSimpleName(); } StringConcatenation _builder = new StringConcatenation(); String _simpleName = type.getType().getSimpleName(); _builder.append(_simpleName); _builder.append("<"); final Function1<LightweightTypeReference, CharSequence> _function = (LightweightTypeReference it) -> { return it.getSimpleName(); }; String _join = IterableExtensions.<LightweightTypeReference>join(type.getTypeArguments(), ", ", _function); _builder.append(_join); _builder.append(">"); return _builder.toString(); }
Example 3
Source File: NewFeatureNameUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected String getBaseName(XExpression expression) { if (expression instanceof XMemberFeatureCall || expression instanceof XFeatureCall) { String featureName = ((XAbstractFeatureCall) expression).getFeature().getSimpleName(); if (featureName.startsWith("get")) return featureName.substring(3); else if (featureName.startsWith("is")) return featureName.substring(2); else return featureName; } if(expression instanceof XClosure) return "function"; LightweightTypeReference type = batchTypeResolver.resolveTypes(expression).getActualType(expression); if (type != null) return type.getSimpleName(); return ""; }
Example 4
Source File: CommonSuperTypeTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public String getEquivalent(final ParameterizedTypeReference type) { boolean _isEmpty = type.getTypeArguments().isEmpty(); if (_isEmpty) { return type.getType().getSimpleName(); } StringConcatenation _builder = new StringConcatenation(); String _simpleName = type.getType().getSimpleName(); _builder.append(_simpleName); _builder.append("<"); final Function1<LightweightTypeReference, CharSequence> _function = (LightweightTypeReference it) -> { return it.getSimpleName(); }; String _join = IterableExtensions.<LightweightTypeReference>join(type.getTypeArguments(), ", ", _function); _builder.append(_join); _builder.append(">"); return _builder.toString(); }
Example 5
Source File: TypeReferenceImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Type getType() { Type _switchResult = null; LightweightTypeReference _delegate = this.getDelegate(); final LightweightTypeReference it = _delegate; boolean _matched = false; boolean _isUnknown = it.isUnknown(); if (_isUnknown) { _matched=true; CompilationUnitImpl _compilationUnit = this.getCompilationUnit(); String _packageName = this.getCompilationUnit().getPackageName(); String _plus = (_packageName + "."); String _simpleName = it.getSimpleName(); String _plus_1 = (_plus + _simpleName); _switchResult = new UnknownType(_compilationUnit, _plus_1); } if (!_matched) { _switchResult = this.getCompilationUnit().toType(it.getType()); } return _switchResult; }
Example 6
Source File: AbstractXbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getDefaultValueLiteral(XExpression expr) { LightweightTypeReference type = getTypeForVariableDeclaration(expr); if (type.isPrimitive()) { if (type.getPrimitiveKind() == Primitives.Primitive.Boolean) { return "false"; } else { return "(" + type.getSimpleName() + ") 0"; } } return "null"; }
Example 7
Source File: AbstractBatchReturnTypeTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public String getEquivalent(final ParameterizedTypeReference type) { StringConcatenation _builder = new StringConcatenation(); String _simpleName = type.getType().getSimpleName(); _builder.append(_simpleName); final Function1<LightweightTypeReference, CharSequence> _function = (LightweightTypeReference it) -> { return it.getSimpleName(); }; String _join = IterableExtensions.<LightweightTypeReference>join(type.getTypeArguments(), "<", ", ", ">", _function); _builder.append(_join); return _builder.toString(); }
Example 8
Source File: AbstractExpectationTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void recordExpectation(final XExpression expression, final ITypeComputationState state) { List<? extends ITypeExpectation> _expectations = state.getExpectations(); Iterables.<ITypeExpectation>addAll(this.finalExpectations, _expectations); final Function1<ITypeExpectation, String> _function = (ITypeExpectation it) -> { LightweightTypeReference _expectedType = it.getExpectedType(); String _simpleName = null; if (_expectedType!=null) { _simpleName=_expectedType.getSimpleName(); } return _simpleName; }; List<String> _map = ListExtensions.map(state.getExpectations(), _function); Iterables.<String>addAll(this.expectations, _map); this.expressions.add(expression); }
Example 9
Source File: CreateMemberQuickfixes.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.3 */ protected String getDefaultValueLiteral(/* @Nullable */ LightweightTypeReference type) { if (type != null && type.isPrimitive()) { Primitive primitiveKind = primitives.primitiveKind((JvmPrimitiveType) type.getType()); if (primitiveKind == Primitive.Boolean) return "false"; else return "0 as " + type.getSimpleName(); } return "null"; }
Example 10
Source File: AbstractSuperTypesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void assertSuperTypes(final Pair<String, String> type, final String... superTypes) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def "); { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(type.getValue()); boolean _not = (!_isNullOrEmpty); if (_not) { _builder.append("<"); String _value = type.getValue(); _builder.append(_value); _builder.append("> "); } } _builder.append("void method("); String _key = type.getKey(); _builder.append(_key); _builder.append(" type) {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); final LightweightTypeReference subtype = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()); final Function1<LightweightTypeReference, String> _function = (LightweightTypeReference it) -> { return it.getSimpleName(); }; Assert.assertEquals(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(superTypes))), IterableExtensions.<String>toList(IterableExtensions.<LightweightTypeReference, String>map(this.collectSuperTypes(subtype), _function))); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 11
Source File: ReplAutoEdit.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected String computeResultText(final IDocument document, final DocumentCommand command, XtextResource resource) throws BadLocationException { if (resource.getContents().isEmpty()) return null; if (!(resource.getContents().get(0) instanceof Model)) return null; Model model = (Model) resource.getContents().get(0); if (model.getBlock() == null) return null; EList<XExpression> expressions = model.getBlock().getExpressions(); if (expressions.isEmpty()) return null; XExpression expression = expressions.get(expressions.size() - 1); if (expression == null) { return null; } ICompositeNode node = NodeModelUtils.getNode(expression); if (node == null || document.getLineOfOffset(command.offset) + 1 != node.getEndLine()) return null; List<Issue> issues = validator.validate(resource, CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl); if (issues.stream().anyMatch(i -> i.getSeverity() == Severity.ERROR)) { return null; } XbaseInterpreter xbaseInterpreter = getConfiguredInterpreter(resource); IEvaluationResult result = xbaseInterpreter.evaluate(model.getBlock(), new DefaultEvaluationContext(), new CancelIndicator() { private long stopAt = System.currentTimeMillis() + 2000; @Override public boolean isCanceled() { return System.currentTimeMillis() > stopAt; } }); if (result == null) return null; String value = "" + result.getResult(); if (result.getException() != null) value = "threw " + result.getException().getClass().getSimpleName(); LightweightTypeReference expressionType = typeResolver.resolveTypes(expression).getActualType(expression); if (expressionType != null) { String newText = command.text + "// " + value + " (" + expressionType.getSimpleName() + ")" + command.text; return newText; } return command.text + "// " + value; }
Example 12
Source File: AbstractAssignabilityTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def "); { boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue()); boolean _not = (!_isNullOrEmpty); if (_not) { _builder.append("<"); String _value = lhsAndParams.getValue(); _builder.append(_value); _builder.append("> "); } } _builder.append("void method("); String _fixup = this.fixup(lhsAndParams.getKey()); _builder.append(_fixup); _builder.append(" lhs, "); String _fixup_1 = this.fixup(rhs); _builder.append(_fixup_1); _builder.append(" rhs) {}"); final String signature = _builder.toString(); final XtendFunction function = this.function(signature.toString()); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); LightweightTypeReference _xifexpression = null; String _key = lhsAndParams.getKey(); boolean _tripleNotEquals = (_key != null); if (_tripleNotEquals) { _xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType()); } else { _xifexpression = this.getOwner().newAnyTypeReference(); } final LightweightTypeReference lhsType = _xifexpression; LightweightTypeReference _xifexpression_1 = null; if ((rhs != null)) { _xifexpression_1 = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType()); } else { _xifexpression_1 = this.getOwner().newAnyTypeReference(); } final LightweightTypeReference rhsType = _xifexpression_1; String _simpleName = lhsType.getSimpleName(); String _plus = (_simpleName + " := "); String _simpleName_1 = rhsType.getSimpleName(); String _plus_1 = (_plus + _simpleName_1); Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(lhsType, rhsType))); if (expectation) { List<LightweightTypeReference> _allSuperTypes = lhsType.getAllSuperTypes(); for (final LightweightTypeReference superType : _allSuperTypes) { if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) { Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(superType, rhsType))); } } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }