use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method checkSuperTypes.
@Check
public void checkSuperTypes(AnonymousClass anonymousClass) {
JvmGenericType inferredType = associations.getInferredType(anonymousClass);
if (inferredType != null) {
JvmTypeReference superTypeRef = Iterables.getLast(inferredType.getSuperTypes());
JvmType superType = superTypeRef.getType();
if (superType instanceof JvmGenericType && ((JvmGenericType) superType).isFinal())
error("Attempt to override final class", anonymousClass.getConstructorCall(), XCONSTRUCTOR_CALL__CONSTRUCTOR, INSIGNIFICANT_INDEX, OVERRIDDEN_FINAL);
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method checkAnnotationTarget.
@Check
public void checkAnnotationTarget(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return;
}
Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
if (targets.isEmpty())
return;
final EObject eContainer = getContainingAnnotationTarget(annotation);
Class<? extends EObject> clazz = eContainer.getClass();
if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
clazz = XtendFunction.class;
}
for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
if (mapping.getKey().isAssignableFrom(clazz)) {
targets.retainAll(mapping.getValue());
if (targets.isEmpty()) {
error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET);
}
}
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method contributesToConflict.
/**
* Determine whether the given type contributes to the conflict caused by the given default interface implementation.
*/
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
}
RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
if (rootType.isInterface()) {
int contributingCount = 0;
for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
JvmType rawType = typeRef.getType();
if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
contributingCount++;
}
}
return contributingCount >= 2;
} else {
return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class XtendValidator method validateInferredType.
protected void validateInferredType(JvmTypeReference inferredType, XtendMember member, String messagePrefix, EAttribute location) {
if (inferredType != null) {
TreeIterator<EObject> iterator = EcoreUtil2.eAll(inferredType);
while (iterator.hasNext()) {
EObject next = iterator.next();
if (next instanceof JvmParameterizedTypeReference) {
JvmParameterizedTypeReference candidate = (JvmParameterizedTypeReference) next;
JvmType type = candidate.getType();
if (type instanceof JvmGenericType && !((JvmGenericType) type).getTypeParameters().isEmpty()) {
if (candidate.getArguments().isEmpty()) {
StringBuilder message = new StringBuilder(messagePrefix);
message = proxyAwareUIStrings.visit(inferredType, message);
if (message != null) {
message.append(" uses the raw type ");
message.append(type.getSimpleName());
message.append(". References to generic type ");
message = proxyAwareUIStrings.appendTypeSignature(type, message);
message.append(" should be parameterized");
warning(message.toString(), member, location, org.eclipse.xtext.xbase.validation.IssueCodes.RAW_TYPE);
}
return;
}
}
} else if (next instanceof XComputedTypeReference) {
validateInferredType(((XComputedTypeReference) next).getEquivalent(), member, messagePrefix, location);
iterator.prune();
}
}
}
}
use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.
the class Declarators method getDeclaratorData.
public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) {
Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY);
if ((result != null)) {
return result;
}
final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet();
final Consumer<URI> _function = (URI uri) -> {
final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> {
Object _xblockexpression = null;
{
final Consumer<URI> _function_2 = (URI objectURI) -> {
final EObject object = it.getEObject(objectURI, true);
if ((object != null)) {
final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class);
if ((type != null)) {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase();
declaratorNames.add(_lowerCase);
QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase();
declaratorNames.add(_lowerCase_1);
}
}
};
targetURIs.getEObjectURIs(uri).forEach(_function_2);
_xblockexpression = null;
}
return _xblockexpression;
};
resourceAccess.<Object>readOnly(uri, _function_1);
};
targetURIs.getTargetResourceURIs().forEach(_function);
Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames);
result = _declaratorsData;
targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result);
return result;
}
Aggregations