use of org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken in project jphp by jphp-compiler.
the class ClosureStmtCompiler method compile.
@Override
public ClosureEntity compile() {
ClosureEntity entity = new ClosureEntity(getCompiler().getContext());
entity.setReturnReference(statement.getFunction().isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_closure" + statement.getId());
entity.setId(statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
ClassStmtToken classStmtToken = new ClassStmtToken(statement.getMeta());
classStmtToken.setNamespace(NamespaceStmtToken.getDefault());
classStmtToken.setName(NameToken.valueOf(entity.getInternalName()));
classStmtToken.setExtend(ExtendsStmtToken.valueOf(Closure.class.getSimpleName()));
MethodStmtToken methodToken = new MethodStmtToken(statement.getFunction());
methodToken.setClazz(classStmtToken);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(NameToken.valueOf("__invoke"));
classStmtToken.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
classStmtCompiler.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setClassContext(statement.getOwnerClass());
classStmtCompiler.setFunctionName(null);
ClassEntity clazzEntity = classStmtCompiler.compile();
MethodEntity __invoke = clazzEntity.findMethod("__invoke");
entity.getMethods().putAll(clazzEntity.getMethods());
if (clazzEntity.getParent() != null)
entity.setParent(clazzEntity.getParent());
entity.setData(clazzEntity.getData());
entity.setParameters(__invoke.getParameters());
entity.doneDeclare();
entity.setGeneratorEntity(__invoke.getGeneratorEntity());
return entity;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken in project jphp by jphp-compiler.
the class FunctionStmtCompiler method compile.
@Override
public FunctionEntity compile() {
//
ModuleEntity module = compiler.getModule();
FunctionEntity entity = new FunctionEntity(compiler.getContext());
entity.setModule(module);
entity.setName(statement.getFulledName());
entity.setReturnReference(statement.isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_func" + statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
if (statement.getDocComment() != null)
entity.setDocComment(new DocumentComment(statement.getDocComment().getComment()));
NamespaceStmtToken namespace = NamespaceStmtToken.getDefault();
ClassStmtToken token = new ClassStmtToken(statement.getMeta());
token.setFinal(true);
token.setNamespace(namespace);
token.setName(new NameToken(TokenMeta.of(entity.getInternalName())));
MethodStmtToken methodToken = new MethodStmtToken(statement);
methodToken.setClazz(token);
methodToken.setFinal(true);
methodToken.setStatic(true);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(new NameToken(TokenMeta.of("__invoke")));
token.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(compiler, token);
classStmtCompiler.setSystem(true);
classStmtCompiler.setFunctionName(entity.getName());
ClassEntity clazzEntity = classStmtCompiler.compile();
entity.setData(clazzEntity.getData());
MethodEntity methodEntity = clazzEntity.findMethod("__invoke");
entity.setParameters(methodEntity.getParameters());
entity.setEmpty(methodEntity.isEmpty());
entity.setUsesStackTrace(methodEntity.isUsesStackTrace());
entity.setImmutable(methodEntity.isImmutable());
entity.setResult(methodEntity.getResult());
entity.setGeneratorEntity(methodEntity.getGeneratorEntity());
return entity;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken in project jphp by jphp-compiler.
the class ApiDocument method generate.
public void generate(File targetDirectory, String language, Map<String, ClassDescription> classMap) {
for (ClassStmtToken el : classes) {
ClassDescription cls = classMap.get(el.getFulledName().toLowerCase());
if (cls == null)
throw new IllegalStateException("Cannot find class " + el.getFulledName() + " in classMap");
System.out.println("[" + language + "] gen class: " + cls.getName());
String result = template.printClass(cls);
File file = new File(targetDirectory, cls.getName().replace('\\', '/') + ".rst");
if (!file.getParentFile().exists()) {
if (!file.getParentFile().mkdirs()) {
throw new IllegalStateException("Cannot create the '" + file.getParent() + "' directory");
}
}
try {
FileWriter fileWriter = new FileWriter(file, false);
try {
fileWriter.write(result);
} finally {
fileWriter.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
template.onEnd(targetDirectory);
}
Aggregations