allow object types to be inner classes

This commit is contained in:
Renaud Pawlak 2016-01-19 18:46:57 +01:00
parent f83e8462cd
commit efe74a329c
3 changed files with 44 additions and 0 deletions

View File

@ -483,6 +483,10 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
@Override @Override
public void visitClassDef(JCClassDecl classdecl) { public void visitClassDef(JCClassDecl classdecl) {
if(Util.hasAnnotationType(classdecl.type.tsym, JSweetConfig.ANNOTATION_OBJECT_TYPE)) {
// object types are ignored
return;
}
if (getParent() instanceof JCClassDecl) { if (getParent() instanceof JCClassDecl) {
report(classdecl, JSweetProblem.INNER_CLASS, classdecl.name); report(classdecl, JSweetProblem.INNER_CLASS, classdecl.name);
return; return;

View File

@ -40,6 +40,7 @@ import source.structural.NameClashes;
import source.structural.NameClashesWithMethodInvocations; import source.structural.NameClashesWithMethodInvocations;
import source.structural.NoInstanceofForInterfaces; import source.structural.NoInstanceofForInterfaces;
import source.structural.NoWildcardsInImports; import source.structural.NoWildcardsInImports;
import source.structural.ObjectTypes;
import source.structural.TwoClassesInSameFile; import source.structural.TwoClassesInSameFile;
import source.structural.WrongConstructsInEnums; import source.structural.WrongConstructsInEnums;
import source.structural.WrongConstructsInInterfaces; import source.structural.WrongConstructsInInterfaces;
@ -239,4 +240,11 @@ public class StructuralTests extends AbstractTest {
} , getSourceFile(source.structural.wrongglobals.Globals.class)); } , getSourceFile(source.structural.wrongglobals.Globals.class));
} }
@Test
public void testObjectTypes() {
transpile(logHandler -> {
logHandler.assertReportedProblems();
} , getSourceFile(ObjectTypes.class));
}
} }

View File

@ -0,0 +1,32 @@
/*
* JSweet - http://www.jsweet.org
* Copyright (C) 2015 CINCHEO SAS <renaud.pawlak@cincheo.fr>
*
* 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; }});
}
}