forked from Prunoideae/ProbeJS-Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
168 additions
and
18 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,73 @@ | ||
package com.probejs.rewrite.doc; | ||
|
||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.ListMultimap; | ||
import com.probejs.document.comment.CommentHandler; | ||
import com.probejs.document.comment.SpecialComment; | ||
import com.probejs.util.Pair; | ||
import lombok.Getter; | ||
import lombok.val; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* only java doc comment, regular line comment / block comment are not supported by this | ||
*/ | ||
@Getter | ||
public class DocComment { | ||
|
||
private final List<SpecialComment> specials; | ||
private final ListMultimap<Class<? extends SpecialComment>, SpecialComment> specials; | ||
private final List<String> normals; | ||
|
||
/** | ||
* construct a new, empty DocComment | ||
*/ | ||
DocComment() { | ||
this.specials = new ArrayList<>(0); | ||
this.specials = ArrayListMultimap.create(3,1); | ||
this.normals = new ArrayList<>(0); | ||
} | ||
|
||
DocComment(List<String> lines) { | ||
this(); | ||
//TODO: parse | ||
} | ||
|
||
/** | ||
* @return {trimmed line, special comment} | ||
*/ | ||
private static Pair<String, SpecialComment> parseFirstLine(String line) { | ||
line = line.trim(); | ||
if (!line.startsWith("/**")) { | ||
throw new IllegalArgumentException("arg not first line of a javadoc comment"); | ||
} | ||
line = line.substring(3); | ||
return new Pair<>(line, CommentHandler.tryParseSpecialComment(line)); | ||
} | ||
|
||
private static Pair<String, SpecialComment> parseLastLine(String line) { | ||
line = line.trim(); | ||
if (!line.endsWith("*/")) { | ||
throw new IllegalArgumentException("arg not last line of a javadoc comment"); | ||
} | ||
//TODO | ||
return null; | ||
} | ||
|
||
public <T extends SpecialComment> void acceptSpecials(Collection<T> specials) { | ||
for (T special : specials) { | ||
this.specials.put(special.getClass(), special); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T extends SpecialComment> List<T> getSpecialComment(Class<T> type) { | ||
val comments = this.specials.get(type); | ||
val special = new ArrayList<T>(comments.size()); | ||
for (val comment : comments) { | ||
special.add((T) comment); | ||
} | ||
return special; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,79 @@ | ||
package com.probejs.rewrite.doc; | ||
|
||
import com.probejs.document.comment.SpecialComment; | ||
import com.probejs.document.comment.special.CommentModify; | ||
import com.probejs.document.comment.special.CommentRename; | ||
import com.probejs.document.type.IDocType; | ||
import com.probejs.info.clazz.MethodInfo; | ||
import com.probejs.info.type.IType; | ||
import com.probejs.rewrite.doc.comments.CommentHolder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.val; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class DocMethod implements CommentHolder { | ||
|
||
private final DocComment comment; | ||
private final List<MethodInfo.ParamInfo> params; | ||
private IType returnType; | ||
private final List<DocParam> params; | ||
private IDocType returnType; | ||
|
||
DocMethod(MethodInfo mInfo) { | ||
this.comment = new DocComment(); | ||
this.params = mInfo.getParams().stream().map(DocParam::new).collect(Collectors.toList()); | ||
//TODO: doc type | ||
this.params = mInfo.getParams(); | ||
this.returnType = mInfo.getType(); | ||
this.returnType = (IDocType) mInfo.getType(); | ||
} | ||
|
||
@Override | ||
public void applyComment() { | ||
//rename | ||
for (val rename : this.comment.getSpecialComment(CommentRename.class)) { | ||
for (val param : this.params) { | ||
if (param.applyComment(rename)) { | ||
break; | ||
} | ||
} | ||
} | ||
//type modify | ||
val modifys = this.comment.getSpecialComment(CommentModify.class); | ||
if (!modifys.isEmpty()) { | ||
val modify = modifys.get(0); | ||
if (modify.getName().equals(this.returnType.getTypeName())) { | ||
this.returnType = modify.getType(); | ||
} | ||
} | ||
} | ||
|
||
@Getter | ||
@Setter | ||
public static class DocParam { | ||
|
||
private String name; | ||
private IDocType type; | ||
|
||
DocParam(MethodInfo.ParamInfo pInfo) { | ||
this.name = pInfo.getName(); | ||
//TODO: doc type | ||
this.type = (IDocType) pInfo.getType(); | ||
} | ||
|
||
public boolean applyComment(SpecialComment comment) { | ||
//TODO: totally mess | ||
if (comment instanceof CommentRename rename) { | ||
if (rename.getName().equals(this.name)) { | ||
this.name = rename.getTo(); | ||
} | ||
} else if (comment instanceof CommentModify modify) { | ||
if (modify.getName().equals(this.type.getTypeName())) { | ||
this.type = modify.getType(); | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/probejs/rewrite/doc/type/DocTypeArray.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,15 @@ | ||
package com.probejs.rewrite.doc.type; | ||
|
||
import com.probejs.info.type.IType; | ||
import com.probejs.info.type.TypeArray; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DocTypeArray implements DocType { | ||
|
||
private final DocType base; | ||
|
||
DocTypeArray(IType type) { | ||
this.base = DocTypeResolver.of(((TypeArray)type).getBase()); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/probejs/rewrite/doc/type/DocTypeResolver.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,24 @@ | ||
package com.probejs.rewrite.doc.type; | ||
|
||
import com.probejs.info.type.IType; | ||
import com.probejs.info.type.TypeArray; | ||
import com.probejs.info.type.TypeClass; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public abstract class DocTypeResolver { | ||
|
||
private static final Map<Class<? extends IType>, Function<IType, DocType>> REGISTRIES; | ||
|
||
static { | ||
REGISTRIES = new HashMap<>(); | ||
REGISTRIES.put(TypeClass.class, DocTypeClazz::new); | ||
REGISTRIES.put(TypeArray.class, DocTypeClazz::new); | ||
} | ||
|
||
public static DocType of(IType type) { | ||
return REGISTRIES.get(type.getClass()).apply(type); | ||
} | ||
} |