Skip to content

Commit

Permalink
Merge pull request #37 from GoodforGod/dev
Browse files Browse the repository at this point in the history
[1.1.1]
  • Loading branch information
GoodforGod authored Jul 12, 2021
2 parents 566c908 + 9342cee commit d172b99
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 99 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,6 @@ This issue is due to library used in plugin unable to create Java Enums.
if found. Standard Java naming convention expected from *getters* to be found.
- Annotations Class Params are not supported. Thus, most of annotation parameters like String, Boolean, etc. are supported, but Class or other complex parameters not supported.

## Version History

**1.0.2** - Compatibility with 2020.3, AVRO Jackson options fixed.

**1.0.1** - Fixed AVRO namespace mapping, fixed path scanning on OSX, fixed java.time.* package serialization in ISO8601 format when mapping to Json.

**1.0.0** - Initial project with support for Json, Json array, Json Schema, Avro Schema, GraphQL formats.

## Licence

This project licensed under the Apache 2.0 - see the [LICENSE](LICENSE) file for details.
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ plugins {
id 'java-library'
id 'maven-publish'

id 'org.jetbrains.intellij' version '0.7.3'
id 'org.jetbrains.intellij' version '1.1.2'
id 'org.sonarqube' version '3.1.1'
id 'com.diffplug.spotless' version '5.11.0'
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
}

group = groupId
Expand All @@ -21,8 +20,8 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

intellij {
plugins 'java'
version '2021.1'
plugins = ['java']
version = '2021.1'
downloadSources = false
}

Expand All @@ -31,7 +30,7 @@ runIde {
}

patchPluginXml {
sinceBuild '202'
sinceBuild = '202'
}

