use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method checkDefaultSuperConstructor.
@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
JvmGenericType inferredType = associations.getInferredType(xtendClass);
if (inferredType == null)
return;
Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
if (inferredType.getExtendedClass() != null) {
JvmType superType = inferredType.getExtendedClass().getType();
if (superType instanceof JvmGenericType) {
Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
for (JvmConstructor superConstructor : superConstructors) {
if (superConstructor.getParameters().isEmpty())
// there is a default super constructor. nothing more to check
return;
}
if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
List<String> issueData = newArrayList();
for (JvmConstructor superConstructor : superConstructors) {
issueData.add(EcoreUtil.getURI(superConstructor).toString());
issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
}
error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
} else {
for (JvmConstructor constructor : constructors) {
XExpression expression = containerProvider.getAssociatedExpression(constructor);
if (expression instanceof XBlockExpression) {
List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
EObject source = associations.getPrimarySourceElement(constructor);
error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
}
}
}
}
}
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method checkMemberNamesAreUnique.
@Check
public void checkMemberNamesAreUnique(XtendTypeDeclaration xtendType) {
final Multimap<String, XtendField> name2field = HashMultimap.create();
final Multimap<String, XtendTypeDeclaration> name2type = HashMultimap.create();
final Multimap<JvmType, XtendField> type2extension = HashMultimap.create();
for (XtendMember member : xtendType.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (isEmpty(field.getName())) {
if (field.isExtension()) {
JvmTypeReference typeReference = field.getType();
if (typeReference != null) {
JvmType type = typeReference.getType();
if (type != null)
type2extension.put(type, field);
}
}
} else {
name2field.put(field.getName(), field);
}
} else if (member instanceof XtendTypeDeclaration) {
String name = ((XtendTypeDeclaration) member).getName();
if (name != null && name.length() > 0) {
name2type.put(name, (XtendTypeDeclaration) member);
}
}
}
for (String name : name2field.keySet()) {
Collection<XtendField> fields = name2field.get(name);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate field " + name, field, XtendPackage.Literals.XTEND_FIELD__NAME, DUPLICATE_FIELD);
}
}
for (String name : name2type.keySet()) {
Collection<XtendTypeDeclaration> types = name2type.get(name);
if (types.size() > 1) {
for (XtendTypeDeclaration type : types) error("Duplicate nested type " + name, type, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, DUPLICATE_TYPE_NAME);
}
}
for (JvmType type : type2extension.keySet()) {
Collection<XtendField> fields = type2extension.get(type);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate extension with same type", field, XTEND_FIELD__TYPE, DUPLICATE_FIELD);
}
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendAnnotationReferenceImpl method getAnnotationTypeDeclaration.
@Override
public AnnotationTypeDeclaration getAnnotationTypeDeclaration() {
AnnotationTypeDeclaration _switchResult = null;
JvmType _annotationType = this.getAnnotationType();
final JvmType type = _annotationType;
boolean _matched = false;
if (type instanceof JvmAnnotationType) {
_matched = true;
TypeDeclaration _typeDeclaration = this.getCompilationUnit().toTypeDeclaration(((JvmDeclaredType) type));
_switchResult = ((AnnotationTypeDeclaration) _typeDeclaration);
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class AnnotationValidation method isValidAnnotationValueType.
public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
JvmTypeReference _switchResult = null;
boolean _matched = false;
if (reference instanceof JvmGenericArrayTypeReference) {
_matched = true;
_switchResult = ((JvmGenericArrayTypeReference) reference).getComponentType();
}
if (!_matched) {
_switchResult = reference;
}
final JvmTypeReference toCheck = _switchResult;
if ((toCheck == null)) {
return true;
}
JvmType _type = toCheck.getType();
if ((_type instanceof JvmPrimitiveType)) {
return true;
}
JvmType _type_1 = toCheck.getType();
if ((_type_1 instanceof JvmEnumerationType)) {
return true;
}
JvmType _type_2 = toCheck.getType();
if ((_type_2 instanceof JvmAnnotationType)) {
return true;
}
if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
return true;
}
return false;
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendHighlightingCalculator method highlightAnnotation.
@Override
protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType instanceof JvmAnnotationTarget) {
for (JvmAnnotationReference annotationReference : ((JvmAnnotationTarget) annotationType).getAnnotations()) {
JvmAnnotationType otherAnnotation = annotationReference.getAnnotation();
if (otherAnnotation != null && !otherAnnotation.eIsProxy() && Active.class.getName().equals(otherAnnotation.getIdentifier())) {
highlightAnnotation(annotation, acceptor, ACTIVE_ANNOTATION);
return;
}
}
}
super.highlightAnnotation(annotation, acceptor);
}
Aggregations