use of org.eclipse.ceylon.model.loader.mirror.VariableMirror in project ceylon by eclipse.
the class AbstractModelLoader method isEqualsMethod.
private boolean isEqualsMethod(MethodMirror methodMirror) {
if (!isNonGenericMethod(methodMirror) || methodMirror.isStatic())
return false;
String name = methodMirror.getName();
if (!"equals".equals(name) || methodMirror.getParameters().size() != 1)
return false;
VariableMirror param = methodMirror.getParameters().get(0);
return sameType(param.getType(), OBJECT_TYPE);
}
use of org.eclipse.ceylon.model.loader.mirror.VariableMirror in project ceylon by eclipse.
the class AbstractModelLoader method setParameters.
private void setParameters(Functional decl, ClassMirror classMirror, MethodMirror methodMirror, boolean isCeylon, Scope container, boolean isCoercedMethod) {
ParameterList parameters = new ParameterList();
parameters.setNamedParametersSupported(isCeylon);
decl.addParameterList(parameters);
int parameterCount = methodMirror.getParameters().size();
int parameterIndex = 0;
for (VariableMirror paramMirror : methodMirror.getParameters()) {
// ignore some parameters
if (paramMirror.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
continue;
boolean isLastParameter = parameterIndex == parameterCount - 1;
boolean isVariadic = isLastParameter && methodMirror.isVariadic();
String paramName = getAnnotationStringValue(paramMirror, CEYLON_NAME_ANNOTATION);
// use whatever param name we find as default
if (paramName == null)
paramName = paramMirror.getName();
Parameter parameter = new Parameter();
parameter.setName(paramName);
TypeMirror typeMirror = paramMirror.getType();
Scope scope = (Scope) decl;
Module module = ModelUtil.getModuleContainer(scope);
Type type;
boolean coercedParameter = false;
if (isVariadic) {
// possibly make it optional
TypeMirror variadicType = typeMirror.getComponentType();
// we pretend it's toplevel because we want to get magic string conversion for variadic methods
if (isCoercedMethod && isCoercedType(variadicType)) {
type = applyTypeCoercion(variadicType, paramMirror, methodMirror, paramName, (Declaration) decl, module, scope);
coercedParameter = true;
} else {
type = obtainType(module, variadicType, scope, TypeLocation.TOPLEVEL);
}
if (!isCeylon) {
// Java parameters are all optional unless primitives or annotated as such
if (getUncheckedNullPolicy(isCeylon, variadicType, paramMirror) != NullStatus.NonOptional) {
type = makeOptionalTypePreserveUnderlyingType(type, module);
}
}
// turn it into a Sequential<T>
type = typeFactory.getSequentialType(type);
} else {
if (isCoercedMethod && isCoercedType(typeMirror)) {
type = applyTypeCoercion(typeMirror, paramMirror, methodMirror, paramName, (Declaration) decl, module, scope);
coercedParameter = true;
} else {
type = obtainType(typeMirror, paramMirror, scope, module, "parameter '" + paramName + "' of method '" + methodMirror.getName() + "'", (Declaration) decl);
}
if (!isCeylon) {
// Java parameters are all optional unless primitives or annotated as such
if (getUncheckedNullPolicy(isCeylon, typeMirror, paramMirror) != NullStatus.NonOptional) {
type = makeOptionalTypePreserveUnderlyingType(type, module);
}
}
}
if (type.isCached()) {
type = type.clone();
}
if (!type.isRaw())
type.setRaw(isRaw(ModelUtil.getModuleContainer(container), typeMirror));
FunctionOrValue value = null;
boolean lookedup = false;
if (isCeylon && decl instanceof Class) {
// For a functional parameter to a class, we can just lookup the member
value = (FunctionOrValue) ((Class) decl).getDirectMember(paramName, null, false);
lookedup = value != null;
}
if (value == null) {
// So either decl is not a Class,
// or the method or value member of decl is not shared
AnnotationMirror functionalParameterAnnotation = paramMirror.getAnnotation(CEYLON_FUNCTIONAL_PARAMETER_ANNOTATION);
if (functionalParameterAnnotation != null) {
// A functional parameter to a method
Function method = loadFunctionalParameter((Declaration) decl, paramName, type, (String) functionalParameterAnnotation.getValue());
value = method;
parameter.setDeclaredAnything(method.isDeclaredVoid());
} else if (coercedParameter && isFunctionCercion(typeMirror)) {
Function method = loadFunctionCoercionParameter((Declaration) decl, paramName, typeMirror, module, scope);
value = method;
parameter.setDeclaredAnything(method.isDeclaredVoid());
} else {
// A value parameter to a method
value = isCeylon ? new Value() : new JavaParameterValue();
value.setType(type);
}
value.setContainer(scope);
value.setScope(scope);
ModelUtil.setVisibleScope(value);
value.setUnit(scope.getUnit());
value.setName(paramName);
} else {
// the method return type, so we try to detect this and fix it
if (value instanceof Function && isCeylon1Dot1(classMirror)) {
Type newType = getSimpleCallableReturnType(value.getType());
if (!newType.isUnknown())
value.setType(newType);
}
}
value.setInitializerParameter(parameter);
value.setCoercionPoint(coercedParameter);
parameter.setModel(value);
if (paramMirror.getAnnotation(CEYLON_SEQUENCED_ANNOTATION) != null || isVariadic)
parameter.setSequenced(true);
if (paramMirror.getAnnotation(CEYLON_DEFAULTED_ANNOTATION) != null)
parameter.setDefaulted(true);
if (parameter.isSequenced() && // FIXME: store info in Sequenced
"ceylon.language.Sequence".equals(paramMirror.getType().getQualifiedName())) {
parameter.setAtLeastOne(true);
}
// unboxed is already set if it's a real method
if (!lookedup) {
// if it's variadic, consider the array element type (T[] == T...) for boxing rules
markUnboxed(value, null, isVariadic ? paramMirror.getType().getComponentType() : paramMirror.getType());
markSmall(value, paramMirror.getType());
}
parameter.setDeclaration((Declaration) decl);
value.setDeprecated(value.isDeprecated() || isDeprecated(paramMirror));
setAnnotations(value, paramMirror, false);
parameters.getParameters().add(parameter);
if (!lookedup) {
parameter.getDeclaration().getMembers().add(parameter.getModel());
}
parameterIndex++;
}
if (decl instanceof Function) {
// Multiple parameter lists
AnnotationMirror functionalParameterAnnotation = methodMirror.getAnnotation(CEYLON_FUNCTIONAL_PARAMETER_ANNOTATION);
if (functionalParameterAnnotation != null) {
parameterNameParser.parseMpl((String) functionalParameterAnnotation.getValue(), ((Function) decl).getType().getFullType(), (Function) decl);
}
}
}
use of org.eclipse.ceylon.model.loader.mirror.VariableMirror in project ceylon by eclipse.
the class JavacMethod method getParameters.
@Override
public List<VariableMirror> getParameters() {
if (parameters == null) {
org.eclipse.ceylon.langtools.tools.javac.util.List<VarSymbol> params = methodSymbol.getParameters();
List<VariableMirror> ret = new ArrayList<VariableMirror>(params.size());
for (VarSymbol parameter : params) ret.add(new JavacVariable(parameter));
parameters = Collections.unmodifiableList(ret);
}
return parameters;
}
use of org.eclipse.ceylon.model.loader.mirror.VariableMirror in project ceylon by eclipse.
the class AbstractModelLoader method checkReifiedTypeDescriptors.
private boolean checkReifiedTypeDescriptors(int tpCount, String containerName, MethodMirror methodMirror, boolean isConstructor) {
List<VariableMirror> params = methodMirror.getParameters();
int actualTypeDescriptorParameters = 0;
for (VariableMirror param : params) {
if (param.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null && sameType(CEYLON_TYPE_DESCRIPTOR_TYPE, param.getType())) {
actualTypeDescriptorParameters++;
} else
break;
}
if (tpCount != actualTypeDescriptorParameters) {
if (isConstructor)
logError("Constructor for '" + containerName + "' should take " + tpCount + " reified type arguments (TypeDescriptor) but has '" + actualTypeDescriptorParameters + "': skipping constructor.");
else
logError("Function '" + containerName + "." + methodMirror.getName() + "' should take " + tpCount + " reified type arguments (TypeDescriptor) but has '" + actualTypeDescriptorParameters + "': method is invalid.");
return false;
}
return true;
}
use of org.eclipse.ceylon.model.loader.mirror.VariableMirror in project ceylon by eclipse.
the class AbstractModelLoader method propertiesMatch.
private boolean propertiesMatch(ClassOrInterface klass, MethodMirror getter, MethodMirror setter) {
// only add the setter if it has the same visibility as the getter
if (setter.isPublic() && getter.isPublic() || setter.isProtected() && getter.isProtected() || setter.isDefaultAccess() && getter.isDefaultAccess() || (!setter.isPublic() && !getter.isPublic() && !setter.isProtected() && !getter.isProtected() && !setter.isDefaultAccess() && !getter.isDefaultAccess())) {
Module module = ModelUtil.getModuleContainer(klass);
VariableMirror setterParam = setter.getParameters().get(0);
Type paramType = obtainType(setterParam.getType(), setterParam, klass, module, "setter '" + setter.getName() + "'", klass);
Type returnType = obtainType(getter.getReturnType(), getter, klass, module, "getter '" + getter.getName() + "'", klass);
// only add the setter if it has exactly the same type as the getter
if (paramType.isExactly(returnType)) {
return true;
}
}
return false;
}
Aggregations