Search in sources :

Example 1 with ClassStmtToken

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;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) MethodEntity(php.runtime.reflection.MethodEntity) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) MethodStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)

Example 2 with ClassStmtToken

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;
}
Also used : NamespaceStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) MethodStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)

Example 3 with ClassStmtToken

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);
}
Also used : FileWriter(java.io.FileWriter) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) ClassDescription(org.develnext.jphp.genapi.description.ClassDescription) IOException(java.io.IOException) File(java.io.File)

Aggregations

ClassStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken)3 MethodStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)1 NamespaceStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.NamespaceStmtToken)1 ClassDescription (org.develnext.jphp.genapi.description.ClassDescription)1 ClassEntity (php.runtime.reflection.ClassEntity)1 MethodEntity (php.runtime.reflection.MethodEntity)1 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)1