-
Notifications
You must be signed in to change notification settings - Fork 47
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
2 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.hykes.codegen.directive; | ||
|
||
import org.apache.velocity.context.InternalContextAdapter; | ||
import org.apache.velocity.exception.MethodInvocationException; | ||
import org.apache.velocity.exception.ParseErrorException; | ||
import org.apache.velocity.exception.ResourceNotFoundException; | ||
import org.apache.velocity.runtime.directive.Directive; | ||
import org.apache.velocity.runtime.parser.node.Node; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* 拼接元素 | ||
* ${Append '#' 'ABC' '%'} => #ABC% | ||
* @author [email protected] | ||
* @date 2017/12/19 | ||
*/ | ||
public class GetPackage extends Directive { | ||
@Override | ||
public String getName() { | ||
return "GetPackage"; | ||
} | ||
|
||
@Override | ||
public int getType() { | ||
return LINE; | ||
} | ||
|
||
@Override | ||
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { | ||
String clazz = (String) node.jjtGetChild(0).value(context); | ||
if (context.containsKey(clazz)) { | ||
String packagePath = context.get(clazz).toString(); | ||
packagePath = new StringBuilder("").append(packagePath).toString(); | ||
writer.write(packagePath); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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