Skip to content

Commit 47b64c0

Browse files
author
mmews
committed
Merge remote-tracking branch 'origin/master' into GH-2571
2 parents b57c8d6 + 55f98a7 commit 47b64c0

37 files changed

+2594
-2437
lines changed

plugins/org.eclipse.n4js.transpiler.dts/.classpath

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="xtend-gen"/>
54
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
65
<attributes>
76
<attribute name="module" value="true"/>

plugins/org.eclipse.n4js.transpiler.dts/build.properties

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
source.. = src/,\
2-
xtend-gen/
1+
source.. = src/
32
output.. = bin/
43
bin.includes = META-INF/,\
54
.,\

plugins/org.eclipse.n4js.transpiler.dts/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ Contributors:
3434
<artifactId>maven-resources-plugin</artifactId>
3535
<version>${maven-resources-plugin.version}</version>
3636
</plugin>
37-
<plugin>
38-
<groupId>org.eclipse.xtend</groupId>
39-
<artifactId>xtend-maven-plugin</artifactId>
40-
</plugin>
41-
4237
</plugins>
4338
</build>
4439

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) 2021 NumberFour AG.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* NumberFour AG - Initial API and implementation
10+
*/
11+
package org.eclipse.n4js.transpiler.dts.transform;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
import org.eclipse.n4js.n4JS.N4ClassifierDeclaration;
17+
import org.eclipse.n4js.n4JS.TypeReferenceNode;
18+
import org.eclipse.n4js.transpiler.Transformation;
19+
import org.eclipse.n4js.transpiler.dts.utils.DtsUtils;
20+
import org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef;
21+
import org.eclipse.n4js.ts.typeRefs.TypeRef;
22+
import org.eclipse.n4js.ts.types.Type;
23+
24+
/**
25+
* Remove from extends/implements clauses of classifiers all references to types that are not .d.ts exportable.
26+
*/
27+
public class CutOffTransformation extends Transformation {
28+
29+
@Override
30+
public void assertPreConditions() {
31+
// empty
32+
}
33+
34+
@Override
35+
public void assertPostConditions() {
36+
// empty
37+
}
38+
39+
@Override
40+
public void analyze() {
41+
// ignore
42+
}
43+
44+
@Override
45+
public void transform() {
46+
for (N4ClassifierDeclaration decl : collectNodes(getState().im, N4ClassifierDeclaration.class, false)) {
47+
cutOffReferencesInExtendsImplements(decl);
48+
}
49+
}
50+
51+
private void cutOffReferencesInExtendsImplements(N4ClassifierDeclaration classifierDecl) {
52+
List<TypeReferenceNode<ParameterizedTypeRef>> toBeRemoved = new ArrayList<>();
53+
for (TypeReferenceNode<ParameterizedTypeRef> superTypeRefNode : classifierDecl.getSuperClassifierRefs()) {
54+
TypeRef superTypeRef = getState().info.getOriginalProcessedTypeRef(superTypeRefNode);
55+
Type superDeclType = superTypeRef == null ? null : superTypeRef.getDeclaredType();
56+
if (!DtsUtils.isDtsExportableReference(superDeclType, getState())) {
57+
toBeRemoved.add(superTypeRefNode);
58+
}
59+
}
60+
for (TypeReferenceNode<ParameterizedTypeRef> tbr : toBeRemoved) {
61+
remove(tbr);
62+
}
63+
}
64+
}

plugins/org.eclipse.n4js.transpiler.dts/src/org/eclipse/n4js/transpiler/dts/transform/CutOffTransformation.xtend

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Copyright (c) 2021 NumberFour AG.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* NumberFour AG - Initial API and implementation
10+
*/
11+
package org.eclipse.n4js.transpiler.dts.transform;
12+
13+
import static org.eclipse.n4js.transpiler.TranspilerBuilderBlocks._StringLiteral;
14+
15+
import org.eclipse.n4js.n4JS.ExportDeclaration;
16+
import org.eclipse.n4js.n4JS.Expression;
17+
import org.eclipse.n4js.n4JS.Literal;
18+
import org.eclipse.n4js.n4JS.N4EnumDeclaration;
19+
import org.eclipse.n4js.n4JS.N4EnumLiteral;
20+
import org.eclipse.n4js.n4JS.ScriptElement;
21+
import org.eclipse.n4js.n4JS.StringLiteral;
22+
import org.eclipse.n4js.transpiler.Transformation;
23+
import org.eclipse.n4js.transpiler.im.SymbolTableEntry;
24+
import org.eclipse.n4js.transpiler.im.SymbolTableEntryOriginal;
25+
import org.eclipse.n4js.transpiler.utils.TranspilerUtils;
26+
import org.eclipse.n4js.ts.types.TEnumLiteral;
27+
import org.eclipse.n4js.utils.N4JSLanguageUtils;
28+
import org.eclipse.n4js.utils.N4JSLanguageUtils.EnumKind;
29+
30+
/**
31+
* Transformer to add initializers to string-/number-based enums
32+
*/
33+
public class EnumAddMissingInitializersTransformation extends Transformation {
34+
35+
@Override
36+
public void assertPreConditions() {
37+
// empty
38+
}
39+
40+
@Override
41+
public void assertPostConditions() {
42+
// empty
43+
}
44+
45+
@Override
46+
public void analyze() {
47+
// ignore
48+
}
49+
50+
@Override
51+
public void transform() {
52+
makeInferredTypesExplicit();
53+
}
54+
55+
private void makeInferredTypesExplicit() {
56+
for (ScriptElement rootElemRaw : getState().im.getScriptElements()) {
57+
ScriptElement rootElem = (rootElemRaw instanceof ExportDeclaration)
58+
? ((ExportDeclaration) rootElemRaw).getExportedElement()
59+
: rootElemRaw;
60+
61+
if (rootElem instanceof N4EnumDeclaration) {
62+
N4EnumDeclaration enumDecl = (N4EnumDeclaration) rootElem;
63+
EnumKind enumKind = N4JSLanguageUtils.getEnumKind(enumDecl);
64+
boolean isLiteralBased = enumKind != EnumKind.Normal;
65+
boolean isPartiallyInitialized = false;
66+
for (N4EnumLiteral literal : enumDecl.getLiterals()) {
67+
Expression valueExpr = literal.getValueExpression();
68+
isPartiallyInitialized = isPartiallyInitialized
69+
|| (valueExpr != null && valueExpr instanceof StringLiteral);
70+
71+
if (valueExpr == null) {
72+
if (isPartiallyInitialized) {
73+
literal.setValueExpression(_StringLiteral(literal.getName()));
74+
} else if (isLiteralBased) {
75+
SymbolTableEntry propSTE = getState().steCache.mapNamedElement_2_STE.get(literal);
76+
TEnumLiteral tLiteral = (propSTE instanceof SymbolTableEntryOriginal)
77+
? (TEnumLiteral) ((SymbolTableEntryOriginal) propSTE).getOriginalTarget()
78+
: null;
79+
Literal newLit = TranspilerUtils.enumLiteralToNumericOrStringLiteral(tLiteral);
80+
literal.setValueExpression(newLit);
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}
87+
88+
}

plugins/org.eclipse.n4js.transpiler.dts/src/org/eclipse/n4js/transpiler/dts/transform/EnumAddMissingInitializersTransformation.xtend

-71
This file was deleted.

0 commit comments

Comments
 (0)