Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TsIgnore prevents interface members from being present on subtypes #100

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void testTypesLinks() throws IOException {
public void testMethodsLinks() throws IOException {
testDocs("links.methods");
}

@Test
public void testIssue99() throws IOException {
testDocs("links.issue99");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Vertispan
*
* 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 com.vertispan.tsdefs.tests.tsdocs.doclet.links.issue99;

import jsinterop.annotations.JsType;

@JsType
public class JsTypeGrandChild extends NonJsTypeParent {

public String propertyFromA;

public String doSomethingFromA() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Vertispan
*
* 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 com.vertispan.tsdefs.tests.tsdocs.doclet.links.issue99;

import com.vertispan.tsdefs.annotations.TsIgnore;

@TsIgnore
public class NonJsTypeParent extends TsInterfaceParent {

public String propertyFromB;

public String doSomethingFromB() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright © 2024 Vertispan
*
* 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 com.vertispan.tsdefs.tests.tsdocs.doclet.links.issue99;

import com.vertispan.tsdefs.annotations.TsInterface;
import jsinterop.annotations.JsType;

@TsInterface
@JsType
public class TsInterfaceParent {
public String propertyFromC;

public String doSomethingFromC() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2023 Vertispan
* Copyright © 2024 Vertispan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,21 +89,26 @@ public void visit(TypeScriptModule.TsModuleBuilder moduleBuilder) {

private void processSuperClass(TsClass tsClass, TypeMirror superclass) {
TsElement superTsElement = TsElement.of(superclass, env);

if (superTsElement.isTsIgnored() || superTsElement.isTsInterface()) {
TsClass.TsClassBuilder superBuilder =
TsClass.builder(superTsElement.getName(), superTsElement.getNamespace());
superTsElement.element().getEnclosedElements().forEach(e -> visit(superBuilder, e));
TsClass superTsClass = superBuilder.build();
tsClass.mergeFunctions(superTsClass);
tsClass.mergeProperties(superTsClass);
} else {
superTsElement
.getJavaSuperClass()
.ifPresent(
typeMirror -> {
processSuperClass(tsClass, typeMirror);
});
mergeSuperClass(tsClass, superTsElement);
}

superTsElement
.getJavaSuperClass()
.ifPresent(
typeMirror -> {
processSuperClass(tsClass, typeMirror);
});
}

private void mergeSuperClass(TsClass tsClass, TsElement superTsElement) {
TsClass.TsClassBuilder superBuilder =
TsClass.builder(superTsElement.getName(), superTsElement.getNamespace());
superTsElement.element().getEnclosedElements().forEach(e -> visit(superBuilder, e));
TsClass superTsClass = superBuilder.build();
tsClass.mergeFunctions(superTsClass);
tsClass.mergeProperties(superTsClass);
}

private boolean isSameNameSpaceAsParent(TsElement e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Vertispan
*
* 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 com.vertispan.tsdefs.tests.inheritance;

import jsinterop.annotations.JsType;

@JsType
public class JsTypeGrandChildOfTsIgnoredParent extends NonJsTypeTsIgnoredParent {

public String propertyFromA;

public String doSomethingFromA() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2024 Vertispan
*
* 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 com.vertispan.tsdefs.tests.inheritance;

import com.vertispan.tsdefs.annotations.TsIgnore;

@TsIgnore
public class NonJsTypeTsIgnoredParent extends JsTypeGrandParent {

public String propertyFromB;

public String doSomethingFromB() {
return "";
}
}
7 changes: 7 additions & 0 deletions jsinterop-ts-defs-test/src/test/resources/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import JsInterfaceWithIgnoredMembers = com.vertispan.tsdefs.tests.tsignore.JsInt

import JsTypeGrandChild = com.vertispan.tsdefs.tests.inheritance.JsTypeGrandChild;
import JsTypeGrandChild2 = com.vertispan.tsdefs.tests.inheritance.JsTypeGrandChild2;
import JsTypeGrandChildOfTsIgnoredParent = com.vertispan.tsdefs.tests.inheritance.JsTypeGrandChildOfTsIgnoredParent;
import JsTypeWithPrivateAndIgnoredConstructors = com.vertispan.tsdefs.tests.constructors.JsTypeWithPrivateAndIgnoredConstructors;
// ---------- Properties tests -------------------------
const jsTypeWithProperties = new JsTypeWithProperties();
Expand Down Expand Up @@ -566,6 +567,12 @@ jsTypeGrandChild2.propertyFromB;
// @ts-expect-error
jsTypeGrandChild2.doSomethingFromB;

const jsTypeGrandChildOfTsIgnoredParent = new JsTypeGrandChildOfTsIgnoredParent();
jsTypeGrandChildOfTsIgnoredParent.propertyFromA;
jsTypeGrandChildOfTsIgnoredParent.doSomethingFromA();
jsTypeGrandChildOfTsIgnoredParent.propertyFromC;
jsTypeGrandChildOfTsIgnoredParent.doSomethingFromC();

// ------------------------ TsName ---------------------

class ImplementsJsInterfaceWithTsName implements JsInterfaceByTsName {
Expand Down
Loading