Skip to content

Commit

Permalink
DocType, framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZank committed May 29, 2024
1 parent 772efa5 commit 9244fb3
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 22 deletions.
15 changes: 0 additions & 15 deletions src/main/java/com/probejs/rewrite/doc/type/DocTypeArray.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.probejs.info.type.IType;
import com.probejs.info.type.TypeArray;
import com.probejs.info.type.TypeClass;
import com.probejs.rewrite.doc.type.java.TypeClazz;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -14,8 +15,8 @@ public abstract class DocTypeResolver {

static {
REGISTRIES = new HashMap<>();
REGISTRIES.put(TypeClass.class, DocTypeClazz::new);
REGISTRIES.put(TypeArray.class, DocTypeClazz::new);
REGISTRIES.put(TypeClass.class, TypeClazz::new);
REGISTRIES.put(TypeArray.class, com.probejs.rewrite.doc.type.java.TypeArray::new);
}

public static DocType of(IType type) {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/probejs/rewrite/doc/type/java/JavaType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.probejs.rewrite.doc.type.java;

import com.probejs.rewrite.doc.type.DocType;

import java.lang.reflect.Type;
import java.util.Collection;

/**
* @author ZZZank
*/
public interface JavaType extends DocType {

Type raw();

JavaType base();

Collection<Class<?>> relatedClasses();
}
16 changes: 16 additions & 0 deletions src/main/java/com/probejs/rewrite/doc/type/java/TypeArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.probejs.rewrite.doc.type.java;

import com.probejs.info.type.IType;
import com.probejs.rewrite.doc.type.DocType;
import com.probejs.rewrite.doc.type.DocTypeResolver;
import lombok.Getter;

@Getter
public class TypeArray implements DocType {

private final DocType base;

public TypeArray(IType type) {
this.base = DocTypeResolver.of(type.getBase());
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.probejs.rewrite.doc.type;
package com.probejs.rewrite.doc.type.java;

import com.probejs.info.clazz.ClassInfo;
import com.probejs.info.type.IType;
import com.probejs.info.type.TypeClass;
import com.probejs.rewrite.ClazzPath;
import com.probejs.rewrite.doc.DocClazz;
import com.probejs.rewrite.doc.type.DocType;
import lombok.Getter;

@Getter
public class DocTypeClazz implements DocType {
public class TypeClazz implements DocType {

private final ClazzPath path;
private final DocClazz doc;
private final boolean assigned;

DocTypeClazz(Class<?> clazz) {
TypeClazz(Class<?> clazz) {
this.doc = DocClazz.of(clazz);
this.path = this.doc.getPath();
this.assigned = !this.doc.getAssignables().isEmpty();
}

DocTypeClazz(ClassInfo clazz) {
TypeClazz(ClassInfo clazz) {
this(clazz.getRaw());
}

public DocTypeClazz(IType iType) {
public TypeClazz(IType iType) {
this(((TypeClass) iType).getRaw());
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/probejs/rewrite/doc/type/java/TypeVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.probejs.rewrite.doc.type.java;

import com.probejs.info.type.TypeResolver;
import com.probejs.rewrite.doc.type.DocTypeResolver;
import lombok.AllArgsConstructor;
import lombok.val;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* @author ZZZank
*/
@AllArgsConstructor
public class TypeVariable implements JavaType {
private final java.lang.reflect.TypeVariable<?> raw;

@Override
public Type raw() {
return raw;
}

@Override
public JavaType base() {
return this;
}

@Override
public Collection<Class<?>> relatedClasses() {
val related = new ArrayList<Class<?>>();
for (Type bound : raw.getBounds()) {

}
return related;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.probejs.rewrite.doc.type.typescript;

import com.probejs.rewrite.doc.type.DocType;

/**
* @author ZZZank
*/
public interface TSType extends DocType {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.probejs.rewrite.doc.type.typescript;

import com.probejs.rewrite.doc.type.DocType;

/**
* aka TypeAnd, "string & number"
* @author ZZZank
*/
public record TypeIntersection(DocType left, DocType right) implements TSType {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.probejs.rewrite.doc.type.typescript;

import lombok.AllArgsConstructor;

/**
* @author ZZZank
*/
@AllArgsConstructor
public class TypeLiteral {
private final String literal;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.probejs.rewrite.doc.type.typescript;

import com.probejs.rewrite.doc.type.DocType;
import lombok.AllArgsConstructor;

import java.util.Map;

/**
* @author ZZZank
*/
@AllArgsConstructor
public class TypeObject implements TSType {
private final Map<String, ? extends DocType> map;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.probejs.rewrite.doc.type.typescript;

import com.probejs.rewrite.doc.type.DocType;

/**
* aka TypeOr, "string | number"
*
* @author ZZZank
*/
public record TypeUnion(DocType left, DocType right) implements TSType {
}

0 comments on commit 9244fb3

Please sign in to comment.