From b956b6fde3a1a3e485956f1075412fa8a52e8fe9 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 14 Aug 2007 17:09:20 +0000 Subject: Removed support for Storable definition to accept Repository in constructor. --- .../amazon/carbonado/gen/StorableGenerator.java | 46 ++-------------------- .../carbonado/info/StorableIntrospector.java | 23 ++++------- 2 files changed, 12 insertions(+), 57 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index 41ba8b9..388b52a 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -21,9 +21,7 @@ package com.amazon.carbonado.gen; import java.lang.annotation.Annotation; import java.lang.ref.Reference; import java.lang.ref.SoftReference; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -451,8 +449,8 @@ public final class StorableGenerator { final int supportParam = 0; MethodInfo mi = mClassFile.addConstructor(Modifiers.PROTECTED, params); CodeBuilder b = new CodeBuilder(mi); - - addInvokeSuperConstructor(b, supportParam); + b.loadThis(); + b.invokeSuperConstructor(null); //// this.support = support b.loadThis(); @@ -468,8 +466,8 @@ public final class StorableGenerator { final int wrappedStorableParam = 1; MethodInfo mi = mClassFile.addConstructor(Modifiers.PUBLIC, params); CodeBuilder b = new CodeBuilder(mi); - - addInvokeSuperConstructor(b, wrappedSupportParam); + b.loadThis(); + b.invokeSuperConstructor(null); //// this.wrappedSupport = wrappedSupport b.loadThis(); @@ -1961,42 +1959,6 @@ public final class StorableGenerator { } } - /** - * Generates code to invoke super class constructor with no arguments or a - * Repository. - */ - private void addInvokeSuperConstructor(CodeBuilder b, final int supportParam) { - // Look for constructor that accepts a Repository. - - boolean passRepo = false; - { - for (Constructor c : mStorableType.getDeclaredConstructors()) { - int modifiers = c.getModifiers(); - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - continue; - } - if (c.getParameterTypes().length == 1) { - if (c.getParameterTypes()[0] == Repository.class) { - passRepo = true; - break; - } - } - } - } - - b.loadThis(); - - if (passRepo) { - b.loadLocal(b.getParameter(supportParam)); - b.invokeInterface(StorableSupport.class.getName(), "getRootRepository", - TypeDesc.forClass(Repository.class), null); - b.invokeSuperConstructor(new TypeDesc[] {TypeDesc.forClass(Repository.class)}); - } else { - // Assume no-arg constructor. - b.invokeSuperConstructor(null); - } - } - /** * If GEN_WRAPPED, generates a method implementation which delgates to the * WrappedSupport. Also clears join property state if called method diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index 133e175..b7f7744 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -62,7 +62,6 @@ import com.amazon.carbonado.Nullable; import com.amazon.carbonado.Independent; import com.amazon.carbonado.PrimaryKey; import com.amazon.carbonado.Query; -import com.amazon.carbonado.Repository; import com.amazon.carbonado.Sequence; import com.amazon.carbonado.Storable; import com.amazon.carbonado.Version; @@ -491,35 +490,29 @@ public class StorableIntrospector { checkTypeParameter(errorMessages, type); - // If type is a class, it must have a public/protected constructor that - // takes no arguments or a Repository. If overloaded, the constructor - // with the Repository parameter is preferred by the code generator. + // If type is a class, it must have a public or protected no-arg + // constructor. if (!type.isInterface()) { Constructor[] ctors = type.getDeclaredConstructors(); findCtor: { for (Constructor c : ctors) { - modifiers = c.getModifiers(); - if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { - continue; - } if (c.getParameterTypes().length == 0) { - break findCtor; - } - if (c.getParameterTypes().length == 1) { - if (c.getParameterTypes()[0] == Repository.class) { - break findCtor; + modifiers = c.getModifiers(); + if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) { + errorMessages.add("Cannot call constructor: " + c); } + break findCtor; } } if (type.getEnclosingClass() == null) { errorMessages.add ("Class must have a public or protected constructor " + - "that takes no arguments or a Repository"); + "that accepts no arguments"); } else { errorMessages.add ("Inner class must have a public or protected constructor " + - "that takes no arguments or a Repository"); + "that accepts no arguments"); } } } -- cgit v1.2.3