-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
- Loading branch information
Showing
11 changed files
with
412 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDtoDTSGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.typescript.dto; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
import com.google.common.io.Resources; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.eclipse.che.plugin.typescript.dto.model.DtoModel; | ||
import org.eclipse.che.plugin.typescript.dto.model.DtoNamespace; | ||
import org.stringtemplate.v4.ST; | ||
|
||
/** Write all DTOs found in classpath into a specific '.d.ts' file */ | ||
public class TypeScriptDtoDTSGenerator extends TypeScriptDtoGenerator { | ||
|
||
/** Name of the template */ | ||
public static final String TEMPLATE_NAME = | ||
"/" | ||
.concat(TypeScriptDtoDTSGenerator.class.getPackage().getName().replace(".", "/")) | ||
.concat("/typescript.d.ts.template"); | ||
|
||
/** String template instance used */ | ||
private ST st; | ||
|
||
private Map<String, DtoNamespace> dtoNamespaces = new HashMap<>(); | ||
|
||
public static void main(String[] args) { | ||
TypeScriptDtoGenerator.main(args); | ||
} | ||
|
||
@Override | ||
protected void analyze(Class<?> dto) { | ||
// for each dto class, store some data about it | ||
DtoModel model = new DtoModel(dto); | ||
String namespace = model.getDTSPackageName(); | ||
if (!dtoNamespaces.containsKey(namespace)) { | ||
dtoNamespaces.put(namespace, new DtoNamespace(namespace)); | ||
} | ||
|
||
dtoNamespaces.get(namespace).addModel(model); | ||
} | ||
|
||
@Override | ||
public String execute() { | ||
init(); | ||
ST template = getTemplate(); | ||
template.add("dtoNamespaces", this.dtoNamespaces.values()); | ||
String output = template.render(); | ||
return output; | ||
} | ||
|
||
/** | ||
* Get the template for typescript | ||
* | ||
* @return the String Template | ||
*/ | ||
protected ST getTemplate() { | ||
if (st == null) { | ||
URL url = Resources.getResource(TypeScriptDtoGenerator.class, TEMPLATE_NAME); | ||
try { | ||
st = new ST(Resources.toString(url, UTF_8)); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("Unable to read template", e); | ||
} | ||
} | ||
return st; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/model/DtoNamespace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.typescript.dto.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** Class for storing all Dto TS namespace interfaces */ | ||
public class DtoNamespace { | ||
|
||
private final String namespace; | ||
private List<DtoModel> childs = new ArrayList<>(); | ||
|
||
public DtoNamespace(String namespace) { | ||
this.namespace = namespace; | ||
} | ||
|
||
/** @return the namespace name */ | ||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
/** @return all interfaces that placed in this namespace */ | ||
public List<DtoModel> getDtoInterfaces() { | ||
return childs; | ||
} | ||
|
||
/** | ||
* Add Dto in this namespace | ||
* | ||
* @param model the dto | ||
*/ | ||
public void addModel(DtoModel model) { | ||
childs.add(model); | ||
} | ||
} |
Oops, something went wrong.