use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method hasCycleInHierarchy.
protected boolean hasCycleInHierarchy(JvmGenericType type, Set<JvmGenericType> processedSuperTypes) {
JvmDeclaredType container = type;
do {
if (processedSuperTypes.contains(container))
return true;
container = container.getDeclaringType();
} while (container != null);
processedSuperTypes.add(type);
for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
if (superTypeRef.getType() instanceof JvmGenericType) {
if (hasCycleInHierarchy((JvmGenericType) superTypeRef.getType(), processedSuperTypes))
return true;
}
}
processedSuperTypes.remove(type);
return false;
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkExceptions.
private void checkExceptions(EObject context, List<JvmTypeReference> exceptions, EReference reference) {
Set<String> declaredExceptionNames = Sets.newHashSet();
JvmTypeReference throwableType = getServices().getTypeReferences().getTypeForName(Throwable.class, context);
if (throwableType == null) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), context);
LightweightTypeReference throwableReference = owner.toLightweightTypeReference(throwableType);
for (int i = 0; i < exceptions.size(); i++) {
JvmTypeReference exception = exceptions.get(i);
// throwables may not carry generics thus the raw comparison is sufficient
if (exception.getType() != null && !exception.getType().eIsProxy()) {
if (!throwableReference.isAssignableFrom(exception.getType()))
error("No exception of type " + exception.getSimpleName() + " can be thrown; an exception type must be a subclass of Throwable", reference, i, EXCEPTION_NOT_THROWABLE);
if (!declaredExceptionNames.add(exception.getQualifiedName()))
error("Exception " + exception.getSimpleName() + " is declared twice", reference, i, EXCEPTION_DECLARED_TWICE);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendGenerator method compileLocalTypeStubs.
public void compileLocalTypeStubs(final JvmFeature feature, final ITreeAppendable appendable, final GeneratorConfig config) {
final Function1<JvmGenericType, Boolean> _function = (JvmGenericType it) -> {
boolean _isAnonymous = it.isAnonymous();
return Boolean.valueOf((!_isAnonymous));
};
final Consumer<JvmGenericType> _function_1 = (JvmGenericType it) -> {
appendable.newLine();
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
final ITreeAppendable childAppendable = appendable.trace(anonymousClass);
childAppendable.append("abstract class ");
this._treeAppendableUtil.traceSignificant(childAppendable, anonymousClass).append(it.getSimpleName());
boolean _isEmpty = it.getTypeParameters().isEmpty();
if (_isEmpty) {
childAppendable.append(" ");
}
this.generateExtendsClause(it, childAppendable, null);
childAppendable.append("{").increaseIndentation();
boolean _needSyntheticThisVariable = this.needSyntheticThisVariable(anonymousClass, it);
if (_needSyntheticThisVariable) {
Pair<String, JvmGenericType> _mappedTo = Pair.<String, JvmGenericType>of("this", it);
String _simpleName = it.getSimpleName();
String _plus = ("_this" + _simpleName);
final String thisName = childAppendable.declareSyntheticVariable(_mappedTo, _plus);
childAppendable.newLine().append("final ").append(it.getSimpleName()).append(" ").append(thisName).append(" = this;").newLine();
}
final Procedure1<LoopParams> _function_2 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_3 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_3);
};
final Procedure1<JvmMember> _function_3 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(childAppendable, it_1);
memberAppendable.openScope();
if ((it_1 instanceof JvmOperation)) {
final ITreeAppendable tracedAppendable = childAppendable.trace(it_1);
tracedAppendable.newLine();
this.generateJavaDoc(it_1, tracedAppendable, config);
this.generateVisibilityModifier(it_1, tracedAppendable);
tracedAppendable.append("abstract ");
this.generateTypeParameterDeclaration(((JvmTypeParameterDeclarator) it_1), tracedAppendable, null);
JvmTypeReference _returnType = ((JvmOperation) it_1).getReturnType();
boolean _tripleEquals = (_returnType == null);
if (_tripleEquals) {
tracedAppendable.append("void");
} else {
this._errorSafeExtensions.serializeSafely(((JvmOperation) it_1).getReturnType(), "Object", tracedAppendable);
}
tracedAppendable.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(((JvmOperation) it_1).getSimpleName());
tracedAppendable.append("(");
this.generateParameters(((JvmExecutable) it_1), tracedAppendable, null);
tracedAppendable.append(")");
this.generateThrowsClause(((JvmExecutable) it_1), tracedAppendable, null);
tracedAppendable.append(";");
} else {
if ((it_1 instanceof JvmField)) {
final ITreeAppendable tracedAppendable_1 = childAppendable.trace(it_1);
tracedAppendable_1.newLine();
this.generateJavaDoc(it_1, tracedAppendable_1, config);
this.generateAnnotations(((JvmField) it_1).getAnnotations(), tracedAppendable_1, true, config);
if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
tracedAppendable_1.append("final ");
}
boolean _isStatic = ((JvmField) it_1).isStatic();
if (_isStatic) {
tracedAppendable_1.append("static ");
}
boolean _isTransient = ((JvmField) it_1).isTransient();
if (_isTransient) {
tracedAppendable_1.append("transient ");
}
boolean _isVolatile = ((JvmField) it_1).isVolatile();
if (_isVolatile) {
tracedAppendable_1.append("volatile ");
}
this._errorSafeExtensions.serializeSafely(((JvmField) it_1).getType(), "Object", tracedAppendable_1);
tracedAppendable_1.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable_1, it_1).append(((JvmField) it_1).getSimpleName());
if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
Object _constantValue = ((JvmField) it_1).getConstantValue();
boolean _tripleNotEquals = (_constantValue != null);
if (_tripleNotEquals) {
tracedAppendable_1.append(" = ");
this.generateJavaConstant(((JvmField) it_1).getConstantValue(), tracedAppendable_1);
} else {
this.generateInitialization(((JvmField) it_1), tracedAppendable_1, config);
}
}
tracedAppendable_1.append(";");
} else {
this.generateMember(it_1, memberAppendable, config);
}
}
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(childAppendable, this.getAddedDeclarations(it, anonymousClass), _function_2, _function_3);
childAppendable.decreaseIndentation().newLine().append("}");
appendable.newLine();
};
IterableExtensions.<JvmGenericType>filter(feature.getLocalClasses(), _function).forEach(_function_1);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendFormatter method _format.
protected void _format(final XtendParameter param, @Extension final IFormattableDocument format) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.append(this.textRegionExtensions.regionFor(param).keyword("extension"), _function);
this.formatAnnotations(param, format, XbaseFormatterPreferenceKeys.newLineAfterParameterAnnotations);
format.<JvmTypeReference>format(param.getParameterType());
final ISemanticRegion nameNode = this.textRegionExtensions.regionFor(param).feature(XtendPackage.Literals.XTEND_PARAMETER__NAME);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.prepend(nameNode, _function_1);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class AnonymousClassUtil method isSameSignature.
protected boolean isSameSignature(JvmConstructor constructor, JvmConstructor superConstructor) {
if (constructor.getParameters().size() != superConstructor.getParameters().size())
return false;
for (int i = 0; i < constructor.getParameters().size(); ++i) {
JvmTypeReference paramType = constructor.getParameters().get(i).getParameterType();
JvmTypeReference superParamType = superConstructor.getParameters().get(i).getParameterType();
if (!paramType.getIdentifier().equals(superParamType.getIdentifier()))
return false;
}
return true;
}
Aggregations