use of org.eclipse.xtext.common.types.JvmPrimitiveType in project xtext-xtend by eclipse.
the class XtendValidator method checkDispatchFunctions.
@Check
public void checkDispatchFunctions(XtendClass clazz) {
JvmGenericType type = associations.getInferredType(clazz);
if (type != null) {
Multimap<DispatchHelper.DispatchSignature, JvmOperation> dispatchMethods = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
checkDispatchNonDispatchConflict(clazz, dispatchMethods);
for (DispatchHelper.DispatchSignature signature : dispatchMethods.keySet()) {
Collection<JvmOperation> dispatchOperations = dispatchMethods.get(signature);
JvmOperation syntheticDispatchMethod = dispatchHelper.getDispatcherOperation(type, signature);
if (syntheticDispatchMethod != null) {
JvmOperation overriddenOperation = overrideHelper.findOverriddenOperation(syntheticDispatchMethod);
Boolean expectStatic = null;
if (overriddenOperation != null) {
if (isMorePrivateThan(syntheticDispatchMethod.getVisibility(), overriddenOperation.getVisibility())) {
String msg = "Synthetic dispatch method reduces visibility of overridden method " + overriddenOperation.getIdentifier();
addDispatchError(type, dispatchOperations, msg, null, OVERRIDE_REDUCES_VISIBILITY);
}
expectStatic = overriddenOperation.isStatic();
}
LightweightTypeReference dispatchMethodReturnType = getActualType(clazz, syntheticDispatchMethod);
if (dispatchOperations.size() == 1) {
JvmOperation singleOp = dispatchOperations.iterator().next();
XtendFunction function = associations.getXtendFunction(singleOp);
addIssue("Single dispatch method.", function, XTEND_MEMBER__MODIFIERS, function.getModifiers().indexOf("dispatch"), SINGLE_DISPATCH_FUNCTION);
} else {
Multimap<List<JvmType>, JvmOperation> signatures = HashMultimap.create();
boolean[] allPrimitive = new boolean[signature.getArity()];
Arrays.fill(allPrimitive, true);
boolean isFirstLocalOperation = true;
JvmVisibility commonVisibility = null;
Boolean commonStatic = null;
for (JvmOperation jvmOperation : dispatchOperations) {
signatures.put(getParamTypes(jvmOperation, true), jvmOperation);
for (int i = 0; i < jvmOperation.getParameters().size(); i++) {
JvmFormalParameter parameter = jvmOperation.getParameters().get(i);
if (!(parameter.getParameterType().getType() instanceof JvmPrimitiveType)) {
allPrimitive[i] = false;
}
}
if (jvmOperation.getDeclaringType() == type) {
if (expectStatic != null) {
if (expectStatic && !jvmOperation.isStatic()) {
String msg = "The dispatch method must be static because the dispatch methods in the superclass are static.";
addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_STATIC_EXPECTED);
}
if (!expectStatic && jvmOperation.isStatic()) {
String msg = "The dispatch method must not be static because the dispatch methods in the superclass are not static.";
addDispatchError(jvmOperation, msg, "static", DISPATCH_FUNCTIONS_NON_STATIC_EXPECTED);
}
}
if (isFirstLocalOperation) {
commonVisibility = jvmOperation.getVisibility();
commonStatic = jvmOperation.isStatic();
isFirstLocalOperation = false;
} else {
if (jvmOperation.getVisibility() != commonVisibility) {
commonVisibility = null;
}
if (commonStatic != null && commonStatic != jvmOperation.isStatic()) {
commonStatic = null;
}
}
// TODO move validation to type computation
if (dispatchMethodReturnType != null) {
XtendFunction function = associations.getXtendFunction(jvmOperation);
if (function != null) {
LightweightTypeReference operationType = getActualType(function.getExpression(), jvmOperation);
if (!dispatchMethodReturnType.isAssignableFrom(operationType)) {
error("Incompatible return type of dispatch method. Expected " + dispatchMethodReturnType.getHumanReadableName() + " but was " + operationType.getHumanReadableName(), function, XtendPackage.Literals.XTEND_FUNCTION__RETURN_TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_RETURN_TYPE);
}
}
}
}
}
if (commonVisibility == null) {
addDispatchError(type, dispatchOperations, "All local dispatch methods must have the same visibility.", null, DISPATCH_FUNCTIONS_WITH_DIFFERENT_VISIBILITY);
}
if (expectStatic == null && commonStatic == null) {
addDispatchError(type, dispatchOperations, "Static and non-static dispatch methods can not be mixed.", "static", DISPATCH_FUNCTIONS_MIXED_STATIC_AND_NON_STATIC);
}
for (final List<JvmType> paramTypes : signatures.keySet()) {
Collection<JvmOperation> ops = signatures.get(paramTypes);
if (ops.size() > 1) {
if (Iterables.any(ops, new Predicate<JvmOperation>() {
@Override
public boolean apply(JvmOperation input) {
return !getParamTypes(input, false).equals(paramTypes);
}
})) {
for (JvmOperation jvmOperation : ops) {
XtendFunction function = associations.getXtendFunction(jvmOperation);
error("Duplicate dispatch methods. Primitives cannot overload their wrapper types in dispatch methods.", function, null, DUPLICATE_METHOD);
}
}
}
}
for (int i = 0; i < allPrimitive.length; i++) {
if (allPrimitive[i]) {
Iterator<JvmOperation> operationIter = dispatchOperations.iterator();
JvmType paramType1 = operationIter.next().getParameters().get(i).getParameterType().getType();
while (operationIter.hasNext()) {
JvmType paramType2 = operationIter.next().getParameters().get(i).getParameterType().getType();
if (!paramType2.equals(paramType1)) {
for (JvmOperation jvmOperation : dispatchOperations) {
XtendFunction function = associations.getXtendFunction(jvmOperation);
addIssue("Dispatch methods have arguments with different primitive types.", function, XTEND_EXECUTABLE__PARAMETERS, i, DISPATCH_FUNCTIONS_DIFFERENT_PRIMITIVE_ARGS);
}
break;
}
}
}
}
}
}
}
}
}
use of org.eclipse.xtext.common.types.JvmPrimitiveType 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.JvmPrimitiveType in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toType.
public Type toType(final JvmType delegate) {
final Function1<JvmType, Type> _function = (JvmType it) -> {
Type _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmDeclaredType) {
_matched = true;
_switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
}
if (!_matched) {
if (delegate instanceof JvmTypeParameter) {
_matched = true;
_switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter) delegate));
}
}
if (!_matched) {
if (delegate instanceof JvmVoid) {
_matched = true;
VoidTypeImpl _voidTypeImpl = new VoidTypeImpl();
final Procedure1<VoidTypeImpl> _function_1 = (VoidTypeImpl it_1) -> {
it_1.setDelegate(((JvmVoid) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<VoidTypeImpl>operator_doubleArrow(_voidTypeImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof JvmPrimitiveType) {
_matched = true;
PrimitiveTypeImpl _primitiveTypeImpl = new PrimitiveTypeImpl();
final Procedure1<PrimitiveTypeImpl> _function_1 = (PrimitiveTypeImpl it_1) -> {
it_1.setDelegate(((JvmPrimitiveType) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<PrimitiveTypeImpl>operator_doubleArrow(_primitiveTypeImpl, _function_1);
}
}
return _switchResult;
};
return this.<JvmType, Type>getOrCreate(delegate, _function);
}
Aggregations