spotless {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
groupId=com.github.goodforgod
artifactId=dummymapper
artifactVersion=1.1.0
artifactVersion=1.1.1


##### GRADLE #####
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public ClassBuildException(String message) {
}

public ClassBuildException(Throwable cause) {
super("Error building Java Class", cause);
super(cause.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public class GraphQLMapper implements IMapper<GraphQLConfig> {
final SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions()
.includeDirectives(false)
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeSchemaDefintion(true);
.includeExtendedScalarTypes(false)
.includeSchemaDefintion(false);

return new SchemaPrinter(options).print(schema);
final String result = new SchemaPrinter(options).print(schema);
return result.replace("type Query", "type " + marker.getSourceSimpleName());
}
}
49 changes: 46 additions & 3 deletions src/main/java/io/goodforgod/dummymapper/marker/Marker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.goodforgod.dummymapper.marker;

import io.dummymaker.util.CollectionUtils;
import io.dummymaker.util.StringUtils;
import io.goodforgod.dummymapper.model.AnnotationMarker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -37,7 +38,9 @@ public Marker(@NotNull String root, @NotNull String source) {

@SuppressWarnings("unchecked")
public <T extends Marker> T setAnnotations(@Nullable Collection<AnnotationMarker> annotations) {
this.annotations = CollectionUtils.isEmpty(annotations) ? Collections.emptySet() : new HashSet<>(annotations);
this.annotations = CollectionUtils.isEmpty(annotations)
? Collections.emptySet()
: new HashSet<>(annotations);
return (T) this;
}

Expand All @@ -51,12 +54,52 @@ public <T extends Marker> T addAnnotation(@NotNull AnnotationMarker annotation)

public abstract boolean isEmpty();

public @NotNull String getRoot() {
return root;
}

public @NotNull String getRootPackage() {
if (StringUtils.isEmpty(root))
return "";

final String cleanRoot = getCleanRoot();
return cleanRoot.substring(0, cleanRoot.lastIndexOf('.'));
}

public @NotNull String getRootSimpleName() {
if (StringUtils.isEmpty(source))
return "";

final String cleanRoot = getCleanRoot();
return cleanRoot.substring(cleanRoot.lastIndexOf('.') + 1);
}

public @NotNull String getSource() {
return source;
}

public @NotNull String getRoot() {
return root;
public @NotNull String getSourcePackage() {
if (StringUtils.isEmpty(source))
return "";

final String cleanSource = getCleanSource();
return cleanSource.substring(0, cleanSource.lastIndexOf('.'));
}

public @NotNull String getSourceSimpleName() {
if (StringUtils.isEmpty(source))
return "";

final String cleanSource = getCleanSource();
return cleanSource.substring(cleanSource.lastIndexOf('.') + 1);
}

private String getCleanRoot() {
return root.replaceFirst("\\.java$", "");
}

private String getCleanSource() {
return source.replaceFirst("\\.java$", "");
}

public @NotNull Collection<AnnotationMarker> getAnnotations() {
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/io/goodforgod/dummymapper/marker/RawMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ public RawMarker(@NotNull String root,
: new ConcurrentHashMap<>(structure);
}

public String getSourcePackage() {
return getSource().substring(0, getSource().lastIndexOf('.'));
}

public String getRootPackage() {
return getRoot().substring(0, getRoot().lastIndexOf('.'));
}

@Override
public boolean isEmpty() {
return structure.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,41 @@
@SuppressWarnings("UnstableApiUsage")
public class PsiJavaFileScanner implements IFileScanner {

private final Map<String, Map<String, Marker>> scanned = new HashMap<>();
private static class Target {

private final String root;
private final String source;

public Target(String root, String source) {
this.root = root;
this.source = source;
}

public String getRoot() {
return root;
}

public String getSource() {
return source;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Target target = (Target) o;
return Objects.equals(root, target.root) && Objects.equals(source, target.source);
}

@Override
public int hashCode() {
return Objects.hash(root, source);
}
}

private final Map<Target, Map<String, Marker>> scanned = new HashMap<>();

public @NotNull RawMarker scan(@Nullable PsiFile file) {
if (!(file instanceof PsiJavaFile)) {
Expand Down Expand Up @@ -85,8 +119,11 @@ public class PsiJavaFileScanner implements IFileScanner {
private Map<String, Marker> scanJavaClass(@NotNull PsiClass rootClass,
@NotNull PsiClass targetClass,
@NotNull Map<String, PsiType> parentTypes) {
if (isTypeSimple(getFileFullName(targetClass)) || isTypeEnum(getFileFullName(targetClass)))
return Collections.emptyMap();

final String root = getFileFullName(rootClass);
final String source = getFileFullName(targetClass);
final String root = getFileFullName(targetClass);

final PsiClass superTarget = targetClass.getSuperClass();
final Map<String, Marker> structure = new LinkedHashMap<>();
Expand All @@ -99,7 +136,7 @@ private Map<String, Marker> scanJavaClass(@NotNull PsiClass rootClass,

final EnumMarker marker = new EnumMarker(root, source, enumValues);
structure.put(targetClass.getName(), marker);
scanned.put(source, structure);
scanned.put(new Target(root, source), structure);
return structure;
}

Expand Down Expand Up @@ -138,7 +175,7 @@ private Map<String, Marker> scanJavaClass(@NotNull PsiClass rootClass,
// return cached;
// }

scanned.put(source, structure);
scanned.put(new Target(root, source), structure);
final PsiField[] fields = targetClass.getFields();

for (PsiField field : fields) {
Expand Down Expand Up @@ -170,7 +207,7 @@ private Map<String, Marker> scanJavaClass(@NotNull PsiClass rootClass,
}

} else if (!isTypeForbidden(type)) { // COMPLEX CLASS SCAN IF NOT FORBIDDEN ONE
final Optional<Marker> marker = scanJavaFileClass(root, type);
final Optional<Marker> marker = scanJavaFileClass(targetClass, type);
if (marker.isPresent()) {
structure.put(fieldName, marker.get());
} else {
Expand Down Expand Up @@ -217,34 +254,37 @@ private Optional<Marker> scanJavaInnerClass(@NotNull PsiClass rootClass,
.flatMap(psiClass -> Arrays.stream(psiClass.getAllInnerClasses())
.filter(c -> type.getCanonicalText().equals(c.getQualifiedName()))
.findFirst()
.map(c -> {
final String fullName = getFileFullName(c);
final Map<String, Marker> cached = scanned.get(fullName);
.map(sourceClass -> {
final String source = getFileFullName(sourceClass);
final Map<String, Marker> cached = scanned.get(new Target(root, source));
final Map<String, Marker> structure = (cached == null)
? scanJavaClass(c, c, new HashMap<>())
? scanJavaClass(sourceClass, sourceClass, new HashMap<>())
: cached;

final Marker marker = structure.get(type.getPresentableText());
if (marker instanceof EnumMarker) { // ENUM
return new EnumMarker(root, marker.getSource(), ((EnumMarker) marker).getValues());
} else {
return new RawMarker(root, fullName, structure);
return new RawMarker(root, source, structure);
}
}));
}

private Optional<Marker> scanJavaFileClass(@NotNull String root,
private Optional<Marker> scanJavaFileClass(@NotNull PsiClass rootClass,
@NotNull PsiType type) {
return getPsiJavaClass(type).map(psiClass -> {
final String fullName = getClassFullName(psiClass);
final Map<String, Marker> cached = scanned.get(fullName);
final Map<String, Marker> structure = (cached == null) ? scanJavaClass(psiClass) : cached;
final String root = getFileFullName(rootClass);
final String source = getFileFullName(psiClass);
final Map<String, Marker> cached = scanned.get(new Target(source, source));
final Map<String, Marker> structure = (cached == null)
? scanJavaClass(psiClass)
: cached;

final Marker marker = structure.get(type.getPresentableText());
if (marker instanceof EnumMarker) { // ENUM
return new EnumMarker(root, marker.getSource(), ((EnumMarker) marker).getValues());
} else {
return new RawMarker(root, fullName, structure);
return new RawMarker(root, source, structure);
}
});
}
Expand Down Expand Up @@ -315,7 +355,7 @@ private Marker getMarkerFromPsiType(@NotNull String source,
@NotNull PsiType type) {
return Optional.ofNullable(getSimpleTypeByName(type))
.map(t -> ((Marker) new TypedMarker(source, rootName, t)))
.orElseGet(() -> scanJavaFileClass(rootName, type)
.orElseGet(() -> scanJavaFileClass(rootClass, type)
.orElseGet(() -> scanJavaInnerClass(rootClass, type)
.orElseGet(() -> new TypedMarker(rootName, source, String.class))));
}
Expand Down Expand Up @@ -432,8 +472,4 @@ private String getFileFullName(@NotNull PsiType type) {
private String getClassFullName(@NotNull PsiType type) {
return type.getCanonicalText();
}

private String getClassFullName(@NotNull PsiClass psiClass) {
return psiClass.getQualifiedName();
}
}
Loading

0 comments on commit d172b99

Please sign in to comment.