public MethodDefinitionBuilder resultType(Method method, int flags) { if (Decl.isMpl(method)) { // Create a String with the TypeInfo StringBuilder sb = new StringBuilder(); // It's a bunch of nested callables (# of param lists - 1) for (int i = 1; i < method.getParameterLists().size(); i++) { sb.append("ceylon.language::Callable<"); } // Then the return type as defined originally sb.append(method.getType().getProducedTypeQualifiedName()); // And then the parameter types of each nested callable for (int i = method.getParameterLists().size() - 1; i > 0; i--) { ParameterList plist = method.getParameterLists().get(i); for (Parameter p : plist.getParameters()) { sb.append(','); sb.append(p.getType().getProducedTypeQualifiedName()); } sb.append('>'); } return resultType( gen.makeAtType(sb.toString(), false), gen.makeJavaType(gen.functionalReturnType(method), flags)); } else { ProducedTypedReference typedRef = gen.getTypedReference(method); ProducedTypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef); ProducedType nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef); return resultType( makeResultType(nonWideningTypedRef.getDeclaration(), nonWideningType, flags), method); } }
@Override public void visit(Tree.BaseMemberExpression bme) { if (annotationConstructor != null) { Declaration declaration = bme.getDeclaration(); if (checkingInvocationPrimary && isAnnotationConstructor(bme.getDeclaration())) { Method ctor = (Method) bme.getDeclaration(); instantiation.setPrimary(ctor); if (ctor.getAnnotationConstructor() != null) { instantiation .getConstructorParameters() .addAll( ((AnnotationInvocation) ctor.getAnnotationConstructor()) .getConstructorParameters()); } } else if (checkingArguments || checkingDefaults) { if (declaration instanceof Value && ((Value) declaration).isParameter()) { Value constructorParameter = (Value) declaration; ParameterAnnotationTerm a = new ParameterAnnotationTerm(); a.setSpread(spread); // XXX Is this right? a.setSourceParameter(constructorParameter.getInitializerParameter()); this.term = a; } else if (isBooleanTrue(declaration)) { LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(true); appendLiteralArgument(bme, argument); } else if (isBooleanFalse(declaration)) { LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(false); appendLiteralArgument(bme, argument); } else if (bme.getUnit().isEmptyType(bme.getTypeModel()) && bme.getUnit().isIterableType(bme.getTypeModel()) && elements == null) { // If we're dealing with an iterable, empty means empty collection, not object endCollection(startCollection(bme), bme); } else if (Decl.isAnonCaseOfEnumeratedType(bme)) { LiteralAnnotationTerm argument = new ObjectLiteralAnnotationTerm(bme.getTypeModel()); appendLiteralArgument(bme, argument); } else { bme.addError( "compiler bug: unsupported base member expression in annotation constructor"); } } else { bme.addError("compiler bug: unsupported base member expression in annotation constructor"); } } }
private void writeTypeParameters(Method m) throws IOException { List<TypeParameter> typeParameters = m.getTypeParameters(); if (!typeParameters.isEmpty()) { write("<"); boolean first = true; for (TypeParameter type : typeParameters) { if (first) first = false; else write(", "); write(type.getName()); } write(">"); } }
public void defaultedParameter(Tree.SpecifierOrInitializerExpression d) { if (annotationConstructor != null) { AnnotationConstructorParameter annotationConstructorParameter = instantiation .getConstructorParameters() .get(instantiation.getConstructorParameters().size() - 1); Declaration t = d.getUnit().getTrueValueDeclaration(); Declaration f = d.getUnit().getFalseValueDeclaration(); Term term = d.getExpression().getTerm(); if (term instanceof Tree.InvocationExpression) { Tree.Primary primary = ((Tree.InvocationExpression) term).getPrimary(); if (primary instanceof Tree.BaseMemberOrTypeExpression && (isAnnotationConstructor( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration()) || isAnnotationClass( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration()))) { final AnnotationInvocation prevInstantiation = this.instantiation; this.instantiation = new AnnotationInvocation(); if (isAnnotationConstructor( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration())) { Method constructor = (Method) ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration(); instantiation.setConstructorDeclaration(constructor); instantiation .getConstructorParameters() .addAll( ((AnnotationInvocation) constructor.getAnnotationConstructor()) .getConstructorParameters()); } checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; this.instantiation = prevInstantiation; } else { errorDefaultedParameter(d); } } else if (term instanceof Tree.Literal || (term instanceof Tree.BaseMemberExpression && (((Tree.BaseMemberExpression) term).getDeclaration().equals(t) || ((Tree.BaseMemberExpression) term).getDeclaration().equals(f) || ((Tree.BaseMemberExpression) term).getDeclaration().isParameter() || Decl.isAnonCaseOfEnumeratedType((Tree.BaseMemberExpression) term)))) { checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; } else if (term instanceof Tree.Tuple || term instanceof Tree.SequenceEnumeration) { // TODO Tuples and SequenceEnumerations of the above cases should also be allowed checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; } else { errorDefaultedParameter(d); } } }