Search in sources :

Example 26 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class ClassMapping method selectors.

public java.util.Set<st.gravel.core.Symbol> selectors() {
    final java.util.Set<st.gravel.core.Symbol>[] _set;
    _set = new java.util.Set[1];
    _set[0] = new java.util.HashSet();
    for (final MethodNode _each : _classNode.methods()) {
        _set[0].add(st.gravel.core.Symbol.value(_each.selector()));
    }
    return _set[0];
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashSet(java.util.HashSet) MethodNode(st.gravel.support.compiler.ast.MethodNode)

Example 27 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class JavaTestcaseClassWriter method write_.

public JavaTestcaseClassWriter write_(final ClassNode _aClassNode) {
    final MethodNode[] _testMethods;
    final StringBuilder[] _wstr;
    final String _className;
    final java.io.File _dir;
    _wstr = new StringBuilder[1];
    _testMethods = st.gravel.support.jvm.ArrayExtensions.select_(_aClassNode.methods(), new st.gravel.support.jvm.Predicate1<MethodNode>() {

        @Override
        public boolean value_(final MethodNode _m) {
            return _m.selector().startsWith("test");
        }
    });
    if (_testMethods.length == 0) {
        return JavaTestcaseClassWriter.this;
    }
    _className = _aClassNode.name().asString();
    _dir = new java.io.File(new java.io.File(new java.io.File(_root, "st"), "gravel"), "systemtests");
    _dir.mkdirs();
    _wstr[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
    _wstr[0].append("package st.gravel.systemtests;\n\nimport org.junit.Before;\nimport org.junit.Test;\n\nimport st.gravel.support.jvm.runtime.ImageBootstrapper;\nimport st.gravel.support.jvm.runtime.MethodTools;\n\npublic class ");
    _wstr[0].append(_className);
    _wstr[0].append(" {\n\t@Before\n\tpublic void setUp() {\n\t\tst.gravel.support.compiler.testtools.TestBootstrap.getSingleton();\n\t}\n");
    for (final MethodNode _each : _testMethods) {
        _wstr[0].append("\t@Test\n\tpublic void ");
        _wstr[0].append(_each.selector());
        _wstr[0].append("() throws Throwable {\n\t\tMethodTools.debugTest(\"");
        _wstr[0].append(_aClassNode.reference().toString());
        _wstr[0].append("\", \"");
        _wstr[0].append(_each.selector());
        _wstr[0].append("\");\n\t}\n");
    }
    _wstr[0].append("}");
    st.gravel.support.jvm.StringExtensions.writeToFile_(_wstr[0].toString(), new java.io.File(_dir, _className + ".java"));
    return this;
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode)

Example 28 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class DiskClassWriter method writeClass_in_.

public DiskClassWriter writeClass_in_(final ClassNode _aClassNode, final java.io.File _aFilename) {
    final java.io.File _nsFn;
    final java.io.File _clFn;
    final StringBuilder[] _str;
    final VariableNode[] _reader;
    _reader = new VariableNode[1];
    _str = new StringBuilder[1];
    _nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aClassNode.reference().namespace().path(), _aFilename, ((st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>) (new st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>() {

        @Override
        public java.io.File value_value_(final java.io.File _fn, final st.gravel.core.Symbol _each) {
            return (java.io.File) new java.io.File(_fn, _each.asString());
        }
    }))));
    _nsFn.mkdirs();
    _clFn = new java.io.File(_nsFn, _aClassNode.reference().name().asString() + ".st");
    _str[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
    _reader[0] = VariableNode.factory.name_("reader");
    if (_aClassNode.isExtension()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_(_aClassNode.isTrait() ? "extendTrait:" : "extendClass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString())), _str[0]);
    } else {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_(_aClassNode.isTrait() ? "defineTrait:superclass:" : "defineClass:superclass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString()), DiskClassWriter.this.referenceAsLiteralNode_(_aClassNode.superclassReference())), _str[0]);
        for (final SharedDeclarationNode _sv : _aClassNode.metaclassNode().sharedVariables()) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("defineSharedVariable:init:", DiskClassWriter.this.asLiteralNode_(_sv.name()), DiskClassWriter.this.initializerSource_(_sv.initializer())), _str[0]);
        }
    }
    for (final Node _each : TraitUsageToDirectiveConverter.factory.visit_(_aClassNode.traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final Node _each : ClassTraitUsageToDirectiveConverter.factory.visit_(_aClassNode.metaclassNode().traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final VariableDeclarationNode _each : _aClassNode.instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final VariableDeclarationNode _each : _aClassNode.metaclassNode().instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addClassInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final Map.Entry<String, String> _temp1 : _aClassNode.properties().entrySet()) {
        String _k = _temp1.getKey();
        String _v = _temp1.getValue();
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("propertyAt:put:", DiskClassWriter.this.asLiteralNode_(_k), DiskClassWriter.this.asLiteralNode_(_v)), _str[0]);
    }
    for (final MethodNode _each : _aClassNode.methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    for (final MethodNode _each : _aClassNode.metaclassNode().methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    st.gravel.support.jvm.StringExtensions.writeToFile_(_str[0].toString(), _clFn);
    return this;
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Node(st.gravel.support.compiler.ast.Node) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassNode(st.gravel.support.compiler.ast.ClassNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MethodNode (st.gravel.support.compiler.ast.MethodNode)28 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)10 UnaryMethodNode (st.gravel.support.compiler.ast.UnaryMethodNode)9 HashMap (java.util.HashMap)7 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ExtensionClassPartMapping (st.gravel.support.compiler.ast.ExtensionClassPartMapping)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)4 ClassNode (st.gravel.support.compiler.ast.ClassNode)4 IdentityClassPartMapping (st.gravel.support.compiler.ast.IdentityClassPartMapping)4 Map (java.util.Map)3 Symbol (st.gravel.core.Symbol)3 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 MethodMapping (st.gravel.support.compiler.ast.MethodMapping)2 PackageNode (st.gravel.support.compiler.ast.PackageNode)2