[seam-commits] Seam SVN: r13553 - in sandbox/encore: core/src/main/java/org/jboss/encore/grammar/java and 4 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Aug 4 13:15:51 EDT 2010
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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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;
+
+ at Deprecated
+ at SuppressWarnings("deprecation")
+ at 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;
- at 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)
More information about the seam-commits
mailing list