Skip to content
Browse files

fix namespace declaration with extends

  • Loading branch information...
1 parent 047860f commit 0f6d0b4f226b52bb0ce22645f58c460f7b85345b @acraciun acraciun committed Aug 28, 2012
View
13 generator/src/main/java/org/stjs/generator/utils/ClassUtils.java
@@ -120,6 +120,18 @@ public static boolean isRootType(TypeWrapper type) {
return superClass == null || superClass.equals(TypeWrappers.wrap(Object.class));
}
+ /**
+ * @param type
+ * @return true if the given type is defined within another type
+ */
+ public static boolean isInnerType(TypeWrapper type) {
+ if (type == null || !(type instanceof ClassWrapper)) {
+ return false;
+ }
+ ClassWrapper classWrapper = (ClassWrapper) type;
+ return classWrapper.getDeclaringClass().isDefined();
+ }
+
public static boolean isSyntheticType(TypeWrapper clazz) {
if (clazz == null || !(clazz instanceof ClassWrapper)) {
return false;
@@ -321,4 +333,5 @@ private static boolean isAssignableFromUpperBounds(final Class<?> cls, final jav
public static String getPropertiesFileName(String className) {
return className.replace('.', '/') + ".stjs";
}
+
}
View
2 generator/src/main/java/org/stjs/generator/writer/JavascriptWriterVisitor.java
@@ -809,7 +809,7 @@ public void visit(ClassOrInterfaceDeclaration n, GenerationContext context) {
ClassWrapper type = (ClassWrapper) resolvedType(n);
String namespace = null;
- if (ClassUtils.isRootType(type)) {
+ if (!ClassUtils.isInnerType(type)) {
namespace = ClassUtils.getNamespace(type);
if (namespace != null) {
printer.printLn("stjs.ns(\"" + namespace + "\");");
View
8 generator/src/test/java/org/stjs/generator/writer/namespace/Namespace2a.java
@@ -0,0 +1,8 @@
+package org.stjs.generator.writer.namespace;
+
+import org.stjs.javascript.annotation.Namespace;
+
+@Namespace("a.b")
+public class Namespace2a extends Namespace1 {
+
+}
View
9 generator/src/test/java/org/stjs/generator/writer/namespace/NamespaceGeneratorTest.java
@@ -27,6 +27,12 @@ public void testExtends() {
}
@Test
+ public void testExtends2() {
+ assertCodeContains(Namespace2a.class, "stjs.extend(a.b.Namespace2a, a.b.Namespace1, [],");
+ assertCodeDoesNotContain(Namespace2a.class, "var a.b");
+ }
+
+ @Test
public void testConstructor() {
assertCodeContains(Namespace3.class, "var n = new a.b.Namespace3()");
}
@@ -53,8 +59,7 @@ public void testTypeDesc() {
@Test
public void testInlineConstruct() {
- assertCodeContains(Namespace8.class,
- "stjs.extend(function Namespace8$1(){a.b.Namespace8.apply(this, arguments);}, a.b.Namespace8, [], ");
+ assertCodeContains(Namespace8.class, "stjs.extend(function Namespace8$1(){a.b.Namespace8.apply(this, arguments);}, a.b.Namespace8, [], ");
}
@Test(expected = JavascriptGenerationException.class)

0 comments on commit 0f6d0b4

Please sign in to comment.
Something went wrong with that request. Please try again.