|
From: <ls...@us...> - 2007-06-25 07:24:47
|
Revision: 3299
http://jnode.svn.sourceforge.net/jnode/?rev=3299&view=rev
Author: lsantha
Date: 2007-06-25 00:24:46 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/com/com/sun/codemodel/
trunk/core/src/openjdk/com/com/sun/codemodel/internal/
trunk/core/src/openjdk/com/com/sun/codemodel/internal/ClassType.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/CodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotatable.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationArrayMember.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationStringValue.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationUse.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationValue.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnonymousClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArray.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayCompRef.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignment.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignmentTarget.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAtom.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JBlock.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JBreak.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JCase.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JCast.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JCatchBlock.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JClassAlreadyExistsException.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JClassContainer.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JCodeModel.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JCommentPart.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JConditional.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JContinue.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JDeclaration.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JDefinedClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JDirectClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JDoLoop.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JDocComment.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JEnumConstant.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JExpr.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JExpression.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JExpressionImpl.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JFieldRef.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JFieldVar.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JForEach.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JForLoop.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JFormatter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JGenerable.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JGenerifiable.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JGenerifiableImpl.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JInvocation.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JJavaName.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JLabel.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JMethod.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JMod.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JMods.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JNarrowedClass.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JNullType.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JOp.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JPackage.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JPrimitiveType.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JResourceFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JReturn.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JStatement.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JStringLiteral.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JSwitch.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JThrow.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JTryBlock.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JType.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JTypeVar.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JTypeWildcard.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JVar.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/JWhileLoop.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/TypedAnnotationWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JBinaryFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JPropertyFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JSerializedObject.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JStaticFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JStaticJavaFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/JTextFile.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/fmt/package.html
trunk/core/src/openjdk/com/com/sun/codemodel/internal/package-info.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/ClassNameComparator.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/EncoderFactory.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/JavadocEscapeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/MS1252Encoder.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/SingleByteEncoder.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/Surrogate.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/util/UnicodeEscapeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/FileCodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/FilterCodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/ProgressCodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/PrologCodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/SingleStreamCodeWriter.java
trunk/core/src/openjdk/com/com/sun/codemodel/internal/writer/ZipCodeWriter.java
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/ClassType.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/ClassType.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/ClassType.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+/**
+ * This helps enable whether the JDefinedClass is a Class or Interface or
+ * AnnotationTypeDeclaration or Enum
+ *
+ * @author
+ * Bhakti Mehta (bha...@su...)
+ */
+public final class ClassType {
+
+ /**
+ * The keyword used to declare this type.
+ */
+ final String declarationToken;
+
+ private ClassType(String token) {
+ this.declarationToken = token;
+ }
+
+ public static final ClassType CLASS = new ClassType("class");
+ public static final ClassType INTERFACE = new ClassType("interface");
+ public static final ClassType ANNOTATION_TYPE_DECL = new ClassType("@interface");
+ public static final ClassType ENUM = new ClassType("enum");
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/CodeWriter.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/CodeWriter.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/CodeWriter.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.CharsetEncoder;
+
+import com.sun.codemodel.internal.util.EncoderFactory;
+import com.sun.codemodel.internal.util.UnicodeEscapeWriter;
+
+/**
+ * Receives generated code and writes to the appropriate storage.
+ *
+ * @author
+ * Kohsuke Kawaguchi (koh...@su...)
+ */
+public abstract class CodeWriter {
+
+ /**
+ * Called by CodeModel to store the specified file.
+ * The callee must allocate a storage to store the specified file.
+ *
+ * <p>
+ * The returned stream will be closed before the next file is
+ * stored. So the callee can assume that only one OutputStream
+ * is active at any given time.
+ *
+ * @param pkg
+ * The package of the file to be written.
+ * @param fileName
+ * File name without the path. Something like
+ * "Foo.java" or "Bar.properties"
+ */
+ public abstract OutputStream openBinary( JPackage pkg, String fileName ) throws IOException;
+
+ /**
+ * Called by CodeModel to store the specified file.
+ * The callee must allocate a storage to store the specified file.
+ *
+ * <p>
+ * The returned stream will be closed before the next file is
+ * stored. So the callee can assume that only one OutputStream
+ * is active at any given time.
+ *
+ * @param pkg
+ * The package of the file to be written.
+ * @param fileName
+ * File name without the path. Something like
+ * "Foo.java" or "Bar.properties"
+ */
+ public Writer openSource( JPackage pkg, String fileName ) throws IOException {
+ final OutputStreamWriter bw = new OutputStreamWriter(openBinary(pkg,fileName));
+
+ // create writer
+ try {
+ return new UnicodeEscapeWriter(bw) {
+ // can't change this signature to Encoder because
+ // we can't have Encoder in method signature
+ private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
+ protected boolean requireEscaping(int ch) {
+ // control characters
+ if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 ) return true;
+ // check ASCII chars, for better performance
+ if( ch<0x80 ) return false;
+
+ return !encoder.canEncode((char)ch);
+ }
+ };
+ } catch( Throwable t ) {
+ return new UnicodeEscapeWriter(bw);
+ }
+ }
+
+ /**
+ * Called by CodeModel at the end of the process.
+ */
+ public abstract void close() throws IOException;
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotatable.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotatable.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotatable.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Annotatable program elements.
+ *
+ * @author Kohsuke Kawaguchi
+ */
+public interface JAnnotatable {
+ /**
+ * Adds an annotation to this program element.
+ * @param clazz
+ * The annotation class to annotate the program element with
+ */
+ JAnnotationUse annotate(JClass clazz);
+
+ /**
+ * Adds an annotation to this program element.
+ *
+ * @param clazz
+ * The annotation class to annotate the program element with
+ */
+ JAnnotationUse annotate(Class <? extends Annotation> clazz);
+
+ /**
+ * Adds an annotation to this program element
+ * and returns a type-safe writer to fill in the values of such annotations.
+ */
+ <W extends JAnnotationWriter> W annotate2(Class<W> clazz);
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationArrayMember.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationArrayMember.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationArrayMember.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an arrays as annotation members
+ *
+ * <p>
+ * This class implements {@link JAnnotatable} to allow
+ * new annotations to be added as a member of the array.
+ *
+ * @author
+ * Bhakti Mehta (bha...@su...)
+ */
+public final class JAnnotationArrayMember extends JAnnotationValue implements JAnnotatable {
+ private final List<JAnnotationValue> values = new ArrayList<JAnnotationValue>();
+ private final JCodeModel owner;
+
+ JAnnotationArrayMember(JCodeModel owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Adds an array member to this annotation
+ *
+ * @param value Adds a string value to the array member
+ * @return The JAnnotationArrayMember. More elements can be added by calling
+ * the same method multiple times
+ */
+ public JAnnotationArrayMember param(String value) {
+ JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
+ values.add(annotationValue);
+ return this;
+ }
+
+ public JAnnotationArrayMember param(boolean value) {
+ JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
+ values.add(annotationValue);
+ return this;
+ }
+
+ /**
+ * Adds an array member to this annotation
+ *
+ * @param value Adds an int value to the array member
+ * @return The JAnnotationArrayMember. More elements can be added by calling
+ * the same method multiple times
+ */
+ public JAnnotationArrayMember param(int value) {
+ JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
+ values.add(annotationValue);
+ return this;
+ }
+
+ /**
+ * Adds an array member to this annotation
+ *
+ * @param value Adds a float value to the array member
+ * @return The JAnnotationArrayMember. More elements can be added by calling
+ * the same method multiple times
+ */
+ public JAnnotationArrayMember param(float value) {
+ JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
+ values.add(annotationValue);
+ return this;
+ }
+
+ public JAnnotationArrayMember param(Class value){
+ JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value.getName()));
+ values.add(annotationValue);
+ return this;
+ }
+
+ public JAnnotationArrayMember param(JType type){
+ JClass clazz = type.boxify();
+ JAnnotationValue annotationValue = new JAnnotationStringValue ( clazz.dotclass() );
+ values.add(annotationValue);
+ return this;
+ }
+
+ /**
+ * Adds a new annotation to the array.
+ */
+ public JAnnotationUse annotate(Class<? extends Annotation> clazz){
+ return annotate(owner.ref(clazz));
+ }
+
+ /**
+ * Adds a new annotation to the array.
+ */
+ public JAnnotationUse annotate(JClass clazz){
+ JAnnotationUse a = new JAnnotationUse(clazz);
+ values.add(a);
+ return a;
+ }
+
+ public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
+ return TypedAnnotationWriter.create(clazz,this);
+ }
+
+ /**
+ * Adds an annotation member to this annotation array
+ * This can be used for e.g @XmlCollection(values= @XmlCollectionItem(type=Foo.class))
+ * @param value
+ * Adds a annotation to the array member
+ * @return
+ * The JAnnotationArrayMember. More elements can be added by calling
+ * the same method multiple times
+ *
+ * @deprecated
+ * use {@link #annotate}
+ */
+ public JAnnotationArrayMember param (JAnnotationUse value ){
+ values.add(value);
+ return this;
+ }
+
+ public void generate(JFormatter f) {
+ f.p('{').nl().i();
+
+ boolean first = true;
+ for (JAnnotationValue aValue : values) {
+ if (!first)
+ f.p(',').nl();
+ f.g(aValue);
+ first = false;
+ }
+ f.nl().o().p('}');
+ }
+}
+
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationStringValue.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationStringValue.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationStringValue.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+
+/**
+ * Captures the value of the annotation.
+ *
+ * @author
+ * Bhakti Mehta (bha...@su...)
+ */
+final class JAnnotationStringValue extends JAnnotationValue {
+
+ /**
+ * The value of the Annotation member
+ */
+ private final JExpression value;
+
+ JAnnotationStringValue(JExpression value) {
+ this.value = value;
+ }
+
+ public void generate(JFormatter f) {
+ f.g(value);
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationUse.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationUse.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationUse.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+import java.lang.annotation.Annotation;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Represents an annotation on a program element.
+ *
+ * TODO
+ * How to add enums to the annotations
+ * @author
+ * Bhakti Mehta (bha...@su...)
+ */
+public final class JAnnotationUse extends JAnnotationValue {
+
+ /**
+ * The {@link Annotation} class
+ */
+ private final JClass clazz;
+
+ /**
+ * Map of member values.
+ */
+ private Map<String,JAnnotationValue> memberValues;
+
+ JAnnotationUse(JClass clazz){
+ this.clazz = clazz;
+ }
+
+ private JCodeModel owner() {
+ return clazz.owner();
+ }
+
+ private void addValue(String name, JAnnotationValue annotationValue) {
+ // Use ordered map to keep the code generation the same on any JVM.
+ // Lazily created.
+ if(memberValues==null)
+ memberValues = new LinkedHashMap<String, JAnnotationValue>();
+ memberValues.put(name,annotationValue);
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ *
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The boolean value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse param(String name, boolean value){
+ addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The int member value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse param(String name, int value){
+ addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The String member value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse param(String name, String value){
+ //Escape string values with quotes so that they can
+ //be generated accordingly
+ addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * For adding class values as param
+ * @see #param(String, Class)
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The annotation class which is member value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse annotationParam(String name, Class<? extends Annotation> value) {
+ JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(value));
+ addValue(name, annotationUse);
+ return annotationUse;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The enum class which is member value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse param(String name, final Enum value) {
+ addValue(name, new JAnnotationValue() {
+ public void generate(JFormatter f) {
+ f.t(owner().ref(value.getDeclaringClass())).p('.').p(value.name());
+ }
+ });
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * @param name
+ * The simple name for this annotation
+ *
+ * @param value
+ * The JEnumConstant which is member value for this annotation
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ */
+ public JAnnotationUse param(String name, JEnumConstant value){
+ addValue(name, new JAnnotationStringValue(value));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation
+ * This can be used for e.g to specify
+ * <pre>
+ * @XmlCollectionItem(type=Integer.class);
+ * <pre>
+ * For adding a value of Class<? extends Annotation>
+ * @link
+ * #annotationParam(java.lang.String, java.lang.Class<? extends java.lang.annotation.Annotation>)
+ * @param name
+ * The simple name for this annotation param
+ *
+ * @param value
+ * The class type of the param
+ * @return
+ * The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ *
+ *
+ *
+ */
+ public JAnnotationUse param(String name, Class value){
+ addValue(name, new JAnnotationStringValue(JExpr.lit(value.getName())));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair to this annotation based on the
+ * type represented by the given JType
+ *
+ * @param name The simple name for this annotation param
+ * @param type the JType representing the actual type
+ * @return The JAnnotationUse. More member value pairs can
+ * be added to it using the same or the overloaded methods.
+ */
+ public JAnnotationUse param(String name, JType type){
+ JClass clazz = type.boxify();
+ addValue(name, new JAnnotationStringValue ( clazz.dotclass() ));
+ return this;
+ }
+
+ /**
+ * Adds a member value pair which is of type array to this annotation
+ * @param name
+ * The simple name for this annotation
+ *
+ * @return
+ * The JAnnotationArrayMember. For adding array values
+ * @see JAnnotationArrayMember
+ *
+ */
+ public JAnnotationArrayMember paramArray(String name){
+ JAnnotationArrayMember arrayMember = new JAnnotationArrayMember(owner());
+ addValue(name, arrayMember);
+ return arrayMember;
+ }
+
+
+// /**
+// * This can be used to add annotations inside annotations
+// * for e.g @XmlCollection(values= @XmlCollectionItem(type=Foo.class))
+// * @param className
+// * The classname of the annotation to be included
+// * @return
+// * The JAnnotationUse that can be used as a member within this JAnnotationUse
+// * @deprecated
+// * use {@link JAnnotationArrayMember#annotate}
+// */
+// public JAnnotationUse annotate(String className) {
+// JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(className));
+// return annotationUse;
+// }
+
+ /**
+ * This can be used to add annotations inside annotations
+ * for e.g @XmlCollection(values= @XmlCollectionItem(type=Foo.class))
+ * @param clazz
+ * The annotation class to be included
+ * @return
+ * The JAnnotationUse that can be used as a member within this JAnnotationUse
+ * @deprecated
+ * use {@link JAnnotationArrayMember#annotate}
+ */
+ public JAnnotationUse annotate(Class <? extends Annotation> clazz) {
+ JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(clazz));
+ return annotationUse;
+ }
+
+ public void generate(JFormatter f) {
+ f.p('@').g(clazz);
+ if(memberValues!=null) {
+ f.p('(');
+ boolean first = true;
+
+ if(isOptimizable()) {
+ // short form
+ f.g(memberValues.get("value"));
+ } else {
+ for (Map.Entry<String, JAnnotationValue> mapEntry : memberValues.entrySet()) {
+ if (!first) f.p(',');
+ f.p(mapEntry.getKey()).p('=').g(mapEntry.getValue());
+ first = false;
+ }
+ }
+ f.p(')');
+ }
+ }
+
+ private boolean isOptimizable() {
+ return memberValues.size()==1 && memberValues.containsKey("value");
+ }
+}
+
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationValue.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationValue.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationValue.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+/**
+ * Things that can be values of an annotation element.
+ *
+ * @author
+ * Bhakti Mehta (bha...@su...)
+ */
+public abstract class JAnnotationValue implements JGenerable {
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationWriter.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationWriter.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnnotationWriter.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Base interface for typed annotation writer.
+ *
+ * <p>
+ * Annotation compiler can generate a strongly typed annotation
+ * writer to assist applications to write uses of annotations.
+ * Such typed annotation writer interfaces all derive from
+ * this common interface.
+ *
+ * <p>
+ * The type parameter 'A' represents the
+ * @author Kohsuke Kawaguchi
+ */
+public interface JAnnotationWriter<A extends Annotation> {
+ /**
+ * Gets the underlying annotation use object to which we are writing.
+ */
+ JAnnotationUse getAnnotationUse();
+
+ /**
+ * The type of the annotation that this writer is writing.
+ */
+ Class<A> getAnnotationType();
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnonymousClass.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnonymousClass.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAnonymousClass.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+/**
+ * Anonymous class quick hack.
+ *
+ * @author
+ * Kohsuke Kawaguchi (koh...@su...)
+ */
+class JAnonymousClass extends JDefinedClass {
+
+ /**
+ * Base interface/class from which this anonymous class is built.
+ */
+ private final JClass base;
+
+ JAnonymousClass( JClass _base) {
+ super(_base.owner(), 0, null);
+ this.base = _base;
+ }
+
+ public String fullName() {
+ return base.fullName();
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArray.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArray.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArray.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * array creation and initialization.
+ */
+public final class JArray extends JExpressionImpl {
+
+ private final JType type;
+ private final JExpression size;
+ private List<JExpression> exprs = null;
+
+ /**
+ * Add an element to the array initializer
+ */
+ public JArray add(JExpression e) {
+ if (exprs == null)
+ exprs = new ArrayList<JExpression>();
+ exprs.add(e);
+ return this;
+ }
+
+ JArray(JType type, JExpression size) {
+ this.type = type;
+ this.size = size;
+ }
+
+ public void generate(JFormatter f) {
+
+ // generally we produce new T[x], but when T is an array type (T=T'[])
+ // then new T'[][x] is wrong. It has to be new T'[x][].
+ int arrayCount = 0;
+ JType t = type;
+
+ while( t.isArray() ) {
+ t = t.elementType();
+ arrayCount++;
+ }
+
+ f.p("new").g(t).p('[');
+ if (size != null)
+ f.g(size);
+ f.p(']');
+
+ for( int i=0; i<arrayCount; i++ )
+ f.p("[]");
+
+ if ((size == null) || (exprs != null))
+ f.p('{');
+ if (exprs != null) {
+ f.g(exprs);
+ } else {
+ f.p(' ');
+ }
+ if ((size == null) || (exprs != null))
+ f.p('}');
+ }
+
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayClass.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayClass.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayClass.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.util.Iterator;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Array class.
+ *
+ * @author
+ * Kohsuke Kawaguchi (koh...@su...)
+ */
+final class JArrayClass extends JClass {
+
+ // array component type
+ private final JType componentType;
+
+
+ JArrayClass( JCodeModel owner, JType component ) {
+ super(owner);
+ this.componentType = component;
+ }
+
+
+ public String name() {
+ return componentType.name()+"[]";
+ }
+
+ public String fullName() {
+ return componentType.fullName()+"[]";
+ }
+
+ public String binaryName() {
+ return componentType.binaryName()+"[]";
+ }
+
+ public void generate(JFormatter f) {
+ f.g(componentType).p("[]");
+ }
+
+ public JPackage _package() {
+ return owner().rootPackage();
+ }
+
+ public JClass _extends() {
+ return owner().ref(Object.class);
+ }
+
+ public Iterator<JClass> _implements() {
+ return Collections.<JClass>emptyList().iterator();
+ }
+
+ public boolean isInterface() {
+ return false;
+ }
+
+ public boolean isAbstract() {
+ return false;
+ }
+
+ public JType elementType() {
+ return componentType;
+ }
+
+ public boolean isArray() {
+ return true;
+ }
+
+
+ //
+ // Equality is based on value
+ //
+
+ public boolean equals(Object obj) {
+ if(!(obj instanceof JArrayClass)) return false;
+
+ if( componentType.equals( ((JArrayClass)obj).componentType ) )
+ return true;
+
+ return false;
+ }
+
+ public int hashCode() {
+ return componentType.hashCode();
+ }
+
+ protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
+ if( componentType.isPrimitive() )
+ return this;
+
+ JClass c = ((JClass)componentType).substituteParams(variables,bindings);
+ if(c==componentType)
+ return this;
+
+ return new JArrayClass(owner(),c);
+ }
+
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayCompRef.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayCompRef.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JArrayCompRef.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+/**
+ * array component reference.
+ */
+final class JArrayCompRef extends JExpressionImpl implements JAssignmentTarget {
+ /**
+ * JArray expression upon which this component will be accessed.
+ */
+ private final JExpression array;
+
+ /**
+ * Integer expression representing index of the component
+ */
+ private final JExpression index;
+
+ /**
+ * JArray component reference constructor given an array expression
+ * and index.
+ *
+ * @param array
+ * JExpression for the array upon which
+ * the component will be accessed,
+ *
+ * @param index
+ * JExpression for index of component to access
+ */
+ JArrayCompRef(JExpression array, JExpression index) {
+ if ((array == null) || (index == null)) {
+ throw new NullPointerException();
+ }
+ this.array = array;
+ this.index = index;
+ }
+
+ public void generate(JFormatter f) {
+ f.g(array).p('[').g(index).p(']');
+ }
+
+ public JExpression assign(JExpression rhs) {
+ return JExpr.assign(this,rhs);
+ }
+ public JExpression assignPlus(JExpression rhs) {
+ return JExpr.assignPlus(this,rhs);
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignment.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignment.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignment.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+/**
+ * Assignment statements, which are also expressions.
+ */
+public class JAssignment extends JExpressionImpl implements JStatement {
+
+ JAssignmentTarget lhs;
+ JExpression rhs;
+ String op = "";
+
+ JAssignment(JAssignmentTarget lhs, JExpression rhs) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ }
+
+ JAssignment(JAssignmentTarget lhs, JExpression rhs, String op) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ this.op = op;
+ }
+
+ public void generate(JFormatter f) {
+ f.g(lhs).p(op + '=').g(rhs);
+ }
+
+ public void state(JFormatter f) {
+ f.g(this).p(';').nl();
+ }
+
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignmentTarget.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignmentTarget.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAssignmentTarget.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+/**
+ * Marker interface for code components that can be placed to
+ * the left of '=' in an assignment.
+ *
+ * A left hand value can always be a right hand value, so
+ * this interface derives from {@link JExpression}.
+ */
+public interface JAssignmentTarget extends JGenerable, JExpression {
+ JExpression assign(JExpression rhs);
+ JExpression assignPlus(JExpression rhs);
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAtom.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAtom.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JAtom.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+
+/**
+ * JAtoms: Simple code components that merely generate themselves.
+ */
+final class JAtom extends JExpressionImpl {
+
+ private final String what;
+
+ JAtom(String what) {
+ this.what = what;
+ }
+
+ public void generate(JFormatter f) {
+ f.p(what);
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/codemodel/internal/JBlock.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/codemodel/internal/JBlock.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/codemodel/internal/JBlock.java 2007-06-25 07:24:46 UTC (rev 3299)
@@ -0,0 +1,451 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.codemodel.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+
+/**
+ * A block of Java code, which may contain statements and local declarations.
+ *
+ * <p>
+ * {@link JBlock} contains a large number of factory methods that creates new
+ * statements/declarations. Those newly created statements/declarations are
+ * inserted into the {@link #pos() "current position"}. The position advances
+ * one every time you add a new instruction.
+ */
+public final class JBlock implements JGenerable, JStatement {
+
+ /**
+ * Declarations and statements contained in this block.
+ * Either {@link JStatement} or {@link JDeclaration}.
+ */
+ private final List<Object> content = new ArrayList<Object>();
+
+ /**
+ * Whether or not this block must be braced and indented
+ */
+ private boolean bracesRequired = true;
+ private boolean indentRequired = true;
+
+ /**
+ * Current position.
+ */
+ private int pos;
+
+ public JBlock() {
+ this(true,true);
+ }
+
+ public JBlock(boolean bracesRequired, boolean indentRequired) {
+ this.bracesRequired = bracesRequired;
+ this.indentRequired = indentRequired;
+ }
+
+ /**
+ * Returns a read-only view of {@link JStatement}s and {@link JDeclaration}
+ * in this block.
+ */
+ public List<Object> getContents() {
+ return Collections.unmodifiableList(content);
+ }
+
+ private <T> T insert( T statementOrDeclaration ) {
+ content.add(pos,statementOrDeclarati...
[truncated message content] |