From 3262e2b58e5e0c77c40121b2a42d866cd9702f3c Mon Sep 17 00:00:00 2001 From: Tom Bentley Date: Tue, 29 May 2012 12:40:37 +0100 Subject: [PATCH] Refactor AbstractTransformer: Make public and proected things package access; make some procted members private --- .../java/codegen/AbstractTransformer.java | 255 +++++++++--------- .../java/codegen/ClassTransformer.java | 2 +- 2 files changed, 131 insertions(+), 126 deletions(-) diff --git a/src/com/redhat/ceylon/compiler/java/codegen/AbstractTransformer.java b/src/com/redhat/ceylon/compiler/java/codegen/AbstractTransformer.java index ae7b1e9e3..f0a868cb6 100755 --- a/src/com/redhat/ceylon/compiler/java/codegen/AbstractTransformer.java +++ b/src/com/redhat/ceylon/compiler/java/codegen/AbstractTransformer.java @@ -111,7 +111,7 @@ public AbstractTransformer(Context context) { log = CeylonLog.instance(context); } - public Context getContext() { + Context getContext() { return context; } @@ -164,11 +164,11 @@ public TypeFactory typeFact() { return typeFact; } - public void setMap(LineMap map) { + void setMap(LineMap map) { gen().setMap(map); } - protected LineMap getMap() { + LineMap getMap() { return gen().getMap(); } @@ -197,7 +197,7 @@ public ClassTransformer classGen() { * @param ident The identifier * @return The ident */ - protected JCExpression makeUnquotedIdent(String ident) { + JCExpression makeUnquotedIdent(String ident) { return make().Ident(names().fromString(ident)); } @@ -206,7 +206,7 @@ protected JCExpression makeUnquotedIdent(String ident) { * @param ident The identifier * @return The ident */ - protected JCIdent makeQuotedIdent(String ident) { + JCIdent makeQuotedIdent(String ident) { return make().Ident(names().fromString(Util.quoteIfJavaKeyword(ident))); } @@ -216,7 +216,7 @@ protected JCIdent makeQuotedIdent(String ident) { * quoted if it is a Java keyword. * @param qualifiedName The qualified name */ - protected JCExpression makeQuotedQualIdentFromString(String qualifiedName) { + JCExpression makeQuotedQualIdentFromString(String qualifiedName) { return makeQualIdent(null, Util.quoteJavaKeywords(qualifiedName.split("\\."))); } @@ -226,7 +226,7 @@ protected JCExpression makeQuotedQualIdentFromString(String qualifiedName) { * @param components The components of the name. * @see #makeQuotedQualIdentFromString(String) */ - protected JCExpression makeQualIdent(Iterable components) { + JCExpression makeQualIdent(Iterable components) { JCExpression type = null; for (String component : components) { if (type == null) @@ -237,7 +237,7 @@ protected JCExpression makeQualIdent(Iterable components) { return type; } - protected JCExpression makeQuotedQualIdent(Iterable components) { + JCExpression makeQuotedQualIdent(Iterable components) { JCExpression type = null; for (String component : components) { if (type == null) @@ -255,7 +255,7 @@ protected JCExpression makeQuotedQualIdent(Iterable components) { * @param names The components of the name (may be null) * @see #makeQuotedQualIdentFromString(String) */ - protected JCExpression makeQualIdent(JCExpression expr, String... names) { + JCExpression makeQualIdent(JCExpression expr, String... names) { if (names != null) { for (String component : names) { if (component != null) { @@ -270,7 +270,7 @@ protected JCExpression makeQualIdent(JCExpression expr, String... names) { return expr; } - protected JCExpression makeQuotedQualIdent(JCExpression expr, String... names) { + JCExpression makeQuotedQualIdent(JCExpression expr, String... names) { if (names != null) { for (String component : names) { if (component != null) { @@ -285,19 +285,19 @@ protected JCExpression makeQuotedQualIdent(JCExpression expr, String... names) { return expr; } - protected JCExpression makeFQIdent(String... components) { + JCExpression makeFQIdent(String... components) { return makeQualIdent(makeUnquotedIdent(""), components); } - protected JCExpression makeQuotedFQIdent(String... components) { + JCExpression makeQuotedFQIdent(String... components) { return makeQuotedQualIdent(makeUnquotedIdent(""), components); } - protected JCExpression makeQuotedFQIdent(String qualifiedName) { + JCExpression makeQuotedFQIdent(String qualifiedName) { return makeQuotedFQIdent(Util.quoteJavaKeywords(qualifiedName.split("\\."))); } - protected JCExpression makeIdent(Type type) { + JCExpression makeIdent(Type type) { return make().QualIdent(type.tsym); } @@ -307,7 +307,7 @@ protected JCExpression makeIdent(Type type) { * @param s2 The field to access * @return The field access */ - protected JCFieldAccess makeSelect(JCExpression s1, String s2) { + JCFieldAccess makeSelect(JCExpression s1, String s2) { return make().Select(s1, names().fromString(s2)); } @@ -317,7 +317,7 @@ protected JCFieldAccess makeSelect(JCExpression s1, String s2) { * @param s2 The field to access * @return The field access */ - protected JCFieldAccess makeSelect(String s1, String s2) { + JCFieldAccess makeSelect(String s1, String s2) { return makeSelect(makeUnquotedIdent(s1), s2); } @@ -328,11 +328,11 @@ protected JCFieldAccess makeSelect(String s1, String s2) { * @param rest The remaining fields to access * @return The field access */ - protected JCFieldAccess makeSelect(String s1, String s2, String... rest) { + JCFieldAccess makeSelect(String s1, String s2, String... rest) { return makeSelect(makeSelect(s1, s2), rest); } - private JCFieldAccess makeSelect(JCFieldAccess s1, String[] rest) { + JCFieldAccess makeSelect(JCFieldAccess s1, String[] rest) { JCFieldAccess acc = s1; for (String s : rest) { acc = makeSelect(acc, s); @@ -340,19 +340,19 @@ private JCFieldAccess makeSelect(JCFieldAccess s1, String[] rest) { return acc; } - protected JCLiteral makeNull() { + JCLiteral makeNull() { return make().Literal(TypeTags.BOT, null); } - protected JCExpression makeInteger(int i) { + JCExpression makeInteger(int i) { return make().Literal(Integer.valueOf(i)); } - protected JCExpression makeLong(long i) { + JCExpression makeLong(long i) { return make().Literal(Long.valueOf(i)); } - protected JCExpression makeBoolean(boolean b) { + JCExpression makeBoolean(boolean b) { JCExpression expr; if (b) { expr = make().Literal(TypeTags.BOOLEAN, Integer.valueOf(1)); @@ -363,7 +363,7 @@ protected JCExpression makeBoolean(boolean b) { } // Creates a "foo foo = new foo();" - protected JCTree.JCVariableDecl makeLocalIdentityInstance(String varName, String className, boolean isShared) { + JCTree.JCVariableDecl makeLocalIdentityInstance(String varName, String className, boolean isShared) { JCExpression name = makeQuotedIdent(className); JCExpression initValue = makeNewClass(className, false); @@ -378,42 +378,42 @@ protected JCTree.JCVariableDecl makeLocalIdentityInstance(String varName, String return var; } - protected JCTree.JCVariableDecl makeLocalIdentityInstance(String varName, boolean isShared) { + JCTree.JCVariableDecl makeLocalIdentityInstance(String varName, boolean isShared) { return makeLocalIdentityInstance(varName, varName, isShared); } // Creates a "new foo();" - protected JCTree.JCNewClass makeNewClass(String className, boolean fullyQualified) { + JCTree.JCNewClass makeNewClass(String className, boolean fullyQualified) { return makeNewClass(className, List.nil(), fullyQualified); } // Creates a "new foo(arg1, arg2, ...);" - protected JCTree.JCNewClass makeNewClass(String className, List args, boolean fullyQualified) { + JCTree.JCNewClass makeNewClass(String className, List args, boolean fullyQualified) { JCExpression name = fullyQualified ? makeQuotedFQIdent(className) : makeQuotedQualIdentFromString(className); return makeNewClass(name, args); } // Creates a "new foo(arg1, arg2, ...);" - protected JCTree.JCNewClass makeNewClass(JCExpression clazz, List args) { + JCTree.JCNewClass makeNewClass(JCExpression clazz, List args) { if (args == null) { args = List.nil(); } return make().NewClass(null, null, clazz, args, null); } - protected JCVariableDecl makeVar(String varName, JCExpression typeExpr, JCExpression valueExpr) { + JCVariableDecl makeVar(String varName, JCExpression typeExpr, JCExpression valueExpr) { return make().VarDef(make().Modifiers(0), names().fromString(varName), typeExpr, valueExpr); } // Creates a "( let var1=expr1,var2=expr2,...,varN=exprN in varN; )" // or a "( let var1=expr1,var2=expr2,...,varN=exprN,exprO in exprO; )" - protected JCExpression makeLetExpr(JCExpression... args) { + JCExpression makeLetExpr(JCExpression... args) { return makeLetExpr(tempName(), null, args); } // Creates a "( let var1=expr1,var2=expr2,...,varN=exprN in statements; varN; )" // or a "( let var1=expr1,var2=expr2,...,varN=exprN in statements; exprO; )" - protected JCExpression makeLetExpr(String varBaseName, List statements, JCExpression... args) { + JCExpression makeLetExpr(String varBaseName, List statements, JCExpression... args) { String varName = null; ListBuffer decls = ListBuffer.lb(); int i; @@ -458,17 +458,17 @@ private long nextUniqueId() { return id.nextId(); } - protected String tempName() { + String tempName() { String result = "$ceylontmp" + nextUniqueId(); return result; } - protected String tempName(String prefix) { + String tempName(String prefix) { String result = "$ceylontmp" + prefix + nextUniqueId(); return result; } - protected String aliasName(String name) { + String aliasName(String name) { String result = "$" + name + "$" + nextUniqueId(); return result; } @@ -488,13 +488,13 @@ boolean isBooleanFalse(Declaration decl) { /** * Determines whether the given type is optional. */ - public boolean isOptional(ProducedType type) { + boolean isOptional(ProducedType type) { // Note we don't use typeFact().isOptionalType(type) because // that implements a stricter test used in the type checker. return typeFact().getNullDeclaration().getType().isSubtypeOf(type); } - public boolean isNothing(ProducedType type) { + boolean isNothing(ProducedType type) { return type.getSupertype(typeFact.getNothingDeclaration()) != null; } @@ -506,7 +506,7 @@ private boolean isObject(ProducedType type) { return typeFact.getObjectDeclaration().getType().isExactly(type); } - protected ProducedType simplifyType(ProducedType type) { + ProducedType simplifyType(ProducedType type) { if (isOptional(type)) { // For an optional type T?: // - The Ceylon type T? results in the Java type T @@ -536,7 +536,7 @@ && isObject(satisfiedTypes.get(1))) return type; } - protected TypedDeclaration nonWideningTypeDecl(TypedDeclaration decl) { + TypedDeclaration nonWideningTypeDecl(TypedDeclaration decl) { TypedDeclaration refinedDeclaration = (TypedDeclaration) decl.getRefinedDeclaration(); if(decl != refinedDeclaration){ /* @@ -554,7 +554,7 @@ && willEraseToObject(decl.getType()) return decl; } - protected ProducedType nonWideningType(TypedDeclaration declaration, TypedDeclaration refinedDeclaration){ + ProducedType nonWideningType(TypedDeclaration declaration, TypedDeclaration refinedDeclaration){ if(declaration == refinedDeclaration) return declaration.getType(); // we must get the return type of the refined decl with any type param instantiated @@ -582,7 +582,7 @@ private boolean sameType(Type t1, ProducedType t2) { } // Determines if a type will be erased to java.lang.Object once converted to Java - protected boolean willEraseToObject(ProducedType type) { + boolean willEraseToObject(ProducedType type) { type = simplifyType(type); return (sameType(syms().ceylonVoidType, type) || sameType(syms().ceylonObjectType, type) || sameType(syms().ceylonNothingType, type) @@ -592,41 +592,41 @@ protected boolean willEraseToObject(ProducedType type) { || typeFact().isUnion(type)|| typeFact().isIntersection(type)); } - protected boolean willEraseToException(ProducedType type) { + boolean willEraseToException(ProducedType type) { type = simplifyType(type); return (sameType(syms().ceylonExceptionType, type)); } - protected boolean isCeylonString(ProducedType type) { + boolean isCeylonString(ProducedType type) { return (sameType(syms().ceylonStringType, type)); } - protected boolean isCeylonBoolean(ProducedType type) { + boolean isCeylonBoolean(ProducedType type) { return type.isSubtypeOf(typeFact.getBooleanDeclaration().getType()) && !(type.getDeclaration() instanceof BottomType); } - protected boolean isCeylonInteger(ProducedType type) { + boolean isCeylonInteger(ProducedType type) { return (sameType(syms().ceylonIntegerType, type)); } - protected boolean isCeylonFloat(ProducedType type) { + boolean isCeylonFloat(ProducedType type) { return (sameType(syms().ceylonFloatType, type)); } - protected boolean isCeylonCharacter(ProducedType type) { + boolean isCeylonCharacter(ProducedType type) { return (sameType(syms().ceylonCharacterType, type)); } - protected boolean isCeylonArray(ProducedType type) { + boolean isCeylonArray(ProducedType type) { return (sameType(syms().ceylonArrayType, type.getDeclaration().getType())); } - protected boolean isCeylonBasicType(ProducedType type) { + boolean isCeylonBasicType(ProducedType type) { return (isCeylonString(type) || isCeylonBoolean(type) || isCeylonInteger(type) || isCeylonFloat(type) || isCeylonCharacter(type)); } - protected boolean isCeylonCallable(ProducedType type) { + boolean isCeylonCallable(ProducedType type) { // FIXME This is ugly, we should find a proper way to do this! return type.getDeclaration().getType().getProducedTypeQualifiedName().startsWith("ceylon.language.Callable<"); } @@ -647,7 +647,7 @@ protected boolean isCeylonCallable(ProducedType type) { /** * This function is used solely for method return types and parameters */ - protected JCExpression makeJavaType(TypedDeclaration typeDecl, ProducedType type) { + JCExpression makeJavaType(TypedDeclaration typeDecl, ProducedType type) { if (typeDecl instanceof FunctionalParameter) { FunctionalParameter p = (FunctionalParameter)typeDecl; ProducedType pt = type; @@ -661,11 +661,11 @@ protected JCExpression makeJavaType(TypedDeclaration typeDecl, ProducedType type } } - protected JCExpression makeJavaType(ProducedType producedType) { + JCExpression makeJavaType(ProducedType producedType) { return makeJavaType(producedType, 0); } - protected JCExpression makeJavaType(ProducedType type, final int flags) { + JCExpression makeJavaType(ProducedType type, final int flags) { if(type == null) return make().Erroneous(); @@ -964,57 +964,62 @@ private boolean isJavaString(ProducedType type) { return "java.lang.String".equals(type.getUnderlyingType()); } - protected java.util.Map locals; - protected java.util.Set interfaces; + private java.util.Map locals; + private java.util.Set interfaces; private void resetLocals() { - gen().locals = new java.util.HashMap(); + ((AbstractTransformer)gen()).locals = new java.util.HashMap(); } private void local(Scope decl) { - Map locals = gen().locals; + Map locals = ((AbstractTransformer)gen()).locals; locals.put(decl, locals.size()); } - protected void noteDecl(Declaration decl) { + boolean hasInterface(Interface iface) { + return ((AbstractTransformer)gen()).interfaces != null + && ((AbstractTransformer)gen()).interfaces.contains(iface); + } + + void noteDecl(Declaration decl) { if (decl.isToplevel()) { resetLocals(); } else if (Decl.isLocal(decl)){ local(decl.getContainer()); } if (decl instanceof Interface) { - if (gen().interfaces == null) { - gen().interfaces = new HashSet(); + if (((AbstractTransformer)gen()).interfaces == null) { + ((AbstractTransformer)gen()).interfaces = new HashSet(); } - gen().interfaces.add((Interface)decl); + ((AbstractTransformer)gen()).interfaces.add((Interface)decl); } } private int getLocalId(Scope decl) { - Integer id = gen().locals.get(decl); + Integer id = ((AbstractTransformer)gen()).locals.get(decl); if (id == null) { throw new RuntimeException(decl + " has no local id"); } return id; } - protected ClassDefinitionBuilder ccdb; + private ClassDefinitionBuilder ccdb; - public ClassDefinitionBuilder current() { - return gen().ccdb; + ClassDefinitionBuilder current() { + return ((AbstractTransformer)gen()).ccdb; } - public ClassDefinitionBuilder replace(ClassDefinitionBuilder ccdb) { - ClassDefinitionBuilder result = gen().ccdb; - gen().ccdb = ccdb; + ClassDefinitionBuilder replace(ClassDefinitionBuilder ccdb) { + ClassDefinitionBuilder result = ((AbstractTransformer)gen()).ccdb; + ((AbstractTransformer)gen()).ccdb = ccdb; return result; } - protected String getFQDeclarationName(final Declaration decl) { + String getFQDeclarationName(final Declaration decl) { return getDeclarationName(decl, true, true); } - public String getDeclarationName(final Declaration decl, boolean fqLocalInterface, boolean includePackage) { + String getDeclarationName(final Declaration decl, boolean fqLocalInterface, boolean includePackage) { int nmFlags = 0; if (fqLocalInterface) { nmFlags |= NM_FQ_LOCAL; @@ -1125,7 +1130,7 @@ private JCExpression makeDeclarationName(Declaration decl) { return makeQuotedQualIdentFromString(getFQDeclarationName(decl)); } - public String getCompanionClassName(Declaration decl){ + String getCompanionClassName(Declaration decl){ return getDeclarationName(decl, false, true) + "$impl"; } @@ -1155,7 +1160,7 @@ private ProducedType getThisType(Declaration decl) { * @param typeModel A {@code ceylon.language.Callable}. * @return The result type of the {@code Callable}. */ - protected ProducedType getReturnTypeOfCallable(ProducedType typeModel) { + ProducedType getReturnTypeOfCallable(ProducedType typeModel) { if (!isCeylonCallable(typeModel)) { throw new RuntimeException("Not a Callable<>: " + typeModel); } @@ -1178,7 +1183,7 @@ protected ProducedType getReturnTypeOfCallable(ProducedType typeModel) { * * */ - protected ProducedType functionalType(Functional model) { + ProducedType functionalType(Functional model) { return typeFact().getCallableType(functionalReturnType(model)); } @@ -1197,7 +1202,7 @@ protected ProducedType functionalType(Functional model) { * * */ - protected ProducedType functionalReturnType(Functional model) { + ProducedType functionalReturnType(Functional model) { ProducedType callableType = model.getType(); for (int ii = 1; ii < model.getParameterLists().size(); ii++) { callableType = typeFact().getCallableType(callableType); @@ -1211,7 +1216,7 @@ protected ProducedType functionalReturnType(Functional model) { */ static final int TP_TO_BOUND = 1<<0; - protected ProducedType getTypeForParameter(Parameter parameter, ProducedReference producedReference, int flags) { + ProducedType getTypeForParameter(Parameter parameter, ProducedReference producedReference, int flags) { if (parameter instanceof FunctionalParameter) { return getTypeForFunctionalParameter((FunctionalParameter)parameter); } @@ -1255,14 +1260,14 @@ List makeAtOverride() { return List. of(make().Annotation(makeIdent(syms().overrideType), List. nil())); } - public boolean checkCompilerAnnotations(Tree.Declaration decl){ + boolean checkCompilerAnnotations(Tree.Declaration decl){ boolean old = gen().disableModelAnnotations; if(Util.hasCompilerAnnotation(decl, "nomodel")) gen().disableModelAnnotations = true; return old; } - public void resetCompilerAnnotations(boolean value){ + void resetCompilerAnnotations(boolean value){ gen().disableModelAnnotations = value; } @@ -1276,11 +1281,11 @@ private List makeModelAnnotation(Type annotationType) { return makeModelAnnotation(annotationType, List.nil()); } - protected List makeAtCeylon() { + List makeAtCeylon() { return makeModelAnnotation(syms().ceylonAtCeylonType); } - protected List makeAtModule(Module module) { + List makeAtModule(Module module) { String name = module.getNameAsString(); String version = module.getVersion(); java.util.List dependencies = module.getImports(); @@ -1312,7 +1317,7 @@ protected List makeAtModule(Module module) { List.of(nameAttribute, versionAttribute, importAttribute)); } - protected List makeAtPackage(Package pkg) { + List makeAtPackage(Package pkg) { String name = pkg.getNameAsString(); boolean shared = pkg.isShared(); JCExpression nameAttribute = make().Assign(makeUnquotedIdent("name"), make().Literal(name)); @@ -1321,15 +1326,15 @@ protected List makeAtPackage(Package pkg) { List.of(nameAttribute, sharedAttribute)); } - protected List makeAtName(String name) { + List makeAtName(String name) { return makeModelAnnotation(syms().ceylonAtNameType, List.of(make().Literal(name))); } - protected List makeAtType(String name) { + List makeAtType(String name) { return makeModelAnnotation(syms().ceylonAtTypeInfoType, List.of(make().Literal(name))); } - public final JCAnnotation makeAtTypeParameter(String name, java.util.List satisfiedTypes, boolean covariant, boolean contravariant) { + final JCAnnotation makeAtTypeParameter(String name, java.util.List satisfiedTypes, boolean covariant, boolean contravariant) { JCExpression nameAttribute = make().Assign(makeUnquotedIdent("value"), make().Literal(name)); // variance String variance = "NONE"; @@ -1352,32 +1357,32 @@ else if(contravariant) List.of(nameAttribute, varianceAttribute, satisfiesAttribute)); } - public List makeAtTypeParameters(List typeParameters) { + List makeAtTypeParameters(List typeParameters) { JCExpression value = make().NewArray(null, null, typeParameters); return makeModelAnnotation(syms().ceylonAtTypeParameters, List.of(value)); } - protected List makeAtSequenced() { + List makeAtSequenced() { return makeModelAnnotation(syms().ceylonAtSequencedType); } - protected List makeAtDefaulted() { + List makeAtDefaulted() { return makeModelAnnotation(syms().ceylonAtDefaultedType); } - protected List makeAtAttribute() { + List makeAtAttribute() { return makeModelAnnotation(syms().ceylonAtAttributeType); } - protected List makeAtMethod() { + List makeAtMethod() { return makeModelAnnotation(syms().ceylonAtMethodType); } - protected List makeAtObject() { + List makeAtObject() { return makeModelAnnotation(syms().ceylonAtObjectType); } - protected List makeAtClass(ProducedType extendedType) { + List makeAtClass(ProducedType extendedType) { List attributes = List.nil(); if(!extendedType.isExactly(typeFact.getIdentifiableObjectDeclaration().getType())){ JCExpression extendsAttribute = make().Assign(makeUnquotedIdent("extendsType"), @@ -1387,11 +1392,11 @@ protected List makeAtClass(ProducedType extendedType) { return makeModelAnnotation(syms().ceylonAtClassType, attributes); } - protected List makeAtSatisfiedTypes(java.util.List satisfiedTypes) { + List makeAtSatisfiedTypes(java.util.List satisfiedTypes) { return makeTypesListAnnotation(syms().ceylonAtSatisfiedTypes, satisfiedTypes); } - protected List makeAtCaseTypes(java.util.List caseTypes) { + List makeAtCaseTypes(java.util.List caseTypes) { return makeTypesListAnnotation(syms().ceylonAtCaseTypes, caseTypes); } @@ -1409,11 +1414,11 @@ private List makeTypesListAnnotation(Type annotationType, java.uti return makeModelAnnotation(annotationType, List.of(caseAttribute)); } - protected List makeAtIgnore() { + List makeAtIgnore() { return makeModelAnnotation(syms().ceylonAtIgnore); } - protected List makeAtAnnotations(java.util.List annotations) { + List makeAtAnnotations(java.util.List annotations) { if(annotations == null || annotations.isEmpty()) return List.nil(); ListBuffer array = new ListBuffer(); @@ -1460,7 +1465,7 @@ private JCExpression makeAtAnnotation(Annotation annotation) { return make().Annotation(makeIdent(syms().ceylonAtAnnotationType), attributes); } - protected boolean needsAnnotations(Declaration decl) { + boolean needsAnnotations(Declaration decl) { Declaration reqdecl = decl; if (reqdecl instanceof Parameter) { Parameter p = (Parameter)reqdecl; @@ -1469,7 +1474,7 @@ protected boolean needsAnnotations(Declaration decl) { return reqdecl.isToplevel() || (reqdecl.isClassOrInterfaceMember() && reqdecl.isShared() && !Decl.isAncestorLocal(reqdecl)); } - protected List makeJavaTypeAnnotations(TypedDeclaration decl) { + List makeJavaTypeAnnotations(TypedDeclaration decl) { if(decl == null || decl.getType() == null) return List.nil(); ProducedType type; @@ -1502,14 +1507,14 @@ public enum BoxingStrategy { UNBOXED, BOXED, INDIFFERENT; } - protected JCExpression boxUnboxIfNecessary(JCExpression javaExpr, Tree.Term expr, + JCExpression boxUnboxIfNecessary(JCExpression javaExpr, Tree.Term expr, ProducedType exprType, BoxingStrategy boxingStrategy) { boolean exprBoxed = !Util.isUnBoxed(expr); return boxUnboxIfNecessary(javaExpr, exprBoxed, exprType, boxingStrategy); } - protected JCExpression boxUnboxIfNecessary(JCExpression javaExpr, boolean exprBoxed, + JCExpression boxUnboxIfNecessary(JCExpression javaExpr, boolean exprBoxed, ProducedType exprType, BoxingStrategy boxingStrategy) { if(boxingStrategy == BoxingStrategy.INDIFFERENT) @@ -1528,14 +1533,14 @@ protected JCExpression boxUnboxIfNecessary(JCExpression javaExpr, boolean exprBo return javaExpr; } - protected boolean isTypeParameter(ProducedType type) { + boolean isTypeParameter(ProducedType type) { if (typeFact().isOptionalType(type)) { type = type.minus(typeFact().getNothingDeclaration()); } return type.getDeclaration() instanceof TypeParameter; } - protected JCExpression unboxType(JCExpression expr, ProducedType targetType) { + JCExpression unboxType(JCExpression expr, ProducedType targetType) { if (isCeylonInteger(targetType)) { expr = unboxInteger(expr); } else if (isCeylonFloat(targetType)) { @@ -1553,7 +1558,7 @@ protected JCExpression unboxType(JCExpression expr, ProducedType targetType) { return expr; } - protected JCExpression boxType(JCExpression expr, ProducedType exprType) { + JCExpression boxType(JCExpression expr, ProducedType exprType) { if (isCeylonInteger(exprType)) { expr = boxInteger(expr); } else if (isCeylonFloat(exprType)) { @@ -1646,7 +1651,7 @@ private JCTree.JCMethodInvocation makeUnboxType(JCExpression value, String unbox * @return a JCExpression * @see #makeSequenceRaw(java.util.List) */ - protected JCExpression makeSequence(List elems, ProducedType seqElemType, int makeJavaTypeOpts) { + JCExpression makeSequence(List elems, ProducedType seqElemType, int makeJavaTypeOpts) { ProducedType seqType = typeFact().getDefaultSequenceType(seqElemType); JCExpression typeExpr = makeJavaType(seqType, makeJavaTypeOpts); return makeNewClass(typeExpr, elems); @@ -1660,7 +1665,7 @@ protected JCExpression makeSequence(List elems, ProducedType seqEl * @return a JCExpression * @see #makeSequenceRaw(java.util.List) */ - protected JCExpression makeSequence(java.util.List list, ProducedType seqElemType) { + JCExpression makeSequence(java.util.List list, ProducedType seqElemType) { ListBuffer elems = new ListBuffer(); for (Expression expr : list) { // no need for erasure casts here @@ -1676,7 +1681,7 @@ protected JCExpression makeSequence(java.util.List list, ProducedTyp * @return a JCExpression * @see #makeSequence(java.util.List, ProducedType) */ - protected JCExpression makeSequenceRaw(java.util.List list) { + JCExpression makeSequenceRaw(java.util.List list) { ListBuffer elems = new ListBuffer(); for (Expression expr : list) { // no need for erasure casts here @@ -1685,18 +1690,18 @@ protected JCExpression makeSequenceRaw(java.util.List list) { return makeSequence(elems.toList(), typeFact().getObjectDeclaration().getType(), CeylonTransformer.WANT_RAW_TYPE); } - protected JCExpression makeSequenceRaw(List elems) { + JCExpression makeSequenceRaw(List elems) { return makeSequence(elems, typeFact().getObjectDeclaration().getType(), CeylonTransformer.WANT_RAW_TYPE); } - protected JCExpression makeEmpty() { + JCExpression makeEmpty() { return make().Apply( List.nil(), makeFQIdent("ceylon", "language", "$empty", Util.getGetterName("$empty")), List.nil()); } - protected JCExpression makeFinished() { + JCExpression makeFinished() { return make().Apply( List.nil(), makeFQIdent("ceylon", "language", "$finished", Util.getGetterName("$finished")), @@ -1745,7 +1750,7 @@ String substitute(String varName) { } // Creates comparisons of expressions against types - protected JCExpression makeTypeTest(JCExpression firstTimeExpr, String varName, ProducedType type) { + JCExpression makeTypeTest(JCExpression firstTimeExpr, String varName, ProducedType type) { JCExpression result = null; if (typeFact().isUnion(type)) { UnionType union = (UnionType)type.getDeclaration(); @@ -1794,7 +1799,7 @@ protected JCExpression makeTypeTest(JCExpression firstTimeExpr, String varName, return result; } - protected JCExpression makeNonEmptyTest(JCExpression firstTimeExpr, String varName) { + JCExpression makeNonEmptyTest(JCExpression firstTimeExpr, String varName) { Interface fixedSize = typeFact().getFixedSizedDeclaration(); JCExpression test = makeTypeTest(firstTimeExpr, varName, fixedSize.getType()); JCExpression fixedSizeType = makeJavaType(fixedSize.getType(), NO_PRIMITIVES | WANT_RAW_TYPE); @@ -1802,7 +1807,7 @@ protected JCExpression makeNonEmptyTest(JCExpression firstTimeExpr, String varNa return make().Binary(JCTree.AND, test, nonEmpty); } - protected JCExpression makeNonEmptyTest(JCExpression expr){ + JCExpression makeNonEmptyTest(JCExpression expr){ JCExpression getEmptyCall = make().Select(expr, names().fromString("getEmpty")); JCExpression empty = make().Apply(List.nil(), getEmptyCall, List.nil()); return make().Unary(JCTree.NOT, empty); @@ -1828,28 +1833,28 @@ private LetExpr makeIgnoredEvalAndReturn(JCExpression toEval, JCExpression toRet } - protected JCExpression makeErroneous() { + JCExpression makeErroneous() { return makeErroneous(null); } /** * Makes an 'erroneous' AST node with no message */ - protected JCExpression makeErroneous(Node node) { + JCExpression makeErroneous(Node node) { return makeErroneous(node, null, List.nil()); } /** * Makes an 'erroneous' AST node with a message to be logged as an error */ - protected JCExpression makeErroneous(Node node, String message) { + JCExpression makeErroneous(Node node, String message) { return makeErroneous(node, message, List.nil()); } /** * Makes an 'erroneous' AST node with a message to be logged as an error */ - protected JCExpression makeErroneous(Node node, String message, List errs) { + JCExpression makeErroneous(Node node, String message, List errs) { if (node != null) { at(node); } @@ -1873,47 +1878,47 @@ private JCTypeParameter makeTypeParameter(String name, java.util.List typeArguments(Tree.AnyMethod method) { + final List typeArguments(Tree.AnyMethod method) { return typeArguments(method.getDeclarationModel()); } - public final List typeArguments(Tree.AnyClass type) { + final List typeArguments(Tree.AnyClass type) { return typeArguments(type); } - public final List typeArguments(Functional method) { + final List typeArguments(Functional method) { return typeArguments(method.getTypeParameters(), method.getType().getTypeArguments()); } - public final List typeArguments(Tree.ClassOrInterface type) { + final List typeArguments(Tree.ClassOrInterface type) { return typeArguments(type.getDeclarationModel().getTypeParameters(), type.getDeclarationModel().getType().getTypeArguments()); } - public final List typeArguments(java.util.List typeParameters, Map typeArguments) { + final List typeArguments(java.util.List typeParameters, Map typeArguments) { ListBuffer typeArgs = ListBuffer.lb(); for (TypeParameter tp : typeParameters) { ProducedType type = typeArguments.get(tp); @@ -1926,17 +1931,17 @@ public final List typeArguments(java.util.List type return typeArgs.toList(); } - public final String getCompanionFieldName(Interface def) { + final String getCompanionFieldName(Interface def) { return "$" + Util.getCompanionClassName(def.getName()); } - public final JCExpression makeDefaultedParamMethodIdent(Method method, Parameter param) { + final JCExpression makeDefaultedParamMethodIdent(Method method, Parameter param) { Interface iface = (Interface)method.getRefinedDeclaration().getContainer(); return makeQuotedQualIdent(makeQuotedIdent(getCompanionFieldName(iface)), Util.getDefaultedParamMethodName(method, param)); } - public final JCExpression makeCompanionType(final ClassOrInterface decl, Map typeParameters, boolean goRaw) { + final JCExpression makeCompanionType(final ClassOrInterface decl, Map typeParameters, boolean goRaw) { List typeArgs; if (goRaw) { typeArgs = List.nil(); @@ -1946,7 +1951,7 @@ public final JCExpression makeCompanionType(final ClassOrInterface decl, Map typeArgs) { String companionClassName = getCompanionClassName(decl); JCExpression baseName = makeQuotedQualIdentFromString(companionClassName); diff --git a/src/com/redhat/ceylon/compiler/java/codegen/ClassTransformer.java b/src/com/redhat/ceylon/compiler/java/codegen/ClassTransformer.java index ba25dbe97..b7114d141 100755 --- a/src/com/redhat/ceylon/compiler/java/codegen/ClassTransformer.java +++ b/src/com/redhat/ceylon/compiler/java/codegen/ClassTransformer.java @@ -348,7 +348,7 @@ private JCMethodDecl makeDelegateToCompanion(Interface iface, private Boolean hasImpl(Interface iface) { // If we're already transformed the interface then it will have a $impl - if (gen().interfaces != null && gen().interfaces.contains(iface)) { + if (gen().hasInterface(iface)) { return true; } // Otherwise, ask the model loader