You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/09/14 18:21:05 UTC

svn commit: r280879 [3/16] - in /struts/sandbox/trunk/ti: ./ jars/compiler-apt/ jars/compiler-apt/src/ jars/compiler-apt/src/java/ jars/compiler-apt/src/java/org/ jars/compiler-apt/src/java/org/apache/ jars/compiler-apt/src/java/org/apache/ti/ jars/com...

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletCompilerUtils.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletCompilerUtils.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletCompilerUtils.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletCompilerUtils.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.TypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.type.TypeInstance;
+import org.apache.ti.compiler.internal.typesystem.util.SourcePosition;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.WrapperFactory;
+import xjavadoc.XClass;
+import xjavadoc.XJavaDoc;
+import xjavadoc.XPackage;
+
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ResourceBundle;
+
+public class XDocletCompilerUtils {
+
+    private static final ResourceBundle MESSAGES =
+            ResourceBundle.getBundle("org.apache.ti.compiler.xdoclet.Messages");
+
+    public static void addError(SourcePosition sourcePosition, String messageKey, String[] args) {
+        assert sourcePosition != null;
+        String message = getMessage(messageKey, args);
+        PageFlowDocletTask.get().addError(message, sourcePosition);
+    }
+
+    public static void addWarning(SourcePosition sourcePosition, String messageKey, String[] args) {
+        assert sourcePosition != null;
+        String message = getMessage(messageKey, args);
+        PageFlowDocletTask.get().addWarning(message, sourcePosition);
+    }
+
+    public static String getMessage(String messageKey, String[] args) {
+        String message = MESSAGES.getString(messageKey);
+        if (args != null) message = MessageFormat.format(message, args);
+        return message;
+    }
+
+    public static TypeDeclaration resolveTypeDeclaration(String typeName) {
+        assert ! typeName.endsWith("[]") : "array type not allowed here: " + typeName;
+        return (TypeDeclaration) resolveTypeInstanceOrTypeDecl(typeName, true, null, false);
+    }
+
+    private static XClass getXClass(String typeName, XJavaDoc xJavaDoc) {
+        assert ! typeName.endsWith("[]") : "array type not allowed here: " + typeName;
+
+        XClass type = xJavaDoc.getXClass(typeName);
+
+        //
+        // This may be an inner class, which needs a '$' instead of a '.'.
+        //
+        if (isUnknownClass(type)) {
+            int lastDot = typeName.lastIndexOf('.');
+
+            if (lastDot != -1) {
+                return getXClass(typeName.substring(0, lastDot) + '$' + typeName.substring(lastDot + 1), xJavaDoc);
+            }
+        }
+
+        return type;
+    }
+
+    private static boolean isUnknownClass(XClass xclass) {
+        return xclass == null || xclass.getClass().getName().equals("xjavadoc.UnknownClass");
+    }
+
+    public static TypeInstance resolveType(String typeName, boolean allowErrorType, XClass currentClass) {
+        return (TypeInstance) resolveTypeInstanceOrTypeDecl(typeName, allowErrorType, currentClass, true);
+    }
+
+    private static Object resolveTypeInstanceOrTypeDecl(String typeName, boolean allowUnknownType, XClass currentClass,
+                                                        boolean returnTypeInstance) {
+        int arrayDimensions = 0;
+
+        if (typeName.endsWith(".class")) typeName = typeName.substring(0, typeName.length() - 6);
+
+        while (typeName.endsWith("[]")) {
+            typeName = typeName.substring(0, typeName.length() - 2);
+            ++arrayDimensions;
+        }
+
+        if (currentClass == null) currentClass = PageFlowDocletSubTask.get().getCurrentSourceClass();
+        XJavaDoc xJavaDoc = currentClass.getXJavaDoc();
+
+        XClass originalResolvedType = getXClass(typeName, xJavaDoc);
+        XClass attemptedResolvedType = originalResolvedType;
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            attemptedResolvedType = getXClass("java.lang." + typeName, xJavaDoc);
+        }
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            // See if it was an imported class.
+            List importedClasses = currentClass.getImportedClasses();
+            String dotPrepended = '.' + typeName;
+
+            for (Iterator i = importedClasses.iterator(); i.hasNext();) {
+                XClass importedClass = (XClass) i.next();
+                if (importedClass.getQualifiedName().endsWith(dotPrepended)) {
+                    attemptedResolvedType = getXClass(importedClass.getQualifiedName(), xJavaDoc);
+                    break;
+                }
+            }
+        }
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            // See if it was in an imported package.
+            List importedPackages = currentClass.getImportedPackages();
+            String dotPrepended = '.' + typeName;
+
+            for (Iterator i = importedPackages.iterator(); i.hasNext();) {
+                XPackage importedPackage = (XPackage) i.next();
+                XClass implicitImportedClass = getXClass(importedPackage.getName() + dotPrepended, xJavaDoc);
+                if (! isUnknownClass(implicitImportedClass)) {
+                    attemptedResolvedType = implicitImportedClass;
+                    break;
+                }
+            }
+        }
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            // Try it with the full outer classname appended.
+            String outerClassName = currentClass.getQualifiedName();
+            attemptedResolvedType = getXClass(outerClassName + '.' + typeName, xJavaDoc);
+        }
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            // Finally, it may be of the form <outer-class-short-name>.<inner-class-name>
+            String outerClassName = currentClass.getQualifiedName();
+            int lastDot = outerClassName.lastIndexOf('.');
+            outerClassName = lastDot != -1 ? outerClassName.substring(0, lastDot) : outerClassName;
+            attemptedResolvedType = getXClass(outerClassName + '.' + typeName, xJavaDoc);
+        }
+
+        if (isUnknownClass(attemptedResolvedType)) {
+            if (! allowUnknownType) return null;
+            if (returnTypeInstance) return WrapperFactory.get().getTypeInstance(originalResolvedType);
+            return WrapperFactory.get().getTypeDeclaration(originalResolvedType);
+        }
+
+        if (returnTypeInstance) return WrapperFactory.get().getTypeInstance(attemptedResolvedType, arrayDimensions);
+        return WrapperFactory.get().getTypeDeclaration(attemptedResolvedType);
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletUtils.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletUtils.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletUtils.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/XDocletUtils.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet;
+
+import xjavadoc.XClass;
+import xjavadoc.XProgramElement;
+
+public class XDocletUtils {
+
+    public static XClass getOutermostClass(XProgramElement element) {
+        XClass containingClass;
+        while ((containingClass = element.getContainingClass()) != null) {
+            element = containingClass;
+        }
+
+        assert element instanceof XClass : element.getClass().getName();
+        return (XClass) element;
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDoclet.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDoclet.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDoclet.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDoclet.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,389 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.tools;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+
+public class AnnotationsToXDoclet {
+
+    private static final String[] QUALIFIED_ANNOTATIONS =
+            {
+                    "@org.apache.ti.pageflow.annotations."
+            };
+
+    private static void usage() {
+        System.err.println("usage: " + AnnotationsToXDoclet.class.getName() + " input-file output-file");
+        System.err.println("                            -or-");
+        System.err.println("usage: " + AnnotationsToXDoclet.class.getName()
+                + " -input-dir <root of input dir> -output-dir <root of output dir> -extensions <comma-separated list>");
+    }
+
+    public static void main(String[] args)
+            throws IOException, FileNotFoundException {
+        // Recurse
+        if (args.length == 6) {
+            if (! args[0].equals("-input-dir") || ! args[2].equals("-output-dir") || ! args[4].equals("-extensions")) {
+                usage();
+                System.exit(1);
+            }
+
+            File inputDir = new File(args[1]);
+            if (! inputDir.exists()) {
+                System.err.println(inputDir + " is not a directory");
+                System.exit(2);
+            }
+
+            File outputDir = new File(args[3]);
+            if (! outputDir.exists()) {
+                System.err.println(outputDir + " is not a directory");
+                System.exit(2);
+            }
+
+            String[] extensions = args[5].split(",");
+            new AnnotationsToXDoclet().translateRecursive(inputDir, outputDir, extensions);
+            return;
+        }
+
+        // ...or, do a single file translation.
+        if (args.length != 2) {
+            usage();
+            System.exit(1);
+        }
+
+        File input = new File(args[0]);
+        File output = new File(args[1]);
+
+        if (input.equals(output)) {
+            System.err.println("input file " + input + " must be different from output file");
+            System.exit(2);
+        }
+
+        if (! input.canRead()) {
+            System.err.println("cannot read " + input);
+            System.exit(2);
+        }
+
+        if (output.exists() && ! output.canWrite()) {
+            System.err.println("cannot write to " + output);
+            System.exit(2);
+        }
+
+        new AnnotationsToXDoclet().translate(input, output);
+    }
+
+    public void translateRecursive(File inputDir, File outputDir, String[] extensions)
+            throws IOException, FileNotFoundException {
+        File[] children = inputDir.listFiles();
+
+        outputDir.mkdirs();
+
+        for (int i = 0; i < children.length; i++) {
+            File child = children[i];
+
+            if (child.isFile()) {
+                for (int j = 0; j < extensions.length; j++) {
+                    String extension = extensions[j];
+                    if (child.getName().endsWith(extension)) {
+                        translate(child, new File(outputDir, child.getName()));
+                    }
+                }
+            } else if (child.isDirectory()) {
+                File childOutputDir = new File(outputDir, child.getName());
+                translateRecursive(child, childOutputDir, extensions);
+            }
+        }
+    }
+
+    public void translate(File input, File output)
+            throws IOException, FileNotFoundException {
+        System.err.println(input + " -> " + output);
+        output.getAbsoluteFile().getParentFile().mkdirs();
+        FileReader in = new FileReader(input);
+        PrintWriter out = null;
+
+        try {
+            out = new PrintWriter(new FileWriter(output));
+            StreamTokenizer tok = getJavaTokenizer(in);
+            boolean addedSpace = false;
+            StringBuffer indentBuffer = new StringBuffer();
+            String indent = "";
+
+            while (tok.nextToken() != StreamTokenizer.TT_EOF) {
+                boolean wasSpace = false;
+                boolean wasChar = false;
+
+                switch (tok.ttype) {
+                    case StreamTokenizer.TT_WORD:
+                        if (indentBuffer != null) {
+                            indent = indentBuffer.toString();
+                            indentBuffer = null;
+                        }
+                        String str = tok.sval;
+                        if (str.startsWith("@ti.viewProperties")) {
+                            ignoreUntil(tok, ")");
+                        } else if (str.startsWith("@ti.") || str.startsWith("@org.apache.ti")) {
+                            out.println("/**");
+                            ArrayList tags = new ArrayList();
+                            translateAnnotation(tok, out, str, indent, tags);
+                            for (int i = 0; i < tags.size(); ++i) {
+                                out.print(indent);
+                                out.print(" * ");
+                                out.println((String) tags.get(i));
+                            }
+                            out.print(indent);
+                            out.print(" */");
+                        } else if (str.equals("import")) {
+                            filterImport(tok, out);
+                        } else {
+                            out.print(str);
+                            if (str.length() == 1) {
+                                char c = str.charAt(0);
+                                if (c == '\'' || c == '"') wasChar = true;
+                            }
+                        }
+                        break;
+
+                    case StreamTokenizer.TT_NUMBER:
+                        assert false : tok.nval;   // parseNumbers() was set to false on the tokenizer.
+                        break;
+
+                    default:
+                        char c = (char) tok.ttype;
+                        wasChar = true;
+                        if (! addedSpace || c != ' ') out.print(c);
+                        wasSpace = Character.isWhitespace(c);
+                        if (! wasSpace && indentBuffer != null) {
+                            indent = indentBuffer.toString();
+                            indentBuffer = null;
+                        }
+                        if (indentBuffer != null) indentBuffer.append(c);
+                        if (c == '\n') indentBuffer = new StringBuffer();
+                }
+
+                if (! wasChar) {
+                    out.print(' ');
+                    addedSpace = true;
+                } else {
+                    addedSpace = false;
+                }
+            }
+        }
+        finally {
+            in.close();
+            if (out != null) out.close();
+        }
+    }
+
+    private void ignoreUntil(StreamTokenizer tok, String str)
+            throws IOException {
+        while (! getToken(tok).equals(str)) {
+        }
+    }
+
+    private void filterImport(StreamTokenizer tok, PrintWriter out)
+            throws IOException {
+        String importName = getToken(tok);
+        if (! importName.startsWith("org.apache.ti.pageflow.annotations")) {
+            out.print("import ");
+            out.print(importName);
+        } else {
+            expectToken(tok, ";");
+        }
+    }
+
+    private void translateAnnotation(StreamTokenizer tok, PrintWriter out, String firstToken, String indent,
+                                     ArrayList tags)
+            throws IOException {
+        for (int i = 0; i < QUALIFIED_ANNOTATIONS.length; i++) {
+            String qualifiedAnnotation = QUALIFIED_ANNOTATIONS[i];
+            if (firstToken.startsWith(qualifiedAnnotation)) {
+                firstToken = '@' + firstToken.substring(qualifiedAnnotation.length());
+            }
+        }
+
+        String nextToken = getToken(tok);
+
+        if (! nextToken.equals("(")) {
+            tok.pushBack();
+            tags.add(firstToken);
+            return;
+        } else {
+            StringBuffer tag = new StringBuffer(firstToken);
+            int thisTagPos = tags.size();
+            tags.add("");
+
+            while (! (nextToken = getToken(tok)).equals(")")) {
+                if (nextToken.equals(",")) nextToken = getToken(tok);
+                String attrName = nextToken;
+                expectToken(tok, "=");
+                String value = getToken(tok);
+                int pos;
+
+                if (value.charAt(0) == '@') {
+                    if (attrName.equals("validationErrorForward")) {
+                        // Special case:
+                        //     validationErrorForward=@ti.forward(...)
+                        // goes to
+                        //     @ti.validationErrorForward(...)
+                        value = "@ti.validationErrorForward";
+                    }
+
+                    translateAnnotation(tok, out, value, indent, tags);
+                    value = null;
+                } else if (value.equals("{")) {
+                    StringBuffer stringArray = null;
+
+                    while (! (nextToken = getToken(tok)).equals("}")) {
+                        if (nextToken.equals(",")) nextToken = getToken(tok);
+
+                        if (nextToken.charAt(0) == '@') {
+                            translateAnnotation(tok, out, nextToken, indent, tags);
+                        } else {
+                            // We're expecting a string array element here.
+                            assert nextToken.length() > 1 && nextToken.charAt(0) == '"'
+                                    && nextToken.charAt(nextToken.length() - 1) == '"' : nextToken;
+                            if (stringArray == null) {
+                                stringArray = new StringBuffer("\"");
+                            } else {
+                                stringArray.append(',');
+                            }
+                            stringArray.append(nextToken.substring(1, nextToken.length() - 1));
+                        }
+                    }
+
+                    value = stringArray != null ? stringArray.append('"').toString() : null;
+                } else if (value.equals("true") || value.equals("false")) {
+                    value = '"' + value + '"';
+                } else if (value.endsWith(".class")) {
+                    value = '"' + value.substring(0, value.length() - 6) + '"';
+                } else if ((pos = value.indexOf("ti.NavigateTo.")) != -1) {
+                    value = '"' + value.substring(pos + 14) + '"';
+                } else if ((pos = value.indexOf("ti.validatorVersion.")) != -1) {
+                    value = '"' + value.substring(pos + 20) + '"';
+                } else if (isNumber(value)) {
+                    value = '"' + value + '"';
+                } else {
+                    assert value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"' : value;
+                    if (value.charAt(0) != '"') value = '"' + value;
+                    if (value.charAt(value.length() - 1) != '"') value += '"';
+                }
+
+                if (value != null) {
+                    tag.append(' ').append(attrName).append('=').append(value);
+                }
+            }
+
+            tags.set(thisTagPos, tag.toString());
+        }
+    }
+
+    private static boolean isNumber(String str) {
+        char firstChar = str.charAt(0);
+        if (firstChar != '-' && ! Character.isDigit(firstChar) && firstChar != '.') return false;
+
+        for (int i = 1; i < str.length(); ++i) {
+            char c = str.charAt(i);
+            if (! Character.isDigit(c) && c != '.') return false;
+        }
+
+        return true;
+    }
+
+    private String expectToken(StreamTokenizer tok, String expected)
+            throws IOException {
+        String token = getToken(tok);
+        assert token.equals(expected) : "expected \"" + expected + "\", got \"" + token + "\" (line " + tok.lineno() + ')';
+        return token;
+    }
+
+    private String getToken(StreamTokenizer tok)
+            throws IOException {
+        return getToken(tok, false, "");
+    }
+
+    private String getToken(StreamTokenizer tok, boolean includeSpace, String prepend)
+            throws IOException {
+        tok.nextToken();
+        assert tok.ttype != StreamTokenizer.TT_EOF : "unexpected eof";
+        String retVal;
+
+        switch (tok.ttype) {
+            case StreamTokenizer.TT_WORD:
+                retVal = prepend + tok.sval;
+                break;
+
+            case StreamTokenizer.TT_NUMBER:
+                assert false : tok.nval;   // parseNumbers() was set to false on the tokenizer.
+                retVal = new Double(tok.nval).toString();
+                break;
+
+            default:
+                char c = (char) tok.ttype;
+                if (Character.isWhitespace(c) && ! includeSpace) return getToken(tok);
+                retVal = prepend + Character.toString(c);
+        }
+
+        // If quotes are imbalanced, keep reading tokens until they're balanced.
+        return count(retVal, '"') % 2 != 0 ? getToken(tok, true, retVal) : retVal;
+    }
+
+    private static int count(String s, char c) {
+        int count = 0;
+        char lastChar = '\0';
+
+        for (int i = 0; i < s.length(); ++i) {
+            if (lastChar != '\\' && s.charAt(i) == c) ++count;
+            lastChar = c;
+        }
+
+        return count;
+    }
+
+    private static StreamTokenizer getJavaTokenizer(Reader reader) {
+        StreamTokenizer tok = new StreamTokenizer(reader);
+        tok.resetSyntax();
+        tok.eolIsSignificant(true);
+        tok.lowerCaseMode(false);
+        tok.wordChars('A', 'Z');
+        tok.wordChars('a', 'z');
+        tok.wordChars('_', '_');
+        tok.wordChars('@', '@');
+        tok.wordChars('[', '[');
+        tok.wordChars(']', ']');
+        tok.wordChars('.', '.');
+        tok.wordChars('"', '"');
+        tok.wordChars('\'', '\'');
+        tok.wordChars('-', '-');
+        tok.wordChars('0', '9');
+        tok.wordChars(':', ':');
+        tok.wordChars('$', '$');
+        tok.wordChars('/', '/');
+        tok.wordChars('*', '*');
+        tok.wordChars('\\', '\\');
+        tok.wordChars('?', '?');
+        return tok;
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDocletTask.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDocletTask.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDocletTask.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDocletTask.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.tools;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+public class AnnotationsToXDocletTask
+        extends Copy {
+
+    protected void doFileOperations() {
+        try {
+            AnnotationsToXDoclet atx = new AnnotationsToXDoclet();
+
+            for (Iterator i = fileCopyMap.entrySet().iterator(); i.hasNext();) {
+                Map.Entry entry = (Map.Entry) i.next();
+                String[] values = (String[]) entry.getValue();
+                assert values.length == 1 : values.length;
+                atx.translate(new File((String) entry.getKey()), new File(values[0]));
+            }
+        }
+        catch (IOException e) {
+            throw new BuildException(e);
+        }
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/SourceCopy.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/SourceCopy.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/SourceCopy.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/SourceCopy.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,120 @@
+package org.apache.ti.compiler.xdoclet.internal.tools;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Copy;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+
+/**
+ * Extend the default ant copy task to do some verification on java and pageflow source files.
+ */
+public class SourceCopy extends Copy {
+
+    protected static final String PACKAGE = "package";
+
+    /**
+     * Override doFileOperations to verify things that a source file's
+     * package name is the same as directory name.
+     * <p/>
+     * Note: we are not checking that anything named .jpf extends PageFlowController because
+     * that would require more advanced source parsing; the netui doclet task handles this by
+     * making sure that if we find a class that extends PageFlowController, there is a corresponding
+     * jpf file.
+     */
+    protected void doFileOperations() {
+        if (fileCopyMap.size() > 0) {
+            log("Verifying " + fileCopyMap.size()
+                    + " source file" + (fileCopyMap.size() == 1 ? "" : "s")
+                    + " before copy");
+
+
+            Enumeration e = fileCopyMap.keys();
+            while (e.hasMoreElements()) {
+                String fromFile = (String) e.nextElement();
+
+                if (!fromFile.endsWith(".java") && !fromFile.endsWith(".jpf") &&
+                        !fromFile.endsWith(".app"))
+                    continue;
+
+                try {
+                    File sourceFile = new File(fromFile);
+                    if (sourceFile.exists() && sourceFile.isFile()) {
+                        String packageName = getPackage(sourceFile);
+                        if (packageName != null && packageName.length() > 0) {
+                            String path = sourceFile.getParentFile().getPath();
+                            path = path.replace(File.separatorChar, '.');
+                            if (!path.endsWith(packageName)) {
+                                throw new BuildException("File " + fromFile + " failed verification because its package (" +
+                                        packageName + ") differs from its directory location. This will cause errors with the pageflow compiler.");
+                            }
+                        }
+                    }
+                }
+                catch (Exception ioe) {
+                    String msg = "Failed to verify " + fromFile
+                            + " due to " + ioe.getMessage();
+                    throw new BuildException(msg, ioe, getLocation());
+                }
+            }
+        }
+
+        super.doFileOperations();
+    }
+
+    /**
+     * Get the package name of a java source file. This just does some really basic parsing to find
+     * the first line that starts with "package", and then returns the rest of that line before the
+     * first semicolon. It won't catch any possible way that a package could be specified (after a comment,
+     * with line breaks, etc) but it's a good-faith effort to determine the package name. If no package
+     * name is found, the file will be skipped during the verification process.
+     *
+     * @param sourceFile
+     * @return
+     * @throws IOException
+     */
+    protected String getPackage(File sourceFile)
+            throws IOException {
+        BufferedReader in = null;
+        String packageName = null;
+        String encoding = getEncoding();
+
+        try {
+            if (encoding == null) {
+                in = new BufferedReader(new FileReader(sourceFile));
+            } else {
+                in = new BufferedReader(new InputStreamReader(
+                        new FileInputStream(sourceFile),
+                        encoding));
+            }
+
+            String line = in.readLine();
+            while (line != null) {
+                if (line.length() != 0) {
+                    line = line.trim();
+                    if (line.startsWith(PACKAGE)) {
+                        int semi = line.indexOf(";");
+                        if (semi != -1) {
+                            packageName = line.substring(PACKAGE.length() + 1, semi);
+                            packageName = packageName.trim();
+                        }
+                        break;
+                    }
+                }
+                line = in.readLine();
+            }
+        }
+        finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+
+        return packageName;
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/DelegatingImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/DelegatingImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/DelegatingImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/DelegatingImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl;
+
+public class DelegatingImpl {
+
+    private Object _delegate;
+
+    protected DelegatingImpl(Object delegate) {
+        assert delegate != null;
+        _delegate = delegate;
+    }
+
+    public boolean equals(Object o) {
+        if (o == null) return false;
+        if (o == this) return true;
+        if (! (o instanceof DelegatingImpl)) return false;
+        return _delegate.equals(((DelegatingImpl) o)._delegate);
+    }
+
+    public int hashCode() {
+        return _delegate.hashCode();
+    }
+
+    public String toString() {
+        return _delegate.toString();
+    }
+
+    protected Object getDelegate() {
+        return _delegate;
+    }
+
+    protected void setDelegate(Object delegate) {
+        _delegate = delegate;
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/WrapperFactory.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/WrapperFactory.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/WrapperFactory.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/WrapperFactory.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.*;
+import org.apache.ti.compiler.internal.typesystem.type.ArrayType;
+import org.apache.ti.compiler.internal.typesystem.type.ClassType;
+import org.apache.ti.compiler.internal.typesystem.type.DeclaredType;
+import org.apache.ti.compiler.internal.typesystem.type.InterfaceType;
+import org.apache.ti.compiler.internal.typesystem.type.PrimitiveType;
+import org.apache.ti.compiler.internal.typesystem.type.TypeInstance;
+import org.apache.ti.compiler.internal.typesystem.type.VoidType;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.ClassDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.ConstructorDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.FieldDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.InterfaceDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.MethodDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.PackageDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration.ParameterDeclarationImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.type.ArrayTypeImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.type.ClassTypeImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.type.InterfaceTypeImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.type.PrimitiveTypeImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.type.VoidTypeImpl;
+import xjavadoc.*;
+
+import java.util.HashSet;
+
+public class WrapperFactory {
+
+    private static final WrapperFactory INSTANCE = new WrapperFactory();
+    private static final HashSet PRIMITIVE_TYPES = new HashSet();
+
+    static {
+        PRIMITIVE_TYPES.add("boolean");
+        PRIMITIVE_TYPES.add("byte");
+        PRIMITIVE_TYPES.add("short");
+        PRIMITIVE_TYPES.add("int");
+        PRIMITIVE_TYPES.add("long");
+        PRIMITIVE_TYPES.add("char");
+        PRIMITIVE_TYPES.add("float");
+        PRIMITIVE_TYPES.add("double");
+    }
+
+    private WrapperFactory() {
+    }
+
+    public static WrapperFactory get() {
+        return INSTANCE;
+    }
+
+    public TypeInstance getTypeInstance(Type delegate) {
+        if (delegate == null) return null;
+
+        if (delegate.getDimension() > 0) {
+            return getArrayType(delegate);
+        } else {
+            return getTypeInstance(delegate.getType());
+        }
+    }
+
+    public TypeInstance getTypeInstance(XClass delegate, int dimension) {
+        if (delegate == null) return null;
+
+        if (dimension > 0) {
+            return getArrayType(new SynthesizedXJavaDocArrayType(delegate, dimension));
+        } else {
+            return getTypeInstance(delegate);
+        }
+    }
+
+    private static class SynthesizedXJavaDocArrayType
+            implements Type {
+
+        private XClass _baseType;
+        private int _dimension;
+
+        public SynthesizedXJavaDocArrayType(XClass type, int dimension) {
+            _baseType = type;
+            _dimension = dimension;
+        }
+
+        public int getDimension() {
+            return _dimension;
+        }
+
+        public String getDimensionAsString() {
+            StringBuffer buf = new StringBuffer();
+            for (int i = 0; i < _dimension; ++i) {
+                buf.append("[]");
+            }
+            return buf.toString();
+        }
+
+        public XClass getType() {
+            return _baseType;
+        }
+    }
+
+    public TypeInstance getTypeInstance(XClass delegate) {
+        if (delegate == null) return null;
+
+        String name = delegate.getName();
+
+        if (name.equals("void")) {
+            return getVoidType(delegate);
+        } else if (PRIMITIVE_TYPES.contains(name)) {
+            return getPrimitiveType(delegate);
+        } else {
+            return getDeclaredType(delegate);
+        }
+    }
+
+    public ArrayType getArrayType(Type delegate) {
+        return new ArrayTypeImpl(delegate);
+    }
+
+    public VoidType getVoidType(XClass delegate) {
+        if (delegate == null) return null;
+        return new VoidTypeImpl(delegate);
+    }
+
+    public PrimitiveType getPrimitiveType(XClass delegate) {
+        if (delegate == null) return null;
+        return new PrimitiveTypeImpl(delegate);
+    }
+
+    public DeclaredType getDeclaredType(XClass delegate) {
+        if (delegate == null) return null;
+        return isInterface(delegate) ? (DeclaredType) getInterfaceType(delegate) : getClassType(delegate);
+    }
+
+    private static boolean isInterface(XClass xClass) {
+        // There's a bug where some returned XClass objects won't think they're interfaces, even when they are.
+        // In these cases, the word "interface" appears in the list of Modifiers.
+        if (xClass.isInterface()) return true;
+        return xClass.getModifiers().indexOf("interface") != -1;
+    }
+
+    public ClassType getClassType(XClass delegate) {
+        if (delegate == null) return null;
+        return new ClassTypeImpl(delegate);
+    }
+
+    public InterfaceType getInterfaceType(XClass delegate) {
+        if (delegate == null) return null;
+        return new InterfaceTypeImpl(delegate);
+    }
+
+    public Declaration getDeclaration(XProgramElement delegate) {
+        if (delegate == null) return null;
+
+        if (delegate instanceof XMember) {
+            return getMemberDeclaration((XMember) delegate);
+        } else {
+            assert delegate instanceof XType : delegate.getClass().getName();
+            return getTypeDeclaration((XType) delegate);
+        }
+    }
+
+    public MemberDeclaration getMemberDeclaration(XMember delegate) {
+        if (delegate == null) return null;
+
+        else if (delegate instanceof XExecutableMember) {
+            return getExecutableDeclaration((XExecutableMember) delegate);
+        } else {
+            assert delegate instanceof XField : delegate.getClass().getName();
+            return getFieldDeclaration((XField) delegate);
+        }
+    }
+
+    public TypeDeclaration getTypeDeclaration(XType delegate) {
+        if (delegate == null) return null;
+        assert delegate instanceof XClass : delegate.getClass().getName();
+        XClass xclass = (XClass) delegate;
+        return isInterface(xclass) ? (TypeDeclaration) getInterfaceDeclaration(xclass) : getClassDeclaration(xclass);
+    }
+
+    public ClassDeclaration getClassDeclaration(XClass delegate) {
+        if (delegate == null) return null;
+
+        String qualifiedName = delegate.getQualifiedName();
+        //ClassDeclaration decl = ( ClassDeclaration ) _classDeclarations.get( qualifiedName );
+//        if ( decl != null ) return decl;
+
+        return new ClassDeclarationImpl(delegate);
+//        _classDeclarations.put( qualifiedName, decl );
+//        return decl;
+    }
+
+    public InterfaceDeclaration getInterfaceDeclaration(XClass delegate) {
+        if (delegate == null) return null;
+        return new InterfaceDeclarationImpl(delegate);
+    }
+
+    public ExecutableDeclaration getExecutableDeclaration(XExecutableMember delegate) {
+        if (delegate == null) return null;
+
+        if (delegate instanceof XMethod) {
+            return getMethodDeclaration((XMethod) delegate);
+        }
+
+        assert delegate instanceof XConstructor : delegate.getClass().getName();
+        return getConstructorDeclaration((XConstructor) delegate);
+    }
+
+    public ParameterDeclaration getParameterDeclaration(XParameter delegate) {
+        if (delegate == null) return null;
+        return new ParameterDeclarationImpl(delegate);
+    }
+
+    public PackageDeclaration getPackageDeclaration(XPackage delegate) {
+        if (delegate == null) return null;
+        return new PackageDeclarationImpl(delegate);
+    }
+
+    public ConstructorDeclaration getConstructorDeclaration(XConstructor delegate) {
+        if (delegate == null) return null;
+        return new ConstructorDeclarationImpl(delegate);
+    }
+
+    public MethodDeclaration getMethodDeclaration(XMethod delegate) {
+        if (delegate == null) return null;
+        return new MethodDeclarationImpl(delegate);
+    }
+
+    public FieldDeclaration getFieldDeclaration(XField delegate) {
+        if (delegate == null) return null;
+        return new FieldDeclarationImpl(delegate);
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInstanceImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInstanceImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInstanceImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInstanceImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.CompilerUtils;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationInstance;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeElementDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.MemberDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.TypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.type.AnnotationType;
+import org.apache.ti.compiler.internal.typesystem.util.SourcePosition;
+import org.apache.ti.compiler.xdoclet.XDocletCompilerUtils;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.DelegatingImpl;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.WrapperFactory;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.env.SourcePositionImpl;
+import xjavadoc.XMember;
+import xjavadoc.XProgramElement;
+import xjavadoc.XTag;
+import xjavadoc.XType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AnnotationInstanceImpl
+        extends DelegatingImpl
+        implements AnnotationInstance {
+
+    private AnnotationType _type;
+    private SourcePosition _sourcePosition;
+    private XProgramElement _containingElement;
+
+    // Map<AnnotationTypeElementDeclaration, AnnotationValue> getElementValues();
+    private HashMap _elementValues;
+
+    public AnnotationInstanceImpl(XTag tag, XProgramElement element, AnnotationType type, HashMap elementValues) {
+        super(tag);
+        _sourcePosition = SourcePositionImpl.get(tag, element);
+        _type = type;
+        _elementValues = elementValues;
+        assert element != null;
+        _containingElement = element;
+    }
+
+    public AnnotationType getAnnotationType() {
+        return _type;
+    }
+
+    public SourcePosition getPosition() {
+        return _sourcePosition;
+    }
+
+    public void addElementValue(String memberName, boolean memberIsArray, Object value, SourcePosition sourcePosition) {
+        AnnotationTypeElementDeclaration elementDecl = _type.getAnnotationTypeDeclaration().getMember(memberName);
+
+        if (elementDecl == null) {
+            XDocletCompilerUtils.addError(getPosition(), "error.no-such-member",
+                    new String[]{memberName, _type.getAnnotationTypeDeclaration().getQualifiedName()});
+        } else if (memberIsArray) {
+            AnnotationValueImpl av = (AnnotationValueImpl) _elementValues.get(elementDecl);
+            List list;
+
+            if (av == null) {
+                list = new ArrayList();
+                av = new AnnotationValueImpl(list, sourcePosition, elementDecl);
+                _elementValues.put(elementDecl, av);
+            } else {
+                list = (List) av.getValue();
+            }
+
+            list.add(new AnnotationValueImpl(value, sourcePosition, null));
+        } else {
+            _elementValues.put(elementDecl, new AnnotationValueImpl(value, sourcePosition, elementDecl));
+        }
+    }
+
+    // Map<AnnotationTypeElementDeclaration, AnnotationValue> getElementValues();
+    public Map getElementValues() {
+        return _elementValues;
+    }
+
+    public boolean equals(Object o) {
+        if (o == null) return false;
+        if (o == this) return true;
+        if (! (o instanceof AnnotationInstanceImpl)) return false;
+        assert false : "didn't finish equals()";
+        return false;
+    }
+
+    public String toString() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public XTag getDelegateXTag() {
+        return (XTag) super.getDelegate();
+    }
+
+    public TypeDeclaration getContainingType() {
+        if (_containingElement instanceof XType) {
+            return WrapperFactory.get().getTypeDeclaration((XType) _containingElement);
+        }
+        assert _containingElement instanceof XMember : _containingElement.getClass().getName();
+        MemberDeclaration member = WrapperFactory.get().getMemberDeclaration((XMember) _containingElement);
+        return CompilerUtils.getOuterClass(member);
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInterfaceParser.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInterfaceParser.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInterfaceParser.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationInterfaceParser.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,331 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.JpfLanguageConstants;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeElementDeclaration;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+public class AnnotationInterfaceParser implements JpfLanguageConstants {
+
+    private HashMap _memberArrayAnnotations = new HashMap();
+    private HashMap _memberAnnotations = new HashMap();
+    private HashSet _memberOrTopLevelAnnotations = new HashSet();
+    private String _annotationInterfacePrefix;
+
+
+    /**
+     * Map of String intermediate-name (e.g., "ti.action") to AnnotationTypeDeclaration
+     */
+    private HashMap _annotations = new HashMap();
+    private AnnotationTypeDeclaration[] _allAnnotations;
+
+    public AnnotationInterfaceParser(String annotationInterfacePrefix) {
+        _annotationInterfacePrefix = annotationInterfacePrefix;
+        parseAnnotations();
+        _allAnnotations = (AnnotationTypeDeclaration[])
+                _annotations.values().toArray(new AnnotationTypeDeclaration[ _annotations.size() ]);
+    }
+
+    public void addMemberAnnotation(String tagName, String parentAttribute) {
+        _memberAnnotations.put(_annotationInterfacePrefix + tagName, parentAttribute);
+    }
+
+    public void addMemberArrayAnnotation(String tagName, String parentAttribute) {
+        _memberArrayAnnotations.put(_annotationInterfacePrefix + tagName, parentAttribute);
+    }
+
+    public void addMemberOrTopLevelAnnotation(String tagName) {
+        _memberOrTopLevelAnnotations.add(_annotationInterfacePrefix + tagName);
+    }
+
+    public AnnotationTypeDeclaration[] getAllAnnotations() {
+        return _allAnnotations;
+    }
+
+    public AnnotationTypeDeclaration getAnnotationTypeDecl(String tagName) {
+        return (AnnotationTypeDeclaration) _annotations.get(tagName);
+    }
+
+    AnnotationTypeDeclarationImpl getAnnotationTypeDeclImpl(String tagName) {
+        return (AnnotationTypeDeclarationImpl) _annotations.get(tagName);
+    }
+
+    void addAnnotation(String tagName, AnnotationTypeDeclarationImpl annotation) {
+        _annotations.put(_annotationInterfacePrefix + tagName, annotation);
+    }
+
+    /**
+     * Get the name of the parent annotation member for the given tag.
+     */
+    public String getParentMemberName(String tagName) {
+        return (String) _memberAnnotations.get(tagName);
+    }
+
+    /**
+     * Get the name of the parent annotation array member for the given tag.
+     */
+    public String getParentMemberArrayName(String tagName) {
+        return (String) _memberArrayAnnotations.get(tagName);
+    }
+
+    public boolean isMemberOrTopLevelAnnotation(String tagName) {
+        return _memberOrTopLevelAnnotations.contains(tagName);
+    }
+
+    private static StreamTokenizer getJavaTokenizer(Reader reader) {
+        StreamTokenizer tok = new StreamTokenizer(reader);
+        tok.eolIsSignificant(false);
+        tok.lowerCaseMode(false);
+        tok.parseNumbers();
+        tok.slashSlashComments(true);
+        tok.slashStarComments(true);
+        tok.wordChars('_', '_');
+        tok.wordChars('@', '@');
+        tok.wordChars('[', '[');
+        tok.wordChars(']', ']');
+        tok.wordChars('.', '.');
+        tok.wordChars('"', '"');
+        tok.wordChars('-', '-');
+        return tok;
+    }
+
+    private void parseAnnotations() {
+        String annotationsSource = ANNOTATIONS_CLASSNAME.replace('.', '/') + ".java";
+        InputStream in = DeclarationImpl.class.getClassLoader().getResourceAsStream(annotationsSource);
+        assert in != null : "annotations source not found: " + annotationsSource;
+        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+
+        try {
+            HashMap enums = new HashMap();  // String enumTypeName -> HashSet values
+            StreamTokenizer tok = getJavaTokenizer(reader);
+
+
+            String interfaceQualifier = null;
+            String packageName = null;
+
+            while (tok.nextToken() != StreamTokenizer.TT_EOF) {
+                switch (tok.ttype) {
+                    case StreamTokenizer.TT_WORD:
+                        String str = tok.sval;
+
+                        if (packageName == null && str.equals("package")) {
+                            packageName = assertWord(tok);
+                        } else if (str.equals("public")) {
+                            str = assertWord(tok);
+
+                            if (str.equals("interface")) {
+                                interfaceQualifier = assertWord(tok) + '.';
+                                assertChar(tok, '{');
+                            } else if (str.equals("@interface")) {
+                                AnnotationTypeDeclarationImpl ann =
+                                        readAnnotation(tok, interfaceQualifier, packageName, enums);
+                                _annotations.put(ann.getIntermediateName(), ann);
+                            } else if (str.equals("enum")) {
+                                readEnum(tok, enums);
+                            }
+                        } else if (str.charAt(0) == '@') {
+                            if (tok.nextToken() == '(') {
+                                ignoreAnnotation(tok);
+                            } else {
+                                tok.pushBack();
+                            }
+                        }
+                        break;
+
+                    case StreamTokenizer.TT_NUMBER:
+                        break;
+
+                    default:
+                        char c = (char) tok.ttype;
+                        if (c == '}') {
+                            assert interfaceQualifier != null;
+                            interfaceQualifier = null;
+                        }
+                }
+            }
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+            assert false : e;
+        }
+        finally {
+            try {
+                reader.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+                assert false : e;
+            }
+        }
+    }
+
+    private static String assertWord(StreamTokenizer tok)
+            throws IOException {
+        tok.nextToken();
+        assert tok.ttype == StreamTokenizer.TT_WORD : tok.ttype;
+        return tok.sval;
+    }
+
+    private static void assertChar(StreamTokenizer tok, char c)
+            throws IOException {
+        tok.nextToken();
+        assert tok.ttype == c : tok.ttype;
+    }
+
+    private static AnnotationTypeDeclarationImpl readAnnotation(StreamTokenizer tok, String interfaceQualifier,
+                                                                String packageName, HashMap enums)
+            throws IOException {
+        String annotationName = assertWord(tok);
+        ArrayList memberDecls = new ArrayList();
+        assertChar(tok, '{');
+
+        while (tok.nextToken() == StreamTokenizer.TT_WORD) {
+            String memberType = tok.sval;
+            HashSet enumVals = (HashSet) enums.get(memberType);
+
+            tok.nextToken();
+            if (tok.ttype == '<') // ignore generics
+            {
+                while (tok.nextToken() != '>') {
+                    assert tok.ttype != StreamTokenizer.TT_EOF;
+                    assert tok.ttype != ';';
+                }
+                tok.nextToken();
+            }
+            assert tok.ttype == StreamTokenizer.TT_WORD;
+            String memberName = tok.sval;
+            assertChar(tok, '(');
+            assertChar(tok, ')');
+
+            Object defaultVal = null;
+
+            if (tok.nextToken() == StreamTokenizer.TT_WORD) {
+                assert tok.sval.equals("default");
+
+                tok.nextToken();
+                if (tok.ttype == '{') {
+                    assertChar(tok, '}');
+                    defaultVal = new ArrayList();
+                } else {
+                    assert tok.ttype == StreamTokenizer.TT_WORD || tok.ttype == StreamTokenizer.TT_NUMBER : tok.ttype;
+
+                    if (tok.ttype == StreamTokenizer.TT_NUMBER) {
+                        defaultVal = getNumericDefaultVal(memberType, tok.nval);
+                    } else {
+                        String defaultString = tok.sval;
+
+                        if (defaultString.charAt(0) == '@') {
+                            // It's a default value that is an annotation.  We ignore these for now.
+                            ignoreAnnotation(tok);
+                        } else {
+                            if (memberType.equals("String")) {
+                                assert defaultString.charAt(0) == '"' : defaultString;
+                                int len = defaultString.length();
+                                assert len > 1 && defaultString.charAt(len - 1) == '"' : defaultString;
+                                defaultVal = defaultString.substring(0, len - 1);
+                            } else if (memberType.equals("boolean")) {
+                                defaultVal = Boolean.valueOf(defaultString);
+                            } else if (memberType.equals("Class")) {
+                                assert defaultString.endsWith(".class");
+                                defaultVal = defaultString.substring(0, defaultString.indexOf(".class"));
+                            } else {
+                                defaultVal = readDefaultEnumVal(defaultString, memberType, enumVals);
+                            }
+                        }
+                    }
+                }
+
+                tok.nextToken();
+            }
+
+            assert tok.ttype == ';';
+
+            if (enumVals != null) memberType = "String";
+            memberDecls.add(new AnnotationTypeElementDeclarationImpl(memberName, memberType, defaultVal, enumVals));
+        }
+
+        assert tok.ttype == '}';
+
+        AnnotationTypeElementDeclaration[] memberArray = (AnnotationTypeElementDeclaration[])
+                memberDecls.toArray(new AnnotationTypeElementDeclaration[ memberDecls.size() ]);
+        return new AnnotationTypeDeclarationImpl(annotationName, interfaceQualifier, packageName, memberArray);
+    }
+
+    private static String readDefaultEnumVal(String defaultString, String memberType, HashSet enumVals) {
+        int dot = defaultString.indexOf('.');
+        assert dot != -1 : "expected an enum value: " + defaultString;
+        String type = defaultString.substring(0, dot);
+        assert type.equals(memberType) : "expected enum " + memberType + ", got " + type;
+        assert enumVals != null : "no enum " + memberType
+                + " defined; currently, enum must be defined before its use";
+        String defaultVal = defaultString.substring(dot + 1);
+        assert enumVals.contains(defaultVal) :
+                "invalid enum field " + defaultVal + " on enum " + type;
+        return defaultVal;
+    }
+
+    private static Object getNumericDefaultVal(String expectedType, double defaultNumber) {
+        if (expectedType.equals("int")) {
+            return new Integer((int) defaultNumber);
+        } else if (expectedType.equals("long")) {
+            return new Long((long) defaultNumber);
+        } else if (expectedType.equals("float")) {
+            return new Float((float) defaultNumber);
+        } else if (expectedType.equals("double")) {
+            return new Double(defaultNumber);
+        }
+
+        assert false : "type " + expectedType + " cannot accept value " + defaultNumber;
+        return null;
+    }
+
+    private static void ignoreAnnotation(StreamTokenizer tok)
+            throws IOException {
+        while (tok.nextToken() != ')') {
+            assert tok.ttype != StreamTokenizer.TT_EOF;
+            assert tok.ttype != ';';
+        }
+    }
+
+    private static void readEnum(StreamTokenizer tok, HashMap enums)
+            throws IOException {
+        String enumName = assertWord(tok);
+
+        assertChar(tok, '{');
+        HashSet fieldNames = new HashSet();
+
+        while (true) {
+            fieldNames.add(assertWord(tok));
+            tok.nextToken();
+            if (tok.ttype == '}') break;
+            assert tok.ttype == ',' : tok.ttype;    // for now, we only do very simple enums.
+        }
+
+        enums.put(enumName, fieldNames);
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeDeclarationImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeDeclarationImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeDeclarationImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.JpfLanguageConstants;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationInstance;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeElementDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.FieldDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.MethodDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.Modifier;
+import org.apache.ti.compiler.internal.typesystem.declaration.PackageDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.TypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.type.InterfaceType;
+import org.apache.ti.compiler.internal.typesystem.util.SourcePosition;
+
+import java.util.HashMap;
+import java.util.Set;
+
+public class AnnotationTypeDeclarationImpl
+        implements AnnotationTypeDeclaration, JpfLanguageConstants {
+
+    private String _annotationName;
+    private String _packageName;
+    private String _intermediateName;
+    private AnnotationTypeElementDeclaration[] _members;
+    private HashMap _membersByName;
+
+    public AnnotationTypeDeclarationImpl(String annotationName, String interfaceQualifier,
+                                         String packageName, AnnotationTypeElementDeclaration[] members) {
+        _annotationName = annotationName;
+        _intermediateName = interfaceQualifier != null ? interfaceQualifier + annotationName : annotationName;
+        _packageName = packageName;
+        _members = members;
+
+        _membersByName = new HashMap();
+        for (int i = 0; i < members.length; i++) {
+            AnnotationTypeElementDeclaration member = members[i];
+            _membersByName.put(member.getSimpleName(), member);
+        }
+    }
+
+    public AnnotationTypeDeclarationImpl(AnnotationTypeDeclarationImpl source, String annotationName,
+                                         String interfaceQualifier) {
+        _annotationName = annotationName;
+        _intermediateName = interfaceQualifier != null ? interfaceQualifier + annotationName : annotationName;
+        _packageName = source._packageName;
+        _members = source._members;
+        _membersByName = source._membersByName;
+    }
+
+    public AnnotationTypeElementDeclaration[] getAnnotationMembers() {
+        return _members;
+    }
+
+    public AnnotationTypeElementDeclaration getMember(String name) {
+        return (AnnotationTypeElementDeclaration) _membersByName.get(name);
+    }
+
+    public PackageDeclaration getPackage() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public String getQualifiedName() {
+        return _packageName + '.' + _intermediateName;
+    }
+
+    public InterfaceType[] getSuperinterfaces() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public FieldDeclaration[] getFields() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public MethodDeclaration[] getMethods() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public TypeDeclaration[] getNestedTypes() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public TypeDeclaration getDeclaringType() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public String getDocComment() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public AnnotationInstance[] getAnnotationInstances() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public Set getModifiers() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public String getSimpleName() {
+        return _annotationName;
+    }
+
+    public String getIntermediateName() {
+        return _intermediateName;
+    }
+
+    public SourcePosition getPosition() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public boolean hasModifier(Modifier modifier) {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public boolean equals(Object o) {
+        if (o == null) return false;
+        if (o == this) return true;
+        if (! (o instanceof AnnotationTypeDeclarationImpl)) return false;
+        return getQualifiedName().equals(((AnnotationTypeDeclarationImpl) o).getQualifiedName());
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeElementDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeElementDeclarationImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeElementDeclarationImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationTypeElementDeclarationImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationInstance;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeElementDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationValue;
+import org.apache.ti.compiler.internal.typesystem.declaration.Modifier;
+import org.apache.ti.compiler.internal.typesystem.declaration.ParameterDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.TypeDeclaration;
+import org.apache.ti.compiler.internal.typesystem.type.TypeInstance;
+import org.apache.ti.compiler.internal.typesystem.util.SourcePosition;
+import org.apache.ti.compiler.xdoclet.XDocletCompilerUtils;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class AnnotationTypeElementDeclarationImpl
+        implements AnnotationTypeElementDeclaration {
+
+    private String _name;
+    private TypeInstance _type;
+    private String _typeName;
+    private AnnotationValue _defaultVal;
+    private HashSet _validValues;
+
+    public AnnotationTypeElementDeclarationImpl(String name, String typeName, Object defaultVal, HashSet validValues) {
+        _name = name;
+        _typeName = typeName;
+        if (defaultVal != null) _defaultVal = new AnnotationValueImpl(defaultVal, null, this);
+        _validValues = validValues;
+    }
+
+    public boolean isValidValue(Object value) {
+        return _validValues == null || _validValues.contains(value);
+    }
+
+    public Set getValidValues() {
+        return _validValues;
+    }
+
+    public AnnotationValue getDefaultValue() {
+        return _defaultVal;
+    }
+
+    public TypeInstance getReturnType() {
+        if (_typeName != null) {
+            _type = XDocletCompilerUtils.resolveType(_typeName, false, null);
+            assert _type != null : "unresolvable type " + _typeName;
+            _typeName = null;
+        }
+
+        return _type;
+    }
+
+    public ParameterDeclaration[] getParameters() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public TypeDeclaration getDeclaringType() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public AnnotationInstance[] getAnnotationInstances() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public Set getModifiers() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public String getSimpleName() {
+        return _name;
+    }
+
+    public SourcePosition getPosition() {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+
+    public boolean hasModifier(Modifier modifier) {
+        assert false : "NYI";
+        throw new UnsupportedOperationException("NYI");
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationValueImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationValueImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationValueImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/AnnotationValueImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationTypeElementDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.AnnotationValue;
+import org.apache.ti.compiler.internal.typesystem.util.SourcePosition;
+import org.apache.ti.compiler.xdoclet.XDocletCompilerUtils;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.DelegatingImpl;
+
+import java.util.Iterator;
+
+public class AnnotationValueImpl
+        extends DelegatingImpl
+        implements AnnotationValue {
+
+    private SourcePosition _position;
+
+    public AnnotationValueImpl(Object value, SourcePosition position, AnnotationTypeElementDeclaration decl) {
+        super(value);
+        _position = position;
+
+        if (decl != null) {
+            assert decl instanceof AnnotationTypeElementDeclarationImpl : decl.getClass().getName();
+            AnnotationTypeElementDeclarationImpl declImpl = (AnnotationTypeElementDeclarationImpl) decl;
+
+            if (! declImpl.isValidValue(value)) {
+                StringBuffer values = new StringBuffer();
+                for (Iterator i = declImpl.getValidValues().iterator(); i.hasNext();) {
+                    String validValue = (String) i.next();
+                    values.append(' ').append(validValue);
+                }
+
+                XDocletCompilerUtils.addError(position, "error.invalid-enum-value",
+                        new String[]{value.toString(), decl.getSimpleName(), values.toString()});
+            }
+        }
+    }
+
+    public Object getValue() {
+        return getDelegate();
+    }
+
+    public SourcePosition getPosition() {
+        return _position;
+    }
+
+    public boolean equals(Object o) {
+        return this == o;
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ClassDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ClassDeclarationImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ClassDeclarationImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ClassDeclarationImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.ClassDeclaration;
+import org.apache.ti.compiler.internal.typesystem.declaration.ConstructorDeclaration;
+import org.apache.ti.compiler.internal.typesystem.type.ClassType;
+import org.apache.ti.compiler.xdoclet.internal.typesystem.impl.WrapperFactory;
+import xjavadoc.XClass;
+import xjavadoc.XConstructor;
+import xjavadoc.XDoc;
+import xjavadoc.XJavaDoc;
+import xjavadoc.XPackage;
+import xjavadoc.XProgramElement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class ClassDeclarationImpl
+        extends TypeDeclarationImpl
+        implements ClassDeclaration {
+
+    private ConstructorDeclaration[] _constructors;
+
+    public ClassDeclarationImpl(XClass delegate) {
+        super(delegate);
+    }
+
+    public ClassType getSuperclass() {
+        return WrapperFactory.get().getClassType(getDelegateXClass().getSuperclass());
+    }
+
+    public ConstructorDeclaration[] getConstructors() {
+        if (_constructors == null) {
+            Collection delegateCollection = getDelegateXClass().getConstructors();
+            ConstructorDeclaration[] array = new ConstructorDeclaration[delegateCollection.size()];
+            int j = 0;
+            for (Iterator i = delegateCollection.iterator(); i.hasNext();) {
+                array[j++] = WrapperFactory.get().getConstructorDeclaration((XConstructor) i.next());
+            }
+
+            if (array.length == 0) {
+                XConstructor ctor = new DefaultConstructor(getDelegateXClass());
+                ConstructorDeclaration decl = WrapperFactory.get().getConstructorDeclaration(ctor);
+                _constructors = new ConstructorDeclaration[]{decl};
+            } else {
+                _constructors = array;
+            }
+        }
+
+        return _constructors;
+    }
+
+    protected XClass getDelegateXClass() {
+        return (XClass) super.getDelegate();
+    }
+
+    private static class DefaultConstructor
+            implements XConstructor {
+
+        private XClass _containingClass;
+
+        public DefaultConstructor(XClass containingClass) {
+            _containingClass = containingClass;
+        }
+
+        public boolean isNative() {
+            return false;
+        }
+
+        public boolean isSynchronized() {
+            return false;
+        }
+
+        public List getParameters() {
+            return Collections.EMPTY_LIST;
+        }
+
+        public List getThrownExceptions() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public boolean throwsException(String s) {
+            return false;
+        }
+
+        public boolean isConstructor() {
+            return true;
+        }
+
+        public String getSignature(boolean b) {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public String getNameWithSignature(boolean b) {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public String getParameterTypes() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public XClass getContainingClass() {
+            return _containingClass;
+        }
+
+        public XPackage getContainingPackage() {
+            return _containingClass.getContainingPackage();
+        }
+
+        public boolean isFinal() {
+            return false;
+        }
+
+        public boolean isPackagePrivate() {
+            return false;
+        }
+
+        public boolean isPrivate() {
+            return false;
+        }
+
+        public boolean isProtected() {
+            return false;
+        }
+
+        public boolean isAbstract() {
+            return false;
+        }
+
+        public boolean isPublic() {
+            return true;
+        }
+
+        public boolean isStatic() {
+            return false;
+        }
+
+        public String getModifiers() {
+            return "public";
+        }
+
+        public int getModifierSpecifier() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public XDoc getDoc() {
+            return null;
+        }
+
+        public XProgramElement getSuperElement() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public List getSuperInterfaceElements() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public XJavaDoc getXJavaDoc() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public void updateDoc() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public int compareTo(Object o) {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+
+        public String getName() {
+            assert false : "NYI";
+            throw new UnsupportedOperationException("NYI");
+        }
+    }
+}

Added: struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ConstructorDeclarationImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ConstructorDeclarationImpl.java?rev=280879&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ConstructorDeclarationImpl.java (added)
+++ struts/sandbox/trunk/ti/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/typesystem/impl/declaration/ConstructorDeclarationImpl.java Wed Sep 14 09:20:05 2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.ti.compiler.xdoclet.internal.typesystem.impl.declaration;
+
+import org.apache.ti.compiler.internal.typesystem.declaration.ConstructorDeclaration;
+import xjavadoc.XConstructor;
+
+public class ConstructorDeclarationImpl
+        extends ExecutableDeclarationImpl
+        implements ConstructorDeclaration {
+
+    public ConstructorDeclarationImpl(XConstructor delegate) {
+        super(delegate);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org