[jboss-svn-commits] JBoss Common SVN: r4254 - in jboss-i18ntool/trunk: src/main and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Apr 9 17:51:32 EDT 2010
Author: david.lloyd at jboss.com
Date: 2010-04-09 17:51:32 -0400 (Fri, 09 Apr 2010)
New Revision: 4254
Added:
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/AutoMap.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nClass.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nMethod.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/LogMessageMethod.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/MessageLoggerClass.java
jboss-i18ntool/trunk/src/main/resources/
jboss-i18ntool/trunk/src/main/resources/META-INF/
jboss-i18ntool/trunk/src/main/resources/META-INF/services/
jboss-i18ntool/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor
Modified:
jboss-i18ntool/trunk/pom.xml
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nProcessor.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/LogMessage.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/Message.java
jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/MessageLogger.java
Log:
Start roughing in the basic impl
Modified: jboss-i18ntool/trunk/pom.xml
===================================================================
--- jboss-i18ntool/trunk/pom.xml 2010-04-09 18:58:49 UTC (rev 4253)
+++ jboss-i18ntool/trunk/pom.xml 2010-04-09 21:51:32 UTC (rev 4254)
@@ -11,6 +11,21 @@
<name>JBoss I18n Tool</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <compilerArgument>-proc:none</compilerArgument>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<dependency>
<groupId>com.sun</groupId>
Added: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/AutoMap.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/AutoMap.java (rev 0)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/AutoMap.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.i18ntool;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+final class AutoMap<K, V> extends AbstractMap<K, List<V>> implements Map<K, List<V>> {
+ private final Map<K, List<V>> map = new HashMap<K, List<V>>();
+ private final Class<K> keyClass;
+
+ public AutoMap(final Class<K> keyClass) {
+ this.keyClass = keyClass;
+ }
+
+ public List<V> get(final K key) {
+ List<V> list = map.get(key);
+ if (list == null) {
+ list = new ArrayList<V>();
+ map.put(keyClass.cast(key), list);
+ }
+ return list;
+ }
+
+ public Set<K> keySet() {
+ return map.keySet();
+ }
+
+ public Set<Entry<K, List<V>>> entrySet() {
+ return Collections.unmodifiableSet(map.entrySet());
+ }
+}
Added: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nClass.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nClass.java (rev 0)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nClass.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.i18ntool;
+
+/**
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+class I18nClass {
+
+}
Added: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nMethod.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nMethod.java (rev 0)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nMethod.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.i18ntool;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.i18ntool.annotation.Message;
+
+import javax.lang.model.element.ExecutableElement;
+
+/**
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+class I18nMethod {
+ private final String name;
+ private final List<ExecutableElement> elements = new ArrayList<ExecutableElement>();
+
+ private String message;
+ private int id;
+ private Message.Format format;
+ private String converterClass;
+
+ I18nMethod(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<ExecutableElement> getElements() {
+ return elements;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(final int id) {
+ this.id = id;
+ }
+
+ public Message.Format getFormat() {
+ return format;
+ }
+
+ public void setFormat(final Message.Format format) {
+ this.format = format;
+ }
+
+ public String getConverterClass() {
+ return converterClass;
+ }
+
+ public void setConverterClass(final String converterClass) {
+ this.converterClass = converterClass;
+ }
+}
Modified: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nProcessor.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nProcessor.java 2010-04-09 18:58:49 UTC (rev 4253)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/I18nProcessor.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -30,8 +30,6 @@
import org.jboss.i18ntool.annotation.Message;
import org.jboss.i18ntool.annotation.MessageBundle;
import org.jboss.i18ntool.annotation.MessageLogger;
-import org.jboss.i18ntool.annotation.Translation;
-import org.jboss.i18ntool.annotation.Translations;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Completion;
@@ -39,9 +37,13 @@
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
+import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
/**
* @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
@@ -50,23 +52,73 @@
public Set<String> getSupportedAnnotationTypes() {
return new HashSet<String>(Arrays.asList(
- LogMessage.class.getName(),
- Message.class.getName(),
MessageBundle.class.getName(),
- MessageLogger.class.getName(),
- Translation.class.getName(),
- Translations.class.getName()
+ MessageLogger.class.getName()
));
}
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
for (TypeElement element : annotations) {
final Name elementName = element.getQualifiedName();
- System.out.println("ELEMENT NAME = " + elementName);
+ final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(element);
+ if (elementName.contentEquals(MessageBundle.class.getName())) {
+ generateMessageBundle(elements, roundEnv);
+ } else if (elementName.contentEquals(MessageLogger.class.getName())) {
+ generateMessageLogger(elements, roundEnv);
+ }
}
return true;
}
+ private static String getBinaryName(TypeElement typeElement) {
+ if (typeElement.getNestingKind() == NestingKind.TOP_LEVEL) {
+ return typeElement.getQualifiedName().toString();
+ } else if (typeElement.getNestingKind() == NestingKind.MEMBER) {
+ final String enclosingName = getBinaryName((TypeElement) typeElement.getEnclosingElement());
+ if (enclosingName == null) return null;
+ return enclosingName + "$" + typeElement.getSimpleName().toString();
+ } else {
+ return null;
+ }
+ }
+
+ private void generateMessageLogger(final Set<? extends Element> elements, final RoundEnvironment roundEnv) {
+ for (final Element element : elements) {
+ if (element.getKind() != ElementKind.INTERFACE) {
+ System.err.println("Skipping non-interface '" + element.toString() + "'");
+ continue;
+ }
+ final TypeElement typeElement = (TypeElement) element;
+ final String typeName = getBinaryName(typeElement);
+ if (typeName == null) {
+ System.err.println("Skipping inner type '" + element.toString() + "'");
+ continue;
+ }
+ final MessageLogger topAnnotation = typeElement.getAnnotation(MessageLogger.class);
+ final String projectCode = topAnnotation.projectCode();
+ for (TypeMirror mirror : typeElement.getInterfaces()) {
+ DeclaredType declaredType = (DeclaredType) mirror;
+ TypeElement parent = (TypeElement) declaredType.asElement();
+
+ }
+ for (Element child : typeElement.getEnclosedElements()) {
+ if (!(child instanceof ExecutableElement)) {
+ continue;
+ }
+ final ExecutableElement executableElement = (ExecutableElement) child;
+ final LogMessage logMessageAnnotation = executableElement.getAnnotation(LogMessage.class);
+ final Message messageAnnotation = executableElement.getAnnotation(Message.class);
+
+ }
+ }
+ }
+
+ private void generateMessageBundle(final Set<? extends Element> elements, final RoundEnvironment roundEnv) {
+ for (Element element : elements) {
+ System.out.println("Message bundle: " + element);
+ }
+ }
+
public Iterable<? extends Completion> getCompletions(final Element element, final AnnotationMirror annotation, final ExecutableElement member, final String userText) {
return Collections.emptySet();
}
Added: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/LogMessageMethod.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/LogMessageMethod.java (rev 0)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/LogMessageMethod.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.i18ntool;
+
+/**
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+class LogMessageMethod extends I18nMethod {
+
+ LogMessageMethod() {
+ super(name);
+ }
+}
Added: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/MessageLoggerClass.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/MessageLoggerClass.java (rev 0)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/MessageLoggerClass.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.i18ntool;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+class MessageLoggerClass extends I18nClass {
+ private final List<I18nClass> parents;
+ private final Map<String, List<I18nMethod>> methods = new AutoMap<String, I18nMethod>(String.class);
+ private final boolean hasBasicLogger;
+
+ MessageLoggerClass(final List<I18nClass> parents, final boolean hasBasicLogger) {
+ this.parents = parents;
+ this.hasBasicLogger = hasBasicLogger;
+ }
+
+
+}
Modified: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/LogMessage.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/LogMessage.java 2010-04-09 18:58:49 UTC (rev 4253)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/LogMessage.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -26,7 +26,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jboss.logging.Logger;
/**
* A typed logger method. Indicates that this method will log the associated {@link Message} to the logger system, as
@@ -43,5 +42,14 @@
*
* @return the log level
*/
- Logger.Level level() default Logger.Level.INFO;
+ Level level() default Level.INFO;
+
+ enum Level {
+ TRACE,
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR,
+ FATAL
+ }
}
Modified: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/Message.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/Message.java 2010-04-09 18:58:49 UTC (rev 4253)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/Message.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -26,7 +26,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jboss.logging.ParameterConverter;
/**
* Assigns a message string to a resource method. The method arguments are used to supply the positional parameter
@@ -69,7 +68,8 @@
Format format() default Format.PRINTF;
/**
- * The converter to use. Any specified converter must implement {@link ParameterConverter}.
+ * The converter to use. Any specified converter must implement the {@code ParameterConverter} interface
+ * from JBoss Logging or JBoss I18n.
*
* @return the converter
*/
Modified: jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/MessageLogger.java
===================================================================
--- jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/MessageLogger.java 2010-04-09 18:58:49 UTC (rev 4253)
+++ jboss-i18ntool/trunk/src/main/java/org/jboss/i18ntool/annotation/MessageLogger.java 2010-04-09 21:51:32 UTC (rev 4254)
@@ -36,4 +36,11 @@
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface MessageLogger {
+
+ /**
+ * Get the project code for messages that have an associated code.
+ *
+ * @return the project code
+ */
+ String projectCode() default "";
}
Added: jboss-i18ntool/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor
===================================================================
--- jboss-i18ntool/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor (rev 0)
+++ jboss-i18ntool/trunk/src/main/resources/META-INF/services/javax.annotation.processing.Processor 2010-04-09 21:51:32 UTC (rev 4254)
@@ -0,0 +1 @@
+org.jboss.i18ntool.I18nProcessor
More information about the jboss-svn-commits
mailing list