开发者

How to build a simple IDE using Groovy?

Following this question Click Here. I thought of creating a simple IDE for groovy and Java. Code is reproduced here for easy reference:

import groovy.swing.SwingBuilder
import java.awt.BorderLayout as BL
import static javax.swing.JFrame.EXIT_ON_CLOSE
import org.fife.ui.rsyntaxtextarea.*

RSyntaxTextArea textArea = new RSyntaxTextArea()
textArea.syntaxEditingStyle = SyntaxConstants.SYNTAX_STYLE_JAVA

swing =  new SwingBuilder()
frame = swing.frame(title:"开发者_高级运维test", defaultCloseOperation:EXIT_ON_CLOSE, size:[600,400], show:true ) {
  borderLayout()
  panel( constraints:BL.CENTER ) {
    borderLayout()
    scrollPane( constraints:BL.CENTER ) {
      widget textArea
    }
  }
}

Now I have all the codings entered by the user in textarea which is an Object of RSynataxTextArea, how i should perform compilation for all the code written by the user? Is there any class for this purpose or any ways of doing it in Groovy?

Thanks in advance.


I you look in the src/main/groovy/ui folder of the source download for Groovy, you'll see the code which makes the groovyConsole work

If you look inside the ConsoleSupport class, you'll see the way the console does it:

protected Object evaluate(String text) {
    String name = "Script" + counter++;
    try {
        return getShell().evaluate(text, name);
    }
    catch (Exception e) {
        handleException(text, e);
        return null;
    }
}

where getShell() is:

public GroovyShell getShell() {
    if (shell == null) {
        shell = new GroovyShell();
    }
    return shell;
}

So it returns a new GroovyShell or the exiting one if one already exists

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