[Bedework-commit] calendarapi r655 - in trunk: .
annotations/resources
annotations/src/org/bedework/calfacade/annotations
annotations/src/org/bedework/calfacade/annotations/process
calFacade/src/org/bedework/calfacade
calFacade/src/org/bedework/calfacade/base
calFacade/src/org/bedework/calfacade/wrappers
svnadmin at bedework.org
svnadmin at bedework.org
Thu Jun 26 23:08:32 EDT 2008
Author: douglm
Date: 2008-06-26 23:08:17 -0400 (Thu, 26 Jun 2008)
New Revision: 655
Added:
trunk/annotations/src/org/bedework/calfacade/annotations/NoQuota.java
trunk/annotations/src/org/bedework/calfacade/annotations/NoWrap.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/MethodHandler.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperMethod.java
Modified:
trunk/annotations/resources/Wrapper.java.rsrc
trunk/annotations/src/org/bedework/calfacade/annotations/Wrapper.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/AnnUtil.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/FacadeAPF.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/ProcessState.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyHandler.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyMethod.java
trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperHandler.java
trunk/build.xml
trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
trunk/calFacade/src/org/bedework/calfacade/base/BwDbentity.java
trunk/calFacade/src/org/bedework/calfacade/wrappers/BwDbentityWrapper.java
Log:
Now successfully creates a wrapper class from an entity class.
Next step will be to add code to the wrapper to track quota changes.
Modified: trunk/annotations/resources/Wrapper.java.rsrc
===================================================================
--- trunk/annotations/resources/Wrapper.java.rsrc 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/resources/Wrapper.java.rsrc 2008-06-27 03:08:17 UTC (rev 655)
@@ -23,8 +23,10 @@
special, consequential, or incidental damages related to the software,
to the maximum extent the law permits.
*/
-package org.bedework.calfacade;
+package org.bedework.calfacade.wrappers;
+++++++++++++++++++++++++++++++++++++++++++++++++++ Imports inserted here
+
/** <p>DO NOT EDIT THE GENERATED JAVA.
*
* <p>The wrapper java source is generated based on annotations in the class
@@ -34,7 +36,4 @@
* @author Mike Douglass
* @version 1.0
*/
-
++++++++++++++++++++++++++++++++++++++++++++++++++ Code inserted here
-
-}
Added: trunk/annotations/src/org/bedework/calfacade/annotations/NoQuota.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/NoQuota.java (rev 0)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/NoQuota.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -0,0 +1,42 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+
+package org.bedework.calfacade.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** This is used to annotate a method to which we should not apply quotas.
+ *
+ * @author Mike Douglass
+ *
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface NoQuota {
+}
Property changes on: trunk/annotations/src/org/bedework/calfacade/annotations/NoQuota.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Added: trunk/annotations/src/org/bedework/calfacade/annotations/NoWrap.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/NoWrap.java (rev 0)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/NoWrap.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -0,0 +1,42 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+
+package org.bedework.calfacade.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** This is used to annotate a method which we should not wrap.
+ *
+ * @author Mike Douglass
+ *
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface NoWrap {
+}
Property changes on: trunk/annotations/src/org/bedework/calfacade/annotations/NoWrap.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/Wrapper.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/Wrapper.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/Wrapper.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -39,7 +39,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Wrapper {
- /** Superclass for the wrapper
+ /** True if we support quotas for this entity
*/
- String superClass();
+ boolean quotas() default false;
}
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/AnnUtil.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/AnnUtil.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/AnnUtil.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -36,6 +36,8 @@
import com.sun.mirror.declaration.ParameterDeclaration;
import com.sun.mirror.type.ClassType;
import com.sun.mirror.type.InterfaceType;
+import com.sun.mirror.type.PrimitiveType;
+import com.sun.mirror.type.ReferenceType;
import com.sun.mirror.type.TypeMirror;
/** Utility methods for annotations
@@ -146,10 +148,12 @@
* @param methName
* @param pars
* @param returnType
+ * @param thrownTypes
*/
public void generateSignature(String methName,
Collection<ParameterDeclaration> pars,
- TypeMirror returnType) {
+ TypeMirror returnType,
+ Collection<ReferenceType> thrownTypes) {
/* Generate soem javadoc first.
*/
println(" /* (non-Javadoc)");
@@ -159,15 +163,8 @@
int i = 0;
for (ParameterDeclaration par: pars) {
- String parType = par.getType().toString();
+ out.print(nonGeneric(par.getType().toString()));
- if (parType.endsWith(">")) {
- int pos = parType.indexOf("<");
- parType = parType.substring(0, pos);
- }
-
- out.print(parType);
-
i++;
if (i < sz) {
out.print(", ");
@@ -215,7 +212,22 @@
}
}
- out.println(") {");
+ out.print(")");
+
+ if (thrownTypes.size() > 0) {
+ out.println();
+ out.print(" throws ");
+ boolean first = true;
+ for (ReferenceType rt: thrownTypes) {
+ if (!first) {
+ out.print(", ");
+ }
+
+ out.print(fixName(rt.toString()));
+ }
+ }
+
+ out.println(" {");
}
/**
@@ -232,11 +244,56 @@
return fixName(tm.toString());
}
+ /** Return a name we might need to import or null.
+ *
+ * @param tm
+ * @param thisPackage
+ * @return String
+ */
+ public String getImportableClassName(TypeMirror tm,
+ String thisPackage) {
+ /*
+ if (tm instanceof ClassType) {
+ ClassType ct = (ClassType)tm;
+
+ String className = ct.getDeclaration().getQualifiedName();
+
+ if (samePackage(thisPackage, className)) {
+ return null;
+ }
+
+ return className;
+ } else {
+ env.getMessager().printNotice("getImportableClassName: " +
+ tm.getClass().getName() +
+ " " + tm.toString());
+ }*/
+ if (!(tm instanceof PrimitiveType)) {
+ String className = nonGeneric(tm.toString());
+
+ if ("void".equals(className)) {
+ return null;
+ }
+
+ if (className.startsWith("java.lang.")) {
+ return null;
+ }
+
+ if (samePackage(thisPackage, className)) {
+ return null;
+ }
+
+ return className;
+ }
+
+ return null;
+ }
+
/**
* @param str
* @return String
*/
- public String fixName(String str) {
+ public static String fixName(String str) {
if (str == null) {
return null;
}
@@ -246,6 +303,8 @@
str = str.replaceAll("java\\.util\\.", "");
str = str.replaceAll("java\\.lang\\.", "");
str = str.replaceAll("org\\.bedework\\.calfacade\\.Bw", "Bw");
+ str = str.replaceAll("org\\.bedework\\.calfacade\\.base\\.Bw", "Bw");
+ str = str.replaceAll("org\\.bedework\\.calfacade\\.wrappers\\.Bw", "Bw");
//if (str.startsWith("java.util.")) {
// return str.substring("java.util.".length());
//}
@@ -261,12 +320,15 @@
return str;
}
- /** Return the generic type for the given type string
+ /** Return the non-generic type (class without th etype parameters) for the
+ * given type string
*
+ * <p>Note: ClassDeclaration.getQualifiedName() does this.
+ *
* @param type
* @return String generic type name
*/
- public String generic(String type) {
+ public static String nonGeneric(String type) {
if (!type.endsWith(">")) {
return type;
}
@@ -275,6 +337,26 @@
return type.substring(0, pos);
}
+ /** ClassDeclaration.getPackage() could be useful here
+ *
+ * @param thisPackage
+ * @param thatClass
+ * @return boolean
+ */
+ public boolean samePackage(String thisPackage, String thatClass) {
+ //env.getMessager().printNotice("samePackage: " + thisPackage + " " + thatClass);
+
+ if (!thatClass.startsWith(thisPackage)) {
+ return false;
+ }
+
+ if (thatClass.charAt(thisPackage.length()) != '.') {
+ return false;
+ }
+
+ return thatClass.indexOf(".", thisPackage.length() + 1) < 0;
+ }
+
/**
* @param tm
* @return boolean
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/FacadeAPF.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/FacadeAPF.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/FacadeAPF.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -26,6 +26,8 @@
package org.bedework.calfacade.annotations.process;
+import org.bedework.calfacade.annotations.NoWrap;
+import org.bedework.calfacade.annotations.Wrapper;
import org.bedework.calfacade.annotations.ical.IcalProperties;
import org.bedework.calfacade.annotations.ical.IcalProperty;
import org.bedework.calfacade.annotations.ical.NoProxy;
@@ -105,12 +107,17 @@
*/
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
AnnotationProcessorEnvironment env) {
- Map options = env.getOptions();
- for (Object optionObj : options.keySet()) {
- String option = (String)optionObj;
+ Map<String, String> options = env.getOptions();
+ for (String option : options.keySet()) {
+ //env.getMessager().printNotice(option);
+ //env.getMessager().printNotice(options.get(option));
if (option.startsWith("-AresourcePath=")) {
pstate.resourcePath = option.substring("-AresourcePath=".length());
}
+
+ if (option.startsWith("-Adebug=")) {
+ pstate.debug = "true".equals(option.substring("-Adebug=".length()));
+ }
}
env.addListener(new RcListener(env, pstate));
@@ -197,7 +204,9 @@
}
public void visitClassDeclaration(ClassDeclaration d) {
- //msg.printNotice("Start Class: " + d.getQualifiedName());
+ if (pstate.debug) {
+ msg.printNotice("Start Class: " + d.getQualifiedName());
+ }
pstate.setCurrentClassName(d.getQualifiedName());
classDepth++;
@@ -214,6 +223,13 @@
pstate.getProxyHandler().startProxy(env);
}
}
+
+ Wrapper wpr = d.getAnnotation(Wrapper.class);
+
+ if (wpr != null) {
+ pstate.processingWrapper = true;
+ pstate.getWrapperHandler(wpr).start(env);
+ }
}
public void visitMethodDeclaration(MethodDeclaration d) {
@@ -234,10 +250,22 @@
}
}
+ if (pstate.processingWrapper) {
+ if (d.getAnnotation(NoWrap.class) == null) {
+ Collection<Modifier> mods = d.getModifiers();
+
+ if (mods.contains(Modifier.PUBLIC)) {
+ pstate.getWrapperHandler().method(env, d);
+ }
+ }
+ }
+
IcalProperty ip = d.getAnnotation(IcalProperty.class);
if (ip != null) {
pstate.getIcalPropertyHandler().property(env, ip, d);
- msg.printNotice("IcalProperty: " + ip.pindex().name());
+ if (pstate.debug) {
+ msg.printNotice("IcalProperty: " + ip.pindex().name());
+ }
}
IcalProperties ips = d.getAnnotation(IcalProperties.class);
@@ -246,7 +274,9 @@
for (IcalProperty ip1: ips.value()) {
iph.property(env, ip1, d);
- msg.printNotice("IcalProperty: " + ip1.pindex().name());
+ if (pstate.debug) {
+ msg.printNotice("IcalProperty: " + ip1.pindex().name());
+ }
}
}
@@ -258,7 +288,6 @@
}
}*/
}
-
}
private class DeclEndVisitor extends SimpleDeclarationVisitor {
@@ -291,7 +320,35 @@
pstate.processingEvent = false;
}
}
+
+ if (pstate.processingWrapper) {
+ ClassDeclaration superD = d.getSuperclass().getDeclaration();
+ if (superD.getQualifiedName().startsWith("org.bedework")) {
+ processSuper(superD);
+ }
+
+ pstate.getWrapperHandler().end(env);
+
+ pstate.endWrapperHandler();
+ }
}
+
+ private void processSuper(ClassDeclaration d) {
+ for (MethodDeclaration md: d.getMethods()) {
+ if (md.getAnnotation(NoWrap.class) == null) {
+ Collection<Modifier> mods = md.getModifiers();
+
+ if (mods.contains(Modifier.PUBLIC)) {
+ pstate.getWrapperHandler().method(env, md);
+ }
+ }
+ }
+
+ ClassDeclaration superD = d.getSuperclass().getDeclaration();
+ if (superD.getQualifiedName().startsWith("org.bedework")) {
+ processSuper(superD);
+ }
+ }
}
}
}
Added: trunk/annotations/src/org/bedework/calfacade/annotations/process/MethodHandler.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/MethodHandler.java (rev 0)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/MethodHandler.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -0,0 +1,259 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.annotations.process;
+
+import org.bedework.calfacade.annotations.ical.Immutable;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.Messager;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.Modifier;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.type.PrimitiveType;
+import com.sun.mirror.type.ReferenceType;
+import com.sun.mirror.type.TypeMirror;
+
+/** We create a list of these as we process the event. We tie together the
+ * setter and getter methods so that only the setter needs to be annotated
+ *
+ * @author Mike DOuglass
+ */
+/**
+ * @author douglm
+ *
+ */
+public abstract class MethodHandler implements Comparable<MethodHandler> {
+ protected AnnUtil annUtil;
+
+ protected String ucFieldName; // no lower cased first char.
+ protected String fieldName;
+
+ protected boolean basicType; // field type is int, boolean etc.
+
+ protected boolean staticMethod;
+
+ protected String methName;
+
+ protected boolean setter;
+ protected boolean getter;
+
+ protected boolean immutable;
+
+ protected TypeMirror returnType;
+ protected boolean returnsVoid;
+ protected TypeMirror parType;
+
+ protected Collection<ParameterDeclaration> pars;
+
+ protected Collection<ReferenceType> thrownTypes;
+
+ protected AnnotationProcessorEnvironment env;
+ protected Messager msg;
+
+ /**
+ * @param env
+ * @param annUtil
+ * @param d
+ */
+ public MethodHandler(AnnotationProcessorEnvironment env,
+ AnnUtil annUtil,
+ MethodDeclaration d) {
+ this.env = env;
+ this.annUtil = annUtil;
+ msg = env.getMessager();
+
+ staticMethod = d.getModifiers().contains(Modifier.STATIC);
+ methName = d.getSimpleName();
+ getter = methName.startsWith("get");
+ setter = methName.startsWith("set");
+
+ immutable = d.getAnnotation(Immutable.class) != null;
+ returnType = d.getReturnType();
+ returnsVoid = env.getTypeUtils().getVoidType().equals(returnType);
+
+ pars = d.getParameters();
+ thrownTypes = d.getThrownTypes();
+
+ if ((setter) && (pars != null) && (pars.size() == 1)) {
+ parType = pars.iterator().next().getType();
+ basicType = parType instanceof PrimitiveType;
+ }
+
+ if (getter) {
+ basicType = returnType instanceof PrimitiveType;
+ }
+
+ if (setter || getter) {
+ ucFieldName = methName.substring(3);
+ fieldName = ucFieldName.substring(0, 1).toLowerCase() +
+ ucFieldName.substring(1);
+ }
+ }
+
+ /**
+ * @param thisPackage
+ * @return List
+ */
+ public Set<String> getImports(String thisPackage) {
+ TreeSet<String> imports = new TreeSet<String>();
+
+ String cname = annUtil.getImportableClassName(returnType, thisPackage);
+
+ if (cname != null) {
+ imports.add(cname);
+ }
+
+ for (ParameterDeclaration par: pars) {
+ String parType = annUtil.getImportableClassName(par.getType(), thisPackage);
+
+ if (parType != null) {
+ imports.add(parType);
+ }
+ }
+
+ return imports;
+ }
+
+ /** Generate the method
+ */
+ public void generate() {
+ annUtil.generateSignature(methName, pars, returnType, thrownTypes);
+
+ if (getter && (pars.size() == 0)) {
+ generateGet();
+ } else if (setter && (pars.size() == 1)) {
+ generateSet();
+ } else {
+ generateMethod();
+ }
+ }
+
+ /**
+ */
+ public abstract void generateGet();
+
+ /**
+ */
+ public abstract void generateSet();
+
+ /**
+ */
+ public abstract void generateMethod();
+
+ protected String makeCallGetter(String objRef) {
+ return annUtil.makeCallGetter(objRef, ucFieldName);
+ }
+
+ protected String makeCallSetter(String objRef, Object val) {
+ return annUtil.makeCallSetter(objRef, ucFieldName, val);
+ }
+
+ /** Make a cal to this method
+ *
+ * @return String
+ */
+ protected String makeCall() {
+ StringBuilder sb = new StringBuilder(methName);
+
+ sb.append("(");
+
+ boolean first = true;
+ for (ParameterDeclaration par: pars) {
+ if (!first) {
+ sb.append(", ");
+ }
+ sb.append(par.getSimpleName());
+
+ first = false;
+ }
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("Method{");
+ sb.append(fieldName);
+ sb.append(", basic=");
+ sb.append(basicType);
+ sb.append(", method=");
+ sb.append(methName);
+
+ return sb.toString();
+ }
+
+
+ public int compareTo(MethodHandler that) {
+ if (this == that) {
+ return 0;
+ }
+
+ int res = methName.compareTo(that.methName);
+ if (res != 0) {
+ return res;
+ }
+
+ if (pars.size() < that.pars.size()) {
+ return -1;
+ }
+
+ if (pars.size() > that.pars.size()) {
+ return 1;
+ }
+
+ Iterator<ParameterDeclaration> it = that.pars.iterator();
+ for (ParameterDeclaration pd: pars) {
+ ParameterDeclaration thatPd = it.next();
+
+ if (!pd.equals(thatPd)) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ public int hashCode() {
+ return methName.hashCode();
+ }
+
+ /* We always use the compareTo method
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ return compareTo((MethodHandler)obj) == 0;
+ }
+}
\ No newline at end of file
Property changes on: trunk/annotations/src/org/bedework/calfacade/annotations/process/MethodHandler.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/ProcessState.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/ProcessState.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/ProcessState.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -26,8 +26,7 @@
package org.bedework.calfacade.annotations.process;
-import java.io.LineNumberReader;
-import java.io.PrintWriter;
+import org.bedework.calfacade.annotations.Wrapper;
import com.sun.mirror.type.InterfaceType;
import com.sun.mirror.type.TypeMirror;
@@ -46,9 +45,12 @@
private ProxyHandler proxyHandler;
private IcalPropertyHandler icalPropertyHandler;
- PrintWriter proxyOut;
- LineNumberReader proxyRdr;
+ private WrapperHandler wrapperHandler;
+ boolean processingWrapper;
+
+ boolean debug;
+
/**
* @param val
*/
@@ -75,6 +77,35 @@
}
/**
+ *
+ * @param wpr
+ * @return vHandler
+ */
+ public WrapperHandler getWrapperHandler(Wrapper wpr) {
+ if (wrapperHandler == null) {
+ wrapperHandler = new WrapperHandler(this, wpr);
+ }
+
+ return wrapperHandler;
+ }
+
+ /** Get current wrapper handler
+ *
+ * @return vHandler
+ */
+ public WrapperHandler getWrapperHandler() {
+ return wrapperHandler;
+ }
+
+ /** Remove current wrapper handler
+ *
+ */
+ public void endWrapperHandler() {
+ wrapperHandler = null;
+ processingWrapper = false;
+ }
+
+ /**
* @return IcalPropertyHandler
*/
public IcalPropertyHandler getIcalPropertyHandler() {
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyHandler.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyHandler.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyHandler.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -25,8 +25,6 @@
*/
package org.bedework.calfacade.annotations.process;
-import org.bedework.calfacade.annotations.ical.Immutable;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,7 +33,6 @@
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.apt.Messager;
import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.type.PrimitiveType;
/** TODO: We need to be able to handle something less generic than Collection,
* e.g. List or Set.
@@ -91,32 +88,8 @@
MethodDeclaration d) {
Messager msg = env.getMessager();
try {
- ProxyMethod pm = new ProxyMethod(env, annUtil);
+ ProxyMethod pm = new ProxyMethod(env, annUtil, d);
- pm.methName = d.getSimpleName();
- pm.getter = pm.methName.startsWith("get");
- pm.setter = pm.methName.startsWith("set");
-
- pm.immutable = d.getAnnotation(Immutable.class) != null;
- pm.returnType = d.getReturnType();
-
- pm.pars = d.getParameters();
-
- if ((pm.setter) && (pm.pars != null) && (pm.pars.size() == 1)) {
- pm.parType = pm.pars.iterator().next().getType();
- pm.basicType = pm.parType instanceof PrimitiveType;
- }
-
- if (pm.getter) {
- pm.basicType = pm.returnType instanceof PrimitiveType;
- }
-
- if (pm.setter || pm.getter) {
- pm.ucFieldName = pm.methName.substring(3);
- pm.fieldName = pm.ucFieldName.substring(0, 1).toLowerCase() +
- pm.ucFieldName.substring(1);
- }
-
proxyMethods.add(pm);
ProxyMethod setGet = fieldNameMap.get(pm.fieldName);
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyMethod.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyMethod.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/ProxyMethod.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -25,13 +25,11 @@
*/
package org.bedework.calfacade.annotations.process;
-//import org.bedework.calfacade.BwEvent;
-
import java.util.Collection;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.apt.Messager;
-import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
import com.sun.mirror.type.ClassType;
import com.sun.mirror.type.InterfaceType;
import com.sun.mirror.type.PrimitiveType;
@@ -42,55 +40,21 @@
*
* @author Mike DOuglass
*/
-public class ProxyMethod {
- private AnnUtil annUtil;
-
- String ucFieldName; // no lower cased first char.
- String fieldName;
-
- boolean basicType; // field type is int, boolean etc.
-
- String methName;
-
- boolean setter;
- boolean getter;
-
- boolean immutable;
-
- TypeMirror returnType;
- TypeMirror parType;
-
- Collection<ParameterDeclaration> pars;
-
+public class ProxyMethod extends MethodHandler {
// Points at other one of pair. Arranged so that setter is in map if present
ProxyMethod setGet;
- AnnotationProcessorEnvironment env;
- Messager msg;
-
/**
* @param env
* @param annUtil
+ * @param d
*/
public ProxyMethod(AnnotationProcessorEnvironment env,
- AnnUtil annUtil) {
- this.env = env;
- this.annUtil = annUtil;
- msg = env.getMessager();
+ AnnUtil annUtil,
+ MethodDeclaration d) {
+ super(env, annUtil, d);
}
- /** Generate the method
- */
- public void generate() {
- annUtil.generateSignature(methName, pars, returnType);
-
- if (getter) {
- generateGet();
- } else {
- generateSet();
- }
- }
-
/**
*/
public void generateGet() {
@@ -169,7 +133,7 @@
msg.printWarning("Unhandled returnType: " + returnType);
}
- typePar = annUtil.fixName(typePar);
+ typePar = AnnUtil.fixName(typePar);
// XXX Having done all that we didn't use typePar
@@ -209,7 +173,7 @@
if (annUtil.isCollection(parType)) {
String fieldTypeStr = annUtil.getClassName(parType);
- annUtil.println(" if (val instanceof Override", annUtil.generic(fieldTypeStr),
+ annUtil.println(" if (val instanceof Override", AnnUtil.nonGeneric(fieldTypeStr),
") {");
annUtil.println(" val = ((Override", fieldTypeStr, ")val).getOverrideCollection();");
annUtil.println(" }");
@@ -231,14 +195,12 @@
"");
}
- private String makeCallGetter(String objRef) {
- return annUtil.makeCallGetter(objRef, ucFieldName);
+ /**
+ */
+ public void generateMethod() {
+ env.getMessager().printError("Proxy should opnly do set/get");
}
- private String makeCallSetter(String objRef, Object val) {
- return annUtil.makeCallSetter(objRef, ucFieldName, val);
- }
-
private String makeGetEmptyFlag(String objRef) {
StringBuilder sb = new StringBuilder(objRef);
sb.append(".");
Modified: trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperHandler.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperHandler.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperHandler.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -25,17 +25,17 @@
*/
package org.bedework.calfacade.annotations.process;
-import org.bedework.calfacade.annotations.ical.Immutable;
+import org.bedework.calfacade.annotations.Wrapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TreeSet;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.apt.Messager;
import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.type.PrimitiveType;
/** TODO: We need to be able to handle something less generic than Collection,
* e.g. List or Set.
@@ -46,19 +46,31 @@
public class WrapperHandler {
private static final String wrapperTemplateName = "Wrapper.java.rsrc";
- private List<ProxyMethod> proxyMethods = new ArrayList<ProxyMethod>();
+ private List<WrapperMethod> wrapperMethods = new ArrayList<WrapperMethod>();
- private Map<String, ProxyMethod> fieldNameMap = new HashMap<String, ProxyMethod>();
+ private Map<String, WrapperMethod> fieldNameMap = new HashMap<String, WrapperMethod>();
+ private String currentClassName;
+
private ProcessState pstate;
private AnnUtil annUtil;
+ private Wrapper wpr;
+
+ private String wrappedClassName;
+ private String wrapperClassName;
+
/**
* @param pstate
+ * @param wpr
*/
- public WrapperHandler(ProcessState pstate) {
+ public WrapperHandler(ProcessState pstate,
+ Wrapper wpr) {
this.pstate = pstate;
+ this.wpr = wpr;
+ this.currentClassName = pstate.currentClassName;
+ wrappedClassName = AnnUtil.fixName(pstate.currentClassName);
}
/**
@@ -67,12 +79,19 @@
*/
public boolean start(AnnotationProcessorEnvironment env) {
try {
+ wrapperClassName = wrappedClassName + "NewWrapper";
+
annUtil = new AnnUtil(env,
"org.bedework.calfacade.BwEvent",
pstate.resourcePath + "/" + wrapperTemplateName,
- "org.bedework.calfacade." + "BwEventProxy");
+ "org.bedework.calfacade.wrappers." + wrapperClassName);
- return annUtil.emitTemplateSection();
+ if (!annUtil.emitTemplateSection()) {
+ Messager msg = env.getMessager();
+ msg.printError("Apparently no more input available from template");
+ }
+
+ return true;
} catch (Throwable t) {
Messager msg = env.getMessager();
msg.printError("Exception: " + t.getMessage());
@@ -88,55 +107,44 @@
public boolean method(AnnotationProcessorEnvironment env,
MethodDeclaration d) {
Messager msg = env.getMessager();
- try {
- ProxyMethod pm = new ProxyMethod(env, annUtil);
- pm.methName = d.getSimpleName();
- pm.getter = pm.methName.startsWith("get");
- pm.setter = pm.methName.startsWith("set");
+ if (pstate.debug) {
+ msg.printNotice("Wrapperhandler.method: " + d +
+ " declared by " + d.getDeclaringType());
+ }
- pm.immutable = d.getAnnotation(Immutable.class) != null;
- pm.returnType = d.getReturnType();
+ try {
+ WrapperMethod wm = new WrapperMethod(env, annUtil, d);
- pm.pars = d.getParameters();
-
- if ((pm.setter) && (pm.pars != null) && (pm.pars.size() == 1)) {
- pm.parType = pm.pars.iterator().next().getType();
- pm.basicType = pm.parType instanceof PrimitiveType;
+ if (wrapperMethods.contains(wm)) {
+ // Overridden?
+ return true;
}
- if (pm.getter) {
- pm.basicType = pm.returnType instanceof PrimitiveType;
- }
+ wrapperMethods.add(wm);
- if (pm.setter || pm.getter) {
- pm.ucFieldName = pm.methName.substring(3);
- pm.fieldName = pm.ucFieldName.substring(0, 1).toLowerCase() +
- pm.ucFieldName.substring(1);
- }
+ WrapperMethod setGet = fieldNameMap.get(wm.fieldName);
- proxyMethods.add(pm);
-
- ProxyMethod setGet = fieldNameMap.get(pm.fieldName);
-
if (setGet == null) {
- fieldNameMap.put(pm.fieldName, pm);
+ fieldNameMap.put(wm.fieldName, wm);
} else if (setGet.setter) {
// This should be a getter
- if (!pm.getter) {
- msg.printError("Error: found setter in table for " + pm);
+ if (!wm.getter) {
+ msg.printError("Error - class: " + currentClassName +
+ " found setter " + setGet + "\n in table for " + wm + " decl: " + d);
} else {
- setGet.setGet = pm;
- pm.setGet = setGet;
+ setGet.setGet = wm;
+ wm.setGet = setGet;
}
} else if (setGet.getter) {
- if (!pm.setter) {
- msg.printError("Error: found getter in table for " + pm);
+ if (!wm.setter) {
+ msg.printError("Error - class: " + currentClassName +
+ " found getter in table for " + wm);
} else {
// Make setter first
- setGet.setGet = pm;
- pm.setGet = setGet;
- fieldNameMap.put(pm.fieldName, pm);
+ setGet.setGet = wm;
+ wm.setGet = setGet;
+ fieldNameMap.put(wm.fieldName, wm);
}
}
@@ -153,10 +161,93 @@
*/
public boolean end(AnnotationProcessorEnvironment env) {
try {
- for (ProxyMethod pm: proxyMethods) {
- pm.generate();
+ TreeSet<String> imports = new TreeSet<String>();
+
+ for (WrapperMethod wm: wrapperMethods) {
+ imports.addAll(wm.getImports("org.bedework.calfacade.wrappers"));
}
+ for (String imp: imports) {
+ annUtil.println("import ", imp, ";");
+ }
+
+ if (!annUtil.emitTemplateSection()) {
+ Messager msg = env.getMessager();
+ msg.printError("Apparently no more input available from template");
+ }
+
+ boolean generateQuotaSupport = false;
+
+ annUtil.println("public class ", wrapperClassName, " extends ",
+ wrappedClassName, " {");
+
+ annUtil.println(" private ", wrappedClassName, " entity;",
+ "");
+
+ // If quotas supported add the quota methods.
+ generateQuotaSupport = wpr.quotas();
+
+ if (generateQuotaSupport) {
+ annUtil.prntlns(" private int sizeChange;",
+ "");
+ }
+
+ /* Generate constructor */
+ annUtil.println(" ", wrapperClassName, "(",
+ AnnUtil.fixName(currentClassName), " entity) {");
+ annUtil.prntlns(" this.entity = entity;",
+ " }",
+ "");
+
+ for (WrapperMethod wm: wrapperMethods) {
+ if (wm.staticMethod) {
+ continue;
+ }
+
+ wm.generate();
+ }
+
+ /* Add quota support methods */
+
+ annUtil.prntlns(" /* ====================================================================",
+ " * Size methods",
+ " * ==================================================================== */",
+ "",
+ " /** Used to track size changes.",
+ " *",
+ " * @param val",
+ " */",
+ " public void setSizeChange(int val) {",
+ " sizeChange = val;",
+ " }",
+ "",
+ " /**",
+ " * @return int last byte size change",
+ " */",
+ " public int getSizeChange() {",
+ " return sizeChange;",
+ " }",
+ "",
+ " /** Update the size change with the given increment",
+ " *",
+ " * @param val",
+ " */",
+ " public void updateSizeChange(int val) {",
+ " sizeChange += val;",
+ " }",
+ "",
+ " /** Update the size change with the size difference",
+ " *",
+ " * @param oldVal",
+ " * @param newVal",
+ " */");
+ annUtil.println(" public void updateSizeChange(", wrappedClassName, " oldVal, ",
+ wrappedClassName, " newVal) {");
+ annUtil.prntlns(" updateSizeChange(newVal.length() - oldVal.length());",
+ " }",
+ "}",
+ "");
+
if (annUtil.emitTemplateSection()) {
Messager msg = env.getMessager();
msg.printError("Apparently more input available from template");
Added: trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperMethod.java
===================================================================
--- trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperMethod.java (rev 0)
+++ trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperMethod.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -0,0 +1,92 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.annotations.process;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.MethodDeclaration;
+
+/** We create a list of these as we process the event. We tie together the
+ * setter and getter methods so that only the setter needs to be annotated
+ *
+ * @author Mike DOuglass
+ */
+public class WrapperMethod extends MethodHandler {
+ // Points at other one of pair. Arranged so that setter is in map if present
+ WrapperMethod setGet;
+
+ /**
+ * @param env
+ * @param annUtil
+ * @param d
+ */
+ public WrapperMethod(AnnotationProcessorEnvironment env,
+ AnnUtil annUtil,
+ MethodDeclaration d) {
+ super(env, annUtil, d);
+ }
+
+ /**
+ */
+ public void generateGet() {
+ annUtil.println(" return ", makeCallGetter("entity"), ";");
+ annUtil.prntlns(" }",
+ "");
+
+ }
+
+ /**
+ */
+ public void generateSet() {
+ annUtil.println(" ", makeCallSetter("entity", "val"), ";");
+ annUtil.prntlns(" }",
+ "");
+ }
+
+ /**
+ */
+ public void generateMethod() {
+ if (returnsVoid) {
+ annUtil.println(" entity.", makeCall(), ";");
+ } else {
+ annUtil.println(" return entity.", makeCall(), ";");
+ }
+ annUtil.prntlns(" }",
+ "");
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("WrapperMethod{");
+ sb.append(fieldName);
+ sb.append(", basic=");
+ sb.append(basicType);
+ sb.append(", method=");
+ sb.append(methName);
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
Property changes on: trunk/annotations/src/org/bedework/calfacade/annotations/process/WrapperMethod.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/build.xml 2008-06-27 03:08:17 UTC (rev 655)
@@ -189,6 +189,7 @@
<compilerarg value="-XPrintAptRounds"/>
<compilerarg value="-XPrintFactoryInfo"/>
-->
+ <option name="debug" value="true" />
</apt>
</target>
Modified: trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -109,7 +109,7 @@
* @author Mike Douglass douglm - rpi.edu
* @version 1.0
*/
- at Wrapper(superClass="org.bedework.calfacade.wrappers.BwDbentityWrapper")
+ at Wrapper(quotas = true)
public class BwCalendar extends BwShareableContainedDbentity<BwCalendar>
implements CollatableEntity, CategorisedEntity {
/** The internal name of the calendar
Modified: trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwEvent.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/calFacade/src/org/bedework/calfacade/BwEvent.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -311,7 +311,7 @@
*
* @version 1.0
*/
- at Wrapper(superClass="org.bedework.calfacade.wrappers.BwDbentityWrapper")
+ at Wrapper(quotas = true)
public class BwEvent extends BwShareableContainedDbentity<BwEvent>
implements AlarmsEntity, AttachmentsEntity, AttendeesEntity,
CategorisedEntity, CommentedEntity, ContactedEntity,
Modified: trunk/calFacade/src/org/bedework/calfacade/base/BwDbentity.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/base/BwDbentity.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/calFacade/src/org/bedework/calfacade/base/BwDbentity.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -26,6 +26,7 @@
package org.bedework.calfacade.base;
import org.bedework.calfacade.CalFacadeDefs;
+import org.bedework.calfacade.annotations.NoWrap;
import java.io.Serializable;
import java.util.ArrayList;
@@ -234,14 +235,20 @@
/** Make visible
* @return Object of class T
*/
+ @NoWrap
public Object clone() {
return null;
}
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @NoWrap
public int compareTo(T o) {
throw new RuntimeException("compareTo must be implemented for a db object");
}
+ @NoWrap
public int hashCode() {
throw new RuntimeException("hashcode must be implemented for a db object");
}
Modified: trunk/calFacade/src/org/bedework/calfacade/wrappers/BwDbentityWrapper.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/wrappers/BwDbentityWrapper.java 2008-06-20 19:34:32 UTC (rev 654)
+++ trunk/calFacade/src/org/bedework/calfacade/wrappers/BwDbentityWrapper.java 2008-06-27 03:08:17 UTC (rev 655)
@@ -37,7 +37,7 @@
*/
public class BwDbentityWrapper<T extends BwDbentity> extends BwDbentity
implements EntityWrapper<T> {
- private T entity;
+ protected T entity;
private int sizeChange;
@@ -101,7 +101,7 @@
sizeChange += val;
}
- /** Update the size change with the size diffference
+ /** Update the size change with the size difference
*
* @param oldVal
* @param newVal
More information about the Bedework-commit
mailing list