branch feature/3880-java8-api-scan updated (f7de57a -> 9695d4b)
This is an automated email from the git hooks/post-receive script. New change to branch feature/3880-java8-api-scan in repository i18n. See http://git.nuiton.org/i18n.git from f7de57a refs #3880: Use java 8 API to scan code new 9695d4b refs #3880: Fix special case for non affected translation The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 9695d4bcfe24f10cace32e4260bf8a07017d47e0 Author: Eric Chatellier <chatellier@codelutin.com> Date: Fri Feb 19 16:37:39 2016 +0100 refs #3880: Fix special case for non affected translation Summary of changes: .../i18n/plugin/parser/impl/ParserGWTJavaMojo.java | 1 + .../i18n/plugin/parser/impl/ParserJavaMojo.java | 70 ++++++++-------------- .../plugin/parser/impl/JavaFileParserTest.java | 33 ++++++++++ 3 files changed, 58 insertions(+), 46 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3880-java8-api-scan in repository i18n. See http://git.nuiton.org/i18n.git commit 9695d4bcfe24f10cace32e4260bf8a07017d47e0 Author: Eric Chatellier <chatellier@codelutin.com> Date: Fri Feb 19 16:37:39 2016 +0100 refs #3880: Fix special case for non affected translation --- .../i18n/plugin/parser/impl/ParserGWTJavaMojo.java | 1 + .../i18n/plugin/parser/impl/ParserJavaMojo.java | 70 ++++++++-------------- .../plugin/parser/impl/JavaFileParserTest.java | 33 ++++++++++ 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java index 7b86245..f2faf0d 100644 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java @@ -234,6 +234,7 @@ public class ParserGWTJavaMojo extends AbstractI18nParserMojo { boolean match = false; TypeNameContext typeName = ctx.typeName(); + System.out.println("typeName " + typeName); String childText = typeName.getText(); if (annotationPrefix.contains(childText)) { // key is argument 1 of child 2 diff --git a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java index 9253d78..763a2df 100755 --- a/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java +++ b/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java @@ -51,6 +51,7 @@ import org.nuiton.i18n.plugin.parser.java.Java8Lexer; import org.nuiton.i18n.plugin.parser.java.Java8Parser; import org.nuiton.i18n.plugin.parser.java.Java8Parser.ArgumentListContext; import org.nuiton.i18n.plugin.parser.java.Java8Parser.ExpressionContext; +import org.nuiton.i18n.plugin.parser.java.Java8Parser.ExpressionStatementContext; import org.nuiton.i18n.plugin.parser.java.Java8Parser.LambdaBodyContext; import org.nuiton.i18n.plugin.parser.java.Java8Parser.LambdaExpressionContext; import org.nuiton.i18n.plugin.parser.java.Java8Parser.MethodInvocationContext; @@ -192,57 +193,39 @@ public class ParserJavaMojo extends AbstractI18nParserMojo { complexI18nMethodPrefix.add("I18n.l"); complexI18nMethodPrefix.add("l"); } + + @Override + public Void visitMethodInvocation_lfno_primary(MethodInvocation_lfno_primaryContext ctx) { - /*@Override - public Void visitExpression(Java8Parser.ExpressionContext ctx) { - - boolean match = false; - if (ctx.getChildCount() > 2 && ctx.getChild(2) instanceof Java8Parser.ExpressionContext) { - ParseTree child = ctx.getChild(0); - String childText = child.getText(); - if (simpleI18nMethodPrefix.contains(childText)) { - // key is argument 1 of child 2 - Java8Parser.ExpressionContext arguments = (Java8Parser.ExpressionContext) ctx.getChild(2); - String firstArgs = arguments.getChild(0).getText(); - if (firstArgs.matches("^\"[^\"]+\"$")) { - String key = firstArgs.substring(1).substring(0, firstArgs.length() - 2); - if (getLog().isDebugEnabled()) { - getLog().debug(file.getName() + " detected key = " + key); - } - ParserJavaMojo.JavaFileParser.this.registerKey(key); - } - match = true; - } else if (complexI18nMethodPrefix.contains(childText)) { - - // key is argument 2 of child 2 - Java8Parser.ExpressionContext arguments = (Java8Parser.ExpressionContext) ctx.getChild(2); - String firstArgs = arguments.getChild(2).getText(); - if (firstArgs.matches("^\"[^\"]+\"$")) { - String key = firstArgs.substring(1).substring(0, firstArgs.length() - 2); - if (getLog().isDebugEnabled()) { - getLog().debug(file.getName() + " detected key = " + key); - } - ParserJavaMojo.JavaFileParser.this.registerKey(key); - } - match = true; - } - } + ArgumentListContext list = ctx.argumentList(); + MethodNameContext mnc = ctx.methodName(); + TerminalNode tn = ctx.Identifier(); + TypeNameContext tnc = ctx.typeName(); + Void aVoid = null; - if (!match) { + if (!visitMethod(list, mnc, tn, tnc)) { // continue visit - aVoid = super.visitExpression(ctx); + aVoid = super.visitMethodInvocation_lfno_primary(ctx); } return aVoid; - }*/ + } @Override - public Void visitMethodInvocation_lfno_primary(MethodInvocation_lfno_primaryContext ctx) { - + public Void visitMethodInvocation(MethodInvocationContext ctx) { ArgumentListContext list = ctx.argumentList(); MethodNameContext mnc = ctx.methodName(); TerminalNode tn = ctx.Identifier(); TypeNameContext tnc = ctx.typeName(); - + + Void aVoid = null; + if (!visitMethod(list, mnc, tn, tnc)) { + // continue visit + aVoid = super.visitMethodInvocation(ctx); + } + return aVoid; + } + + protected boolean visitMethod(ArgumentListContext list, MethodNameContext mnc, TerminalNode tn, TypeNameContext tnc) { String methodName = mnc != null ? mnc.getText() : tnc.getText() + "." + tn.getText(); @@ -274,12 +257,7 @@ public class ParserJavaMojo extends AbstractI18nParserMojo { } } - Void aVoid = null; - if (!match) { - // continue visit - aVoid = super.visitMethodInvocation_lfno_primary(ctx); - } - return aVoid; + return match; } } } diff --git a/i18n-maven-plugin/src/test/java/org/nuiton/i18n/plugin/parser/impl/JavaFileParserTest.java b/i18n-maven-plugin/src/test/java/org/nuiton/i18n/plugin/parser/impl/JavaFileParserTest.java index f3e70f5..331e1ac 100644 --- a/i18n-maven-plugin/src/test/java/org/nuiton/i18n/plugin/parser/impl/JavaFileParserTest.java +++ b/i18n-maven-plugin/src/test/java/org/nuiton/i18n/plugin/parser/impl/JavaFileParserTest.java @@ -160,6 +160,39 @@ public class JavaFileParserTest { } /** + * This is a special case for non affectation on "l(Locale.FRENCH, \"javaGetter.key3\");". + * @throws IOException + */ + @Test + public void getKeys4() throws IOException { + + String classContent = "" + + "package org.nuiton.i18n.test;" + + + "import java.util.Locale;" + + + "import static org.nuiton.i18n.I18n.t;" + + "import static org.nuiton.i18n.I18n.n;" + + "import static org.nuiton.i18n.I18n.l;" + + + "public class MyBean {" + + + " protected String field1 = n(\"javaGetter.key1\");" + + + " protected String field2 = t(\"javaGetter.key2\");" + + + " public void method() {" + + " l(Locale.FRENCH, \"javaGetter.key3\");" + + " }" + + "}"; + + File file = new File(FileUtils.getTempDirectory(), "getKeys4"); + FileUtils.write(file, classContent); + + parseLine(file, new String[]{}, "javaGetter.key1", "javaGetter.key3", "javaGetter.key3"); + } + + /** * Test que la synthax java 8 est supportée. * @throws IOException */ -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm