Seam SVN: r13561 - in sandbox/encore/core/src: main/java/org/jboss/encore/grammar/java/ast and 4 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-08-05 13:54:51 -0400 (Thu, 05 Aug 2010)
New Revision: 13561
Added:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Abstractable.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/VisibilityScoped.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/AnnotationAccessor.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/util/
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/util/Strings.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldAnnotationTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassAnnotationTest.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClass.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedField.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethod.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClass.java
Removed:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
Modified:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java
Log:
Fields & Field Annotations are working - however, field addition is not.
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Abstractable.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Abstractable.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Abstractable.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface Abstractable<T>
+{
+ public abstract boolean isAbstract();
+
+ public abstract T setAbstract(boolean abstrct);
+}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Field.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java;
+
+import org.jboss.encore.grammar.Internal;
+import org.jboss.encore.grammar.Mutable;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface Field extends Mutable, Internal, VisibilityScoped<Field>, AnnotationTarget<Field>
+{
+
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -31,9 +31,8 @@
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
-public interface JavaClass extends Internal, Mutable, AnnotationTarget<JavaClass>
+public interface JavaClass extends Internal, Mutable, Abstractable<JavaClass>, VisibilityScoped<JavaClass>, AnnotationTarget<JavaClass>
{
-
/*
* Annotation modifiers
*/
@@ -51,22 +50,24 @@
public abstract JavaClass removeImport(Import imprt);
- /**
- * Get a list of the {@link Import}s contained within this {@link JavaClass}.
- * Note that modification of this list does not affect internal state, but
- * modification of individual {@link Import} objects will.
- */
public abstract List<Import> getImports();
+ /*
+ * Fields & Methods
+ */
+
+ public abstract Field addField();
+
+ public abstract Field addField(final String field);
+
+ public abstract List<Field> getFields();
+
+ public abstract JavaClass removeField(final Field method);
+
public abstract Method addMethod();
public abstract Method addMethod(final String method);
- /**
- * Get a list of the {@link Method}s contained within this {@link JavaClass}.
- * Note that modification of this list does not affect internal state, but
- * modification of individual {@link Method} objects will.
- */
public abstract List<Method> getMethods();
public abstract JavaClass removeMethod(final Method method);
@@ -83,29 +84,6 @@
public abstract boolean isDefaultPackage();
- /*
- * Visibility modifiers
- */
- public abstract boolean isPackagePrivate();
-
- public abstract JavaClass setPackagePrivate();
-
- public abstract boolean isPublic();
-
- public abstract JavaClass setPublic();
-
- public abstract boolean isPrivate();
-
- public abstract JavaClass setPrivate();
-
- public abstract boolean isProtected();
-
- public abstract JavaClass setProtected();
-
- public abstract boolean isAbstract();
-
- public abstract JavaClass setAbstract(boolean abstrct);
-
@Override
public abstract int hashCode();
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -29,7 +29,7 @@
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
-public interface Method extends Internal, Mutable, AnnotationTarget<Method>
+public interface Method extends Internal, Mutable, Abstractable<Method>, VisibilityScoped<Method>, AnnotationTarget<Method>
{
public String getBody();
@@ -44,32 +44,12 @@
public boolean isConstructor();
- public boolean isAbstract();
-
- public Method setAbstract(boolean abstrct);
-
public Method setFinal();
public String getName();
public Method setName(final String name);
- public boolean isPackagePrivate();
-
- public Method setPackagePrivate();
-
- public boolean isPublic();
-
- public Method setPublic();
-
- public boolean isPrivate();
-
- public Method setPrivate();
-
- public boolean isProtected();
-
- public Method setProtected();
-
public String getReturnType();
public Method setReturnType(final Class<?> type);
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/VisibilityScoped.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/VisibilityScoped.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/VisibilityScoped.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface VisibilityScoped<T>
+{
+ public abstract boolean isPackagePrivate();
+
+ public abstract T setPackagePrivate();
+
+ public abstract boolean isPublic();
+
+ public abstract T setPublic();
+
+ public abstract boolean isPrivate();
+
+ public abstract T setPrivate();
+
+ public abstract boolean isProtected();
+
+ public abstract T setProtected();
+}
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/AnnotationAccessor.java (from rev 13560, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/AnnotationAccessor.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/AnnotationAccessor.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.AnnotationTarget;
+import org.jboss.encore.grammar.java.impl.AnnotationImpl;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class AnnotationAccessor
+{
+
+ @SuppressWarnings("unchecked")
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body)
+ {
+ Annotation annotation = new AnnotationImpl(target);
+ body.modifiers().add(annotation.getInternal());
+ return annotation;
+ }
+
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, Class<?> clazz)
+ {
+ return addAnnotation(target, body, clazz.getName());
+ }
+
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, final String className)
+ {
+ return addAnnotation(target, body).setName(className);
+ }
+
+ public List<Annotation> getAnnotations(AnnotationTarget<?> target, BodyDeclaration body)
+ {
+ List<Annotation> result = new ArrayList<Annotation>();
+
+ List<?> modifiers = body.modifiers();
+ for (Object object : modifiers)
+ {
+ if (object instanceof org.eclipse.jdt.core.dom.Annotation)
+ {
+ Annotation annotation = new AnnotationImpl(target, object);
+ result.add(annotation);
+ }
+ }
+
+ return result;
+ }
+
+ public <T extends AnnotationTarget<?>> T removeAnnotation(T target, BodyDeclaration body, Annotation annotation)
+ {
+ List<?> modifiers = body.modifiers();
+ for (Object object : modifiers)
+ {
+ if (object.equals(annotation.getInternal()))
+ {
+ modifiers.remove(object);
+ break;
+ }
+ }
+ return target;
+ }
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -37,6 +37,7 @@
import org.jboss.encore.grammar.java.JavaClass;
import org.jboss.encore.grammar.java.JavaParser;
import org.jboss.encore.grammar.java.ValuePair;
+import org.jboss.encore.grammar.java.util.Strings;
/**
*
Deleted: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,87 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.encore.grammar.java.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.jboss.encore.grammar.java.Annotation;
-import org.jboss.encore.grammar.java.AnnotationTarget;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class AnnotationUtil
-{
-
- @SuppressWarnings("unchecked")
- public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body)
- {
- Annotation annotation = new AnnotationImpl(target);
- body.modifiers().add(annotation.getInternal());
- return annotation;
- }
-
- public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, Class<?> clazz)
- {
- return addAnnotation(target, body, clazz.getName());
- }
-
- public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, final String className)
- {
- return addAnnotation(target, body).setName(className);
- }
-
- public List<Annotation> getAnnotations(AnnotationTarget<?> target, BodyDeclaration body)
- {
- List<Annotation> result = new ArrayList<Annotation>();
-
- List<?> modifiers = body.modifiers();
- for (Object object : modifiers)
- {
- if (object instanceof org.eclipse.jdt.core.dom.Annotation)
- {
- Annotation annotation = new AnnotationImpl(target, object);
- result.add(annotation);
- }
- }
-
- return result;
- }
-
- public <T extends AnnotationTarget<?>> T removeAnnotation(T target, BodyDeclaration body, Annotation annotation)
- {
- List<?> modifiers = body.modifiers();
- for (Object object : modifiers)
- {
- if (object.equals(annotation.getInternal()))
- {
- modifiers.remove(object);
- break;
- }
- }
- return target;
- }
-}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/FieldImpl.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.impl;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.Field;
+import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
+import org.jboss.encore.grammar.java.ast.AnnotationAccessor;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class FieldImpl implements Field
+{
+ private static AnnotationAccessor util = new AnnotationAccessor();
+
+ private JavaClass parent;
+ private AST ast;
+ private final FieldDeclaration field;
+
+ private void init(final JavaClass parent)
+ {
+ this.parent = parent;
+ ast = ((ASTNode) parent.getInternal()).getAST();
+ }
+
+ public FieldImpl(JavaClass parent)
+ {
+ init(parent);
+ this.field = ast.newFieldDeclaration(ast.newVariableDeclarationFragment());
+ }
+
+ public FieldImpl(JavaClass parent, String declaration)
+ {
+ init(parent);
+
+ String stub = "public class Stub { " + declaration + " }";
+ JavaClass temp = JavaParser.parse(stub);
+ List<Field> fields = temp.getFields();
+ FieldDeclaration newField = (FieldDeclaration) fields.get(0).getInternal();
+ FieldDeclaration subtree = (FieldDeclaration) ASTNode.copySubtree(ast, newField);
+ this.field = subtree;
+ }
+
+ public FieldImpl(JavaClass parent, Object internal)
+ {
+ init(parent);
+ this.field = (FieldDeclaration) internal;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ parent.applyChanges();
+ }
+
+ @Override
+ public Object getInternal()
+ {
+ return field;
+ }
+
+ @Override
+ public boolean isPackagePrivate()
+ {
+ return false;
+ }
+
+ @Override
+ public Field setPackagePrivate()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isPublic()
+ {
+ return false;
+ }
+
+ @Override
+ public Field setPublic()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isPrivate()
+ {
+ return false;
+ }
+
+ @Override
+ public Field setPrivate()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isProtected()
+ {
+ return false;
+ }
+
+ @Override
+ public Field setProtected()
+ {
+ return null;
+ }
+
+ /*
+ * Annotation Modifiers
+ */
+ @Override
+ public Annotation addAnnotation()
+ {
+ return util.addAnnotation(this, field);
+ }
+
+ @Override
+ public Annotation addAnnotation(Class<?> clazz)
+ {
+ return util.addAnnotation(this, field, clazz);
+ }
+
+ @Override
+ public Annotation addAnnotation(final String className)
+ {
+ return util.addAnnotation(this, field, className);
+ }
+
+ @Override
+ public List<Annotation> getAnnotations()
+ {
+ return util.getAnnotations(this, field);
+ }
+
+ @Override
+ public Field removeAnnotation(Annotation annotation)
+ {
+ return util.removeAnnotation(this, field, annotation);
+ }
+
+ @Override
+ public String toString()
+ {
+ return field.toString();
+ }
+
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -28,6 +28,7 @@
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
@@ -39,9 +40,11 @@
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.TextEdit;
import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.Field;
import org.jboss.encore.grammar.java.Import;
import org.jboss.encore.grammar.java.JavaClass;
import org.jboss.encore.grammar.java.Method;
+import org.jboss.encore.grammar.java.ast.AnnotationAccessor;
import org.jboss.encore.grammar.java.ast.MethodFinderVisitor;
import org.jboss.encore.grammar.java.ast.ModifierAccessor;
import org.jboss.encore.grammar.java.ast.TypeDeclarationFinderVisitor;
@@ -53,7 +56,7 @@
*/
public class JavaClassImpl implements JavaClass
{
- private static AnnotationUtil util = new AnnotationUtil();
+ private static AnnotationAccessor util = new AnnotationAccessor();
private Document document;
private CompilationUnit unit;
@@ -222,11 +225,49 @@
}
/*
- * Method modifiers
+ * Field & Method modifiers
*/
@Override
@SuppressWarnings("unchecked")
+ public Field addField()
+ {
+ Field field = new FieldImpl(this);
+ getTypeDeclaration().bodyDeclarations().add(field.getInternal());
+ return field;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Field addField(String declaration)
+ {
+ Field field = new FieldImpl(this, declaration);
+ getTypeDeclaration().bodyDeclarations().add(field.getInternal());
+ return field;
+ }
+
+ @Override
+ public List<Field> getFields()
+ {
+ List<Field> result = new ArrayList<Field>();
+
+ for (FieldDeclaration field : getTypeDeclaration().getFields())
+ {
+ result.add(new FieldImpl(this, field));
+ }
+
+ return result;
+ }
+
+ @Override
+ public JavaClass removeField(Field field)
+ {
+ getTypeDeclaration().bodyDeclarations().remove(field.getInternal());
+ return this;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
public Method addMethod()
{
Method m = new MethodImpl(this);
@@ -262,10 +303,7 @@
@Override
public JavaClass removeMethod(final Method method)
{
- if (getMethods().contains(method))
- {
- getTypeDeclaration().bodyDeclarations().remove(method.getInternal());
- }
+ getTypeDeclaration().bodyDeclarations().remove(method.getInternal());
return this;
}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -34,6 +34,7 @@
import org.jboss.encore.grammar.java.JavaClass;
import org.jboss.encore.grammar.java.JavaParser;
import org.jboss.encore.grammar.java.Method;
+import org.jboss.encore.grammar.java.ast.AnnotationAccessor;
import org.jboss.encore.grammar.java.ast.ModifierAccessor;
/**
@@ -42,7 +43,7 @@
*/
public class MethodImpl implements Method
{
- private static AnnotationUtil util = new AnnotationUtil();
+ private static AnnotationAccessor util = new AnnotationAccessor();
private JavaClass parent = null;
private AST ast = null;
@@ -82,6 +83,10 @@
this.method = subtree;
}
+ /*
+ * Annotation Modifiers
+ */
+
@Override
public Annotation addAnnotation()
{
@@ -112,6 +117,10 @@
return util.removeAnnotation(this, method, annotation);
}
+ /*
+ * Method Modifiers
+ */
+
@Override
@SuppressWarnings("unchecked")
public String getBody()
Deleted: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.encore.grammar.java.impl;
-
-/**
- * String utilities.
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- */
-public class Strings
-{
- public static String unquote(String value)
- {
- String result = null;
- if (value != null)
- {
- result = value.toString().replaceAll("\"(.*)\"", "$1");
- }
- return result;
- }
-}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -23,6 +23,7 @@
package org.jboss.encore.grammar.java.impl;
import org.jboss.encore.grammar.java.ValuePair;
+import org.jboss.encore.grammar.java.util.Strings;
/**
* Represents an annotation value pair
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/util/Strings.java (from rev 13560, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/util/Strings.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/util/Strings.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.util;
+
+/**
+ * String utilities.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class Strings
+{
+ public static String unquote(String value)
+ {
+ String result = null;
+ if (value != null)
+ {
+ result = value.toString().replaceAll("\"(.*)\"", "$1");
+ }
+ return result;
+ }
+}
Deleted: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.encore.grammar.java;
-
-import java.io.InputStream;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- */
-public class ClassAnnotationTest extends AnnotationTest
-{
- @Override
- public void resetTests()
- {
- InputStream stream = ClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java");
- JavaClass javaClass = JavaParser.parse(stream);
- setTarget(javaClass);
- }
-}
Added: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldAnnotationTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldAnnotationTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class FieldAnnotationTest extends AnnotationTest
+{
+ @Override
+ public void resetTests()
+ {
+ InputStream stream = FieldAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedField.java");
+ Field field = JavaParser.parse(stream).getFields().get(0);
+ setTarget(field);
+ }
+}
Added: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/FieldTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class FieldTest
+{
+ private InputStream stream;
+ private JavaClass javaClass;
+ private Field field;
+
+ @Before
+ public void reset()
+ {
+ stream = FieldTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedField.java");
+ javaClass = JavaParser.parse(stream);
+ javaClass.addField("public Boolean flag = false;");
+ field = javaClass.getFields().get(javaClass.getFields().size() - 1);
+ }
+
+ @Test
+ public void testParse() throws Exception
+ {
+ assertTrue(field instanceof Field);
+ }
+
+}
Copied: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassAnnotationTest.java (from rev 13560, sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java)
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassAnnotationTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassAnnotationTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class JavaClassAnnotationTest extends AnnotationTest
+{
+ @Override
+ public void resetTests()
+ {
+ InputStream stream = JavaClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedClass.java");
+ JavaClass javaClass = JavaParser.parse(stream);
+ setTarget(javaClass);
+ }
+}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -45,22 +45,22 @@
@Before
public void reset()
{
- stream = JavaClassTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
+ stream = JavaClassTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClass.java");
javaClass = JavaParser.parse(stream);
}
@Test
public void testApplyChangesRequiredForModification() throws Exception
{
- assertEquals("MockClassFile", javaClass.getName());
+ assertEquals("MockClass", javaClass.getName());
javaClass.setName("Telephone");
assertEquals("Telephone", javaClass.getName());
assertFalse(javaClass.toString().contains("Telephone"));
- assertTrue(javaClass.toString().contains("MockClassFile"));
+ assertTrue(javaClass.toString().contains("MockClass"));
javaClass.applyChanges();
assertTrue(javaClass.toString().contains("Telephone"));
- assertFalse(javaClass.toString().contains("MockClassFile"));
+ assertFalse(javaClass.toString().contains("MockClass"));
}
@Test
@@ -68,7 +68,7 @@
{
assertEquals(URL.class.getName(), javaClass.getImports().get(0).getName());
assertEquals(2, javaClass.getMethods().size());
- assertEquals("MockClassFile", javaClass.getName());
+ assertEquals("MockClass", javaClass.getName());
assertTrue(javaClass.isPublic());
assertFalse(javaClass.isAbstract());
}
@@ -76,7 +76,7 @@
@Test
public void testSetName() throws Exception
{
- assertEquals("MockClassFile", javaClass.getName());
+ assertEquals("MockClass", javaClass.getName());
javaClass.setName("Telephone");
assertEquals("Telephone", javaClass.getName());
}
@@ -84,8 +84,8 @@
@Test
public void testSetNameUpdatesConstructorNames() throws Exception
{
- assertEquals("MockClassFile", javaClass.getName());
- assertEquals("MockClassFile", javaClass.getMethods().get(0).getName());
+ assertEquals("MockClass", javaClass.getName());
+ assertEquals("MockClass", javaClass.getMethods().get(0).getName());
javaClass.setName("Telephone");
assertEquals("Telephone", javaClass.getName());
assertEquals("Telephone", javaClass.getMethods().get(0).getName());
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -31,7 +31,7 @@
@Override
public void resetTests()
{
- InputStream stream = MethodAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java");
+ InputStream stream = MethodAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedMethod.java");
Method method = JavaParser.parse(stream).getMethods().get(0);
setTarget(method);
}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -42,7 +42,7 @@
@Before
public void reset()
{
- stream = MethodTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
+ stream = MethodTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClass.java");
javaClass = JavaParser.parse(stream);
javaClass.addMethod("public URL rewriteURL(String pattern, String replacement) { return null; }");
method = javaClass.getMethods().get(javaClass.getMethods().size() - 1);
Copied: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClass.java (from rev 13560, sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java)
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClass.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClass.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,15 @@
+package org.jboss.seam.encore.grammar.java;
+
+import java.net.URL;
+
+@Deprecated
+@SuppressWarnings("deprecation")
+@SuppressWarnings(value="unchecked")
+public class MockAnnotatedClass
+{
+ private String field;
+
+ public MockClassFile()
+ {
+ }
+}
Deleted: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,15 +0,0 @@
-package org.jboss.seam.encore.grammar.java;
-
-import java.net.URL;
-
-@Deprecated
-@SuppressWarnings("deprecation")
-@SuppressWarnings(value="unchecked")
-public class MockAnnotatedClassFile
-{
- private String field;
-
- public MockClassFile()
- {
- }
-}
Added: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedField.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedField.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedField.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,9 @@
+package org.jboss.seam.encore.grammar.java;
+
+public class MockAnnotatedField
+{
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ @SuppressWarnings(value="unchecked")
+ private String field;
+}
Copied: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethod.java (from rev 13560, sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java)
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethod.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethod.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,11 @@
+package org.jboss.seam.encore.grammar.java;
+
+public class MockAnnotatedMethod
+{
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ @SuppressWarnings(value="unchecked")
+ public MockAnnotatedMethod()
+ {
+ }
+}
Deleted: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,11 +0,0 @@
-package org.jboss.seam.encore.grammar.java;
-
-public class MockAnnotatedMethodFile
-{
- @Deprecated
- @SuppressWarnings("deprecation")
- @SuppressWarnings(value="unchecked")
- public MockClassFile()
- {
- }
-}
Copied: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClass.java (from rev 13560, sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java)
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClass.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClass.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -0,0 +1,18 @@
+package org.jboss.seam.encore.grammar.java;
+
+import java.net.URL;
+
+public class MockClass
+{
+ private String field;
+ private URL urlField;
+
+ public MockClass()
+ {
+ }
+
+ public String valueOf(URL url)
+ {
+ return url.getPath();
+ }
+}
Deleted: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-08-05 12:31:27 UTC (rev 13560)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-08-05 17:54:51 UTC (rev 13561)
@@ -1,18 +0,0 @@
-package org.jboss.seam.encore.grammar.java;
-
-import java.net.URL;
-
-public class MockClassFile
-{
- private String field;
- private URL urlField;
-
- public MockClassFile()
- {
- }
-
- public String valueOf(URL url)
- {
- return url.getPath();
- }
-}
13 years, 9 months
seam-commits@lists.jboss.org 48% OFF on Pfizer!
by seam-commits@lists.jboss.org
http://groups.yahoo.com/group/snehelwigingtonrw/message
ch der gro.ere
Schwung. Herr Drexler, damals Vorsitzender der Ortsgruppe Munchen, war einfacher Arbeiter, als
Redner ebenfalls wenig bedeutend, im ubrigen aber kein Soldat. Er hatte nicht beim Heer gedient, war
auch wahrend des Krieges nicht Soldat, so da. ihm, der seinem ganzen Wesen nach an sich schwachlich
und unsicher war, die einzige Schule fehlte, die es fertigbringen konnte, aus unsicheren und
umfassend gebildet. Doch hatte er eine fur einen Parteifuhrer au.erordentlich schwere Belastung: er war
kein Redner fur die Masse. So peinlich gewissenhaft und genau seine Arbeit an sich war, so fehlte ihr
jedoch vielleicht gerade infolge der fehlenden gro.en redneris
13 years, 9 months
Seam SVN: r13560 - in modules/xml/trunk: impl and 1 other directory.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 08:31:27 -0400 (Thu, 05 Aug 2010)
New Revision: 13560
Modified:
modules/xml/trunk/impl/pom.xml
modules/xml/trunk/pom.xml
Log:
added test dependency on servlet api to allow the use of a released version of weldx
Modified: modules/xml/trunk/impl/pom.xml
===================================================================
--- modules/xml/trunk/impl/pom.xml 2010-08-05 12:18:29 UTC (rev 13559)
+++ modules/xml/trunk/impl/pom.xml 2010-08-05 12:31:27 UTC (rev 13560)
@@ -36,9 +36,15 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-se</artifactId>
- <version>1.0.2-SNAPSHOT</version>
+ <version>1.0.1-Final</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-08-05 12:18:29 UTC (rev 13559)
+++ modules/xml/trunk/pom.xml 2010-08-05 12:31:27 UTC (rev 13560)
@@ -54,7 +54,12 @@
<groupId>el-impl</groupId>
<artifactId>el-impl</artifactId>
<version>${el-impl.version}</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
</dependencies>
</dependencyManagement>
13 years, 9 months
Seam SVN: r13559 - in modules/xml/trunk: impl/src/main/java/org/jboss/seam/xml/model and 1 other directory.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 08:18:29 -0400 (Thu, 05 Aug 2010)
New Revision: 13559
Modified:
modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
Log:
fixed princess-resuce example
Modified: modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml 2010-08-05 11:55:41 UTC (rev 13558)
+++ modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml 2010-08-05 12:18:29 UTC (rev 13559)
@@ -2,7 +2,7 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="urn:java:ee"
- xmlns:p="org.jboss.seam.xml.examples.princess"
+ xmlns:p="urn:java:org.jboss.seam.xml.examples.princess"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
@@ -13,7 +13,7 @@
</p:Room>
<p:GameManager>
- <s:extends/>
+ <s:modifies/>
<p:allRooms>
<s:Any/>
<s:Inject/>
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-08-05 11:55:41 UTC (rev 13558)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-08-05 12:18:29 UTC (rev 13559)
@@ -43,6 +43,8 @@
import org.jboss.seam.xml.parser.namespace.RootNamespaceElementResolver;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Builds an XML result from sax nodes
@@ -57,6 +59,8 @@
static final String BEANS_ROOT_NAMESPACE = "http://java.sun.com/xml/ns/javaee";
+ static final Logger log = LoggerFactory.getLogger(ModelBuilder.class);
+
private final XmlResult ret;
public ModelBuilder(String fileUrl)
@@ -96,7 +100,6 @@
continue;
}
XmlItem rb = resolveNode(node, null, resolvers, manager);
- // validateXmlItem(rb);
if (rb != null)
{
addNodeToResult(rb, manager);
@@ -173,6 +176,7 @@
NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri(), resolvers);
if (resolver == null)
{
+ log.warn("Could not resolve namspace for seam-xml: {}", node.getNamespaceUri());
return null;
}
XmlItem ret = resolver.getItemForNamespace(node, parent);
13 years, 9 months
Seam SVN: r13558 - modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 07:55:41 -0400 (Thu, 05 Aug 2010)
New Revision: 13558
Modified:
modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml
Log:
fix beans.xml
Modified: modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml 2010-08-05 11:44:53 UTC (rev 13557)
+++ modules/xml/trunk/examples/princess-rescue/src/main/resources/META-INF/beans.xml 2010-08-05 11:55:41 UTC (rev 13558)
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:ee"
+ xmlns:p="org.jboss.seam.xml.examples.princess"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://docs.jboss.org/cdi/beans_1_0.xsd">
+
+ <!-- Makes the Room annotation a qualifier -->
+ <p:Room>
+ <s:Qualifier/>
+ </p:Room>
+
+ <p:GameManager>
+ <s:extends/>
+ <p:allRooms>
+ <s:Any/>
+ <s:Inject/>
+ </p:allRooms>
+ <p:emptyRoomShootMessage>Your arrow does not appear to hit anything.</p:emptyRoomShootMessage>
+ <p:startMessage>You enter the dungeon, with you bow in your hand and your heart in your mouth.</p:startMessage>
+ <p:startRoom>
+ <!-- Inject the starting room -->
+ <s:Inject/>
+ <p:Room>startRoom</p:Room>
+ </p:startRoom>
+ </p:GameManager>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room value="startRoom"/>
+ <p:north><s:Inject/><p:Room>emptyRoom1</p:Room></p:north>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom1</p:Room>
+ <p:north><s:Inject/><p:Room>emptyRoom3</p:Room></p:north>
+ <p:west><s:Inject/><p:Room>dwarfRoom</p:Room></p:west>
+ <p:east><s:Inject/><p:Room>pitRoom1</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>startRoom</p:Room></p:south>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>dwarfRoom</p:Room>
+ <p:roomType>MONSTER</p:roomType>
+ <p:shootEffect>KILL</p:shootEffect>
+ <p:adjacentMessage>You hear drunken singing.</p:adjacentMessage>
+ <p:message>You find a drunken dwarven miner. He belches in your direction, falls over, then seems to forget you are there.</p:message>
+ <p:shootMessage>You hear a 'Thud', followed by a surprised yell.</p:shootMessage>
+ <p:killedRoomMessage>You find a dead dwarven miner with something that looks suspiciously like one of your arrows sticking out of his chest. Probably best you don't mention this to anyone...</p:killedRoomMessage>
+ <p:east><s:Inject/><p:Room>emptyRoom1</p:Room></p:east>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>pitRoom1</p:Room>
+ <p:roomType>GAMEOVER</p:roomType>
+ <p:adjacentMessage>You feel a breeze.</p:adjacentMessage>
+ <p:message>You fall into a bottomless pit. Game Over. </p:message>
+ <p:west><s:Inject/><p:Room>emptyRoom1</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom2</p:Room>
+ <p:north><s:Inject/><p:Room>emptyRoom4</p:Room></p:north>
+ <p:west><s:Inject/><p:Room>pitRoom1</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom3</p:Room>
+ <p:north><s:Inject/><p:Room>pitRoom2</p:Room></p:north>
+ <p:east><s:Inject/><p:Room>batRoom</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>emptyRoom1</p:Room></p:south>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>batRoom</p:Room>
+ <p:adjacentMessage>You hear a screeching noise.</p:adjacentMessage>
+ <p:message>A swarm of bats lands on you and tries to pick you up. They fail miserably. You swat them away with your bow.</p:message>
+ <p:shootMessage>You seem to have disturbed some bats, they fly past your head in the dark.</p:shootMessage>
+ <p:north><s:Inject/><p:Room>emptyRoom6</p:Room></p:north>
+ <p:east><s:Inject/><p:Room>emptyRoom4</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>pitRoom1</p:Room></p:south>
+ <p:west><s:Inject/><p:Room>emptyRoom3</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom4</p:Room>
+ <p:east><s:Inject/><p:Room>emptyRoom5</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>emptyRoom2</p:Room></p:south>
+ <p:west><s:Inject/><p:Room>batRoom</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom5</p:Room>
+ <p:north><s:Inject/><p:Room>emptyRoom7</p:Room></p:north>
+ <p:east><s:Inject/><p:Room>dragonRoom</p:Room></p:east>
+ <p:west><s:Inject/><p:Room>emptyRoom4</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>dragonRoom</p:Room>
+ <p:adjacentMessage>You hear a snoring noise. With every snore you see a flickering light, as if something were breathing flames from its nostrils.</p:adjacentMessage>
+ <p:roomType>GAMEOVER</p:roomType>
+ <p:message>The dragon wakes up as you enter. Then it eats you.</p:message>
+ <p:shootEffect>ANNOY</p:shootEffect>
+ <p:shootMessage>Your arrow wakes up the dragon, without appearing to do any real damage. The last moments of your life are spent running from an angry dragon.</p:shootMessage>
+ <p:north><s:Inject/><p:Room>princessRoom</p:Room></p:north>
+ <p:west><s:Inject/><p:Room>emptyRoom5</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>pitRoom2</p:Room>
+ <p:roomType>GAMEOVER</p:roomType>
+ <p:adjacentMessage>You feel a breeze.</p:adjacentMessage>
+ <p:message>You fall into a bottomless pit. Game Over. </p:message>
+ <p:south><s:Inject/><p:Room>emptyRoom3</p:Room></p:south>
+ <p:east><s:Inject/><p:Room>emptyRoom6</p:Room></p:east>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom6</p:Room>
+ <p:north><s:Inject/><p:Room>emptyRoom8</p:Room></p:north>
+ <p:west><s:Inject/><p:Room>pitRoom2</p:Room></p:west>
+ <p:south><s:Inject/><p:Room>batRoom</p:Room></p:south>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom7</p:Room>
+ <p:north><s:Inject/><p:Room>emptyRoom10</p:Room></p:north>
+ <p:east><s:Inject/><p:Room>princessRoom</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>emptyRoom5</p:Room></p:south>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>princessRoom</p:Room>
+ <p:adjacentMessage>You hear a sobbing noise.</p:adjacentMessage>
+ <p:roomType>GAMEOVER</p:roomType>
+ <p:message>You find the princess and quickly free her, and then escape from the dungeon. You both live happily ever after.</p:message>
+ <p:shootEffect>ANNOY</p:shootEffect>
+ <p:shootMessage>Your arrow clatters against the wall. You hear a cry 'Help i'm being shot at'. The cry wakes the dragon in the room next door, which promptly eats you.</p:shootMessage>
+ <p:south><s:Inject/><p:Room>dragonRoom</p:Room></p:south>
+ <p:west><s:Inject/><p:Room>emptyRoom7</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom8</p:Room>
+ <p:east><s:Inject/><p:Room>emptyRoom9</p:Room></p:east>
+ <p:south><s:Inject/><p:Room>emptyRoom6</p:Room></p:south>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom9</p:Room>
+ <p:north><s:Inject/><p:Room>wumpusRoom</p:Room></p:north>
+ <p:east><s:Inject/><p:Room>emptyRoom10</p:Room></p:east>
+ <p:west><s:Inject/><p:Room>emptyRoom8</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:Room>emptyRoom10</p:Room>
+ <p:south><s:Inject/><p:Room>emptyRoom7</p:Room></p:south>
+ <p:west><s:Inject/><p:Room>emptyRoom9</p:Room></p:west>
+ </p:GameRoom>
+
+ <p:GameRoom>
+ <s:SessionScoped/>
+ <p:roomType>MONSTER</p:roomType>
+ <p:adjacentMessage>You smell a Wumpus</p:adjacentMessage>
+ <p:shootMessage>You hear a 'Thud', followed by a roar of pain.</p:shootMessage>
+ <p:killedRoomMessage>You stumbe accross a dead Wumpus. Well that wasn't so hard...</p:killedRoomMessage>
+ <p:message>You find a Wumpus. It eats you.</p:message>
+ <p:shootEffect>KILL</p:shootEffect>
+ <p:Room>wumpusRoom</p:Room>
+ <p:south><s:Inject/><p:Room>emptyRoom9</p:Room></p:south>
+ </p:GameRoom>
+
+
+</beans>
13 years, 9 months
Seam SVN: r13557 - modules/xml/trunk/docs/src/main/docbook/en-US.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 07:44:53 -0400 (Thu, 05 Aug 2010)
New Revision: 13557
Modified:
modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml
Log:
update seam-xml docs to cover inline beans and el
Modified: modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml
===================================================================
--- modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml 2010-08-05 11:18:31 UTC (rev 13556)
+++ modules/xml/trunk/docs/src/main/docbook/en-US/xml-general.xml 2010-08-05 11:44:53 UTC (rev 13557)
@@ -278,8 +278,53 @@
<para>Type conversion is done automatically for all primitives and primitive wrappers, <literal>Date</literal>,
<literal>Calendar</literal>,<literal>Enum</literal> and <literal>Class</literal> fields.
In this instance <literal>ArrayFieldValue.carray</literal> is actually an array of classes, not an array of Strings.</para>
+ <para>The use of EL to set field values is also supported:</para>
+ <programlisting role="XML">
+ <![CDATA[
+<m:Report>
+ <m:name>#{reportName}</m:name>
+ <m:parameters>
+ <s:key>#{paramName}</s:key>
+ <s:value>#{paramValue}</s:key>
+ </m:parameters>
+</m:Report>
+]]>
+</programlisting>
</section>
<section>
+ <title>Inline Bean Declarations</title>
+ <para>Inline beans allow you to set field values to another bean that is declared inline inside the field declaration.
+ This allows for the configuration of complex types with nestled classes. Inline beans can be declared inside both
+ <literal><s:value></literal> and <literal><s:key></literal> elements, and may be used in both collections
+ and simple field values. Inline beans must not have any qualifier annotations declared on the bean, instead seam-xml assigns
+ them an artificial qualifier. Inline beans may have any scope, however the default <literal>Dependent</literal> scope is
+ recomended.
+ </para>
+<programlisting role="XML">
+<![CDATA[
+<test:Knight>
+ <test:sword>
+ <value>
+ <test:Sword type="sharp"/>
+ </value>
+ </test:sword>
+ <test:horse>
+ <value>
+ <test:Horse>
+ <test:name>
+ <value>billy</value>
+ </test:name>
+ <test:shoe>
+ <Inject/>
+ </test:shoe>
+ </test:Horse>
+ </value>
+ </test:horse>
+</test:Knight>
+]]>
+</programlisting>
+ </section>
+ <section>
<title>Configuring methods</title>
<para>It is also possible to configure methods in a similar way to configuring fields:</para>
13 years, 9 months
Seam SVN: r13556 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/model and 2 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 07:18:31 -0400 (Thu, 05 Aug 2010)
New Revision: 13556
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
Log:
improve el support and add tests for the collection case
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -37,7 +37,6 @@
import org.jboss.seam.xml.model.EntryXmlItem;
import org.jboss.seam.xml.util.TypeReader;
-import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.properties.Property;
/**
@@ -50,7 +49,7 @@
public class MapFieldSet implements FieldValueObject
{
private final Property field;
- private final List<Entry<Object, FieldValue>> values;
+ private final List<Entry<FieldValue, FieldValue>> values;
private final Class<?> keyType;
private final Class<?> valueType;
private final Class<? extends Map> collectionType;
@@ -58,7 +57,7 @@
public MapFieldSet(Property field, List<EntryXmlItem> items)
{
this.field = field;
- this.values = new ArrayList<Entry<Object, FieldValue>>();
+ this.values = new ArrayList<Entry<FieldValue, FieldValue>>();
// figure out the collection type
Type type = field.getBaseType();
if (type instanceof ParameterizedType)
@@ -100,8 +99,7 @@
for (EntryXmlItem i : items)
{
- final Object key = XmlObjectConverter.convert(keyType, i.getKey().getInnerText());
- values.add(new EntryImpl(key, i.getValue().getValue()));
+ values.add(new EntryImpl(i.getKey().getValue(), i.getValue().getValue()));
}
}
@@ -113,8 +111,8 @@
field.setValue(instance, res);
for (int i = 0; i < values.size(); ++i)
{
- Entry<Object, FieldValue> e = values.get(i);
- res.put(e.getKey(), e.getValue().value(valueType, ctx, manager));
+ Entry<FieldValue, FieldValue> e = values.get(i);
+ res.put(e.getKey().value(keyType, ctx, manager), e.getValue().value(valueType, ctx, manager));
}
}
catch (Exception e)
@@ -123,18 +121,18 @@
}
}
- private final class EntryImpl implements Entry<Object, FieldValue>
+ private final class EntryImpl implements Entry<FieldValue, FieldValue>
{
- private Object key;
+ private FieldValue key;
private FieldValue value;
- public EntryImpl(Object key, FieldValue value)
+ public EntryImpl(FieldValue key, FieldValue value)
{
this.key = key;
this.value = value;
}
- public Object getKey()
+ public FieldValue getKey()
{
return key;
}
@@ -149,7 +147,7 @@
return this.value = value;
}
- public void setKey(Object key)
+ public void setKey(FieldValue key)
{
this.key = key;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -94,6 +94,13 @@
}
if (!mapEntries.isEmpty())
{
+ for (EntryXmlItem entry : mapEntries)
+ {
+ // resolve inline beans if nessesary
+ Set<BeanResult<?>> beans = entry.getBeanResults(manager);
+ inlineBeans.addAll(beans);
+
+ }
fieldValue = new MapFieldSet(property, mapEntries);
}
}
@@ -105,6 +112,15 @@
}
if (!valueEntries.isEmpty())
{
+ for (ValueXmlItem value : valueEntries)
+ {
+ // resolve inline beans if nessesary
+ BeanResult<?> result = value.getBeanResult(manager);
+ if (result != null)
+ {
+ inlineBeans.add(result);
+ }
+ }
if (getFieldType().isArray())
{
fieldValue = new ArrayFieldSet(property, valueEntries);
@@ -127,7 +143,7 @@
}
ValueXmlItem value = valueEntries.get(0);
BeanResult<?> result = value.getBeanResult(manager);
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, valueEntries.get(0).getValue());
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, value.getValue());
if (result != null)
{
inlineBeans.add(result);
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,86 @@
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.fieldset.ConstantFieldValue;
+import org.jboss.seam.xml.fieldset.ELFieldValue;
+import org.jboss.seam.xml.fieldset.FieldValue;
+import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
+import org.jboss.seam.xml.fieldset.InlineBeanIdCreator;
+import org.jboss.seam.xml.fieldset.InlineBeanQualifier;
+import org.jboss.seam.xml.util.TypeOccuranceInformation;
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
+public abstract class AbstractValueXmlItem extends AbstractXmlItem
+{
+
+ private int syntheticQualifierId;
+ private BeanResult<?> inlineBean;
+
+ public AbstractValueXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes, String document, int lineno)
+ {
+ super(type, parent, javaClass, innerText, attributes, document, lineno);
+ }
+
+ public Set<TypeOccuranceInformation> getAllowedItem()
+ {
+ return Collections.singleton(TypeOccuranceInformation.of(XmlItemType.CLASS, null, 1));
+ }
+
+ public BeanResult<?> getBeanResult(BeanManager manager)
+ {
+ List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
+ if (!inlineBeans.isEmpty())
+ {
+ ClassXmlItem inline = inlineBeans.get(0);
+ for (AnnotationXmlItem i : inline.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Class annotation = (Class) i.getJavaClass();
+ if (manager.isQualifier(annotation))
+ {
+ throw new XmlConfigurationException("Cannot define qualifiers on inline beans, Qualifier: " + annotation.getName(), i.getDocument(), i.getLineno());
+ }
+ else if (manager.isScope(annotation) && annotation != Dependent.class)
+ {
+ throw new XmlConfigurationException("Inline beans must have @Dependent scope, Scope: " + annotation.getName(), i.getDocument(), i.getLineno());
+ }
+ }
+ syntheticQualifierId = InlineBeanIdCreator.getId();
+ AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this, InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP, getDocument(), getLineno());
+ inline.addChild(syntheticQualifier);
+ inlineBean = inline.createBeanResult(manager);
+ return inlineBean;
+ }
+ inlineBean = null;
+ return null;
+ }
+
+ public int getSyntheticQualifierId()
+ {
+ return syntheticQualifierId;
+ }
+
+ public FieldValue getValue()
+ {
+ if (inlineBean == null)
+ {
+ if (innerText.matches("^#\\{.*\\}$"))
+ {
+ return new ELFieldValue(innerText);
+ }
+ return new ConstantFieldValue(innerText);
+ }
+ else
+ {
+ return new InlineBeanFieldValue(syntheticQualifierId);
+ }
+ }
+
+}
\ No newline at end of file
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -26,6 +26,7 @@
import javax.enterprise.inject.spi.BeanManager;
+import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
@@ -34,8 +35,8 @@
final Set<TypeOccuranceInformation> allowed = new HashSet<TypeOccuranceInformation>();
- XmlItem key;
- XmlItem value;
+ KeyXmlItem key;
+ ValueXmlItem value;
public EntryXmlItem(XmlItem parent, String document, int lineno)
{
@@ -64,7 +65,7 @@
{
throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
}
- value = i;
+ value = (ValueXmlItem) i;
}
else if (i.getType() == XmlItemType.KEY)
{
@@ -72,13 +73,13 @@
{
throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
}
- key = i;
+ key = (KeyXmlItem) i;
}
}
return true;
}
- public XmlItem getKey()
+ public KeyXmlItem getKey()
{
return key;
}
@@ -88,4 +89,26 @@
return (ValueXmlItem) value;
}
+ /**
+ * get the inline beans for the value and the key
+ *
+ * @param manager
+ * @return
+ */
+ public Set<BeanResult<?>> getBeanResults(BeanManager manager)
+ {
+ Set<BeanResult<?>> ret = new HashSet<BeanResult<?>>();
+ BeanResult<?> r = value.getBeanResult(manager);
+ if (r != null)
+ {
+ ret.add(r);
+ }
+ r = key.getBeanResult(manager);
+ if (r != null)
+ {
+ ret.add(r);
+ }
+ return ret;
+ }
+
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -26,7 +26,7 @@
import org.jboss.seam.xml.util.TypeOccuranceInformation;
-public class KeyXmlItem extends AbstractXmlItem
+public class KeyXmlItem extends AbstractValueXmlItem
{
public KeyXmlItem(XmlItem parent, String innerText, String document, int lineno)
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -21,86 +21,13 @@
*/
package org.jboss.seam.xml.model;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.spi.BeanManager;
-import org.jboss.seam.xml.core.BeanResult;
-import org.jboss.seam.xml.fieldset.ConstantFieldValue;
-import org.jboss.seam.xml.fieldset.ELFieldValue;
-import org.jboss.seam.xml.fieldset.FieldValue;
-import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
-import org.jboss.seam.xml.fieldset.InlineBeanIdCreator;
-import org.jboss.seam.xml.fieldset.InlineBeanQualifier;
-import org.jboss.seam.xml.util.TypeOccuranceInformation;
-import org.jboss.seam.xml.util.XmlConfigurationException;
-public class ValueXmlItem extends AbstractXmlItem
+public class ValueXmlItem extends AbstractValueXmlItem
{
- private int syntheticQualifierId;
- private BeanResult<?> inlineBean;
- private BeanManager manager;
-
public ValueXmlItem(XmlItem parent, String innerText, String document, int lineno)
{
super(XmlItemType.VALUE, parent, null, innerText, null, document, lineno);
}
-
- public Set<TypeOccuranceInformation> getAllowedItem()
- {
- return Collections.singleton(TypeOccuranceInformation.of(XmlItemType.CLASS, null, 1));
- }
-
- public BeanResult<?> getBeanResult(BeanManager manager)
- {
- this.manager = manager;
- List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
- if (!inlineBeans.isEmpty())
- {
- ClassXmlItem inline = inlineBeans.get(0);
- for (AnnotationXmlItem i : inline.getChildrenOfType(AnnotationXmlItem.class))
- {
- Class annotation = (Class) i.getJavaClass();
- if (manager.isQualifier(annotation))
- {
- throw new XmlConfigurationException("Cannot define qualifiers on inline beans, Qualifier: " + annotation.getName(), i.getDocument(), i.getLineno());
- }
- else if (manager.isScope(annotation) && annotation != Dependent.class)
- {
- throw new XmlConfigurationException("Inline beans must have @Dependent scope, Scope: " + annotation.getName(), i.getDocument(), i.getLineno());
- }
- }
- syntheticQualifierId = InlineBeanIdCreator.getId();
- AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this, InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP, getDocument(), getLineno());
- inline.addChild(syntheticQualifier);
- inlineBean = inline.createBeanResult(manager);
- return inlineBean;
- }
- inlineBean = null;
- return null;
- }
-
- public int getSyntheticQualifierId()
- {
- return syntheticQualifierId;
- }
-
- public FieldValue getValue()
- {
- if (inlineBean == null)
- {
- if (innerText.matches("^#\\{.*\\}$"))
- {
- return new ELFieldValue(innerText);
- }
- return new ConstantFieldValue(innerText);
- }
- else
- {
- return new InlineBeanFieldValue(syntheticQualifierId);
- }
- }
}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.util.Map.Entry;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.junit.Test;
+
+public class ELFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "el-set-field-value-beans.xml";
+ }
+
+ @Test
+ public void mapSetFieldValue()
+ {
+ ELValueBean bean = getReference(ELValueBean.class);
+ Assert.assertTrue(bean.array.length == 1);
+ Assert.assertEquals(bean.array[0], ELValueProducer.EL_VALUE_STRING);
+ Assert.assertTrue(bean.list.size() == 1);
+ Assert.assertEquals(bean.list.get(0), ELValueProducer.EL_VALUE_STRING);
+ Assert.assertTrue(bean.map.size() == 1);
+ Entry<String, String> entry = bean.map.entrySet().iterator().next();
+ Assert.assertEquals(entry.getKey(), ELValueProducer.EL_VALUE_STRING);
+ Assert.assertEquals(entry.getValue(), ELValueProducer.EL_VALUE_STRING);
+ }
+}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Bean that test values set via el in arrays, lists and maps
+ *
+ * @author stuart
+ *
+ */
+public class ELValueBean
+{
+ public List<String> list;
+ public Map<String, String> map;
+ public String[] array;
+}
Added: modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:ee"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+ <test:ELValueBean>
+ <replaces/>
+ <test:array>
+ <value>#{elValue}</value>
+ </test:array>
+ <test:list>
+ <value>#{elValue}</value>
+ </test:list>
+ <test:map>
+ <entry>
+ <key>#{elValue}</key>
+ <value>#{elValue}</value>
+ </entry>
+ </test:map>
+ </test:ELValueBean>
+
+</beans>
\ No newline at end of file
13 years, 9 months
Seam SVN: r13555 - in modules/persistence/trunk: impl and 3 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-05 06:07:05 -0400 (Thu, 05 Aug 2010)
New Revision: 13555
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java
Modified:
modules/persistence/trunk/impl/pom.xml
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/AbstractManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
modules/persistence/trunk/pom.xml
Log:
port more stuff from seam 2, it compiles but needs to be tested
Modified: modules/persistence/trunk/impl/pom.xml
===================================================================
--- modules/persistence/trunk/impl/pom.xml 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/pom.xml 2010-08-05 10:07:05 UTC (rev 13555)
@@ -114,6 +114,13 @@
<artifactId>arquillian-junit</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/AbstractManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/AbstractManagedPersistenceContextBeanLifecycle.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/AbstractManagedPersistenceContextBeanLifecycle.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -44,7 +44,7 @@
public abstract class AbstractManagedPersistenceContextBeanLifecycle implements BeanLifecycle<EntityManager>
{
- static final Class<?> proxyClass = Proxy.getProxyClass(EntityManager.class.getClassLoader(), EntityManager.class, Serializable.class);
+ static final Class<?> proxyClass = Proxy.getProxyClass(PersistenceContext.class.getClassLoader(), EntityManager.class, Serializable.class, PersistenceContext.class);
static final Constructor<?> proxyConstructor;
@@ -76,7 +76,7 @@
{
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager entityManager = emf.createEntityManager();
- ManagedPersistenceContextProxyHandler handler = new ManagedPersistenceContextProxyHandler(entityManager, manager);
+ ManagedPersistenceContextProxyHandler handler = new ManagedPersistenceContextProxyHandler(entityManager, manager, bean.getQualifiers());
EntityManager proxy = (EntityManager) proxyConstructor.newInstance(handler);
return proxy;
}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Provides for programmatic configuration of the default flush mode.
+ *
+ * TODO: implement this
+ *
+ * @author Stuart Douglas
+ *
+ */
+@ApplicationScoped
+public class FlushModeManager implements Serializable
+{
+ FlushModeType flushModeType = FlushModeType.AUTO;
+
+ public FlushModeType getFlushModeType()
+ {
+ return flushModeType;
+ }
+
+ public void setFlushModeType(FlushModeType flushModeType)
+ {
+ this.flushModeType = flushModeType;
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,42 @@
+package org.jboss.seam.persistence;
+
+/**
+ * A full set of flush modes, including MANUAL,
+ * which is a glaring missing feature of the JPA
+ * spec.
+ *
+ * @author Gavin King
+ *
+ */
+public enum FlushModeType
+{
+
+ /**
+ * Flushing never occurs automatically, all changes are queued
+ * until the application calls flush() explicitly.
+ */
+ MANUAL,
+
+ /**
+ * Flushing occurs automatically at commit time and when necessary
+ * before query executions.
+ */
+ AUTO,
+
+ /**
+ * Flushing occurs automatically at transaction commit time.
+ */
+ COMMIT;
+
+ /**
+ * Does this flush mode keep unflushed changes past a
+ * transaction commit?
+ *
+ * @return false for all flush modes except for MANUAL
+ */
+ public boolean dirtyBetweenTransactions()
+ {
+ return this==MANUAL;
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,289 @@
+package org.jboss.seam.persistence;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+
+import org.hibernate.EntityMode;
+import org.hibernate.FlushMode;
+import org.hibernate.Session;
+import org.hibernate.StaleStateException;
+import org.hibernate.TransientObjectException;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.type.VersionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support for non-standardized features of Hibernate, when used as the JPA
+ * persistence provider.
+ *
+ * @author Gavin King
+ * @author Pete Muir
+ * @author Stuart Douglas
+ *
+ */
+public class HibernatePersistenceProvider extends PersistenceProvider
+{
+
+ @Inject
+ Instance<PersistenceContexts> persistenceContexts;
+
+ private static Logger log = LoggerFactory.getLogger(HibernatePersistenceProvider.class);
+ private static Class FULL_TEXT_SESSION_PROXY_CLASS;
+ private static Method FULL_TEXT_SESSION_CONSTRUCTOR;
+ private static Class FULL_TEXT_ENTITYMANAGER_PROXY_CLASS;
+ private static Method FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR;
+ static
+ {
+ try
+ {
+ String version = null;
+ try
+ {
+ Class searchVersionClass = Class.forName("org.hibernate.search.Version");
+ Field versionField = searchVersionClass.getDeclaredField("VERSION");
+ version = (String) versionField.get(null);
+ }
+ catch (Exception e)
+ {
+ log.debug("no Hibernate Search, sorry :-(", e);
+ }
+ if (version != null)
+ {
+ Class searchClass = Class.forName("org.hibernate.search.Search");
+ try
+ {
+ FULL_TEXT_SESSION_CONSTRUCTOR = searchClass.getDeclaredMethod("getFullTextSession", Session.class);
+ }
+ catch (NoSuchMethodException noSuchMethod)
+ {
+ log.debug("org.hibernate.search.Search.getFullTextSession(Session) not found, trying deprecated method name createFullTextSession");
+ FULL_TEXT_SESSION_CONSTRUCTOR = searchClass.getDeclaredMethod("createFullTextSession", Session.class);
+ }
+ FULL_TEXT_SESSION_PROXY_CLASS = Class.forName("org.jboss.seam.persistence.FullTextHibernateSessionProxy");
+ Class jpaSearchClass = Class.forName("org.hibernate.search.jpa.Search");
+ try
+ {
+ FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR = jpaSearchClass.getDeclaredMethod("getFullTextEntityManager", EntityManager.class);
+ }
+ catch (NoSuchMethodException noSuchMethod)
+ {
+ log.debug("org.hibernate.search.jpa.getFullTextSession(EntityManager) not found, trying deprecated method name createFullTextEntityManager");
+ FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR = jpaSearchClass.getDeclaredMethod("createFullTextEntityManager", EntityManager.class);
+ }
+ FULL_TEXT_ENTITYMANAGER_PROXY_CLASS = Class.forName("org.jboss.seam.persistence.FullTextEntityManagerProxy");
+ log.debug("Hibernate Search is available :-)");
+ }
+ }
+ catch (Exception e)
+ {
+ log.debug("no Hibernate Search, sorry :-(", e);
+ }
+ }
+
+ @Inject
+ public void init()
+ {
+ featureSet.add(Feature.WILDCARD_AS_COUNT_QUERY_SUBJECT);
+ }
+
+ @Override
+ public void setFlushModeManual(EntityManager entityManager)
+ {
+ try
+ {
+ getSession(entityManager).setFlushMode(FlushMode.MANUAL);
+ }
+ catch (NotHibernateException nhe)
+ {
+ super.setFlushModeManual(entityManager);
+ }
+ }
+
+ @Override
+ public void setRenderFlushMode()
+ {
+ persistenceContexts.get().changeFlushMode(FlushModeType.MANUAL, true);
+ }
+
+ @Override
+ public boolean isDirty(EntityManager entityManager)
+ {
+ try
+ {
+ return getSession(entityManager).isDirty();
+ }
+ catch (NotHibernateException nhe)
+ {
+ return super.isDirty(entityManager);
+ }
+ }
+
+ @Override
+ public Object getId(Object bean, EntityManager entityManager)
+ {
+ try
+ {
+ return getSession(entityManager).getIdentifier(bean);
+ }
+ catch (NotHibernateException nhe)
+ {
+ return super.getId(bean, entityManager);
+ }
+ catch (TransientObjectException e)
+ {
+ if (bean instanceof HibernateProxy)
+ {
+ return super.getId(((HibernateProxy) bean).getHibernateLazyInitializer().getImplementation(), entityManager);
+ }
+ else
+ {
+ return super.getId(bean, entityManager);
+ }
+ }
+ }
+
+ @Override
+ public Object getVersion(Object bean, EntityManager entityManager)
+ {
+ try
+ {
+ return getVersion(bean, getSession(entityManager));
+ }
+ catch (NotHibernateException nhe)
+ {
+ return super.getVersion(bean, entityManager);
+ }
+ }
+
+ @Override
+ public void checkVersion(Object bean, EntityManager entityManager, Object oldVersion, Object version)
+ {
+ try
+ {
+ checkVersion(bean, getSession(entityManager), oldVersion, version);
+ }
+ catch (NotHibernateException nhe)
+ {
+ super.checkVersion(bean, entityManager, oldVersion, version);
+ }
+ }
+
+ @Override
+ public boolean registerSynchronization(Synchronization sync, EntityManager entityManager)
+ {
+ try
+ {
+ // TODO: just make sure that a Hibernate JPA EntityTransaction
+ // delegates to the Hibernate Session transaction
+ getSession(entityManager).getTransaction().registerSynchronization(sync);
+ return true;
+ }
+ catch (NotHibernateException nhe)
+ {
+ return super.registerSynchronization(sync, entityManager);
+ }
+
+ }
+
+ @Override
+ public String getName(Object bean, EntityManager entityManager) throws IllegalArgumentException
+ {
+ try
+ {
+ return getSession(entityManager).getEntityName(bean);
+ }
+ catch (NotHibernateException nhe)
+ {
+ return super.getName(bean, entityManager);
+ }
+ catch (TransientObjectException e)
+ {
+ return super.getName(bean, entityManager);
+ }
+ }
+
+ public static void checkVersion(Object value, Session session, Object oldVersion, Object version)
+ {
+ ClassMetadata classMetadata = getClassMetadata(value, session);
+ VersionType versionType = (VersionType) classMetadata.getPropertyTypes()[classMetadata.getVersionProperty()];
+ if (!versionType.isEqual(oldVersion, version))
+ {
+ throw new StaleStateException("current database version number does not match passivated version number");
+ }
+ }
+
+ public static Object getVersion(Object value, Session session)
+ {
+ ClassMetadata classMetadata = getClassMetadata(value, session);
+ return classMetadata != null && classMetadata.isVersioned() ? classMetadata.getVersion(value, EntityMode.POJO) : null;
+ }
+
+ private static ClassMetadata getClassMetadata(Object value, Session session)
+ {
+ Class entityClass = getEntityClass(value);
+ ClassMetadata classMetadata = null;
+ if (entityClass != null)
+ {
+ classMetadata = session.getSessionFactory().getClassMetadata(entityClass);
+ if (classMetadata == null)
+ {
+ throw new IllegalArgumentException("Could not find ClassMetadata object for entity class: " + entityClass.getName());
+ }
+ }
+ return classMetadata;
+ }
+
+ /**
+ * Returns the class of the specified Hibernate entity
+ */
+ @Override
+ public Class getBeanClass(Object bean)
+ {
+ return getEntityClass(bean);
+ }
+
+ public static Class getEntityClass(Object bean)
+ {
+ /*
+ * Class clazz = null; try { clazz = Entity.forBean(bean).getBeanClass();
+ * } catch (NotEntityException e) { // It's ok, try some other methods }
+ *
+ * if (clazz == null) { clazz = Hibernate.getClass(bean); }
+ *
+ * return clazz;
+ */
+ return null;
+ }
+
+ private Session getSession(EntityManager entityManager)
+ {
+ Object delegate = entityManager.getDelegate();
+ if (delegate instanceof Session)
+ {
+ return (Session) delegate;
+ }
+ else
+ {
+ throw new NotHibernateException();
+ }
+ }
+
+ /**
+ * Occurs when Hibernate is in the classpath, but this particular
+ * EntityManager is not from Hibernate
+ *
+ * @author Gavin King
+ *
+ */
+ static class NotHibernateException extends IllegalArgumentException
+ {
+ }
+
+}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -117,6 +117,7 @@
BeanBuilder<EntityManager> builder = new BeanBuilder<EntityManager>(manager).defineBeanFromAnnotatedType(typeBuilder.create());
builder.setQualifiers(qualifiers);
builder.setScope(scope);
+ builder.getTypes().add(PersistenceContext.class);
builder.setBeanLifecycle(new ManagedPersistenceContextBeanLifecycle(qualifiers, manager));
beans.add(builder.create());
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -22,8 +22,12 @@
package org.jboss.seam.persistence;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.BeanManager;
@@ -54,15 +58,18 @@
private final Instance<SeamTransaction> userTransactionInstance;
+ private final Set<Annotation> qualifiers;
+
private transient boolean synchronizationRegistered;
static final Logger log = LoggerFactory.getLogger(ManagedPersistenceContextProxyHandler.class);
- public ManagedPersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager)
+ public ManagedPersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager, Set<Annotation> qualifiers)
{
super(delegate, beanManager);
this.delegate = delegate;
this.userTransactionInstance = InstanceResolver.getInstance(SeamTransaction.class, beanManager, DefaultTransactionLiteral.INSTANCE);
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
@@ -105,4 +112,9 @@
}
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.unmodifiableSet(qualifiers);
+ }
+
}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+/**
+ * Support for changing flushmodes for an existing persistence context.
+ *
+ * @author Gavin King
+ * @author Stuart Douglas
+ *
+ */
+public interface PersistenceContext
+{
+ public void changeFlushMode(FlushModeType flushMode);
+
+ public Set<Annotation> getQualifiers();
+
+ public Class<?> getBeanType();
+}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -50,12 +50,15 @@
private final Instance<Expressions> expressionsInstance;
+ private final Instance<PersistenceProvider> persistenceProvider;
+
static final Logger log = LoggerFactory.getLogger(ManagedPersistenceContextProxyHandler.class);
public PersistenceContextProxyHandler(EntityManager delegate, BeanManager beanManager)
{
this.delegate = delegate;
expressionsInstance = InstanceResolver.getInstance(Expressions.class, beanManager);
+ persistenceProvider = InstanceResolver.getInstance(PersistenceProvider.class, beanManager);
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
@@ -64,9 +67,23 @@
{
return handleCreateQueryWithString(method, args);
}
+ if ("changeFlushMode".equals(method.getName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(FlushModeType.class))
+ {
+ changeFushMode((FlushModeType) args[0]);
+ return null;
+ }
+ if ("getBeanType".equals(method.getName()) && method.getParameterTypes().length == 0)
+ {
+ return EntityManager.class;
+ }
return method.invoke(delegate, args);
}
+ private void changeFushMode(FlushModeType flushModeType)
+ {
+ persistenceProvider.get().setFlushMode(delegate, flushModeType);
+ }
+
protected Object handleCreateQueryWithString(Method method, Object[] args) throws Throwable
{
if (args[0] == null)
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,205 @@
+package org.jboss.seam.persistence;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Maintains the set of persistence contexts that have been touched in a
+ * conversation. Also controls the flush mode used by the persistence contexts
+ * during the render phase.
+ *
+ * @author Gavin King
+ */
+@ConversationScoped
+public class PersistenceContexts implements Serializable
+{
+ private static final long serialVersionUID = -4897350516435283182L;
+ private static final Logger log = LoggerFactory.getLogger(PersistenceContexts.class);
+ /**
+ * persistences contexts are referenced by their qualifiers
+ */
+ private Set<PersistenceContextDefintition> set = new HashSet<PersistenceContextDefintition>();
+
+ private FlushModeType flushMode;
+
+ // the real flush mode is a backup of the flush mode when doing a temporary
+ // switch (such as during render)
+ private FlushModeType realFlushMode;
+
+ @Inject
+ BeanManager beanManager;
+
+ @Inject
+ @Any
+ Instance<PersistenceContext> persistenceContexts;
+
+ @Inject
+ Instance<PersistenceProvider> persistenceProvider;
+
+ @Inject
+ public void create(FlushModeManager manager)
+ {
+ FlushModeType defaultFlushMode = manager.getFlushModeType();
+ if (defaultFlushMode != null)
+ {
+ flushMode = defaultFlushMode;
+ }
+ else
+ {
+ flushMode = FlushModeType.AUTO;
+ }
+ }
+
+ public FlushModeType getFlushMode()
+ {
+ return flushMode;
+ }
+
+ public Set<PersistenceContextDefintition> getTouchedContexts()
+ {
+ return Collections.unmodifiableSet(set);
+ }
+
+ public void touch(PersistenceContext context)
+ {
+ set.add(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
+ }
+
+ public void untouch(PersistenceContext context)
+ {
+ set.remove(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
+ }
+
+ public void changeFlushMode(FlushModeType flushMode)
+ {
+ changeFlushMode(flushMode, false);
+ }
+
+ public void changeFlushMode(FlushModeType flushMode, boolean temporary)
+ {
+ if (temporary)
+ {
+ realFlushMode = this.flushMode;
+ }
+ this.flushMode = flushMode;
+ changeFlushModes();
+ }
+
+ /**
+ * Restore the previous flush mode if the current flush mode is marked as
+ * temporary.
+ */
+ public void restoreFlushMode()
+ {
+ if (realFlushMode != null && realFlushMode != flushMode)
+ {
+ flushMode = realFlushMode;
+ realFlushMode = null;
+ changeFlushModes();
+ }
+ }
+
+ private void changeFlushModes()
+ {
+
+ for (PersistenceContext context : persistenceContexts)
+ {
+ if (set.contains(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType())))
+ try
+ {
+ context.changeFlushMode(flushMode);
+ }
+ catch (UnsupportedOperationException uoe)
+ {
+ // we won't be nasty and throw and exception, but we'll log a
+ // warning to the developer
+ log.warn(uoe.getMessage());
+ }
+ }
+ }
+
+ public void beforeRender()
+ {
+ // some JPA providers may not support MANUAL flushing
+ // defer the decision to the provider manager component
+ persistenceProvider.get().setRenderFlushMode();
+ }
+
+ public void afterRender()
+ {
+ restoreFlushMode();
+ }
+
+ public static class PersistenceContextDefintition
+ {
+ private final Set<Annotation> qualifiers;
+ private final Class<?> type;
+
+ public PersistenceContextDefintition(Set<Annotation> qualifiers, Class<?> type)
+ {
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.type = type;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qualifiers == null) ? 0 : qualifiers.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PersistenceContextDefintition other = (PersistenceContextDefintition) obj;
+ if (qualifiers == null)
+ {
+ if (other.qualifiers != null)
+ return false;
+ }
+ else if (!qualifiers.equals(other.qualifiers))
+ return false;
+ if (type == null)
+ {
+ if (other.type != null)
+ return false;
+ }
+ else if (!type.equals(other.type))
+ return false;
+ return true;
+ }
+
+ }
+
+}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.persistence;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.OptimisticLockException;
+import javax.persistence.PersistenceContexts;
+import javax.transaction.Synchronization;
+
+/**
+ * Abstraction layer for persistence providers (JPA implementations). This class
+ * provides a working base implementation that can be optimized for performance
+ * and non-standardized features by extending and overriding the methods.
+ *
+ * The methods on this class are a great todo list for the next rev of the JPA
+ * spec ;-)
+ *
+ * @author Gavin King
+ * @author Pete Muir
+ * @author Stuart Douglas
+ *
+ */
+public class PersistenceProvider
+{
+ public enum Feature
+ {
+ /**
+ * Identifies whether this JPA provider supports using a wildcard as the
+ * subject of a count query.
+ *
+ * <p>
+ * Here's a count query that uses a wildcard as the subject.
+ * </p>
+ *
+ * <pre>
+ * select count(*) from Vehicle v
+ * </pre>
+ * <p>
+ * Per the JPA 1.0 spec, using a wildcard as a subject of a count query is
+ * not permitted. Instead, the subject must be the entity or the alias, as
+ * in this count query:
+ * </p>
+ *
+ * <pre>
+ * select count(v) from Vehicle v
+ * </pre>
+ * <p>
+ * Hibernate supports the wildcard syntax as an vendor extension.
+ * Furthermore, Hibernate produces an invalid SQL query when using the
+ * compliant subject if the entity has a composite primary key. Therefore,
+ * we prefer to use the wildcard syntax if it is supported.
+ * </p>
+ */
+ WILDCARD_AS_COUNT_QUERY_SUBJECT
+ }
+
+ protected Set<Feature> featureSet = new HashSet<Feature>();
+
+ /**
+ * Indicate whether this JPA provider supports the feature defined by the
+ * provided Feature enum value.
+ */
+ public boolean supportsFeature(Feature feature)
+ {
+ return featureSet.contains(feature);
+ }
+
+ /**
+ * sets the flush mode
+ */
+ public void setFlushMode(EntityManager entityManager, FlushModeType type)
+ {
+ switch (type)
+ {
+ case AUTO:
+ entityManager.setFlushMode(javax.persistence.FlushModeType.AUTO);
+ break;
+ case COMMIT:
+ entityManager.setFlushMode(javax.persistence.FlushModeType.COMMIT);
+ case MANUAL:
+ setFlushModeManual(entityManager);
+ default:
+ throw new RuntimeException("Unkown flush mode: " + type);
+ }
+ }
+
+ /**
+ * Set the flush mode to manual-only flushing. Called when an atomic
+ * persistence context is required.
+ */
+ public void setFlushModeManual(EntityManager entityManager)
+ {
+ throw new UnsupportedOperationException("Use of FlushMode.MANUAL requires Hibernate as the persistence provider. Please use Hibernate, a custom persistenceProvider, or remove the MANUAL flush mode setting.");
+ }
+
+ /**
+ * <p>
+ * Set the FlushMode the persistence contexts should use during rendering by
+ * calling {@link PersistenceContexts#changeFlushMode(FlushModeType, true)}.
+ * The actual changing of the flush mode is handled by the
+ * {@link PersistenceContexts} instance. The boolean argument should be true
+ * to indicate that this is a temporary change and that the old flush mode
+ * should be restored after render.
+ * </p>
+ * <p>
+ * Ideally, this should be MANUAL since changes should never flush to the
+ * database while in render response and the cost of a dirty check can be
+ * avoided. However, since the MANUAL mode is not officially part of the JPA
+ * specification, the default implementation will perform no operation.
+ * </p>
+ */
+ public void setRenderFlushMode()
+ {
+ // no-op in default implementation
+ }
+
+ /**
+ * Does the persistence context have unflushed changes? If it does not,
+ * persistence context replication can be optimized.
+ *
+ * @return true to indicate that there are unflushed changes
+ */
+ public boolean isDirty(EntityManager entityManager)
+ {
+ return true; // best we can do!
+ }
+
+ /**
+ * Get the value of the entity identifier attribute.
+ *
+ * @param bean a managed entity instance
+ */
+ public Object getId(Object bean, EntityManager entityManager)
+ {
+ // return Entity.forBean(bean).getIdentifier(bean);
+ return null;
+ }
+
+ /**
+ * Get the name of the entity
+ *
+ * @param bean
+ * @param entityManager
+ *
+ * @throws IllegalArgumentException if the passed object is not an entity
+ */
+ public String getName(Object bean, EntityManager entityManager) throws IllegalArgumentException
+ {
+ return null;
+ // return Entity.forBean(bean).getName();
+ }
+
+ /**
+ * Get the value of the entity version attribute.
+ *
+ * @param bean a managed entity instance
+ */
+ public Object getVersion(Object bean, EntityManager entityManager)
+ {
+ return null;
+ // return Entity.forBean(bean).getVersion(bean);
+ }
+
+ public void checkVersion(Object bean, EntityManager entityManager, Object oldVersion, Object version)
+ {
+ boolean equal;
+ if (oldVersion instanceof Date)
+ {
+ equal = ((Date) oldVersion).getTime() == ((Date) version).getTime();
+ }
+ else
+ {
+ equal = oldVersion.equals(version);
+ }
+ if (!equal)
+ {
+ throw new OptimisticLockException("Current database version number does not match passivated version number");
+ }
+ }
+
+ /**
+ * Enable a Filter. This is here just especially for Hibernate, since we well
+ * know that other products don't have such cool features.
+ *
+ * public void enableFilter(Filter filter, EntityManager entityManager) {
+ * throw new UnsupportedOperationException("Use of filters requires Hibernate as the persistence provider. Please use Hibernate or remove the filters configuration."
+ * ); }
+ */
+ /**
+ * Register a Synchronization with the current transaction.
+ */
+ public boolean registerSynchronization(Synchronization sync, EntityManager entityManager)
+ {
+ return false; // best we can do!
+ }
+
+ /**
+ * Wrap the delegate before returning it to the application
+ */
+ public Object proxyDelegate(Object delegate)
+ {
+ return delegate;
+ }
+
+ /**
+ * Returns the class of an entity bean instance
+ *
+ * @param bean The entity bean instance
+ * @return The class of the entity bean
+ */
+ public Class getBeanClass(Object bean)
+ {
+ return null;
+ // return Entity.forBean(bean).getBeanClass();
+ }
+
+ public Method getPostLoadMethod(Object bean, EntityManager entityManager)
+ {
+ return null;
+ // return Entity.forBean(bean).getPostLoadMethod();
+ }
+
+ public Method getPrePersistMethod(Object bean, EntityManager entityManager)
+ {
+ return null;
+ // return Entity.forBean(bean).getPrePersistMethod();
+ }
+
+ public Method getPreUpdateMethod(Object bean, EntityManager entityManager)
+ {
+ return null;
+ // return Entity.forBean(bean).getPreUpdateMethod();
+ }
+
+ public Method getPreRemoveMethod(Object bean, EntityManager entityManager)
+ {
+ return null;
+ // return Entity.forBean(bean).getPreRemoveMethod();
+ }
+
+}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -22,6 +22,7 @@
package org.jboss.seam.persistence.transaction;
import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.HeuristicMixedException;
@@ -32,6 +33,7 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
+import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.weld.extensions.core.Veto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,8 +41,8 @@
/**
* Support for the JPA EntityTransaction API.
*
- * Adapts JPA transaction management to a Seam UserTransaction
- * interface.For use in non-JTA-capable environments.
+ * Adapts JPA transaction management to a Seam UserTransaction interface.For use
+ * in non-JTA-capable environments.
*
* @author Gavin King
*
@@ -50,12 +52,14 @@
public class EntityTransaction extends AbstractUserTransaction
{
private static final Logger log = LoggerFactory.getLogger(EntityTransaction.class);
-
+
@Inject
private EntityManager entityManager;
-
-
+
@Inject
+ private Instance<PersistenceProvider> persistenceProvider;
+
+ @Inject
public EntityTransaction(Synchronizations sync)
{
super(sync);
@@ -69,7 +73,7 @@
public void begin() throws NotSupportedException, SystemException
{
log.debug("beginning JPA resource-local transaction");
- //TODO: translate exceptions that occur into the correct JTA exception
+ // TODO: translate exceptions that occur into the correct JTA exception
try
{
getDelegate().begin();
@@ -81,15 +85,14 @@
}
}
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
{
log.debug("committing JPA resource-local transaction");
javax.persistence.EntityTransaction delegate = getDelegate();
boolean success = false;
try
{
- if ( delegate.getRollbackOnly() )
+ if (delegate.getRollbackOnly())
{
delegate.rollback();
throw new RollbackException();
@@ -110,7 +113,7 @@
public void rollback() throws IllegalStateException, SecurityException, SystemException
{
log.debug("rolling back JPA resource-local transaction");
- //TODO: translate exceptions that occur into the correct JTA exception
+ // TODO: translate exceptions that occur into the correct JTA exception
javax.persistence.EntityTransaction delegate = getDelegate();
try
{
@@ -152,18 +155,17 @@
@Override
public void registerSynchronization(Synchronization sync)
{
- if ( log.isDebugEnabled() )
+ if (log.isDebugEnabled())
{
log.debug("registering synchronization: " + sync);
}
- //try to register the synchronization directly with the
- //persistence provider, but if this fails, just hold
- //on to it myself
- // if ( !PersistenceProvider.instance().registerSynchronization(sync,
- // currentEntityManager) )
- // {
- // getSynchronizations().registerSynchronization(sync);
- // }
+ // try to register the synchronization directly with the
+ // persistence provider, but if this fails, just hold
+ // on to it myself
+ if (!persistenceProvider.get().registerSynchronization(sync, entityManager))
+ {
+ getSynchronizations().registerSynchronization(sync);
+ }
}
@Override
@@ -175,7 +177,7 @@
@Override
public void enlist(EntityManager entityManager)
{
- //no-op
+ // no-op
}
}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -37,6 +37,7 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -74,6 +75,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
+ war.addPackage(PersistenceProvider.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
war.addClasses(TransactionAttributeInterceptorTest.class, TransactionAttributeManagedBean.class, HelloService.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -37,6 +37,7 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -75,6 +76,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
+ war.addPackage(PersistenceProvider.class.getPackage());
war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, HelloService.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -13,6 +13,7 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.TransactionExtension;
@@ -40,6 +41,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(TransactionScopeExtension.class.getPackage());
+ war.addPackage(PersistenceProvider.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
war.addClasses(TransactionScopedTest.class, Hotel.class, HelloService.class, TransactionScopedObject.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-08-05 10:07:05 UTC (rev 13555)
@@ -5,6 +5,7 @@
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
@@ -40,6 +41,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
+ war.addPackage(PersistenceException.class.getPackage());
war.addClasses(UserTransactionTest.class, Hotel.class, HelloService.class);
war.addPackage(NamingUtils.class.getPackage());
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
Modified: modules/persistence/trunk/pom.xml
===================================================================
--- modules/persistence/trunk/pom.xml 2010-08-04 17:40:14 UTC (rev 13554)
+++ modules/persistence/trunk/pom.xml 2010-08-05 10:07:05 UTC (rev 13555)
@@ -65,6 +65,12 @@
<artifactId>seam-persistence</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.5.1-Final</version>
+ </dependency>
</dependencies>
</dependencyManagement>
13 years, 9 months
Seam SVN: r13554 - sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-08-04 13:40:14 -0400 (Wed, 04 Aug 2010)
New Revision: 13554
Added:
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/AnnotationTest.java
Modified:
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
Log:
Refactored tests to reduce test-duplication
Added: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/AnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/AnnotationTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/AnnotationTest.java 2010-08-04 17:40:14 UTC (rev 13554)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public abstract class AnnotationTest
+{
+ private AnnotationTarget<?> target;
+
+ public void setTarget(AnnotationTarget<?> target)
+ {
+ this.target = target;
+ }
+
+ @Before
+ public void reset()
+ {
+ resetTests();
+ }
+
+ public abstract void resetTests();
+
+ @Test
+ public void testParseAnnotation() throws Exception
+ {
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(3, annotations.size());
+ assertEquals("deprecation", annotations.get(1).getStringValue());
+ assertEquals("deprecation", annotations.get(1).getStringValue("value"));
+ assertEquals("value", annotations.get(1).getValues().get(0).getName());
+ assertEquals("deprecation", annotations.get(1).getValues().get(0).getStringValue());
+
+ assertEquals("unchecked", annotations.get(2).getStringValue("value"));
+ assertEquals("unchecked", annotations.get(2).getStringValue());
+ assertEquals("value", annotations.get(2).getValues().get(0).getName());
+ assertEquals("unchecked", annotations.get(2).getValues().get(0).getStringValue());
+ }
+
+ @Test
+ public void testAddAnnotation() throws Exception
+ {
+ int size = target.getAnnotations().size();
+ target.addAnnotation().setName("RequestScoped");
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
+ }
+
+ @Test
+ public void testAddAnnotationByClass() throws Exception
+ {
+ int size = target.getAnnotations().size();
+ target.addAnnotation(Test.class);
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
+ target.applyChanges();
+ assertTrue(target.toString().contains("@" + Test.class.getName()));
+ }
+
+ @Test
+ public void testAddAnnotationByName() throws Exception
+ {
+ int size = target.getAnnotations().size();
+ target.addAnnotation("RequestScoped");
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
+ target.applyChanges();
+ assertTrue(target.toString().contains("@RequestScoped"));
+ }
+
+ @Test
+ public void testCanAddAnnotationDuplicate() throws Exception
+ {
+ int size = target.getAnnotations().size();
+ target.addAnnotation(Test.class);
+ target.addAnnotation(Test.class);
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 2, annotations.size());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 2).getName());
+ target.applyChanges();
+ String pattern = "@" + Test.class.getName() + " " + "@" + Test.class.getName();
+ assertTrue(target.toString().contains(pattern));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotAddAnnotationWithIllegalName() throws Exception
+ {
+ target.addAnnotation("sdf*(&#$%");
+ }
+
+ @Test
+ public void testAddLiteralValue() throws Exception
+ {
+ int size = target.getAnnotations().size();
+
+ target.addAnnotation(Test.class).setLiteralValue("435");
+ target.applyChanges();
+
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals("435", annotation.getLiteralValue());
+ }
+
+ @Test
+ public void testAddObjectValue() throws Exception
+ {
+ int size = target.getAnnotations().size();
+
+ target.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class").setLiteralValue("foo", "bar");
+ target.applyChanges();
+
+ List<Annotation> annotations = target.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals(null, annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("expected"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAddValueConvertsToNormalAnnotation() throws Exception
+ {
+ target.addAnnotation(Test.class).setLiteralValue("RuntimeException.class");
+ target.applyChanges();
+ Annotation annotation = target.getAnnotations().get(target.getAnnotations().size() - 1);
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertTrue(annotation.isSingleValue());
+
+ annotation.setLiteralValue("foo", "bar");
+ assertFalse(annotation.isSingleValue());
+ assertTrue(annotation.isNormal());
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("value"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAnnotationBeginsAsMarker() throws Exception
+ {
+ Annotation anno = target.addAnnotation(Test.class);
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setLiteralValue("\"Foo!\"");
+ assertFalse(anno.isMarker());
+ assertTrue(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setStringValue("bar", "Foo!");
+ assertFalse(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertTrue(anno.isNormal());
+
+ assertEquals("\"Foo!\"", anno.getLiteralValue("bar"));
+ assertEquals("Foo!", anno.getStringValue("bar"));
+
+ anno.removeAllValues();
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+ }
+
+ @Test
+ public void testRemoveAllValues() throws Exception
+ {
+ target.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class");
+ target.applyChanges();
+
+ List<Annotation> annotations = target.getAnnotations();
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ annotation.removeAllValues();
+
+ assertEquals(0, annotation.getValues().size());
+ }
+}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-04 17:15:49 UTC (rev 13553)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-04 17:40:14 UTC (rev 13554)
@@ -21,192 +21,18 @@
*/
package org.jboss.encore.grammar.java;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.InputStream;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
-public class ClassAnnotationTest
+public class ClassAnnotationTest extends AnnotationTest
{
- private InputStream stream;
- private JavaClass javaClass;
-
- @Before
- public void reset()
+ @Override
+ public void resetTests()
{
- stream = ClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java");
- javaClass = JavaParser.parse(stream);
+ InputStream stream = ClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java");
+ JavaClass javaClass = JavaParser.parse(stream);
+ setTarget(javaClass);
}
-
- @Test
- public void testParseAnnotation() throws Exception
- {
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(3, annotations.size());
- assertEquals("deprecation", annotations.get(1).getStringValue());
- assertEquals("deprecation", annotations.get(1).getStringValue("value"));
- assertEquals("value", annotations.get(1).getValues().get(0).getName());
- assertEquals("deprecation", annotations.get(1).getValues().get(0).getStringValue());
-
- assertEquals("unchecked", annotations.get(2).getStringValue("value"));
- assertEquals("unchecked", annotations.get(2).getStringValue());
- assertEquals("value", annotations.get(2).getValues().get(0).getName());
- assertEquals("unchecked", annotations.get(2).getValues().get(0).getStringValue());
- }
-
- @Test
- public void testAddAnnotation() throws Exception
- {
- int size = javaClass.getAnnotations().size();
- javaClass.addAnnotation().setName("RequestScoped");
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
- }
-
- @Test
- public void testAddAnnotationByClass() throws Exception
- {
- int size = javaClass.getAnnotations().size();
- javaClass.addAnnotation(Test.class);
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
- javaClass.applyChanges();
- assertTrue(javaClass.toString().contains("@" + Test.class.getName()));
- }
-
- @Test
- public void testAddAnnotationByName() throws Exception
- {
- int size = javaClass.getAnnotations().size();
- javaClass.addAnnotation("RequestScoped");
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
- javaClass.applyChanges();
- assertTrue(javaClass.toString().contains("@RequestScoped"));
- }
-
- @Test
- public void testCanAddAnnotationDuplicate() throws Exception
- {
- int size = javaClass.getAnnotations().size();
- javaClass.addAnnotation(Test.class);
- javaClass.addAnnotation(Test.class);
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 2, annotations.size());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 2).getName());
- javaClass.applyChanges();
- String pattern = "@" + Test.class.getName() + " " + "@" + Test.class.getName();
- assertTrue(javaClass.toString().contains(pattern));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCannotAddAnnotationWithIllegalName() throws Exception
- {
- javaClass.addAnnotation("sdf*(&#$%");
- }
-
- @Test
- public void testAddLiteralValue() throws Exception
- {
- int size = javaClass.getAnnotations().size();
-
- javaClass.addAnnotation(Test.class).setLiteralValue("435");
- javaClass.applyChanges();
-
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 1, annotations.size());
-
- Annotation annotation = annotations.get(annotations.size() - 1);
- assertEquals(Test.class.getName(), annotation.getName());
- assertEquals("435", annotation.getLiteralValue());
- }
-
- @Test
- public void testAddObjectValue() throws Exception
- {
- int size = javaClass.getAnnotations().size();
-
- javaClass.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class").setLiteralValue("foo", "bar");
- javaClass.applyChanges();
-
- List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(size + 1, annotations.size());
-
- Annotation annotation = annotations.get(annotations.size() - 1);
- assertEquals(Test.class.getName(), annotation.getName());
- assertEquals(null, annotation.getLiteralValue());
- assertEquals("RuntimeException.class", annotation.getLiteralValue("expected"));
- assertEquals("bar", annotation.getLiteralValue("foo"));
- }
-
- @Test
- public void testAddValueConvertsToNormalAnnotation() throws Exception
- {
- javaClass.addAnnotation(Test.class).setLiteralValue("RuntimeException.class");
- javaClass.applyChanges();
- Annotation annotation = javaClass.getAnnotations().get(javaClass.getAnnotations().size() - 1);
-
- assertEquals("RuntimeException.class", annotation.getLiteralValue());
- assertTrue(annotation.isSingleValue());
-
- annotation.setLiteralValue("foo", "bar");
- assertFalse(annotation.isSingleValue());
- assertTrue(annotation.isNormal());
-
- assertEquals("RuntimeException.class", annotation.getLiteralValue());
- assertEquals("RuntimeException.class", annotation.getLiteralValue("value"));
- assertEquals("bar", annotation.getLiteralValue("foo"));
- }
-
- @Test
- public void testAnnotationBeginsAsMarker() throws Exception
- {
- Annotation anno = javaClass.addAnnotation(Test.class);
- assertTrue(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertFalse(anno.isNormal());
-
- anno.setLiteralValue("\"Foo!\"");
- assertFalse(anno.isMarker());
- assertTrue(anno.isSingleValue());
- assertFalse(anno.isNormal());
-
- anno.setStringValue("bar", "Foo!");
- assertFalse(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertTrue(anno.isNormal());
-
- assertEquals("\"Foo!\"", anno.getLiteralValue("bar"));
- assertEquals("Foo!", anno.getStringValue("bar"));
-
- anno.removeAllValues();
- assertTrue(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertFalse(anno.isNormal());
- }
-
- @Test
- public void testRemoveAllValues() throws Exception
- {
- javaClass.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class");
- javaClass.applyChanges();
-
- List<Annotation> annotations = javaClass.getAnnotations();
- Annotation annotation = annotations.get(annotations.size() - 1);
- annotation.removeAllValues();
-
- assertEquals(0, annotation.getValues().size());
- }
}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java 2010-08-04 17:15:49 UTC (rev 13553)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java 2010-08-04 17:40:14 UTC (rev 13554)
@@ -21,195 +21,18 @@
*/
package org.jboss.encore.grammar.java;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.InputStream;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
-public class MethodAnnotationTest
+public class MethodAnnotationTest extends AnnotationTest
{
- private InputStream stream;
- private JavaClass javaClass;
- private Method method;
-
- @Before
- public void reset()
+ @Override
+ public void resetTests()
{
- stream = MethodAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java");
- javaClass = JavaParser.parse(stream);
- method = javaClass.getMethods().get(0);
+ InputStream stream = MethodAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java");
+ Method method = JavaParser.parse(stream).getMethods().get(0);
+ setTarget(method);
}
-
- @Test
- public void testParseAnnotation() throws Exception
- {
- List<Annotation> annotations = method.getAnnotations();
-
- assertEquals(3, annotations.size());
- assertEquals("deprecation", annotations.get(1).getStringValue());
- assertEquals("deprecation", annotations.get(1).getStringValue("value"));
- assertEquals("value", annotations.get(1).getValues().get(0).getName());
- assertEquals("deprecation", annotations.get(1).getValues().get(0).getStringValue());
-
- assertEquals("unchecked", annotations.get(2).getStringValue("value"));
- assertEquals("unchecked", annotations.get(2).getStringValue());
- assertEquals("value", annotations.get(2).getValues().get(0).getName());
- assertEquals("unchecked", annotations.get(2).getValues().get(0).getStringValue());
- }
-
- @Test
- public void testAddAnnotation() throws Exception
- {
- int size = method.getAnnotations().size();
- method.addAnnotation().setName("RequestScoped");
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
- }
-
- @Test
- public void testAddAnnotationByClass() throws Exception
- {
- int size = method.getAnnotations().size();
- method.addAnnotation(Test.class);
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
- method.applyChanges();
- assertTrue(method.toString().contains("@" + Test.class.getName()));
- }
-
- @Test
- public void testAddAnnotationByName() throws Exception
- {
- int size = method.getAnnotations().size();
- method.addAnnotation("RequestScoped");
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 1, annotations.size());
- assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
- method.applyChanges();
- assertTrue(method.toString().contains("@RequestScoped"));
- }
-
- @Test
- public void testCanAddAnnotationDuplicate() throws Exception
- {
- int size = method.getAnnotations().size();
- method.addAnnotation(Test.class);
- method.addAnnotation(Test.class);
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 2, annotations.size());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
- assertEquals(Test.class.getName(), annotations.get(annotations.size() - 2).getName());
- method.applyChanges();
- String pattern = "@" + Test.class.getName() + " " + "@" + Test.class.getName();
- assertTrue(method.toString().contains(pattern));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCannotAddAnnotationWithIllegalName() throws Exception
- {
- method.addAnnotation("sdf*(&#$%");
- }
-
- @Test
- public void testAddLiteralValue() throws Exception
- {
- int size = method.getAnnotations().size();
-
- method.addAnnotation(Test.class).setLiteralValue("435");
- method.applyChanges();
-
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 1, annotations.size());
-
- Annotation annotation = annotations.get(annotations.size() - 1);
- assertEquals(Test.class.getName(), annotation.getName());
- assertEquals("435", annotation.getLiteralValue());
- }
-
- @Test
- public void testAddObjectValue() throws Exception
- {
- int size = method.getAnnotations().size();
-
- method.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class").setLiteralValue("foo", "bar");
- method.applyChanges();
-
- List<Annotation> annotations = method.getAnnotations();
- assertEquals(size + 1, annotations.size());
-
- Annotation annotation = annotations.get(annotations.size() - 1);
- assertEquals(Test.class.getName(), annotation.getName());
- assertEquals(null, annotation.getLiteralValue());
- assertEquals("RuntimeException.class", annotation.getLiteralValue("expected"));
- assertEquals("bar", annotation.getLiteralValue("foo"));
- }
-
- @Test
- public void testAddValueConvertsToNormalAnnotation() throws Exception
- {
- method.addAnnotation(Test.class).setLiteralValue("RuntimeException.class");
- method.applyChanges();
- Annotation annotation = method.getAnnotations().get(method.getAnnotations().size() - 1);
-
- assertEquals("RuntimeException.class", annotation.getLiteralValue());
- assertTrue(annotation.isSingleValue());
-
- annotation.setLiteralValue("foo", "bar");
- assertFalse(annotation.isSingleValue());
- assertTrue(annotation.isNormal());
-
- assertEquals("RuntimeException.class", annotation.getLiteralValue());
- assertEquals("RuntimeException.class", annotation.getLiteralValue("value"));
- assertEquals("bar", annotation.getLiteralValue("foo"));
- }
-
- @Test
- public void testAnnotationBeginsAsMarker() throws Exception
- {
- Annotation anno = method.addAnnotation(Test.class);
- assertTrue(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertFalse(anno.isNormal());
-
- anno.setLiteralValue("\"Foo!\"");
- assertFalse(anno.isMarker());
- assertTrue(anno.isSingleValue());
- assertFalse(anno.isNormal());
-
- anno.setStringValue("bar", "Foo!");
- assertFalse(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertTrue(anno.isNormal());
-
- assertEquals("\"Foo!\"", anno.getLiteralValue("bar"));
- assertEquals("Foo!", anno.getStringValue("bar"));
-
- anno.removeAllValues();
- assertTrue(anno.isMarker());
- assertFalse(anno.isSingleValue());
- assertFalse(anno.isNormal());
- }
-
- @Test
- public void testRemoveAllValues() throws Exception
- {
- method.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class");
- method.applyChanges();
-
- List<Annotation> annotations = method.getAnnotations();
- Annotation annotation = annotations.get(annotations.size() - 1);
- annotation.removeAllValues();
-
- assertEquals(0, annotation.getValues().size());
- }
}
13 years, 9 months
Seam SVN: r13553 - in sandbox/encore: core/src/main/java/org/jboss/encore/grammar/java and 4 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-08-04 13:15:49 -0400 (Wed, 04 Aug 2010)
New Revision: 13553
Added:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ValuePair.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java
Removed:
sandbox/encore/core/src/main/java/org/jboss/encore/model/
Modified:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Annotation.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java
Log:
Class and Method level annotations are functioning. API has been completely encapsulated via interfaces. Unfortunately, this is not a true contract because the implementation requires internal knowledge of itself, and hence will not function with user-supplied implementations of interfaces. To be fixed later... maybe.
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Annotation.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Annotation.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Annotation.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -1,13 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.encore.grammar.java;
+import java.util.List;
+
import org.jboss.encore.grammar.Internal;
import org.jboss.encore.grammar.Mutable;
+/**
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
public interface Annotation extends Internal, Mutable
{
+ boolean isSingleValue();
+ boolean isMarker();
+
+ boolean isNormal();
+
String getName();
+ String getLiteralValue();
+
+ String getLiteralValue(String name);
+
+ List<ValuePair> getValues();
+
+ String getStringValue();
+
+ String getStringValue(String name);
+
+ Annotation removeValue(String name);
+
+ Annotation removeAllValues();
+
Annotation setName(String className);
+ Annotation setLiteralValue(String value);
+
+ Annotation setLiteralValue(String name, String value);
+
+ Annotation setStringValue(String value);
+
+ Annotation setStringValue(String name, String value);
}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/AnnotationTarget.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java;
+
+import java.util.List;
+
+import org.jboss.encore.grammar.Internal;
+import org.jboss.encore.grammar.Mutable;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface AnnotationTarget<T> extends Internal, Mutable
+{
+ public abstract Annotation addAnnotation();
+
+ public abstract Annotation addAnnotation(Class<?> clazz);
+
+ public abstract Annotation addAnnotation(final String className);
+
+ public abstract List<Annotation> getAnnotations();
+
+ public abstract T removeAnnotation(Annotation annotation);
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -19,11 +19,9 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.jboss.encore.grammar.java;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.jboss.encore.grammar.Internal;
import org.jboss.encore.grammar.Mutable;
@@ -31,70 +29,14 @@
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
-public class Import implements Internal, Mutable
+public interface Import extends Internal, Mutable
{
+ public String getName();
- private JavaClass parent;
- private AST ast = null;
- private CompilationUnit cu = null;
- private ImportDeclaration imprt = null;
+ public Import setName(final String name);
- private void init(final JavaClass parent)
- {
- this.parent = parent;
- cu = (CompilationUnit) parent.getInternal();
- ast = cu.getAST();
- }
+ public boolean isStatic();
- public Import(final JavaClass parent)
- {
- init(parent);
- imprt = ast.newImportDeclaration();
- }
+ public Import setStatic(final boolean value);
- public Import(final JavaClass parent, final Object internal)
- {
- init(parent);
- imprt = (ImportDeclaration) internal;
- }
-
- public String getName()
- {
- return imprt.getName().getFullyQualifiedName();
- }
-
- public Import setName(final String name)
- {
- imprt.setName(ast.newName(tokenizeClassName(name)));
- return this;
- }
-
- public boolean isStatic()
- {
- return imprt.isStatic();
- }
-
- public Import setStatic(final boolean value)
- {
- imprt.setStatic(value);
- return this;
- }
-
- private String[] tokenizeClassName(final String className)
- {
- String[] result = className.split("\\.");
- return result;
- }
-
- @Override
- public void applyChanges()
- {
- parent.applyChanges();
- }
-
- @Override
- public Object getInternal()
- {
- return imprt;
- }
-}
+}
\ No newline at end of file
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -19,472 +19,97 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.jboss.encore.grammar.java;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Stack;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.ImportDeclaration;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
-import org.eclipse.jdt.core.dom.PackageDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
-import org.eclipse.jdt.internal.compiler.util.Util;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.text.edits.UndoEdit;
import org.jboss.encore.grammar.Internal;
import org.jboss.encore.grammar.Mutable;
-import org.jboss.encore.grammar.java.ast.MethodFinderVisitor;
-import org.jboss.encore.grammar.java.ast.ModifierAccessor;
-import org.jboss.encore.grammar.java.ast.TypeDeclarationFinderVisitor;
-import org.jboss.encore.grammar.java.impl.AnnotationImpl;
/**
- * Represents a Java Source File
- *
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
*/
-public class JavaClass implements Internal, Mutable
+public interface JavaClass extends Internal, Mutable, AnnotationTarget<JavaClass>
{
- private final Stack<UndoEdit> undoStack = new Stack<UndoEdit>();
- private Document document;
- private CompilationUnit unit;
- private final ModifierAccessor ma = new ModifierAccessor();
-
- /**
- * Parses and process the java source code as a compilation unit and the
- * result it abstract syntax tree (AST) representation and this action uses
- * the third edition of java Language Specification.
- *
- * @param source - the java source to be parsed (i.e. the char[] contains
- * Java source).
- * @return CompilationUnit Abstract syntax tree representation of a java
- * source file.
- */
- public JavaClass(final InputStream inputStream)
- {
- try
- {
- char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
- init(source);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
- }
- }
-
- public JavaClass(final String source)
- {
- this(source.toCharArray());
- }
-
- public JavaClass(final char[] source)
- {
- init(source);
- }
-
- private void init(final char[] source)
- {
- document = new Document(new String(source));
- ASTParser parser = ASTParser.newParser(AST.JLS3);
- parser.setSource(document.get().toCharArray());
- parser.setResolveBindings(true);
- parser.setKind(ASTParser.K_COMPILATION_UNIT);
- unit = (CompilationUnit) parser.createAST(null);
- unit.recordModifications();
- }
-
/*
* Annotation modifiers
*/
- @SuppressWarnings("unchecked")
- public Annotation addAnnotation()
- {
- Annotation annotation = new AnnotationImpl(this);
- getTypeDeclaration().modifiers().add(annotation.getInternal());
- return annotation;
- }
+ public abstract Import addImport(final String className);
- public Annotation addAnnotation(Class<?> clazz)
- {
- return addAnnotation(clazz.getName());
- }
+ public abstract Import addImport(final Class<?> type);
- public Annotation addAnnotation(final String className)
- {
- return addAnnotation().setName(className);
- }
+ public abstract JavaClass addImports(final Class<?>... types);
- public List<Annotation> getAnnotations()
- {
- List<Annotation> result = new ArrayList<Annotation>();
+ public abstract JavaClass addImports(final String... types);
- List<?> modifiers = getTypeDeclaration().modifiers();
- for (Object object : modifiers)
- {
- if (object instanceof org.eclipse.jdt.core.dom.Annotation)
- {
- Annotation annotation = new AnnotationImpl(this, object);
- result.add(annotation);
- }
- }
+ public abstract JavaClass removeImport(String name);
- return result;
- }
+ public abstract JavaClass removeImport(Class<?> clazz);
- /*
- * Import modifiers
- */
+ public abstract JavaClass removeImport(Import imprt);
- @SuppressWarnings("unchecked")
- public Import addImport(final String className)
- {
- Import imprt = new Import(this).setName(className);
- unit.imports().add(imprt.getInternal());
- return imprt;
- }
-
- public Import addImport(final Class<?> type)
- {
- return addImport(type.getName());
- }
-
- public JavaClass addImports(final Class<?>... types)
- {
- for (Class<?> type : types)
- {
- addImport(type.getName());
- }
- return this;
- }
-
- public JavaClass addImports(final String... types)
- {
- for (String type : types)
- {
- addImport(type);
- }
- return this;
- }
-
- public JavaClass removeImport(String name)
- {
- for (Import i : getImports())
- {
- if (i.getName().equals(name))
- {
- removeImport(i);
- break;
- }
- }
- return this;
- }
-
- public JavaClass removeImport(Class<?> clazz)
- {
- return removeImport(clazz.getName());
- }
-
- public JavaClass removeImport(Import imprt)
- {
- Object internal = imprt.getInternal();
- if (unit.imports().contains(internal))
- {
- unit.imports().remove(internal);
- }
- return this;
- }
-
/**
* Get a list of the {@link Import}s contained within this {@link JavaClass}.
* Note that modification of this list does not affect internal state, but
* modification of individual {@link Import} objects will.
*/
- @SuppressWarnings("unchecked")
- public List<Import> getImports()
- {
- List<Import> results = new ArrayList<Import>();
+ public abstract List<Import> getImports();
- for (ImportDeclaration i : (List<ImportDeclaration>) unit.imports())
- {
- results.add(new Import(this, i));
- }
+ public abstract Method addMethod();
- return results;
- }
+ public abstract Method addMethod(final String method);
- /*
- * Method modifiers
- */
-
- @SuppressWarnings("unchecked")
- public Method addMethod()
- {
- Method m = new Method(this);
- getTypeDeclaration().bodyDeclarations().add(m.getInternal());
- return m;
- }
-
- @SuppressWarnings("unchecked")
- public Method addMethod(final String method)
- {
- Method m = new Method(this, method);
- getTypeDeclaration().bodyDeclarations().add(m.getInternal());
- return m;
- }
-
/**
* Get a list of the {@link Method}s contained within this {@link JavaClass}.
* Note that modification of this list does not affect internal state, but
* modification of individual {@link Method} objects will.
*/
- public List<Method> getMethods()
- {
- List<Method> result = new ArrayList<Method>();
+ public abstract List<Method> getMethods();
- MethodFinderVisitor methodFinderVisitor = new MethodFinderVisitor();
- unit.accept(methodFinderVisitor);
+ public abstract JavaClass removeMethod(final Method method);
- List<MethodDeclaration> methods = methodFinderVisitor.getMethods();
- for (MethodDeclaration methodDeclaration : methods)
- {
- result.add(new Method(this, methodDeclaration));
- }
- return result;
- }
+ public abstract String getName();
- public JavaClass removeMethod(final Method method)
- {
- if (getMethods().contains(method))
- {
- getTypeDeclaration().bodyDeclarations().remove(method.getInternal());
- }
- return this;
- }
+ public abstract JavaClass setName(String name);
- private TypeDeclaration getTypeDeclaration()
- {
- TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
- unit.accept(typeDeclarationFinder);
- return typeDeclarationFinder.getTypeDeclarations().get(0);
- }
+ public abstract String getPackage();
- /*
- * Name modifiers
- */
+ public abstract JavaClass setPackage(String name);
- public String getName()
- {
- return getTypeDeclaration().getName().getIdentifier();
- }
+ public abstract JavaClass setDefaultPackage();
- public JavaClass setName(String name)
- {
- getTypeDeclaration().setName(unit.getAST().newSimpleName(name));
- updateConstructorNames();
- return this;
- }
+ public abstract boolean isDefaultPackage();
- private void updateConstructorNames()
- {
- for (Method m : getMethods())
- {
- if (m.isConstructor())
- {
- m.setConstructor(false);
- m.setConstructor(true);
- }
- }
- }
-
/*
- * Package modifiers
- */
-
- public String getPackage()
- {
- PackageDeclaration pkg = unit.getPackage();
- if (pkg != null)
- {
- return pkg.getName().getFullyQualifiedName();
- }
- else
- {
- return null;
- }
- }
-
- public JavaClass setPackage(String name)
- {
- unit.getPackage().setName(unit.getAST().newName(name));
- return this;
- }
-
- public JavaClass setDefaultPackage()
- {
- unit.setPackage(null);
- return this;
- }
-
- public boolean isDefaultPackage()
- {
- return unit.getPackage() == null;
- }
-
- /*
* Visibility modifiers
*/
- public boolean isPackagePrivate()
- {
- return (!isPublic() && !isPrivate() && !isProtected());
- }
+ public abstract boolean isPackagePrivate();
- public JavaClass setPackagePrivate()
- {
- ma.clearVisibility(getTypeDeclaration());
- return this;
- }
+ public abstract JavaClass setPackagePrivate();
- public boolean isPublic()
- {
- return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PUBLIC_KEYWORD);
- }
+ public abstract boolean isPublic();
- public JavaClass setPublic()
- {
- ma.clearVisibility(getTypeDeclaration());
- ma.addModifier(getTypeDeclaration(), ModifierKeyword.PUBLIC_KEYWORD);
- return this;
- }
+ public abstract JavaClass setPublic();
- public boolean isPrivate()
- {
- return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PRIVATE_KEYWORD);
- }
+ public abstract boolean isPrivate();
- public JavaClass setPrivate()
- {
- ma.clearVisibility(getTypeDeclaration());
- ma.addModifier(getTypeDeclaration(), ModifierKeyword.PRIVATE_KEYWORD);
- return this;
- }
+ public abstract JavaClass setPrivate();
- public boolean isProtected()
- {
- return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PROTECTED_KEYWORD);
- }
+ public abstract boolean isProtected();
- public JavaClass setProtected()
- {
- ma.clearVisibility(getTypeDeclaration());
- ma.addModifier(getTypeDeclaration(), ModifierKeyword.PROTECTED_KEYWORD);
- return this;
- }
+ public abstract JavaClass setProtected();
- /*
- * Type modifiers
- */
+ public abstract boolean isAbstract();
- public boolean isAbstract()
- {
- return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
- }
+ public abstract JavaClass setAbstract(boolean abstrct);
- public JavaClass setAbstract(boolean abstrct)
- {
- if (abstrct)
- {
- ma.addModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
- }
- else
- {
- ma.removeModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
- }
- return this;
- }
-
- /*
- * Non-manipulation methods.
- */
-
@Override
- public String toString()
- {
- return document.get();
- }
+ public abstract int hashCode();
@Override
- public Object getInternal()
- {
- return unit;
- }
+ public abstract boolean equals(final Object obj);
- @Override
- public void applyChanges()
- {
- try
- {
- TextEdit edit = unit.rewrite(document, null);
- UndoEdit undo = edit.apply(document);
- undoStack.add(undo);
- }
- catch (MalformedTreeException e)
- {
- throw new RuntimeException(e);
- }
- catch (BadLocationException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((unit == null) ? 0 : unit.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- JavaClass other = (JavaClass) obj;
- if (unit == null)
- {
- if (other.unit != null)
- {
- return false;
- }
- }
- else if (!unit.equals(other.unit))
- {
- return false;
- }
- return true;
- }
-
-}
+}
\ No newline at end of file
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java;
+
+import java.io.InputStream;
+
+import org.jboss.encore.grammar.java.impl.JavaClassImpl;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public abstract class JavaParser
+{
+ public static JavaClass parse(char[] data)
+ {
+ return new JavaClassImpl(data);
+ }
+
+ public static JavaClass parse(String data)
+ {
+ return new JavaClassImpl(data);
+ }
+
+ public static JavaClassImpl parse(InputStream data)
+ {
+ return new JavaClassImpl(data);
+ }
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -19,301 +19,65 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
+
package org.jboss.encore.grammar.java;
-import java.util.List;
-
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.Block;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
-import org.eclipse.jdt.core.dom.Statement;
import org.jboss.encore.grammar.Internal;
import org.jboss.encore.grammar.Mutable;
-import org.jboss.encore.grammar.java.ast.ModifierAccessor;
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
-public class Method implements Internal, Mutable
+public interface Method extends Internal, Mutable, AnnotationTarget<Method>
{
- private JavaClass parent = null;
- private AST ast = null;
- private CompilationUnit cu = null;
- private final ModifierAccessor ma = new ModifierAccessor();
- private final MethodDeclaration method;
+ public String getBody();
- private void init(final JavaClass parent)
- {
- this.parent = parent;
- cu = (CompilationUnit) parent.getInternal();
- ast = cu.getAST();
- }
+ public Method setBody(final String body);
- public Method(final JavaClass parent)
- {
- init(parent);
- method = ast.newMethodDeclaration();
- method.setConstructor(false);
- }
-
- public Method(final JavaClass parent, final Object internal)
- {
- init(parent);
- method = (MethodDeclaration) internal;
- }
-
- public Method(final JavaClass parent, final String method)
- {
- init(parent);
-
- String stub = "public class Stub { " + method + " }";
- JavaClass temp = new JavaClass(stub);
- List<Method> methods = temp.getMethods();
- MethodDeclaration newMethod = methods.get(0).getMethodDeclaration();
- MethodDeclaration subtree = (MethodDeclaration) ASTNode.copySubtree(cu.getAST(), newMethod);
- this.method = subtree;
- }
-
- @SuppressWarnings("unchecked")
- public String getBody()
- {
- String result = "";
-
- List<Statement> statements = (List<Statement>) method.getBody().getStructuralProperty(Block.STATEMENTS_PROPERTY);
- for (Statement statement : statements)
- {
- result += statement + " ";
- }
-
- return result;
- }
-
- public Method setBody(final String body)
- {
- String stub = "public class Stub { public void method() {" + body + "} }";
- JavaClass temp = new JavaClass(stub);
- List<Method> methods = temp.getMethods();
- Block block = methods.get(0).getMethodDeclaration().getBody();
-
- block = (Block) ASTNode.copySubtree(method.getAST(), block);
- method.setBody(block);
-
- return this;
- }
-
/**
* Toggle this method as a constructor. If true, and the name of the
* {@link Method} is not the same as the name of its parent {@link JavaClass}
* , update the name of the to match.
*/
- public Method setConstructor(final boolean constructor)
- {
- method.setConstructor(constructor);
- if (isConstructor())
- {
- method.setName(ast.newSimpleName(parent.getName()));
- }
- return this;
- }
+ public Method setConstructor(final boolean constructor);
- public boolean isConstructor()
- {
- return method.isConstructor();
- }
+ public boolean isConstructor();
- public boolean isAbstract()
- {
- return ma.hasModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
- }
+ public boolean isAbstract();
- public Method setAbstract(boolean abstrct)
- {
- if (abstrct)
- {
- ma.addModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
- }
- else
- {
- ma.removeModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
- }
- return this;
- }
+ public Method setAbstract(boolean abstrct);
- public Method setFinal()
- {
- ma.addModifier(method, ModifierKeyword.FINAL_KEYWORD);
- return this;
- }
+ public Method setFinal();
- public String getName()
- {
- return method.getName().getFullyQualifiedName();
- }
+ public String getName();
- public Method setName(final String name)
- {
- if (method.isConstructor())
- {
- throw new IllegalStateException("Cannot set the name of a constructor.");
- }
- method.setName(ast.newSimpleName(name));
- return this;
- }
+ public Method setName(final String name);
- public boolean isPackagePrivate()
- {
- return (!isPublic() && !isPrivate() && !isProtected());
- }
+ public boolean isPackagePrivate();
- public Method setPackagePrivate()
- {
- ma.clearVisibility(method);
- return this;
- }
+ public Method setPackagePrivate();
- public boolean isPublic()
- {
- return ma.hasModifier(method, ModifierKeyword.PUBLIC_KEYWORD);
- }
+ public boolean isPublic();
- public Method setPublic()
- {
- ma.clearVisibility(method);
- ma.addModifier(method, ModifierKeyword.PUBLIC_KEYWORD);
- return this;
- }
+ public Method setPublic();
- public boolean isPrivate()
- {
- return ma.hasModifier(method, ModifierKeyword.PRIVATE_KEYWORD);
- }
+ public boolean isPrivate();
- public Method setPrivate()
- {
- ma.clearVisibility(method);
- ma.addModifier(method, ModifierKeyword.PRIVATE_KEYWORD);
- return this;
- }
+ public Method setPrivate();
- public boolean isProtected()
- {
- return ma.hasModifier(method, ModifierKeyword.PROTECTED_KEYWORD);
- }
+ public boolean isProtected();
- public Method setProtected()
- {
- ma.clearVisibility(method);
- ma.addModifier(method, ModifierKeyword.PROTECTED_KEYWORD);
- return this;
- }
+ public Method setProtected();
- public String getReturnType()
- {
- String result = null;
- if (!isConstructor() && (method.getReturnType2() != null))
- {
- result = method.getReturnType2().toString();
- }
- return result;
- }
+ public String getReturnType();
- public Method setReturnType(final Class<?> type)
- {
- return setReturnType(type.getSimpleName());
- }
+ public Method setReturnType(final Class<?> type);
- public Method setReturnType(final String type)
- {
- method.setReturnType2(ast.newSimpleType(ast.newSimpleName(type)));
- return this;
- }
+ public Method setReturnType(final String type);
- public boolean isReturnTypeVoid()
- {
- return getReturnType() == null;
- }
+ public boolean isReturnTypeVoid();
- public Method setReturnTypeVoid()
- {
- method.setReturnType2(null);
- return this;
- }
+ public Method setReturnTypeVoid();
- private MethodDeclaration getMethodDeclaration()
- {
- return method;
- }
-
- @Override
- public String toString()
- {
- return method.toString();
- }
-
- @Override
- public Object getInternal()
- {
- return method;
- }
-
- @Override
- public void applyChanges()
- {
- parent.applyChanges();
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((method == null) ? 0 : method.hashCode());
- result = prime * result + ((parent == null) ? 0 : parent.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- Method other = (Method) obj;
- if (method == null)
- {
- if (other.method != null)
- {
- return false;
- }
- }
- else if (!method.equals(other.method))
- {
- return false;
- }
- if (parent == null)
- {
- if (other.parent != null)
- {
- return false;
- }
- }
- else if (!parent.equals(other.parent))
- {
- return false;
- }
- return true;
- }
-}
+}
\ No newline at end of file
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ValuePair.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ValuePair.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ValuePair.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+/**
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface ValuePair
+{
+ String getName();
+
+ String getLiteralValue();
+
+ String getStringValue();
+}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationImpl.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -1,31 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.encore.grammar.java.impl;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.jboss.encore.grammar.Mutable;
import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.AnnotationTarget;
import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
+import org.jboss.encore.grammar.java.ValuePair;
+/**
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
public class AnnotationImpl implements Annotation
{
- private JavaClass parent = null;
- private CompilationUnit cu = null;
+ private static final String DEFAULT_VALUE = "value";
+
+ private AnnotationTarget<?> parent = null;
private AST ast = null;
- private final org.eclipse.jdt.core.dom.Annotation annotation;
+ private org.eclipse.jdt.core.dom.Annotation annotation;
- private void init(final JavaClass parent)
+ private enum AnnotationType
{
+ MARKER, SINGLE, NORMAL
+ }
+
+ private void init(final AnnotationTarget<?> parent)
+ {
this.parent = parent;
- cu = (CompilationUnit) parent.getInternal();
- ast = cu.getAST();
+ ast = ((ASTNode) parent.getInternal()).getAST();
}
- public AnnotationImpl(JavaClass parent)
+ public AnnotationImpl(AnnotationTarget<?> parent)
{
+ this(parent, AnnotationType.MARKER);
+ }
+
+ public AnnotationImpl(AnnotationTarget<?> parent, AnnotationType type)
+ {
init(parent);
- this.annotation = ast.newNormalAnnotation();
+ switch (type)
+ {
+ case MARKER:
+ this.annotation = ast.newMarkerAnnotation();
+ break;
+ case SINGLE:
+ this.annotation = ast.newSingleMemberAnnotation();
+ break;
+ case NORMAL:
+ this.annotation = ast.newNormalAnnotation();
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown annotation type: " + type);
+ }
}
- public AnnotationImpl(JavaClass parent, Object internal)
+ public AnnotationImpl(AnnotationTarget<?> parent, Object internal)
{
init(parent);
this.annotation = (org.eclipse.jdt.core.dom.Annotation) internal;
@@ -38,6 +99,155 @@
}
@Override
+ public String getLiteralValue() throws IllegalStateException
+ {
+ String result = null;
+ if (isSingleValue())
+ {
+ SingleMemberAnnotation sm = (SingleMemberAnnotation) annotation;
+ result = sm.getValue().toString();
+ }
+ else if (isNormal())
+ {
+ List<ValuePair> values = getValues();
+ for (ValuePair pair : values)
+ {
+ String name = pair.getName();
+ if (DEFAULT_VALUE.equals(name))
+ {
+ result = pair.getLiteralValue();
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String getLiteralValue(String name)
+ {
+ String result = null;
+ if (isNormal())
+ {
+ for (Object v : ((NormalAnnotation) annotation).values())
+ {
+ if (v instanceof MemberValuePair)
+ {
+ MemberValuePair pair = (MemberValuePair) v;
+ if (pair.getName().getFullyQualifiedName().equals(name))
+ {
+ result = pair.getValue().toString();
+ break;
+ }
+ }
+ }
+ }
+ else if (DEFAULT_VALUE.equals(name) && isSingleValue())
+ {
+ return getLiteralValue();
+ }
+ return result;
+ }
+
+ @Override
+ public List<ValuePair> getValues()
+ {
+ List<ValuePair> result = new ArrayList<ValuePair>();
+ if (isNormal())
+ {
+ for (Object v : ((NormalAnnotation) annotation).values())
+ {
+ if (v instanceof MemberValuePair)
+ {
+ MemberValuePair pair = (MemberValuePair) v;
+ ValuePair temp = new ValuePairImpl(pair.getName().getFullyQualifiedName(), pair.getValue().toString());
+ result.add(temp);
+ }
+ }
+ }
+ else if (isSingleValue())
+ {
+ result.add(new ValuePairImpl(DEFAULT_VALUE, getLiteralValue()));
+ }
+ return result;
+ }
+
+ @Override
+ public String getStringValue() throws IllegalStateException
+ {
+ return Strings.unquote(getLiteralValue());
+ }
+
+ @Override
+ public String getStringValue(String name)
+ {
+ return Strings.unquote(getLiteralValue(name));
+ }
+
+ @Override
+ public boolean isMarker()
+ {
+ return annotation.isMarkerAnnotation();
+ }
+
+ @Override
+ public boolean isNormal()
+ {
+ return annotation.isNormalAnnotation();
+ }
+
+ @Override
+ public boolean isSingleValue()
+ {
+ return annotation.isSingleMemberAnnotation();
+ }
+
+ @Override
+ public Annotation removeAllValues()
+ {
+ convertTo(AnnotationType.MARKER);
+ return this;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Annotation removeValue(String name)
+ {
+ if (annotation.isNormalAnnotation())
+ {
+ NormalAnnotation na = (NormalAnnotation) annotation;
+
+ List<MemberValuePair> toBeRemoved = new ArrayList<MemberValuePair>();
+ for (Object v : na.values())
+ {
+ if (v instanceof MemberValuePair)
+ {
+ MemberValuePair pair = (MemberValuePair) v;
+ if (pair.getValue().toString().equals(name))
+ {
+ toBeRemoved.add(pair);
+ }
+ }
+ }
+ na.values().removeAll(toBeRemoved);
+
+ if ((getLiteralValue() != null) && (getValues().size() == 1))
+ {
+ convertTo(AnnotationType.SINGLE);
+ }
+ else if (getValues().size() == 0)
+ {
+ convertTo(AnnotationType.MARKER);
+ }
+ }
+ else if (annotation.isSingleMemberAnnotation())
+ {
+ removeAllValues();
+ }
+ return this;
+ }
+
+ @Override
public Annotation setName(String className)
{
annotation.setTypeName(ast.newName(className));
@@ -45,15 +255,121 @@
}
@Override
+ public Annotation setLiteralValue(String value)
+ {
+ if (isMarker())
+ {
+ convertTo(AnnotationType.SINGLE);
+ }
+
+ if (isSingleValue())
+ {
+ SingleMemberAnnotation sa = (SingleMemberAnnotation) annotation;
+
+ String stub = "@" + getName() + "(" + value + ") public class Stub { }";
+ JavaClass temp = JavaParser.parse(stub);
+
+ SingleMemberAnnotation anno = (SingleMemberAnnotation) temp.getAnnotations().get(0).getInternal();
+
+ Expression expression = anno.getValue();
+ sa.setValue((Expression) ASTNode.copySubtree(annotation.getAST(), expression));
+ }
+ else
+ {
+ setLiteralValue(DEFAULT_VALUE, value);
+ }
+
+ return this;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Annotation setLiteralValue(String name, String value)
+ {
+ if (!isNormal() && !DEFAULT_VALUE.equals(name))
+ {
+ convertTo(AnnotationType.NORMAL);
+ }
+ else if (!isSingleValue() && !isNormal() && DEFAULT_VALUE.equals(name))
+ {
+ convertTo(AnnotationType.SINGLE);
+ return setLiteralValue(value);
+ }
+
+ NormalAnnotation na = (NormalAnnotation) annotation;
+
+ String stub = "@" + getName() + "(" + name + "=" + value + " ) public class Stub { }";
+ JavaClass temp = JavaParser.parse(stub);
+
+ NormalAnnotation anno = (NormalAnnotation) temp.getAnnotations().get(0).getInternal();
+
+ for (Object v : anno.values())
+ {
+ if (v instanceof MemberValuePair)
+ {
+ na.values().add(ASTNode.copySubtree(annotation.getAST(), (MemberValuePair) v));
+ }
+ }
+
+ return this;
+ }
+
+ @Override
+ public Annotation setStringValue(String value)
+ {
+ return setLiteralValue("\"" + value + "\"");
+ }
+
+ @Override
+ public Annotation setStringValue(String name, String value)
+ {
+ return setLiteralValue(name, "\"" + value + "\"");
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ if (parent instanceof Mutable)
+ {
+ ((Mutable) parent).applyChanges();
+ }
+ }
+
+ @Override
public Object getInternal()
{
return annotation;
}
@Override
- public void applyChanges()
+ public String toString()
{
- parent.applyChanges();
+ return annotation.toString();
}
+ @SuppressWarnings("unchecked")
+ private void convertTo(AnnotationType type)
+ {
+ BodyDeclaration node = (BodyDeclaration) annotation.getParent();
+ String value = this.getLiteralValue();
+
+ for (Object o : node.modifiers())
+ {
+ if (o.equals(annotation))
+ {
+ node.modifiers().remove(annotation);
+ Annotation na = new AnnotationImpl(parent, type);
+ na.setName(getName());
+ annotation = (org.eclipse.jdt.core.dom.Annotation) na.getInternal();
+ node.modifiers().add(annotation);
+ break;
+ }
+ }
+
+ if (!AnnotationType.MARKER.equals(type) && (value != null))
+ {
+ setLiteralValue(value);
+ }
+ }
+
}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/AnnotationUtil.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.AnnotationTarget;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class AnnotationUtil
+{
+
+ @SuppressWarnings("unchecked")
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body)
+ {
+ Annotation annotation = new AnnotationImpl(target);
+ body.modifiers().add(annotation.getInternal());
+ return annotation;
+ }
+
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, Class<?> clazz)
+ {
+ return addAnnotation(target, body, clazz.getName());
+ }
+
+ public Annotation addAnnotation(AnnotationTarget<?> target, BodyDeclaration body, final String className)
+ {
+ return addAnnotation(target, body).setName(className);
+ }
+
+ public List<Annotation> getAnnotations(AnnotationTarget<?> target, BodyDeclaration body)
+ {
+ List<Annotation> result = new ArrayList<Annotation>();
+
+ List<?> modifiers = body.modifiers();
+ for (Object object : modifiers)
+ {
+ if (object instanceof org.eclipse.jdt.core.dom.Annotation)
+ {
+ Annotation annotation = new AnnotationImpl(target, object);
+ result.add(annotation);
+ }
+ }
+
+ return result;
+ }
+
+ public <T extends AnnotationTarget<?>> T removeAnnotation(T target, BodyDeclaration body, Annotation annotation)
+ {
+ List<?> modifiers = body.modifiers();
+ for (Object object : modifiers)
+ {
+ if (object.equals(annotation.getInternal()))
+ {
+ modifiers.remove(object);
+ break;
+ }
+ }
+ return target;
+ }
+}
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java (from rev 13535, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ImportImpl.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java.impl;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.jboss.encore.grammar.java.Import;
+import org.jboss.encore.grammar.java.JavaClass;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class ImportImpl implements Import
+{
+
+ private JavaClass parent;
+ private AST ast = null;
+ private CompilationUnit cu = null;
+ private ImportDeclaration imprt = null;
+
+ private void init(final JavaClass parent)
+ {
+ this.parent = parent;
+ cu = (CompilationUnit) parent.getInternal();
+ ast = cu.getAST();
+ }
+
+ public ImportImpl(final JavaClass parent)
+ {
+ init(parent);
+ imprt = ast.newImportDeclaration();
+ }
+
+ public ImportImpl(final JavaClass parent, final Object internal)
+ {
+ init(parent);
+ imprt = (ImportDeclaration) internal;
+ }
+
+ @Override
+ public String getName()
+ {
+ return imprt.getName().getFullyQualifiedName();
+ }
+
+ @Override
+ public Import setName(final String name)
+ {
+ imprt.setName(ast.newName(tokenizeClassName(name)));
+ return this;
+ }
+
+ @Override
+ public boolean isStatic()
+ {
+ return imprt.isStatic();
+ }
+
+ @Override
+ public Import setStatic(final boolean value)
+ {
+ imprt.setStatic(value);
+ return this;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ parent.applyChanges();
+ }
+
+ @Override
+ public Object getInternal()
+ {
+ return imprt;
+ }
+
+ private String[] tokenizeClassName(final String className)
+ {
+ String[] result = className.split("\\.");
+ return result;
+ }
+}
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java (from rev 13536, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/JavaClassImpl.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,502 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java.impl;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.util.Util;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.TextEdit;
+import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.Import;
+import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.Method;
+import org.jboss.encore.grammar.java.ast.MethodFinderVisitor;
+import org.jboss.encore.grammar.java.ast.ModifierAccessor;
+import org.jboss.encore.grammar.java.ast.TypeDeclarationFinderVisitor;
+
+/**
+ * Represents a Java Source File
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class JavaClassImpl implements JavaClass
+{
+ private static AnnotationUtil util = new AnnotationUtil();
+
+ private Document document;
+ private CompilationUnit unit;
+ private final ModifierAccessor ma = new ModifierAccessor();
+
+ /**
+ * Parses and process the java source code as a compilation unit and the
+ * result it abstract syntax tree (AST) representation and this action uses
+ * the third edition of java Language Specification.
+ *
+ * @param source - the java source to be parsed (i.e. the char[] contains
+ * Java source).
+ * @return CompilationUnit Abstract syntax tree representation of a java
+ * source file.
+ */
+ public JavaClassImpl(final InputStream inputStream)
+ {
+ try
+ {
+ char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
+ init(source);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
+ }
+ }
+
+ public JavaClassImpl(final String source)
+ {
+ this(source.toCharArray());
+ }
+
+ public JavaClassImpl(final char[] source)
+ {
+ init(source);
+ }
+
+ private void init(final char[] source)
+ {
+ document = new Document(new String(source));
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setSource(document.get().toCharArray());
+ parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ unit = (CompilationUnit) parser.createAST(null);
+ unit.recordModifications();
+ }
+
+ /*
+ * Annotation modifiers
+ */
+
+ @Override
+ public Annotation addAnnotation()
+ {
+ return util.addAnnotation(this, getTypeDeclaration());
+ }
+
+ @Override
+ public Annotation addAnnotation(Class<?> clazz)
+ {
+ return util.addAnnotation(this, getTypeDeclaration(), clazz);
+ }
+
+ @Override
+ public Annotation addAnnotation(final String className)
+ {
+ return util.addAnnotation(this, getTypeDeclaration(), className);
+ }
+
+ @Override
+ public List<Annotation> getAnnotations()
+ {
+ return util.getAnnotations(this, getTypeDeclaration());
+ }
+
+ @Override
+ public JavaClass removeAnnotation(Annotation annotation)
+ {
+ return util.removeAnnotation(this, getTypeDeclaration(), annotation);
+ }
+
+ /*
+ * Import modifiers
+ */
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Import addImport(final String className)
+ {
+ Import imprt = new ImportImpl(this).setName(className);
+ unit.imports().add(imprt.getInternal());
+ return imprt;
+ }
+
+ @Override
+ public Import addImport(final Class<?> type)
+ {
+ return addImport(type.getName());
+ }
+
+ @Override
+ public JavaClass addImports(final Class<?>... types)
+ {
+ for (Class<?> type : types)
+ {
+ addImport(type.getName());
+ }
+ return this;
+ }
+
+ @Override
+ public JavaClass addImports(final String... types)
+ {
+ for (String type : types)
+ {
+ addImport(type);
+ }
+ return this;
+ }
+
+ @Override
+ public JavaClass removeImport(String name)
+ {
+ for (Import i : getImports())
+ {
+ if (i.getName().equals(name))
+ {
+ removeImport(i);
+ break;
+ }
+ }
+ return this;
+ }
+
+ @Override
+ public JavaClass removeImport(Class<?> clazz)
+ {
+ return removeImport(clazz.getName());
+ }
+
+ @Override
+ public JavaClass removeImport(Import imprt)
+ {
+ Object internal = imprt.getInternal();
+ if (unit.imports().contains(internal))
+ {
+ unit.imports().remove(internal);
+ }
+ return this;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List<Import> getImports()
+ {
+ List<Import> results = new ArrayList<Import>();
+
+ for (ImportDeclaration i : (List<ImportDeclaration>) unit.imports())
+ {
+ results.add(new ImportImpl(this, i));
+ }
+
+ return results;
+ }
+
+ /*
+ * Method modifiers
+ */
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Method addMethod()
+ {
+ Method m = new MethodImpl(this);
+ getTypeDeclaration().bodyDeclarations().add(m.getInternal());
+ return m;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Method addMethod(final String method)
+ {
+ Method m = new MethodImpl(this, method);
+ getTypeDeclaration().bodyDeclarations().add(m.getInternal());
+ return m;
+ }
+
+ @Override
+ public List<Method> getMethods()
+ {
+ List<Method> result = new ArrayList<Method>();
+
+ MethodFinderVisitor methodFinderVisitor = new MethodFinderVisitor();
+ unit.accept(methodFinderVisitor);
+
+ List<MethodDeclaration> methods = methodFinderVisitor.getMethods();
+ for (MethodDeclaration methodDeclaration : methods)
+ {
+ result.add(new MethodImpl(this, methodDeclaration));
+ }
+ return result;
+ }
+
+ @Override
+ public JavaClass removeMethod(final Method method)
+ {
+ if (getMethods().contains(method))
+ {
+ getTypeDeclaration().bodyDeclarations().remove(method.getInternal());
+ }
+ return this;
+ }
+
+ private TypeDeclaration getTypeDeclaration()
+ {
+ TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
+ unit.accept(typeDeclarationFinder);
+ return typeDeclarationFinder.getTypeDeclarations().get(0);
+ }
+
+ /*
+ * Name modifiers
+ */
+
+ @Override
+ public String getName()
+ {
+ return getTypeDeclaration().getName().getIdentifier();
+ }
+
+ @Override
+ public JavaClass setName(String name)
+ {
+ getTypeDeclaration().setName(unit.getAST().newSimpleName(name));
+ updateConstructorNames();
+ return this;
+ }
+
+ private void updateConstructorNames()
+ {
+ for (Method m : getMethods())
+ {
+ if (m.isConstructor())
+ {
+ m.setConstructor(false);
+ m.setConstructor(true);
+ }
+ }
+ }
+
+ /*
+ * Package modifiers
+ */
+
+ @Override
+ public String getPackage()
+ {
+ PackageDeclaration pkg = unit.getPackage();
+ if (pkg != null)
+ {
+ return pkg.getName().getFullyQualifiedName();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public JavaClass setPackage(String name)
+ {
+ unit.getPackage().setName(unit.getAST().newName(name));
+ return this;
+ }
+
+ @Override
+ public JavaClass setDefaultPackage()
+ {
+ unit.setPackage(null);
+ return this;
+ }
+
+ @Override
+ public boolean isDefaultPackage()
+ {
+ return unit.getPackage() == null;
+ }
+
+ /*
+ * Visibility modifiers
+ */
+ @Override
+ public boolean isPackagePrivate()
+ {
+ return (!isPublic() && !isPrivate() && !isProtected());
+ }
+
+ @Override
+ public JavaClass setPackagePrivate()
+ {
+ ma.clearVisibility(getTypeDeclaration());
+ return this;
+ }
+
+ @Override
+ public boolean isPublic()
+ {
+ return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PUBLIC_KEYWORD);
+ }
+
+ @Override
+ public JavaClass setPublic()
+ {
+ ma.clearVisibility(getTypeDeclaration());
+ ma.addModifier(getTypeDeclaration(), ModifierKeyword.PUBLIC_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public boolean isPrivate()
+ {
+ return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PRIVATE_KEYWORD);
+ }
+
+ @Override
+ public JavaClass setPrivate()
+ {
+ ma.clearVisibility(getTypeDeclaration());
+ ma.addModifier(getTypeDeclaration(), ModifierKeyword.PRIVATE_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public boolean isProtected()
+ {
+ return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.PROTECTED_KEYWORD);
+ }
+
+ @Override
+ public JavaClass setProtected()
+ {
+ ma.clearVisibility(getTypeDeclaration());
+ ma.addModifier(getTypeDeclaration(), ModifierKeyword.PROTECTED_KEYWORD);
+ return this;
+ }
+
+ /*
+ * Type modifiers
+ */
+
+ @Override
+ public boolean isAbstract()
+ {
+ return ma.hasModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+
+ @Override
+ public JavaClass setAbstract(boolean abstrct)
+ {
+ if (abstrct)
+ {
+ ma.addModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+ else
+ {
+ ma.removeModifier(getTypeDeclaration(), ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+ return this;
+ }
+
+ /*
+ * Non-manipulation methods.
+ */
+
+ @Override
+ public String toString()
+ {
+ return document.get();
+ }
+
+ @Override
+ public Object getInternal()
+ {
+ return unit;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ try
+ {
+ TextEdit edit = unit.rewrite(document, null);
+ edit.apply(document);
+ }
+ catch (MalformedTreeException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (BadLocationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((unit == null) ? 0 : unit.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ JavaClassImpl other = (JavaClassImpl) obj;
+ if (unit == null)
+ {
+ if (other.unit != null)
+ {
+ return false;
+ }
+ }
+ else if (!unit.equals(other.unit))
+ {
+ return false;
+ }
+ return true;
+ }
+
+}
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java (from rev 13536, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/MethodImpl.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,365 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java.impl;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
+import org.eclipse.jdt.core.dom.Statement;
+import org.jboss.encore.grammar.java.Annotation;
+import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
+import org.jboss.encore.grammar.java.Method;
+import org.jboss.encore.grammar.java.ast.ModifierAccessor;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class MethodImpl implements Method
+{
+ private static AnnotationUtil util = new AnnotationUtil();
+
+ private JavaClass parent = null;
+ private AST ast = null;
+ private CompilationUnit cu = null;
+ private final ModifierAccessor ma = new ModifierAccessor();
+ private final MethodDeclaration method;
+
+ private void init(final JavaClass parent)
+ {
+ this.parent = parent;
+ cu = (CompilationUnit) parent.getInternal();
+ ast = cu.getAST();
+ }
+
+ public MethodImpl(final JavaClass parent)
+ {
+ init(parent);
+ method = ast.newMethodDeclaration();
+ method.setConstructor(false);
+ }
+
+ public MethodImpl(final JavaClass parent, final Object internal)
+ {
+ init(parent);
+ method = (MethodDeclaration) internal;
+ }
+
+ public MethodImpl(final JavaClass parent, final String method)
+ {
+ init(parent);
+
+ String stub = "public class Stub { " + method + " }";
+ JavaClass temp = JavaParser.parse(stub);
+ List<Method> methods = temp.getMethods();
+ MethodDeclaration newMethod = (MethodDeclaration) methods.get(0).getInternal();
+ MethodDeclaration subtree = (MethodDeclaration) ASTNode.copySubtree(cu.getAST(), newMethod);
+ this.method = subtree;
+ }
+
+ @Override
+ public Annotation addAnnotation()
+ {
+ return util.addAnnotation(this, method);
+ }
+
+ @Override
+ public Annotation addAnnotation(Class<?> clazz)
+ {
+ return util.addAnnotation(this, method, clazz);
+ }
+
+ @Override
+ public Annotation addAnnotation(final String className)
+ {
+ return util.addAnnotation(this, method, className);
+ }
+
+ @Override
+ public List<Annotation> getAnnotations()
+ {
+ return util.getAnnotations(this, method);
+ }
+
+ @Override
+ public Method removeAnnotation(Annotation annotation)
+ {
+ return util.removeAnnotation(this, method, annotation);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public String getBody()
+ {
+ String result = "";
+
+ List<Statement> statements = (List<Statement>) method.getBody().getStructuralProperty(Block.STATEMENTS_PROPERTY);
+ for (Statement statement : statements)
+ {
+ result += statement + " ";
+ }
+
+ return result;
+ }
+
+ @Override
+ public Method setBody(final String body)
+ {
+ String stub = "public class Stub { public void method() {" + body + "} }";
+ JavaClass temp = JavaParser.parse(stub);
+ List<Method> methods = temp.getMethods();
+ Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody();
+
+ block = (Block) ASTNode.copySubtree(method.getAST(), block);
+ method.setBody(block);
+
+ return this;
+ }
+
+ @Override
+ public Method setConstructor(final boolean constructor)
+ {
+ method.setConstructor(constructor);
+ if (isConstructor())
+ {
+ method.setName(ast.newSimpleName(parent.getName()));
+ }
+ return this;
+ }
+
+ @Override
+ public boolean isConstructor()
+ {
+ return method.isConstructor();
+ }
+
+ @Override
+ public boolean isAbstract()
+ {
+ return ma.hasModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+
+ @Override
+ public Method setAbstract(boolean abstrct)
+ {
+ if (abstrct)
+ {
+ ma.addModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+ else
+ {
+ ma.removeModifier(method, ModifierKeyword.ABSTRACT_KEYWORD);
+ }
+ return this;
+ }
+
+ @Override
+ public Method setFinal()
+ {
+ ma.addModifier(method, ModifierKeyword.FINAL_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public String getName()
+ {
+ return method.getName().getFullyQualifiedName();
+ }
+
+ @Override
+ public Method setName(final String name)
+ {
+ if (method.isConstructor())
+ {
+ throw new IllegalStateException("Cannot set the name of a constructor.");
+ }
+ method.setName(ast.newSimpleName(name));
+ return this;
+ }
+
+ @Override
+ public boolean isPackagePrivate()
+ {
+ return (!isPublic() && !isPrivate() && !isProtected());
+ }
+
+ @Override
+ public Method setPackagePrivate()
+ {
+ ma.clearVisibility(method);
+ return this;
+ }
+
+ @Override
+ public boolean isPublic()
+ {
+ return ma.hasModifier(method, ModifierKeyword.PUBLIC_KEYWORD);
+ }
+
+ @Override
+ public Method setPublic()
+ {
+ ma.clearVisibility(method);
+ ma.addModifier(method, ModifierKeyword.PUBLIC_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public boolean isPrivate()
+ {
+ return ma.hasModifier(method, ModifierKeyword.PRIVATE_KEYWORD);
+ }
+
+ @Override
+ public Method setPrivate()
+ {
+ ma.clearVisibility(method);
+ ma.addModifier(method, ModifierKeyword.PRIVATE_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public boolean isProtected()
+ {
+ return ma.hasModifier(method, ModifierKeyword.PROTECTED_KEYWORD);
+ }
+
+ @Override
+ public Method setProtected()
+ {
+ ma.clearVisibility(method);
+ ma.addModifier(method, ModifierKeyword.PROTECTED_KEYWORD);
+ return this;
+ }
+
+ @Override
+ public String getReturnType()
+ {
+ String result = null;
+ if (!isConstructor() && (method.getReturnType2() != null))
+ {
+ result = method.getReturnType2().toString();
+ }
+ return result;
+ }
+
+ @Override
+ public Method setReturnType(final Class<?> type)
+ {
+ return setReturnType(type.getSimpleName());
+ }
+
+ @Override
+ public Method setReturnType(final String type)
+ {
+ method.setReturnType2(ast.newSimpleType(ast.newSimpleName(type)));
+ return this;
+ }
+
+ @Override
+ public boolean isReturnTypeVoid()
+ {
+ return getReturnType() == null;
+ }
+
+ @Override
+ public Method setReturnTypeVoid()
+ {
+ method.setReturnType2(null);
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ return method.toString();
+ }
+
+ @Override
+ public Object getInternal()
+ {
+ return method;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ parent.applyChanges();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((method == null) ? 0 : method.hashCode());
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ MethodImpl other = (MethodImpl) obj;
+ if (method == null)
+ {
+ if (other.method != null)
+ {
+ return false;
+ }
+ }
+ else if (!method.equals(other.method))
+ {
+ return false;
+ }
+ if (parent == null)
+ {
+ if (other.parent != null)
+ {
+ return false;
+ }
+ }
+ else if (!parent.equals(other.parent))
+ {
+ return false;
+ }
+ return true;
+ }
+}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/Strings.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.impl;
+
+/**
+ * String utilities.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class Strings
+{
+ public static String unquote(String value)
+ {
+ String result = null;
+ if (value != null)
+ {
+ result = value.toString().replaceAll("\"(.*)\"", "$1");
+ }
+ return result;
+ }
+}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/impl/ValuePairImpl.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.encore.grammar.java.impl;
+
+import org.jboss.encore.grammar.java.ValuePair;
+
+/**
+ * Represents an annotation value pair
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class ValuePairImpl implements ValuePair
+{
+ private final String name;
+ private final String value;
+
+ public ValuePairImpl(String name, String value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public String getLiteralValue()
+ {
+ return value;
+ }
+
+ @Override
+ public String getStringValue()
+ {
+ return Strings.unquote(getLiteralValue());
+ }
+
+}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/ClassAnnotationTest.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -22,6 +22,7 @@
package org.jboss.encore.grammar.java;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
@@ -41,32 +42,43 @@
@Before
public void reset()
{
- stream = ClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
- javaClass = new JavaClass(stream);
+ stream = ClassAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java");
+ javaClass = JavaParser.parse(stream);
}
@Test
public void testParseAnnotation() throws Exception
{
List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(1, annotations.size());
+ assertEquals(3, annotations.size());
+ assertEquals("deprecation", annotations.get(1).getStringValue());
+ assertEquals("deprecation", annotations.get(1).getStringValue("value"));
+ assertEquals("value", annotations.get(1).getValues().get(0).getName());
+ assertEquals("deprecation", annotations.get(1).getValues().get(0).getStringValue());
+
+ assertEquals("unchecked", annotations.get(2).getStringValue("value"));
+ assertEquals("unchecked", annotations.get(2).getStringValue());
+ assertEquals("value", annotations.get(2).getValues().get(0).getName());
+ assertEquals("unchecked", annotations.get(2).getValues().get(0).getStringValue());
}
@Test
public void testAddAnnotation() throws Exception
{
+ int size = javaClass.getAnnotations().size();
javaClass.addAnnotation().setName("RequestScoped");
List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(2, annotations.size());
+ assertEquals(size + 1, annotations.size());
assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
}
@Test
public void testAddAnnotationByClass() throws Exception
{
+ int size = javaClass.getAnnotations().size();
javaClass.addAnnotation(Test.class);
List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(2, annotations.size());
+ assertEquals(size + 1, annotations.size());
assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
javaClass.applyChanges();
assertTrue(javaClass.toString().contains("@" + Test.class.getName()));
@@ -75,9 +87,10 @@
@Test
public void testAddAnnotationByName() throws Exception
{
+ int size = javaClass.getAnnotations().size();
javaClass.addAnnotation("RequestScoped");
List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(2, annotations.size());
+ assertEquals(size + 1, annotations.size());
assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
javaClass.applyChanges();
assertTrue(javaClass.toString().contains("@RequestScoped"));
@@ -86,14 +99,15 @@
@Test
public void testCanAddAnnotationDuplicate() throws Exception
{
+ int size = javaClass.getAnnotations().size();
javaClass.addAnnotation(Test.class);
javaClass.addAnnotation(Test.class);
List<Annotation> annotations = javaClass.getAnnotations();
- assertEquals(3, annotations.size());
+ assertEquals(size + 2, annotations.size());
assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
assertEquals(Test.class.getName(), annotations.get(annotations.size() - 2).getName());
javaClass.applyChanges();
- String pattern = "@" + Test.class.getName() + "() " + "@" + Test.class.getName() + "()";
+ String pattern = "@" + Test.class.getName() + " " + "@" + Test.class.getName();
assertTrue(javaClass.toString().contains(pattern));
}
@@ -102,4 +116,97 @@
{
javaClass.addAnnotation("sdf*(&#$%");
}
+
+ @Test
+ public void testAddLiteralValue() throws Exception
+ {
+ int size = javaClass.getAnnotations().size();
+
+ javaClass.addAnnotation(Test.class).setLiteralValue("435");
+ javaClass.applyChanges();
+
+ List<Annotation> annotations = javaClass.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals("435", annotation.getLiteralValue());
+ }
+
+ @Test
+ public void testAddObjectValue() throws Exception
+ {
+ int size = javaClass.getAnnotations().size();
+
+ javaClass.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class").setLiteralValue("foo", "bar");
+ javaClass.applyChanges();
+
+ List<Annotation> annotations = javaClass.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals(null, annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("expected"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAddValueConvertsToNormalAnnotation() throws Exception
+ {
+ javaClass.addAnnotation(Test.class).setLiteralValue("RuntimeException.class");
+ javaClass.applyChanges();
+ Annotation annotation = javaClass.getAnnotations().get(javaClass.getAnnotations().size() - 1);
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertTrue(annotation.isSingleValue());
+
+ annotation.setLiteralValue("foo", "bar");
+ assertFalse(annotation.isSingleValue());
+ assertTrue(annotation.isNormal());
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("value"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAnnotationBeginsAsMarker() throws Exception
+ {
+ Annotation anno = javaClass.addAnnotation(Test.class);
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setLiteralValue("\"Foo!\"");
+ assertFalse(anno.isMarker());
+ assertTrue(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setStringValue("bar", "Foo!");
+ assertFalse(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertTrue(anno.isNormal());
+
+ assertEquals("\"Foo!\"", anno.getLiteralValue("bar"));
+ assertEquals("Foo!", anno.getStringValue("bar"));
+
+ anno.removeAllValues();
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+ }
+
+ @Test
+ public void testRemoveAllValues() throws Exception
+ {
+ javaClass.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class");
+ javaClass.applyChanges();
+
+ List<Annotation> annotations = javaClass.getAnnotations();
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ annotation.removeAllValues();
+
+ assertEquals(0, annotation.getValues().size());
+ }
}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -46,7 +46,7 @@
public void reset()
{
stream = JavaClassTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
- javaClass = new JavaClass(stream);
+ javaClass = JavaParser.parse(stream);
}
@Test
Added: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodAnnotationTest.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,215 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.grammar.java;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class MethodAnnotationTest
+{
+ private InputStream stream;
+ private JavaClass javaClass;
+ private Method method;
+
+ @Before
+ public void reset()
+ {
+ stream = MethodAnnotationTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java");
+ javaClass = JavaParser.parse(stream);
+ method = javaClass.getMethods().get(0);
+ }
+
+ @Test
+ public void testParseAnnotation() throws Exception
+ {
+ List<Annotation> annotations = method.getAnnotations();
+
+ assertEquals(3, annotations.size());
+ assertEquals("deprecation", annotations.get(1).getStringValue());
+ assertEquals("deprecation", annotations.get(1).getStringValue("value"));
+ assertEquals("value", annotations.get(1).getValues().get(0).getName());
+ assertEquals("deprecation", annotations.get(1).getValues().get(0).getStringValue());
+
+ assertEquals("unchecked", annotations.get(2).getStringValue("value"));
+ assertEquals("unchecked", annotations.get(2).getStringValue());
+ assertEquals("value", annotations.get(2).getValues().get(0).getName());
+ assertEquals("unchecked", annotations.get(2).getValues().get(0).getStringValue());
+ }
+
+ @Test
+ public void testAddAnnotation() throws Exception
+ {
+ int size = method.getAnnotations().size();
+ method.addAnnotation().setName("RequestScoped");
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
+ }
+
+ @Test
+ public void testAddAnnotationByClass() throws Exception
+ {
+ int size = method.getAnnotations().size();
+ method.addAnnotation(Test.class);
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
+ method.applyChanges();
+ assertTrue(method.toString().contains("@" + Test.class.getName()));
+ }
+
+ @Test
+ public void testAddAnnotationByName() throws Exception
+ {
+ int size = method.getAnnotations().size();
+ method.addAnnotation("RequestScoped");
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+ assertEquals("RequestScoped", annotations.get(annotations.size() - 1).getName());
+ method.applyChanges();
+ assertTrue(method.toString().contains("@RequestScoped"));
+ }
+
+ @Test
+ public void testCanAddAnnotationDuplicate() throws Exception
+ {
+ int size = method.getAnnotations().size();
+ method.addAnnotation(Test.class);
+ method.addAnnotation(Test.class);
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 2, annotations.size());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 1).getName());
+ assertEquals(Test.class.getName(), annotations.get(annotations.size() - 2).getName());
+ method.applyChanges();
+ String pattern = "@" + Test.class.getName() + " " + "@" + Test.class.getName();
+ assertTrue(method.toString().contains(pattern));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotAddAnnotationWithIllegalName() throws Exception
+ {
+ method.addAnnotation("sdf*(&#$%");
+ }
+
+ @Test
+ public void testAddLiteralValue() throws Exception
+ {
+ int size = method.getAnnotations().size();
+
+ method.addAnnotation(Test.class).setLiteralValue("435");
+ method.applyChanges();
+
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals("435", annotation.getLiteralValue());
+ }
+
+ @Test
+ public void testAddObjectValue() throws Exception
+ {
+ int size = method.getAnnotations().size();
+
+ method.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class").setLiteralValue("foo", "bar");
+ method.applyChanges();
+
+ List<Annotation> annotations = method.getAnnotations();
+ assertEquals(size + 1, annotations.size());
+
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ assertEquals(Test.class.getName(), annotation.getName());
+ assertEquals(null, annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("expected"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAddValueConvertsToNormalAnnotation() throws Exception
+ {
+ method.addAnnotation(Test.class).setLiteralValue("RuntimeException.class");
+ method.applyChanges();
+ Annotation annotation = method.getAnnotations().get(method.getAnnotations().size() - 1);
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertTrue(annotation.isSingleValue());
+
+ annotation.setLiteralValue("foo", "bar");
+ assertFalse(annotation.isSingleValue());
+ assertTrue(annotation.isNormal());
+
+ assertEquals("RuntimeException.class", annotation.getLiteralValue());
+ assertEquals("RuntimeException.class", annotation.getLiteralValue("value"));
+ assertEquals("bar", annotation.getLiteralValue("foo"));
+ }
+
+ @Test
+ public void testAnnotationBeginsAsMarker() throws Exception
+ {
+ Annotation anno = method.addAnnotation(Test.class);
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setLiteralValue("\"Foo!\"");
+ assertFalse(anno.isMarker());
+ assertTrue(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+
+ anno.setStringValue("bar", "Foo!");
+ assertFalse(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertTrue(anno.isNormal());
+
+ assertEquals("\"Foo!\"", anno.getLiteralValue("bar"));
+ assertEquals("Foo!", anno.getStringValue("bar"));
+
+ anno.removeAllValues();
+ assertTrue(anno.isMarker());
+ assertFalse(anno.isSingleValue());
+ assertFalse(anno.isNormal());
+ }
+
+ @Test
+ public void testRemoveAllValues() throws Exception
+ {
+ method.addAnnotation(Test.class).setLiteralValue("expected", "RuntimeException.class");
+ method.applyChanges();
+
+ List<Annotation> annotations = method.getAnnotations();
+ Annotation annotation = annotations.get(annotations.size() - 1);
+ annotation.removeAllValues();
+
+ assertEquals(0, annotation.getValues().size());
+ }
+}
Modified: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/MethodTest.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -43,7 +43,7 @@
public void reset()
{
stream = MethodTest.class.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
- javaClass = new JavaClass(stream);
+ javaClass = JavaParser.parse(stream);
javaClass.addMethod("public URL rewriteURL(String pattern, String replacement) { return null; }");
method = javaClass.getMethods().get(javaClass.getMethods().size() - 1);
}
Added: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedClassFile.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,15 @@
+package org.jboss.seam.encore.grammar.java;
+
+import java.net.URL;
+
+@Deprecated
+@SuppressWarnings("deprecation")
+@SuppressWarnings(value="unchecked")
+public class MockAnnotatedClassFile
+{
+ private String field;
+
+ public MockClassFile()
+ {
+ }
+}
Added: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java (rev 0)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockAnnotatedMethodFile.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -0,0 +1,11 @@
+package org.jboss.seam.encore.grammar.java;
+
+public class MockAnnotatedMethodFile
+{
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ @SuppressWarnings(value="unchecked")
+ public MockClassFile()
+ {
+ }
+}
Modified: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -2,7 +2,6 @@
import java.net.URL;
-@Deprecated
public class MockClassFile
{
private String field;
Modified: sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java
===================================================================
--- sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java 2010-08-04 02:45:10 UTC (rev 13552)
+++ sandbox/encore/model/src/main/java/org/jboss/encore/model/AbstractProject.java 2010-08-04 17:15:49 UTC (rev 13553)
@@ -30,6 +30,7 @@
import javax.inject.Inject;
import org.jboss.encore.grammar.java.JavaClass;
+import org.jboss.encore.grammar.java.JavaParser;
import org.jboss.encore.model.events.JavaFileCreated;
/**
@@ -43,7 +44,7 @@
public File createJavaFile(final String path, final char[] data)
{
- return createJavaFile(path, new JavaClass(data));
+ return createJavaFile(path, JavaParser.parse(data));
}
public File createJavaFile(final String path, JavaClass clazz)
13 years, 9 months