Search in sources :

Example 71 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class MethodDefinitionBuilder method implementsRawParameter.

private boolean implementsRawParameter(FunctionOrValue decl) {
    if (ModelUtil.containsRawType(decl.getType()))
        return true;
    // Taken pretty much straight from JvmBackendUtil.getTopmostRefinement
    Functional func = (Functional) JvmBackendUtil.getParameterized((FunctionOrValue) decl);
    if (func == null || func instanceof TypedDeclaration == false)
        return false;
    Declaration kk = getFirstRefinedDeclaration((TypedDeclaration) func);
    // error recovery
    if (kk instanceof Functional == false)
        return false;
    Functional refinedFunc = (Functional) kk;
    // shortcut if the functional doesn't override anything
    if (ModelUtil.equal((Declaration) refinedFunc, (Declaration) func)) {
        return false;
    }
    if (func.getParameterLists().size() != refinedFunc.getParameterLists().size()) {
        // invalid input
        return false;
    }
    for (int ii = 0; ii < func.getParameterLists().size(); ii++) {
        if (func.getParameterLists().get(ii).getParameters().size() != refinedFunc.getParameterLists().get(ii).getParameters().size()) {
            // invalid input
            return false;
        }
        // find the index of the parameter in the declaration
        int index = 0;
        for (Parameter px : func.getParameterLists().get(ii).getParameters()) {
            if (px.getModel() == null || px.getModel().equals(decl)) {
                // And return the corresponding parameter from the refined declaration
                FunctionOrValue refinedDecl = refinedFunc.getParameterLists().get(ii).getParameters().get(index).getModel();
                return implementsRawParameter(refinedDecl);
            }
            index++;
        }
        continue;
    }
    // invalid input
    return false;
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 72 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class MethodDefinitionBuilder method isParamTypeLocalToMethod.

private boolean isParamTypeLocalToMethod(Parameter parameter, Type nonWideningType) {
    // error recovery
    if (nonWideningType == null)
        return false;
    if (parameter.getModel().getTypeErased()) {
        return false;
    }
    // make sure we resolve aliases
    nonWideningType = nonWideningType.resolveAliases();
    Declaration method = parameter.getDeclaration();
    TypeDeclaration paramTypeDecl = nonWideningType.getDeclaration();
    if (paramTypeDecl instanceof TypeParameter && Decl.equalScopeDecl(paramTypeDecl.getContainer(), method)) {
        return false;
    }
    Scope scope = paramTypeDecl.getContainer();
    while (scope != null && !(scope instanceof Package)) {
        if (Decl.equalScopeDecl(scope, method)) {
            return true;
        }
        scope = scope.getContainer();
    }
    return false;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 73 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class Naming method makeDefaultedParamMethod.

JCExpression makeDefaultedParamMethod(JCExpression qualifier, Parameter param) {
    // TODO Can we merge this into makeName(..., NA_DPM) ?
    if (!Strategy.hasDefaultParameterValueMethod(param)) {
        throw new BugException();
    }
    Declaration decl = param.getDeclaration();
    String methodName = getDefaultedParamMethodName(decl, param);
    switch(Strategy.defaultParameterMethodOwner(param.getModel())) {
        case SELF:
            {
                // method not within interface
                Declaration container = param.getDeclaration().getRefinedDeclaration();
                if (!container.isToplevel()) {
                    container = (Declaration) container.getContainer();
                }
                JCExpression className = makeTypeDeclarationExpression(qualifier, (TypeDeclaration) container, DeclNameFlag.COMPANION);
                return makeSelect(className, methodName);
            }
        case OUTER:
        case OUTER_COMPANION:
            return makeQuotedQualIdent(qualifier, methodName);
        case STATIC:
            {
                // top level method or class
                // return makeSelect(gen().makeStaticQualifier(param.getDeclaration().getRefinedDeclaration()), methodName);
                Declaration container = param.getDeclaration().getRefinedDeclaration();
                if (!container.isToplevel() && !container.isStatic()) {
                    container = (Declaration) container.getContainer();
                } else if (container.isStatic() && container instanceof TypedDeclaration) {
                    container = (Declaration) container.getContainer();
                }
                if (container instanceof TypedDeclaration) {
                    return makeSelect(makeName((TypedDeclaration) container, NA_FQ | NA_WRAPPER), methodName);
                } else {
                    return makeSelect(gen().makeJavaType(((TypeDeclaration) container).getType(), AbstractTransformer.JT_RAW | AbstractTransformer.JT_NO_PRIMITIVES), methodName);
                }
            }
        default:
            // inner or local class or method, or method in an interface
            return makeQuotedQualIdent(qualifier, methodName);
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 74 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class Naming method appendTypeDeclaration.

private void appendTypeDeclaration(final TypeDeclaration decl, EnumSet<DeclNameFlag> flags, TypeDeclarationBuilder<?> typeDeclarationBuilder, Scope scope, final boolean last) {
    if (scope instanceof Class || scope instanceof TypeAlias || (scope instanceof Constructor && (scope.equals(decl) || !ModelUtil.isLocalNotInitializerScope(scope)))) {
        TypeDeclaration klass = (TypeDeclaration) scope;
        if (klass.isAnonymous() && !klass.isNamed())
            typeDeclarationBuilder.clear();
        String className = "";
        if (klass.getName() != null) {
            if (ModelUtil.isCeylonDeclaration(klass))
                className = escapeClassName(klass.getName());
            else
                className = getRealName(klass, NA_WRAPPER_UNQUOTED);
        }
        typeDeclarationBuilder.append(className);
        if (ModelUtil.isCeylonDeclaration(klass)) {
            if (flags.contains(DeclNameFlag.COMPANION) && ModelUtil.isLocalNotInitializer(klass) && last) {
                typeDeclarationBuilder.append(IMPL_POSTFIX);
            } else if (flags.contains(DeclNameFlag.ANNOTATION) && last) {
                typeDeclarationBuilder.append(ANNO_POSTFIX);
            } else if (flags.contains(DeclNameFlag.ANNOTATIONS) && last) {
                typeDeclarationBuilder.append(ANNOS_POSTFIX);
            } else if (flags.contains(DeclNameFlag.DELEGATION) && last) {
                typeDeclarationBuilder.append(DELEGATION_POSTFIX);
            }
        }
    } else if (scope instanceof Interface) {
        Interface iface = (Interface) scope;
        String className = "";
        if (iface.getName() != null) {
            if (ModelUtil.isCeylonDeclaration(iface))
                className = iface.getName();
            else
                className = getRealName(iface, NA_WRAPPER_UNQUOTED);
        }
        typeDeclarationBuilder.append(className);
        if (ModelUtil.isCeylonDeclaration(iface) && ((decl instanceof Class || decl instanceof Constructor || decl instanceof TypeAlias || scope instanceof Constructor) || flags.contains(DeclNameFlag.COMPANION))) {
            typeDeclarationBuilder.append(IMPL_POSTFIX);
        }
    } else if (ModelUtil.isLocalNotInitializerScope(scope)) {
        if (flags.contains(DeclNameFlag.COMPANION) || !(decl instanceof Interface)) {
            typeDeclarationBuilder.clear();
        } else if (flags.contains(DeclNameFlag.QUALIFIED) || (decl instanceof Interface)) {
            Scope nonLocal = scope;
            while (!(nonLocal instanceof Declaration)) {
                nonLocal = nonLocal.getContainer();
            }
            typeDeclarationBuilder.append(((Declaration) nonLocal).getPrefixedName());
            if (!Decl.equalScopes(scope, nonLocal)) {
                typeDeclarationBuilder.append('$');
                typeDeclarationBuilder.append(getLocalId(scope));
            }
            if (decl instanceof Interface) {
                typeDeclarationBuilder.append('$');
            } else {
                if (flags.contains(DeclNameFlag.QUALIFIED)) {
                    typeDeclarationBuilder.selectAppended();
                } else {
                    typeDeclarationBuilder.clear();
                }
            }
        }
        return;
    } else if (scope instanceof TypedDeclaration && ((Declaration) scope).isToplevel()) {
    // nothing? that's just weird
    }
    if (!last) {
        if (decl instanceof Interface && ModelUtil.isCeylonDeclaration((TypeDeclaration) decl) && !flags.contains(DeclNameFlag.COMPANION)) {
            typeDeclarationBuilder.append('$');
        } else if (decl instanceof Constructor && ((Class) decl.getContainer()).isMember() && decl.getContainer().equals(scope)) {
            typeDeclarationBuilder.append('$');
        } else {
            if (flags.contains(DeclNameFlag.QUALIFIED)) {
                typeDeclarationBuilder.selectAppended();
            } else {
                typeDeclarationBuilder.clear();
            }
        }
    } else {
        typeDeclarationBuilder.selectAppended();
    }
    return;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Example 75 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class CodegenUtil method isContainerFunctionalParameter.

public static boolean isContainerFunctionalParameter(Declaration declaration) {
    Scope containerScope = declaration.getContainer();
    Declaration containerDeclaration;
    if (containerScope instanceof Specification) {
        containerDeclaration = ((Specification) containerScope).getDeclaration();
    } else if (containerScope instanceof Declaration) {
        containerDeclaration = (Declaration) containerScope;
    } else {
        // probably invalid user code
        return false;
    }
    return containerDeclaration instanceof Function && ((Function) containerDeclaration).isParameter();
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Specification(org.eclipse.ceylon.model.typechecker.model.Specification) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)370 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)309 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)264 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)129 Type (org.eclipse.ceylon.model.typechecker.model.Type)100 Class (org.eclipse.ceylon.model.typechecker.model.Class)78 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)74 Value (org.eclipse.ceylon.model.typechecker.model.Value)73 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)72 Function (org.eclipse.ceylon.model.typechecker.model.Function)71 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)71 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)63 ArrayList (java.util.ArrayList)61 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)60 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)60 ModelUtil.getNativeDeclaration (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration)57 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)51 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)50 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)48 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)45