-
Notifications
You must be signed in to change notification settings - Fork 69
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
21 changed files
with
363 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package gg.jte.compiler.module; | ||
|
||
import java.util.Map; | ||
|
||
import gg.jte.CodeResolver; | ||
|
||
|
||
public final class Module { | ||
|
||
public static String getModuleAlias(String name) { | ||
int index = name.indexOf('/'); | ||
if (index == -1) { | ||
return null; | ||
} | ||
|
||
return name.substring(0, index); | ||
} | ||
|
||
private final String alias; | ||
private final CodeResolver codeResolver; | ||
private final Map<String, Module> children; | ||
|
||
public Module( String alias, CodeResolver codeResolver, Map<String, Module> children ) { | ||
this.alias = alias; | ||
this.codeResolver = isRoot() ? codeResolver : new ModuleCodeResolver(alias, codeResolver); | ||
this.children = children; | ||
} | ||
|
||
public Module resolve(String name) { | ||
if (children.isEmpty()) { | ||
return this; | ||
} | ||
|
||
String moduleAlias = getModuleAlias(name); | ||
if (moduleAlias == null) { | ||
return this; | ||
} | ||
|
||
Module result = children.get(moduleAlias); | ||
if (result == null) { | ||
return this; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public boolean isRoot() { | ||
return alias.isEmpty(); | ||
} | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public CodeResolver getCodeResolver() { | ||
return codeResolver; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
jte/src/main/java/gg/jte/compiler/module/ModuleCodeResolver.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,44 @@ | ||
package gg.jte.compiler.module; | ||
|
||
import gg.jte.CodeResolver; | ||
import gg.jte.TemplateNotFoundException; | ||
|
||
|
||
public class ModuleCodeResolver implements CodeResolver { | ||
|
||
private final CodeResolver codeResolver; | ||
private final String aliasSlash; | ||
|
||
public ModuleCodeResolver( String alias, CodeResolver codeResolver ) { | ||
this.codeResolver = codeResolver; | ||
this.aliasSlash = alias + "/"; | ||
} | ||
|
||
@Override | ||
public String resolve( String name ) { | ||
return codeResolver.resolve(removeAlias(name)); | ||
} | ||
|
||
@Override | ||
public String resolveRequired( String name ) throws TemplateNotFoundException { | ||
return codeResolver.resolveRequired(removeAlias(name)); | ||
} | ||
|
||
@Override | ||
public long getLastModified( String name ) { | ||
return codeResolver.getLastModified(removeAlias(name)); | ||
} | ||
|
||
@Override | ||
public boolean exists( String name ) { | ||
return codeResolver.exists(removeAlias(name)); | ||
} | ||
|
||
private String removeAlias(String name) { | ||
if (name.startsWith(aliasSlash)) { | ||
return name.substring(aliasSlash.length()); | ||
} | ||
|
||
return name; | ||
} | ||
} |
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,3 @@ | ||
package gg.jte.compiler.module; | ||
|
||
public record ModuleImport(String alias, String from) {} |
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,6 @@ | ||
package gg.jte.compiler.module; | ||
|
||
import java.util.List; | ||
|
||
|
||
public record ModuleInfo(List<ModuleImport> imports) {} |
Oops, something went wrong.