use of org.eclipse.ceylon.model.loader.mirror.MethodMirror in project ceylon by eclipse.
the class AnnotationLoader method loadAnnotationConstructorDefaultedParameter.
private AnnotationTerm loadAnnotationConstructorDefaultedParameter(LazyFunction method, MethodMirror meth, Parameter ctorParam, AnnotationConstructorParameter acp) {
// Find the method mirror for the DPM
for (MethodMirror mm : method.classMirror.getDirectMethods()) {
if (mm.getName().equals(Naming.getDefaultedParamMethodName(method, ctorParam))) {
// Create the appropriate AnnotationTerm
if (mm.getAnnotation(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION) != null) {
// If the DPM has a @AnnotationInstantiation
// then it must be an invocation term so recurse
InvocationAnnotationTerm invocationTerm = new InvocationAnnotationTerm();
invocationTerm.setInstantiation(loadAnnotationInvocation(method, mm, meth));
return invocationTerm;
} else {
return loadLiteralAnnotationTerm(method, ctorParam, mm);
}
}
}
return null;
}
use of org.eclipse.ceylon.model.loader.mirror.MethodMirror in project ceylon by eclipse.
the class JavacClass method getDirectMethods.
@Override
public List<MethodMirror> getDirectMethods() {
if (methods == null) {
List<MethodMirror> ret = new LinkedList<MethodMirror>();
for (Symbol sym : classSymbol.getEnclosedElements()) {
if (sym instanceof MethodSymbol && (sym.flags() & Flags.PRIVATE) == 0) {
ret.add(new JavacMethod(this, (MethodSymbol) sym));
}
}
methods = Collections.unmodifiableList(ret);
}
return methods;
}
use of org.eclipse.ceylon.model.loader.mirror.MethodMirror in project ceylon by eclipse.
the class AbstractModelLoader method setSealedFromConstructorMods.
private void setSealedFromConstructorMods(Declaration decl, final List<MethodMirror> constructors) {
boolean effectivelySealed = true;
for (MethodMirror ctor : constructors) {
if (ctor.isPublic() || ctor.isProtected()) {
effectivelySealed = false;
break;
}
}
if (effectivelySealed && decl instanceof Class) {
Class type = (Class) decl;
type.setSealed(effectivelySealed);
if (type.getOverloads() != null) {
for (Declaration oload : type.getOverloads()) {
((Class) oload).setSealed(effectivelySealed);
}
}
}
}
use of org.eclipse.ceylon.model.loader.mirror.MethodMirror in project ceylon by eclipse.
the class AbstractModelLoader method markVariable.
private void markVariable(LazyValue value) {
String setterName = NamingBase.getSetterName(value);
boolean toplevel = value.isToplevel();
for (MethodMirror m : value.classMirror.getDirectMethods()) {
// Do not skip members marked with @Ignore, because the getter is supposed to be ignored
if (m.getName().equals(setterName) && (!toplevel || m.isStatic()) && m.getParameters().size() == 1) {
value.setVariable(true);
}
}
}
use of org.eclipse.ceylon.model.loader.mirror.MethodMirror in project ceylon by eclipse.
the class AbstractModelLoader method loadFunctionCoercionParameter.
@SuppressWarnings("incomplete-switch")
private Function loadFunctionCoercionParameter(Declaration decl, String paramName, TypeMirror typeMirror, Module moduleScope, Scope scope) {
Function method = new Function();
method.setName(paramName);
method.setUnit(decl.getUnit());
try {
FunctionalInterfaceType functionalInterfaceType = getFunctionalInterfaceType(typeMirror);
MethodMirror functionalMethod = functionalInterfaceType.getMethod();
Type returnType = obtainType(moduleScope, functionalInterfaceType.getReturnType(), scope, TypeLocation.TOPLEVEL);
switch(getUncheckedNullPolicy(false, functionalInterfaceType.getReturnType(), functionalMethod)) {
case Optional:
case UncheckedNull:
returnType = makeOptionalTypePreserveUnderlyingType(returnType, moduleScope);
break;
}
method.setType(returnType);
ParameterList pl = new ParameterList();
// List<VariableMirror> functionalParameters = functionalMethod.getParameters();
List<TypeMirror> parameterTypes = functionalInterfaceType.getParameterTypes();
Map<String, Integer> used = new HashMap<String, Integer>();
for (TypeMirror parameterType : parameterTypes) {
String name;
if (parameterTypes.size() == 1) {
name = "it";
} else {
switch(parameterType.getKind()) {
case ARRAY:
name = "array";
break;
case BOOLEAN:
name = "boolean";
break;
case CHAR:
name = "character";
break;
case BYTE:
name = "byte";
break;
case INT:
case LONG:
case SHORT:
name = "integer";
break;
case FLOAT:
case DOUBLE:
name = "float";
break;
case DECLARED:
String typeName = parameterType.getDeclaredClass().getName();
int first = typeName.codePointAt(0);
name = String.valueOf(Character.toChars(Character.toLowerCase(first))) + typeName.substring(Character.charCount(first));
break;
default:
name = "arg";
}
Integer count = used.get(name);
if (count == null) {
used.put(name, 1);
} else {
int next = count + 1;
used.put(name, next);
name += next;
}
}
Type modelParameterType = obtainType(moduleScope, parameterType, scope, TypeLocation.TOPLEVEL);
Parameter p = new Parameter();
Value v = new Value();
p.setName(name);
v.setName(name);
v.setContainer(method);
v.setScope(method);
p.setModel(v);
v.setInitializerParameter(p);
// Java parameters are all optional unless primitives or annotated as such
switch(getUncheckedNullPolicy(false, parameterType, functionalMethod)) {
case Optional:
modelParameterType = makeOptionalTypePreserveUnderlyingType(modelParameterType, moduleScope);
break;
case UncheckedNull:
v.setUncheckedNullType(true);
break;
}
v.setType(modelParameterType);
pl.getParameters().add(p);
method.addMember(v);
}
method.addParameterList(pl);
} catch (ModelResolutionException x) {
method.setType(logModelResolutionException(x, scope, "Failure to turn functional interface to Callable type"));
}
return method;
}
Aggregations