From efe74a329c147e280978dc6710c7690c76f3cd28 Mon Sep 17 00:00:00 2001 From: Renaud Pawlak Date: Tue, 19 Jan 2016 18:46:57 +0100 Subject: [PATCH] allow object types to be inner classes --- .../typescript/Java2TypeScriptTranslator.java | 4 +++ .../test/transpiler/StructuralTests.java | 8 +++++ .../java/source/structural/ObjectTypes.java | 32 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/test/java/source/structural/ObjectTypes.java diff --git a/src/main/java/org/jsweet/transpiler/typescript/Java2TypeScriptTranslator.java b/src/main/java/org/jsweet/transpiler/typescript/Java2TypeScriptTranslator.java index a72436e7..350bb21b 100644 --- a/src/main/java/org/jsweet/transpiler/typescript/Java2TypeScriptTranslator.java +++ b/src/main/java/org/jsweet/transpiler/typescript/Java2TypeScriptTranslator.java @@ -483,6 +483,10 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter { @Override public void visitClassDef(JCClassDecl classdecl) { + if(Util.hasAnnotationType(classdecl.type.tsym, JSweetConfig.ANNOTATION_OBJECT_TYPE)) { + // object types are ignored + return; + } if (getParent() instanceof JCClassDecl) { report(classdecl, JSweetProblem.INNER_CLASS, classdecl.name); return; diff --git a/src/test/java/org/jsweet/test/transpiler/StructuralTests.java b/src/test/java/org/jsweet/test/transpiler/StructuralTests.java index b9ffcd59..58a95266 100644 --- a/src/test/java/org/jsweet/test/transpiler/StructuralTests.java +++ b/src/test/java/org/jsweet/test/transpiler/StructuralTests.java @@ -40,6 +40,7 @@ import source.structural.NameClashes; import source.structural.NameClashesWithMethodInvocations; import source.structural.NoInstanceofForInterfaces; import source.structural.NoWildcardsInImports; +import source.structural.ObjectTypes; import source.structural.TwoClassesInSameFile; import source.structural.WrongConstructsInEnums; import source.structural.WrongConstructsInInterfaces; @@ -239,4 +240,11 @@ public class StructuralTests extends AbstractTest { } , getSourceFile(source.structural.wrongglobals.Globals.class)); } + @Test + public void testObjectTypes() { + transpile(logHandler -> { + logHandler.assertReportedProblems(); + } , getSourceFile(ObjectTypes.class)); + } + } diff --git a/src/test/java/source/structural/ObjectTypes.java b/src/test/java/source/structural/ObjectTypes.java new file mode 100644 index 00000000..81afe553 --- /dev/null +++ b/src/test/java/source/structural/ObjectTypes.java @@ -0,0 +1,32 @@ +/* + * JSweet - http://www.jsweet.org + * Copyright (C) 2015 CINCHEO SAS + * + * 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. + */ +package source.structural; + +import jsweet.lang.ObjectType; + +public class ObjectTypes { + @ObjectType + public static class Indexed { + int index; + } + public static void m(Indexed param) {} + + public static void main(String[] args) { + m(new Indexed() {{ index = 2; }}); + } + +} \ No newline at end of file