├── .gitignore ├── src └── javarepl │ ├── console │ ├── ui │ │ ├── bower_components │ │ │ ├── jquery │ │ │ │ ├── src │ │ │ │ │ ├── outro.js │ │ │ │ │ ├── var │ │ │ │ │ │ ├── arr.js │ │ │ │ │ │ ├── rnotwhite.js │ │ │ │ │ │ ├── document.js │ │ │ │ │ │ ├── push.js │ │ │ │ │ │ ├── slice.js │ │ │ │ │ │ ├── concat.js │ │ │ │ │ │ ├── indexOf.js │ │ │ │ │ │ ├── class2type.js │ │ │ │ │ │ ├── pnum.js │ │ │ │ │ │ ├── toString.js │ │ │ │ │ │ ├── documentElement.js │ │ │ │ │ │ ├── hasOwn.js │ │ │ │ │ │ ├── support.js │ │ │ │ │ │ └── rcssNum.js │ │ │ │ │ ├── selector.js │ │ │ │ │ ├── ajax │ │ │ │ │ │ ├── var │ │ │ │ │ │ │ ├── rquery.js │ │ │ │ │ │ │ ├── location.js │ │ │ │ │ │ │ └── nonce.js │ │ │ │ │ │ ├── parseJSON.js │ │ │ │ │ │ ├── parseXML.js │ │ │ │ │ │ ├── script.js │ │ │ │ │ │ └── load.js │ │ │ │ │ ├── css │ │ │ │ │ │ ├── var │ │ │ │ │ │ │ ├── rmargin.js │ │ │ │ │ │ │ ├── cssExpand.js │ │ │ │ │ │ │ ├── rnumnonpx.js │ │ │ │ │ │ │ ├── isHidden.js │ │ │ │ │ │ │ ├── getStyles.js │ │ │ │ │ │ │ └── swap.js │ │ │ │ │ │ ├── hiddenVisibleSelectors.js │ │ │ │ │ │ ├── addGetHookIf.js │ │ │ │ │ │ ├── showHide.js │ │ │ │ │ │ ├── curCSS.js │ │ │ │ │ │ ├── defaultDisplay.js │ │ │ │ │ │ └── adjustCSS.js │ │ │ │ │ ├── manipulation │ │ │ │ │ │ ├── var │ │ │ │ │ │ │ ├── rtagName.js │ │ │ │ │ │ │ ├── rcheckableType.js │ │ │ │ │ │ │ └── rscriptType.js │ │ │ │ │ │ ├── _evalUrl.js │ │ │ │ │ │ ├── setGlobalEval.js │ │ │ │ │ │ ├── getAll.js │ │ │ │ │ │ ├── wrapMap.js │ │ │ │ │ │ └── support.js │ │ │ │ │ ├── data │ │ │ │ │ │ └── var │ │ │ │ │ │ │ ├── dataPriv.js │ │ │ │ │ │ │ ├── dataUser.js │ │ │ │ │ │ │ └── acceptData.js │ │ │ │ │ ├── core │ │ │ │ │ │ ├── var │ │ │ │ │ │ │ └── rsingleTag.js │ │ │ │ │ │ ├── parseHTML.js │ │ │ │ │ │ └── access.js │ │ │ │ │ ├── traversing │ │ │ │ │ │ └── var │ │ │ │ │ │ │ ├── rneedsContext.js │ │ │ │ │ │ │ ├── siblings.js │ │ │ │ │ │ │ └── dir.js │ │ │ │ │ ├── event │ │ │ │ │ │ ├── support.js │ │ │ │ │ │ ├── ajax.js │ │ │ │ │ │ ├── alias.js │ │ │ │ │ │ └── focusin.js │ │ │ │ │ ├── attributes.js │ │ │ │ │ ├── effects │ │ │ │ │ │ └── animatedSelector.js │ │ │ │ │ ├── selector-sizzle.js │ │ │ │ │ ├── .jshintrc │ │ │ │ │ ├── exports │ │ │ │ │ │ ├── global.js │ │ │ │ │ │ └── amd.js │ │ │ │ │ ├── queue │ │ │ │ │ │ └── delay.js │ │ │ │ │ ├── jquery.js │ │ │ │ │ ├── deprecated.js │ │ │ │ │ ├── attributes │ │ │ │ │ │ └── support.js │ │ │ │ │ ├── intro.js │ │ │ │ │ ├── wrap.js │ │ │ │ │ └── dimensions.js │ │ │ │ ├── bower.json │ │ │ │ ├── .bower.json │ │ │ │ ├── LICENSE.txt │ │ │ │ ├── external │ │ │ │ │ └── sizzle │ │ │ │ │ │ └── LICENSE.txt │ │ │ │ └── README.md │ │ │ ├── jquery.terminal │ │ │ │ ├── .gitignore │ │ │ │ ├── bin │ │ │ │ │ └── yuicompressor-2.4.8.jar │ │ │ │ ├── spec │ │ │ │ │ └── support │ │ │ │ │ │ └── jasmine.json │ │ │ │ ├── .npmignore │ │ │ │ ├── version │ │ │ │ ├── bower.json │ │ │ │ ├── package.in │ │ │ │ ├── package.json │ │ │ │ ├── terminal.jquery.json │ │ │ │ ├── js │ │ │ │ │ ├── jquery.mousewheel-min.js │ │ │ │ │ └── xml_formatting.js │ │ │ │ ├── .bower.json │ │ │ │ ├── LICENSE │ │ │ │ └── SpecRunner.html │ │ │ ├── underscore │ │ │ │ ├── bower.json │ │ │ │ ├── .bower.json │ │ │ │ ├── LICENSE │ │ │ │ └── README.md │ │ │ └── github-fork-ribbon-css │ │ │ │ ├── bower.json │ │ │ │ ├── package.json │ │ │ │ ├── .bower.json │ │ │ │ ├── LICENSE │ │ │ │ ├── README.md │ │ │ │ └── gh-fork-ribbon.ie.css │ │ ├── favicon.ico │ │ ├── javarepl-icon.png │ │ ├── ConsoleUiModule.java │ │ └── console.html │ ├── rest │ │ ├── favicon.ico │ │ ├── MapToJsonResponseHandler.java │ │ ├── RestConsoleExpressionReader.java │ │ ├── RestConsoleApplication.java │ │ ├── RestConsoleModule.java │ │ └── RestConsole.java │ ├── ConsoleStatus.java │ ├── Console.java │ ├── commands │ │ ├── NotAValidCommand.java │ │ ├── ClearScreen.java │ │ ├── ShowResult.java │ │ ├── ShowLastSource.java │ │ ├── ResetAllEvaluations.java │ │ ├── QuitApplication.java │ │ ├── ShowHelp.java │ │ ├── SearchHistory.java │ │ ├── Commands.java │ │ ├── ReplayAllEvaluations.java │ │ ├── ShowTypeOfExpression.java │ │ ├── EvaluateFromHistory.java │ │ ├── EvaluateFile.java │ │ ├── LoadSourceFile.java │ │ ├── ShowHistory.java │ │ ├── AddToClasspath.java │ │ ├── CheckExpression.java │ │ ├── Command.java │ │ └── ListValues.java │ ├── ConsoleResult.java │ ├── DelegatingConsole.java │ ├── ConsoleLog.java │ ├── TimingOutConsole.java │ ├── ConsoleHistory.java │ └── ConsoleLogger.java │ ├── web │ ├── favicon.ico │ ├── WebConsoleApplication.java │ ├── WebConsoleModule.java │ ├── WebConsoleServer.java │ ├── WebConsole.java │ └── embed.html │ ├── completion │ ├── Completer.java │ ├── StringCompleter.java │ ├── Completers.java │ ├── ResolvedClass.java │ ├── ResolvedPackage.java │ ├── CompletionCandidate.java │ ├── AggregateCompleter.java │ ├── CommandCompleter.java │ ├── TypeCompleter.java │ └── ConsoleCompleter.java │ ├── expressions │ ├── Value.java │ ├── Statement.java │ ├── Assignment.java │ ├── Import.java │ ├── AssignmentWithType.java │ ├── Type.java │ ├── Expression.java │ └── Method.java │ ├── reflection │ ├── AnnotatedReflection.java │ ├── ClassReflections.java │ ├── FieldReflection.java │ ├── MethodReflection.java │ ├── ConstructorReflection.java │ └── MemberReflection.java │ ├── rendering │ ├── ExpressionTemplate.java │ ├── TypeRenderer.java │ ├── ExpressionSourceRenderer.java │ ├── MethodNameRenderer.java │ ├── ValueRenderer.java │ └── ExpressionTokenRenderer.java │ ├── client │ ├── EvaluationResult.java │ └── EvaluationLog.java │ ├── EvaluationTemplate.java │ ├── EvaluationClassLoader.java │ ├── examples │ └── EmbedInApplication.java │ ├── Evaluation.java │ ├── ResultPrinter.java │ ├── Result.java │ └── ExpressionCompilationException.java ├── bin ├── javarepl-icon.png ├── ec2-install.sh ├── push-to-docker-hub.sh ├── ec2-cloudconfig.txt ├── restart-javarepl.sh ├── docker-commands.sh └── restart-after-tag.sh ├── test ├── resources │ └── expressions.txt └── javarepl │ ├── testclasses │ ├── PublicBaseTestClass.java │ ├── BaseTestInterface.java │ ├── DefaultAccessTestClass.java │ ├── GenericTestClass.java │ ├── ProtectedAccessTestClass.java │ └── Constructors.java │ ├── rendering │ ├── TypeRendererTest.java │ └── ValueRendererTest.java │ ├── EvaluationContextTest.java │ ├── completion │ ├── helpers │ │ └── SimpleCompletionInstance.java │ ├── TypeCompleterTest.java │ ├── AggregateCompleterTest.java │ ├── StringCompleterTest.java │ ├── CommandCompleterTest.java │ ├── StaticMemberCompleterTest.java │ ├── InstanceMemberCompleterTest.java │ └── CompleterTestHelper.java │ ├── console │ ├── ConsoleHistoryTest.java │ └── commands │ │ └── CommandTest.java │ └── ExpressionReaderTest.java ├── Dockerfile └── .travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .idea 3 | .DS_Store 4 | out 5 | 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/outro.js: -------------------------------------------------------------------------------- 1 | return jQuery; 2 | })); 3 | -------------------------------------------------------------------------------- /bin/javarepl-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/bin/javarepl-icon.png -------------------------------------------------------------------------------- /test/resources/expressions.txt: -------------------------------------------------------------------------------- 1 | void method(){} 2 | System.out.println("Hello world") 3 | int num = 42 -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/arr.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return []; 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/selector.js: -------------------------------------------------------------------------------- 1 | define( [ "./selector-sizzle" ], function() {} ); 2 | -------------------------------------------------------------------------------- /src/javarepl/web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/src/javarepl/web/favicon.ico -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/var/rquery.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /\?/ ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/rnotwhite.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /\S+/g ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/src/javarepl/console/ui/favicon.ico -------------------------------------------------------------------------------- /src/javarepl/console/rest/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/src/javarepl/console/rest/favicon.ico -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/rmargin.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /^margin/ ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/document.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return window.document; 3 | } ); 4 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/PublicBaseTestClass.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | public class PublicBaseTestClass{ 4 | } 5 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/var/location.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return window.location; 3 | } ); 4 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/BaseTestInterface.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | public interface BaseTestInterface { 4 | } 5 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/javarepl-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/src/javarepl/console/ui/javarepl-icon.png -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/var/rtagName.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /<([\w:-]+)/ ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/push.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./arr" 3 | ], function( arr ) { 4 | return arr.push; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/slice.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./arr" 3 | ], function( arr ) { 4 | return arr.slice; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/concat.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./arr" 3 | ], function( arr ) { 4 | return arr.concat; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/indexOf.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./arr" 3 | ], function( arr ) { 4 | return arr.indexOf; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/cssExpand.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return [ "Top", "Right", "Bottom", "Left" ]; 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/class2type.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | // [[Class]] -> type pairs 4 | return {}; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/data/var/dataPriv.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../Data" 3 | ], function( Data ) { 4 | return new Data(); 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/data/var/dataUser.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../Data" 3 | ], function( Data ) { 4 | return new Data(); 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/var/rcheckableType.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /^(?:checkbox|radio)$/i ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/var/rscriptType.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /^$|\/(?:java|ecma)script/i ); 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/pnum.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; 3 | } ); 4 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/var/nonce.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../../core" 3 | ], function( jQuery ) { 4 | return jQuery.now(); 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/toString.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./class2type" 3 | ], function( class2type ) { 4 | return class2type.toString; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/documentElement.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./document" 3 | ], function( document ) { 4 | return document.documentElement; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/hasOwn.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./class2type" 3 | ], function( class2type ) { 4 | return class2type.hasOwnProperty; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/support.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | // All support tests are defined in their respective modules. 4 | return {}; 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/core/var/rsingleTag.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | // Match a standalone tag 4 | return ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ ); 5 | } ); 6 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/DefaultAccessTestClass.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | class DefaultAccessTestClass extends PublicBaseTestClass implements BaseTestInterface { 4 | } 5 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/GenericTestClass.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | 4 | public class GenericTestClass extends PublicBaseTestClass { 5 | } 6 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/ProtectedAccessTestClass.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | public class ProtectedAccessTestClass extends PublicBaseTestClass implements BaseTestInterface{ 4 | } 5 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/rnumnonpx.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../../var/pnum" 3 | ], function( pnum ) { 4 | return new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); 5 | } ); 6 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .[0-9/]* 3 | components 4 | \#*\# 5 | .\#* 6 | www 7 | test 8 | bower_components 9 | node_modules 10 | coverage 11 | reports 12 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/var/rcssNum.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./pnum" 3 | ], function( pnum ) { 4 | 5 | return new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); 6 | 7 | } ); 8 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/traversing/var/rneedsContext.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../../core", 3 | "../../selector" 4 | ], function( jQuery ) { 5 | return jQuery.expr.match.needsContext; 6 | } ); 7 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/bin/yuicompressor-2.4.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albertlatacz/java-repl/HEAD/src/javarepl/console/ui/bower_components/jquery.terminal/bin/yuicompressor-2.4.8.jar -------------------------------------------------------------------------------- /src/javarepl/completion/Completer.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.functions.Function1; 4 | 5 | public abstract class Completer implements Function1 { 6 | } 7 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/event/support.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../var/support" 3 | ], function( support ) { 4 | 5 | support.focusin = "onfocusin" in window; 6 | 7 | return support; 8 | 9 | } ); 10 | -------------------------------------------------------------------------------- /bin/ec2-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | wget 'http://albertlatacz.published.s3.amazonaws.com/javarepl/javarepl.jar' -O /home/ubuntu/javarepl.jar 4 | cd /home/ubuntu 5 | sudo nohup java -cp javarepl.jar javarepl.web.WebConsoleServer --port=80 2>&1 javarepl.pid 7 | -------------------------------------------------------------------------------- /bin/push-to-docker-hub.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | docker build -t ${PROJECT_REPOSITORY}:${PROJECT_VERSION} -t ${PROJECT_REPOSITORY} --build-arg JAVA_REPL_VERSION=${PROJECT_VERSION} . 4 | docker login -u=${DOCKER_HUB_USERNAME} -p=${DOCKER_HUB_PASSWORD}; 5 | docker push ${PROJECT_REPOSITORY} -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/spec/support/jasmine.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec_dir": "spec", 3 | "spec_files": [ 4 | "**/*[sS]pec.js" 5 | ], 6 | "helpers": [ 7 | "helpers/**/*.js" 8 | ], 9 | "stopSpecOnExpectationFailure": false, 10 | "random": false 11 | } 12 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ] 14 | } -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/attributes.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./core", 3 | "./attributes/attr", 4 | "./attributes/prop", 5 | "./attributes/classes", 6 | "./attributes/val" 7 | ], function( jQuery ) { 8 | 9 | // Return jQuery for attributes-only inclusion 10 | return jQuery; 11 | } ); 12 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | *~ 3 | www 4 | bower.* 5 | package.in 6 | Makefile* 7 | manifest 8 | README.in 9 | terminal.jquery.json 10 | SpecRunner.html 11 | spec 12 | examples 13 | bin 14 | css/jquery.terminal-*.css 15 | js/jquery.terminal-*.js 16 | js/jquery-1.7.1.min.js 17 | version 18 | -------------------------------------------------------------------------------- /bin/ec2-cloudconfig.txt: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt_upgrade: true 3 | apt_sources: 4 | - source: "ppa:smoser/ppa" 5 | 6 | packages: 7 | - openjdk-7-jre-headless 8 | 9 | runcmd: 10 | - [ wget, 'http://albertlatacz.published.s3.amazonaws.com/javarepl/ec2-install.sh', -O, /home/ubuntu/ec2-install.sh ] 11 | - /bin/sh /home/ubuntu/ec2-install.sh -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/traversing/var/siblings.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | return function( n, elem ) { 4 | var matched = []; 5 | 6 | for ( ; n; n = n.nextSibling ) { 7 | if ( n.nodeType === 1 && n !== elem ) { 8 | matched.push( n ); 9 | } 10 | } 11 | 12 | return matched; 13 | }; 14 | 15 | } ); 16 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Value.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | import static java.util.UUID.randomUUID; 4 | 5 | public final class Value extends Expression { 6 | public Value(String source) { 7 | super(source); 8 | } 9 | 10 | public String key() { 11 | return randomUUID().toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/javarepl/reflection/AnnotatedReflection.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.lang.annotation.Annotation; 6 | 7 | public interface AnnotatedReflection { 8 | 9 | Sequence annotations(); 10 | 11 | Sequence declaredAnnotations(); 12 | } 13 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/parseJSON.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core" 3 | ], function( jQuery ) { 4 | 5 | // Support: Android 2.3 6 | // Workaround failure to string-cast null input 7 | jQuery.parseJSON = function( data ) { 8 | return JSON.parse( data + "" ); 9 | }; 10 | 11 | return jQuery.parseJSON; 12 | 13 | } ); 14 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Statement.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | import static java.util.UUID.randomUUID; 4 | 5 | public final class Statement extends Expression { 6 | public Statement(String source) { 7 | super(source); 8 | } 9 | 10 | public String key() { 11 | return randomUUID().toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/effects/animatedSelector.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../selector", 4 | "../effects" 5 | ], function( jQuery ) { 6 | 7 | jQuery.expr.filters.animated = function( elem ) { 8 | return jQuery.grep( jQuery.timers, function( fn ) { 9 | return elem === fn.elem; 10 | } ).length; 11 | }; 12 | 13 | } ); 14 | -------------------------------------------------------------------------------- /bin/restart-javarepl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # */5 * * * * /home/ubuntu/restart-javarepl.sh 3 | 4 | PID=`ps -eo 'tty pid args' | grep 'javarepl.jar' | grep -v grep | tr -s ' ' | cut -f2 -d ' '` 5 | 6 | if [ -z "$PID" ] 7 | then 8 | ./ec2-install.sh 9 | echo "Started Process at `date`" 10 | else 11 | echo "Process is already Running with PIS=$PID" 12 | fi 13 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/underscore/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "underscore", 3 | "version": "1.8.3", 4 | "main": "underscore.js", 5 | "keywords": ["util", "functional", "server", "client", "browser"], 6 | "ignore" : ["docs", "test", "*.yml", "CNAME", "index.html", "favicon.ico", "CONTRIBUTING.md", ".*", "component.json", "package.json", "karma.*"] 7 | } 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM albertlatacz/ubuntu-java-base 2 | 3 | ARG JAVA_REPL_VERSION=VERSION_NOT_SET 4 | 5 | WORKDIR javarepl 6 | 7 | ADD https://github.com/albertlatacz/java-repl/releases/download/$JAVA_REPL_VERSION/javarepl-$JAVA_REPL_VERSION.jar javarepl/javarepl.jar 8 | 9 | EXPOSE 8090 10 | 11 | CMD ["java", "-cp", "javarepl/javarepl.jar", "javarepl.web.WebConsoleServer", "--port=8090"] 12 | -------------------------------------------------------------------------------- /src/javarepl/console/ConsoleStatus.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | public enum ConsoleStatus { 4 | Idle, Starting, Running, Terminating, Terminated; 5 | 6 | public static ConsoleStatus consoleStatus(String consoleStatus) { 7 | return valueOf(consoleStatus); 8 | } 9 | 10 | public Boolean isRunning() { 11 | return this == Running; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/javarepl/reflection/ClassReflections.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | 4 | public final class ClassReflections { 5 | 6 | public static ClassReflection reflectionOf(Class aClass) { 7 | return new ClassReflection(aClass); 8 | } 9 | 10 | public static ClassReflection reflectionOf(Object object) { 11 | return new ClassReflection(object.getClass()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/selector-sizzle.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./core", 3 | "../external/sizzle/dist/sizzle" 4 | ], function( jQuery, Sizzle ) { 5 | 6 | jQuery.find = Sizzle; 7 | jQuery.expr = Sizzle.selectors; 8 | jQuery.expr[ ":" ] = jQuery.expr.pseudos; 9 | jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort; 10 | jQuery.text = Sizzle.getText; 11 | jQuery.isXMLDoc = Sizzle.isXML; 12 | jQuery.contains = Sizzle.contains; 13 | 14 | } ); 15 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/data/var/acceptData.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | /** 4 | * Determines whether an object can have data 5 | */ 6 | return function( owner ) { 7 | 8 | // Accepts only: 9 | // - Node 10 | // - Node.ELEMENT_NODE 11 | // - Node.DOCUMENT_NODE 12 | // - Object 13 | // - Any 14 | /* jshint -W018 */ 15 | return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); 16 | }; 17 | 18 | } ); 19 | -------------------------------------------------------------------------------- /src/javarepl/console/rest/MapToJsonResponseHandler.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.rest; 2 | 3 | import com.googlecode.totallylazy.json.Json; 4 | import com.googlecode.utterlyidle.Response; 5 | import com.googlecode.utterlyidle.ResponseHandler; 6 | 7 | public class MapToJsonResponseHandler implements ResponseHandler { 8 | public Response handle(Response response) throws Exception { 9 | return response.entity(Json.json(response.entity().value())); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/event/ajax.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../event" 4 | ], function( jQuery ) { 5 | 6 | // Attach a bunch of functions for handling common AJAX events 7 | jQuery.each( [ 8 | "ajaxStart", 9 | "ajaxStop", 10 | "ajaxComplete", 11 | "ajaxError", 12 | "ajaxSuccess", 13 | "ajaxSend" 14 | ], function( i, type ) { 15 | jQuery.fn[ type ] = function( fn ) { 16 | return this.on( type, fn ); 17 | }; 18 | } ); 19 | 20 | } ); 21 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/_evalUrl.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../ajax" 3 | ], function( jQuery ) { 4 | 5 | jQuery._evalUrl = function( url ) { 6 | return jQuery.ajax( { 7 | url: url, 8 | 9 | // Make this explicit, since user can override this through ajaxSetup (#11264) 10 | type: "GET", 11 | dataType: "script", 12 | async: false, 13 | global: false, 14 | "throws": true 15 | } ); 16 | }; 17 | 18 | return jQuery._evalUrl; 19 | 20 | } ); 21 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/isHidden.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../../core", 3 | "../../selector" 4 | 5 | // css is assumed 6 | ], function( jQuery ) { 7 | 8 | return function( elem, el ) { 9 | 10 | // isHidden might be called from jQuery#filter function; 11 | // in that case, element will be second argument 12 | elem = el || elem; 13 | return jQuery.css( elem, "display" ) === "none" || 14 | !jQuery.contains( elem.ownerDocument, elem ); 15 | }; 16 | } ); 17 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/getStyles.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | return function( elem ) { 3 | 4 | // Support: IE<=11+, Firefox<=30+ (#15098, #14150) 5 | // IE throws on elements created in popups 6 | // FF meanwhile throws on frame elements through "defaultView.getComputedStyle" 7 | var view = elem.ownerDocument.defaultView; 8 | 9 | if ( !view || !view.opener ) { 10 | view = window; 11 | } 12 | 13 | return view.getComputedStyle( elem ); 14 | }; 15 | } ); 16 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/traversing/var/dir.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../../core" 3 | ], function( jQuery ) { 4 | 5 | return function( elem, dir, until ) { 6 | var matched = [], 7 | truncate = until !== undefined; 8 | 9 | while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) { 10 | if ( elem.nodeType === 1 ) { 11 | if ( truncate && jQuery( elem ).is( until ) ) { 12 | break; 13 | } 14 | matched.push( elem ); 15 | } 16 | } 17 | return matched; 18 | }; 19 | 20 | } ); 21 | -------------------------------------------------------------------------------- /src/javarepl/rendering/ExpressionTemplate.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | public final class ExpressionTemplate { 4 | private final String template; 5 | private final String token; 6 | 7 | public ExpressionTemplate(String template, String token) { 8 | this.template = template; 9 | this.token = token; 10 | } 11 | 12 | public String template() { 13 | return template; 14 | } 15 | 16 | public String token() { 17 | return token; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/javarepl/console/Console.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import javarepl.completion.CompletionResult; 4 | import javarepl.rendering.ExpressionTemplate; 5 | 6 | public interface Console { 7 | 8 | ConsoleResult execute(String expression); 9 | 10 | CompletionResult completion(String expression); 11 | 12 | ExpressionTemplate template(String expression); 13 | 14 | ConsoleStatus status(); 15 | 16 | ConsoleHistory history(); 17 | 18 | void start(); 19 | 20 | void shutdown(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/setGlobalEval.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../data/var/dataPriv" 3 | ], function( dataPriv ) { 4 | 5 | // Mark scripts as having already been evaluated 6 | function setGlobalEval( elems, refElements ) { 7 | var i = 0, 8 | l = elems.length; 9 | 10 | for ( ; i < l; i++ ) { 11 | dataPriv.set( 12 | elems[ i ], 13 | "globalEval", 14 | !refElements || dataPriv.get( refElements[ i ], "globalEval" ) 15 | ); 16 | } 17 | } 18 | 19 | return setGlobalEval; 20 | } ); 21 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Assignment.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | public final class Assignment extends Expression { 4 | private final String key; 5 | private final String value; 6 | 7 | public Assignment(String source, String key, String value) { 8 | super(source); 9 | this.key = key; 10 | this.value = value; 11 | } 12 | 13 | public String key() { 14 | return key; 15 | } 16 | 17 | public String value() { 18 | return value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Import.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | 4 | import static java.util.UUID.randomUUID; 5 | 6 | public final class Import extends Expression { 7 | private final String typePackage; 8 | 9 | public Import(String source, String typePackage) { 10 | super(source); 11 | this.typePackage = typePackage; 12 | } 13 | 14 | public String key() { 15 | return randomUUID().toString(); 16 | } 17 | 18 | public String typePackage() { 19 | return typePackage; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION=`grep VERSION= Makefile | sed -e 's/VERSION=\(.*\)/\1/'` 4 | if [ $1 != $VERSION ]; then 5 | sed -e "s/{{VERSION}}/"$1"/" Makefile.in > Makefile 6 | git mv css/jquery.terminal-${VERSION}.css css/jquery.terminal-${1}.css 7 | git mv css/jquery.terminal-${VERSION}.min.css css/jquery.terminal-${1}.min.css 8 | git mv js/jquery.terminal-${VERSION}.js js/jquery.terminal-${1}.js 9 | git mv js/jquery.terminal-${VERSION}.min.js js/jquery.terminal-${1}.min.js 10 | fi 11 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/NotAValidCommand.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.console.ConsoleLogger; 4 | 5 | import static com.googlecode.totallylazy.Strings.startsWith; 6 | 7 | public final class NotAValidCommand extends Command { 8 | private final ConsoleLogger logger; 9 | 10 | public NotAValidCommand(ConsoleLogger logger) { 11 | super(null, startsWith(":"), null); 12 | this.logger = logger; 13 | } 14 | 15 | public void execute(String expression) { 16 | logger.error(expression + " is not a valid command"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/javarepl/client/EvaluationResult.java: -------------------------------------------------------------------------------- 1 | package javarepl.client; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.util.List; 6 | 7 | public final class EvaluationResult { 8 | private final String expression; 9 | private final Sequence logs; 10 | 11 | EvaluationResult(String expression, Sequence logs) { 12 | this.expression = expression; 13 | this.logs = logs; 14 | } 15 | 16 | public String expression() { 17 | return expression; 18 | } 19 | 20 | public List logs() { 21 | return logs.toList(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "boss": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "eqnull": true, 6 | "expr": true, 7 | "immed": true, 8 | "noarg": true, 9 | "quotmark": "double", 10 | "undef": true, 11 | "unused": true, 12 | 13 | "sub": true, 14 | 15 | // Support: IE < 10, Android < 4.1 16 | // The above browsers are failing a lot of tests in the ES5 17 | // test suite at http://test262.ecmascript.org. 18 | "es3": true, 19 | 20 | "globals": { 21 | "window": true, 22 | "JSON": false, 23 | 24 | "jQuery": true, 25 | "define": true, 26 | "module": true, 27 | "noGlobal": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/parseXML.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core" 3 | ], function( jQuery ) { 4 | 5 | // Cross-browser xml parsing 6 | jQuery.parseXML = function( data ) { 7 | var xml; 8 | if ( !data || typeof data !== "string" ) { 9 | return null; 10 | } 11 | 12 | // Support: IE9 13 | try { 14 | xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" ); 15 | } catch ( e ) { 16 | xml = undefined; 17 | } 18 | 19 | if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) { 20 | jQuery.error( "Invalid XML: " + data ); 21 | } 22 | return xml; 23 | }; 24 | 25 | return jQuery.parseXML; 26 | 27 | } ); 28 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/var/swap.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | // A method for quickly swapping in/out CSS properties to get correct calculations. 4 | return function( elem, options, callback, args ) { 5 | var ret, name, 6 | old = {}; 7 | 8 | // Remember the old values, and insert the new ones 9 | for ( name in options ) { 10 | old[ name ] = elem.style[ name ]; 11 | elem.style[ name ] = options[ name ]; 12 | } 13 | 14 | ret = callback.apply( elem, args || [] ); 15 | 16 | // Revert the old values 17 | for ( name in options ) { 18 | elem.style[ name ] = old[ name ]; 19 | } 20 | 21 | return ret; 22 | }; 23 | 24 | } ); 25 | -------------------------------------------------------------------------------- /src/javarepl/client/EvaluationLog.java: -------------------------------------------------------------------------------- 1 | package javarepl.client; 2 | 3 | public class EvaluationLog { 4 | public static enum Type { 5 | INFO, SUCCESS, ERROR, CONTROL; 6 | 7 | public static Type type(String type) { 8 | return valueOf(type); 9 | } 10 | } 11 | 12 | private final Type type; 13 | private final String message; 14 | 15 | public EvaluationLog(Type type, String message) { 16 | this.type = type; 17 | this.message = message; 18 | } 19 | 20 | public Type type() { 21 | return type; 22 | } 23 | 24 | public String message() { 25 | return message; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/hiddenVisibleSelectors.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../selector" 4 | ], function( jQuery ) { 5 | 6 | jQuery.expr.filters.hidden = function( elem ) { 7 | return !jQuery.expr.filters.visible( elem ); 8 | }; 9 | jQuery.expr.filters.visible = function( elem ) { 10 | 11 | // Support: Opera <= 12.12 12 | // Opera reports offsetWidths and offsetHeights less than zero on some elements 13 | // Use OR instead of AND as the element is not visible if either is true 14 | // See tickets #10406 and #13132 15 | return elem.offsetWidth > 0 || elem.offsetHeight > 0 || elem.getClientRects().length > 0; 16 | }; 17 | 18 | } ); 19 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/ConsoleUiModule.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.ui; 2 | 3 | import com.googlecode.utterlyidle.Resources; 4 | import com.googlecode.utterlyidle.modules.ResourcesModule; 5 | 6 | import static com.googlecode.totallylazy.io.URLs.packageUrl; 7 | import static com.googlecode.utterlyidle.dsl.DslBindings.bindings; 8 | import static com.googlecode.utterlyidle.dsl.StaticBindingBuilder.in; 9 | 10 | public class ConsoleUiModule implements ResourcesModule { 11 | @Override 12 | public Resources addResources(Resources resources) throws Exception { 13 | return resources.add(bindings(in(packageUrl(ConsoleUiModule.class)).path("/ui"))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-fork-ribbon-css", 3 | "version": "0.2.0", 4 | "homepage": "https://simonwhitaker.github.io/github-fork-ribbon-css/", 5 | "authors": [ 6 | "Simon Whitaker" 7 | ], 8 | "description": "\"Fork me on GitHub\" CSS ribbon", 9 | "main": [ 10 | "gh-fork-ribbon.css", 11 | "gh-fork-ribbon.ie.css" 12 | ], 13 | "keywords": [ 14 | "css", 15 | "fork", 16 | "GitHub", 17 | "ribbon" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "node_modules", 23 | "bower_components", 24 | "test", 25 | "tests" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ], 14 | "homepage": "https://github.com/jquery/jquery-dist", 15 | "version": "2.2.4", 16 | "_release": "2.2.4", 17 | "_resolution": { 18 | "type": "version", 19 | "tag": "2.2.4", 20 | "commit": "c0185ab7c75aab88762c5aae780b9d83b80eda72" 21 | }, 22 | "_source": "https://github.com/jquery/jquery-dist.git", 23 | "_target": "~2", 24 | "_originalSource": "jquery" 25 | } -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/addGetHookIf.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | function addGetHookIf( conditionFn, hookFn ) { 4 | 5 | // Define the hook, we'll check on the first run if it's really needed. 6 | return { 7 | get: function() { 8 | if ( conditionFn() ) { 9 | 10 | // Hook not needed (or it's not possible to use it due 11 | // to missing dependency), remove it. 12 | delete this.get; 13 | return; 14 | } 15 | 16 | // Hook needed; redefine it so that the support test is not executed again. 17 | return ( this.get = hookFn ).apply( this, arguments ); 18 | } 19 | }; 20 | } 21 | 22 | return addGetHookIf; 23 | 24 | } ); 25 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/getAll.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core" 3 | ], function( jQuery ) { 4 | 5 | function getAll( context, tag ) { 6 | 7 | // Support: IE9-11+ 8 | // Use typeof to avoid zero-argument method invocation on host objects (#15151) 9 | var ret = typeof context.getElementsByTagName !== "undefined" ? 10 | context.getElementsByTagName( tag || "*" ) : 11 | typeof context.querySelectorAll !== "undefined" ? 12 | context.querySelectorAll( tag || "*" ) : 13 | []; 14 | 15 | return tag === undefined || tag && jQuery.nodeName( context, tag ) ? 16 | jQuery.merge( [ context ], ret ) : 17 | ret; 18 | } 19 | 20 | return getAll; 21 | } ); 22 | -------------------------------------------------------------------------------- /test/javarepl/rendering/TypeRendererTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.ArrayList; 6 | 7 | import static java.util.Arrays.asList; 8 | import static javarepl.rendering.TypeRenderer.renderType; 9 | import static org.hamcrest.Matchers.is; 10 | import static org.junit.Assert.assertThat; 11 | 12 | public class TypeRendererTest { 13 | @Test 14 | public void supportsGenericTypesRendering() { 15 | assertThat(renderType(new ArrayList() { 16 | }.getClass()), is("java.util.ArrayList")); 17 | assertThat(renderType(asList(1, 2, 3).getClass()), is("java.util.AbstractList")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/exports/global.js: -------------------------------------------------------------------------------- 1 | var 2 | 3 | // Map over jQuery in case of overwrite 4 | _jQuery = window.jQuery, 5 | 6 | // Map over the $ in case of overwrite 7 | _$ = window.$; 8 | 9 | jQuery.noConflict = function( deep ) { 10 | if ( window.$ === jQuery ) { 11 | window.$ = _$; 12 | } 13 | 14 | if ( deep && window.jQuery === jQuery ) { 15 | window.jQuery = _jQuery; 16 | } 17 | 18 | return jQuery; 19 | }; 20 | 21 | // Expose jQuery and $ identifiers, even in AMD 22 | // (#7102#comment:10, https://github.com/jquery/jquery/pull/557) 23 | // and CommonJS for browser emulators (#13566) 24 | if ( !noGlobal ) { 25 | window.jQuery = window.$ = jQuery; 26 | } 27 | -------------------------------------------------------------------------------- /test/javarepl/EvaluationContextTest.java: -------------------------------------------------------------------------------- 1 | package javarepl; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Option.some; 6 | import static javarepl.EvaluationContext.evaluationContext; 7 | import static javarepl.Result.noResult; 8 | import static javarepl.Result.result; 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class EvaluationContextTest { 12 | 13 | @Test 14 | public void shouldReturnResultByKey() { 15 | EvaluationContext context = evaluationContext().addResult(result("key1", "value1")); 16 | 17 | assertEquals(context.result("key1"), some(result("key1", "value1"))); 18 | assertEquals(context.result("invalidKey"), noResult()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/javarepl/completion/helpers/SimpleCompletionInstance.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion.helpers; 2 | 3 | 4 | import java.util.Date; 5 | 6 | 7 | public class SimpleCompletionInstance { 8 | public void voidMethod() { 9 | } 10 | 11 | 12 | public int primitiveTypeReturningMethod() { 13 | return 0; 14 | } 15 | 16 | public Date complexTypeReturningMethod() { 17 | return new Date(); 18 | } 19 | 20 | public int overloadedMethod() { 21 | return 0; 22 | } 23 | 24 | public int overloadedMethod(int param) { 25 | return param; 26 | } 27 | 28 | public int overloadedMethod(int param1, int param2) { 29 | return param1 + param2; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/javarepl/expressions/AssignmentWithType.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | public final class AssignmentWithType extends Expression { 4 | private final java.lang.reflect.Type type; 5 | private final String key; 6 | private final String value; 7 | 8 | public AssignmentWithType(String source, java.lang.reflect.Type type, String key, String value) { 9 | super(source); 10 | 11 | this.type = type; 12 | this.key = key; 13 | this.value = value; 14 | } 15 | 16 | public String key() { 17 | return key; 18 | } 19 | 20 | public java.lang.reflect.Type type() { 21 | return type; 22 | } 23 | 24 | public String value() { 25 | return value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/javarepl/completion/TypeCompleterTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import org.junit.Test; 4 | 5 | import static javarepl.completion.CompleterTestHelper.*; 6 | import static javarepl.completion.TypeResolver.functions.defaultPackageResolver; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class TypeCompleterTest { 10 | @Test 11 | public void completesTypes() { 12 | TypeCompleter completer = new TypeCompleter(new TypeResolver(defaultPackageResolver())); 13 | 14 | assertThat(completer.apply("java.lang.Obj"), completesTo(candidatesValues("Object"), position(10))); 15 | assertThat(completer.apply("java.lang.Object"), completesTo(candidatesValues("Object"), position(10))); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.terminal", 3 | "version": "0.11.19", 4 | "main": [ 5 | "js/jquery.terminal.min.js", 6 | "js/jquery.mousewheel-min.js", 7 | "css/jquery.terminal.min.css" 8 | ], 9 | "description": "jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications.", 10 | "license": "MIT", 11 | "ignore": [ 12 | "examples", 13 | "CHANGELOG", 14 | "README.in", 15 | "bower.in", 16 | "Makefile", 17 | "manifest" 18 | ], 19 | "dependencies": { 20 | "jquery": "~2" 21 | }, 22 | "devDependencies": { 23 | "jasmine": "latest" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-fork-ribbon-css", 3 | "version": "0.2.0", 4 | "description": "\"Fork me on GitHub\" CSS ribbon", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/simonwhitaker/github-fork-ribbon-css.git" 11 | }, 12 | "keywords": [ 13 | "css", 14 | "fork", 15 | "GitHub", 16 | "ribbon" 17 | ], 18 | "author": "Simon Whitaker", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/simonwhitaker/github-fork-ribbon-css/issues" 22 | }, 23 | "homepage": "http://simonwhitaker.github.io/github-fork-ribbon-css/" 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/queue/delay.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../queue", 4 | "../effects" // Delay is optional because of this dependency 5 | ], function( jQuery ) { 6 | 7 | // Based off of the plugin by Clint Helfers, with permission. 8 | // http://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/ 9 | jQuery.fn.delay = function( time, type ) { 10 | time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; 11 | type = type || "fx"; 12 | 13 | return this.queue( type, function( next, hooks ) { 14 | var timeout = window.setTimeout( next, time ); 15 | hooks.stop = function() { 16 | window.clearTimeout( timeout ); 17 | }; 18 | } ); 19 | }; 20 | 21 | return jQuery.fn.delay; 22 | } ); 23 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/jquery.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./core", 3 | "./selector", 4 | "./traversing", 5 | "./callbacks", 6 | "./deferred", 7 | "./core/ready", 8 | "./data", 9 | "./queue", 10 | "./queue/delay", 11 | "./attributes", 12 | "./event", 13 | "./event/alias", 14 | "./event/focusin", 15 | "./manipulation", 16 | "./manipulation/_evalUrl", 17 | "./wrap", 18 | "./css", 19 | "./css/hiddenVisibleSelectors", 20 | "./serialize", 21 | "./ajax", 22 | "./ajax/xhr", 23 | "./ajax/script", 24 | "./ajax/jsonp", 25 | "./ajax/load", 26 | "./event/ajax", 27 | "./effects", 28 | "./effects/animatedSelector", 29 | "./offset", 30 | "./dimensions", 31 | "./deprecated", 32 | "./exports/amd" 33 | ], function( jQuery ) { 34 | 35 | return ( window.jQuery = window.$ = jQuery ); 36 | 37 | } ); 38 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ClearScreen.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.completion.CommandCompleter; 4 | import javarepl.console.ConsoleLogger; 5 | 6 | import static com.googlecode.totallylazy.Strings.startsWith; 7 | 8 | public final class ClearScreen extends Command { 9 | public static final String CLEAR_SCREEN_CMD = "CLEAR_SCREEN"; 10 | private static final String COMMAND = ":cls"; 11 | private final ConsoleLogger logger; 12 | 13 | public ClearScreen(ConsoleLogger logger) { 14 | super(COMMAND + " - clears screen", startsWith(COMMAND), new CommandCompleter(COMMAND)); 15 | this.logger = logger; 16 | } 17 | 18 | public void execute(String expression) { 19 | this.logger.reset(); 20 | this.logger.control(CLEAR_SCREEN_CMD); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/event/alias.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | 4 | "../event", 5 | "./trigger" 6 | ], function( jQuery ) { 7 | 8 | jQuery.each( ( "blur focus focusin focusout load resize scroll unload click dblclick " + 9 | "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + 10 | "change select submit keydown keypress keyup error contextmenu" ).split( " " ), 11 | function( i, name ) { 12 | 13 | // Handle event binding 14 | jQuery.fn[ name ] = function( data, fn ) { 15 | return arguments.length > 0 ? 16 | this.on( name, null, data, fn ) : 17 | this.trigger( name ); 18 | }; 19 | } ); 20 | 21 | jQuery.fn.extend( { 22 | hover: function( fnOver, fnOut ) { 23 | return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); 24 | } 25 | } ); 26 | 27 | } ); 28 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/deprecated.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "./core" 3 | ], function( jQuery ) { 4 | 5 | jQuery.fn.extend( { 6 | 7 | bind: function( types, data, fn ) { 8 | return this.on( types, null, data, fn ); 9 | }, 10 | unbind: function( types, fn ) { 11 | return this.off( types, null, fn ); 12 | }, 13 | 14 | delegate: function( selector, types, data, fn ) { 15 | return this.on( types, selector, data, fn ); 16 | }, 17 | undelegate: function( selector, types, fn ) { 18 | 19 | // ( namespace ) or ( selector, types [, fn] ) 20 | return arguments.length === 1 ? 21 | this.off( selector, "**" ) : 22 | this.off( types, selector || "**", fn ); 23 | }, 24 | size: function() { 25 | return this.length; 26 | } 27 | } ); 28 | 29 | jQuery.fn.andSelf = jQuery.fn.addBack; 30 | 31 | } ); 32 | 33 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Type.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | 4 | import com.googlecode.totallylazy.Option; 5 | 6 | public final class Type extends Expression { 7 | private final Option typePackage; 8 | private final String type; 9 | 10 | public Type(String source, Option typePackage, String type) { 11 | super(source); 12 | 13 | this.typePackage = typePackage; 14 | this.type = type; 15 | } 16 | 17 | public String key() { 18 | return type; 19 | } 20 | 21 | public Option typePackage() { 22 | return typePackage; 23 | } 24 | 25 | public String type() { 26 | return type; 27 | } 28 | 29 | public String canonicalName() { 30 | return (!typePackage.isEmpty() ? typePackage.get() + "." : "") + type; 31 | } 32 | } -------------------------------------------------------------------------------- /src/javarepl/completion/StringCompleter.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import static com.googlecode.totallylazy.Strings.startsWith; 6 | import static javarepl.completion.CompletionCandidate.asCompletionCandidate; 7 | 8 | public class StringCompleter extends Completer { 9 | private final Sequence candidates; 10 | 11 | public StringCompleter(Sequence candidates) { 12 | this.candidates = candidates; 13 | } 14 | 15 | @Override 16 | public CompletionResult call(String expression) throws Exception { 17 | int lastSpace = expression.lastIndexOf(" ") + 1; 18 | return new CompletionResult(expression, lastSpace, 19 | candidates.filter(startsWith(expression.substring(lastSpace))).map(asCompletionCandidate())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/javarepl/web/WebConsoleApplication.java: -------------------------------------------------------------------------------- 1 | package javarepl.web; 2 | 3 | import com.googlecode.utterlyidle.BasePath; 4 | import com.googlecode.utterlyidle.RestApplication; 5 | import javarepl.console.ui.ConsoleUiModule; 6 | 7 | import static com.googlecode.utterlyidle.annotations.AnnotatedBindings.annotatedClass; 8 | import static com.googlecode.utterlyidle.modules.Modules.applicationInstance; 9 | import static com.googlecode.utterlyidle.modules.Modules.bindingsModule; 10 | 11 | public class WebConsoleApplication extends RestApplication { 12 | public WebConsoleApplication(BasePath basePath) { 13 | super(basePath, 14 | bindingsModule(annotatedClass(WebConsoleResource.class)), 15 | applicationInstance(new WebConsole()) 16 | ); 17 | 18 | add(new ConsoleUiModule()); 19 | add(new WebConsoleModule()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/javarepl/testclasses/Constructors.java: -------------------------------------------------------------------------------- 1 | package javarepl.testclasses; 2 | 3 | public class Constructors { 4 | public static Object defaultAccessTestClass() { 5 | return new DefaultAccessTestClass(); 6 | } 7 | 8 | public static Object protectedAccessTestClass() { 9 | return new ProtectedAccessTestClass(); 10 | } 11 | 12 | public static Object privateAccessTestClass() { 13 | return new PrivateAccessTestClass(); 14 | } 15 | 16 | public static Object anonymousInnerBaseTestInterface() { 17 | return new BaseTestInterface() { 18 | }; 19 | } 20 | 21 | public static Object anonymousInnerGenericTestClass() { 22 | return new GenericTestClass() { 23 | }; 24 | } 25 | 26 | 27 | private static class PrivateAccessTestClass extends PublicBaseTestClass implements BaseTestInterface{} 28 | } 29 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ShowResult.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.predicates.Predicate; 4 | import javarepl.Evaluator; 5 | import javarepl.console.ConsoleLogger; 6 | 7 | public final class ShowResult extends Command { 8 | private final Evaluator evaluator; 9 | private final ConsoleLogger logger; 10 | 11 | public ShowResult(Evaluator evaluator, ConsoleLogger logger) { 12 | super(null, containsResult(evaluator), null); 13 | this.evaluator = evaluator; 14 | this.logger = logger; 15 | } 16 | 17 | public void execute(String expression) { 18 | logger.success(evaluator.result(expression).get().toString()); 19 | } 20 | 21 | private static Predicate containsResult(final Evaluator evaluator) { 22 | return expression -> !evaluator.result(expression).isEmpty(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/reflection/FieldReflection.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.Field; 7 | 8 | import static com.googlecode.totallylazy.Sequences.sequence; 9 | 10 | public final class FieldReflection extends MemberReflection { 11 | 12 | public FieldReflection(Field field) { 13 | super(field); 14 | } 15 | 16 | public Integer modifiers() { 17 | return member().getModifiers(); 18 | } 19 | 20 | public String name() { 21 | return member().getName(); 22 | } 23 | 24 | public Sequence annotations() { 25 | return sequence(member().getAnnotations()); 26 | } 27 | 28 | public Sequence declaredAnnotations() { 29 | return sequence(member().getDeclaredAnnotations()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/javarepl/reflection/MethodReflection.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.Method; 7 | 8 | import static com.googlecode.totallylazy.Sequences.sequence; 9 | 10 | public final class MethodReflection extends MemberReflection { 11 | public MethodReflection(Method method) { 12 | super(method); 13 | } 14 | 15 | public Integer modifiers() { 16 | return member().getModifiers(); 17 | } 18 | 19 | public String name() { 20 | return member().getName(); 21 | } 22 | 23 | public Sequence annotations() { 24 | return sequence(member().getAnnotations()); 25 | } 26 | 27 | public Sequence declaredAnnotations() { 28 | return sequence(member().getDeclaredAnnotations()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/javarepl/EvaluationTemplate.java: -------------------------------------------------------------------------------- 1 | package javarepl; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | 5 | import static com.googlecode.totallylazy.predicates.Predicates.equalTo; 6 | import static com.googlecode.totallylazy.predicates.Predicates.where; 7 | 8 | @SuppressWarnings("unused") 9 | public abstract class EvaluationTemplate { 10 | private final EvaluationContext context; 11 | 12 | public EvaluationTemplate(EvaluationContext context) { 13 | this.context = context; 14 | } 15 | 16 | @SuppressWarnings("unchecked") 17 | public final T valueOf(final String key) { 18 | Option result = context.results() 19 | .find(where(Result::key, equalTo(key))); 20 | 21 | if (result.isEmpty()) 22 | throw new IllegalArgumentException("Result '" + key + "' not found"); 23 | 24 | return (T) result.get().value(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/underscore/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "underscore", 3 | "version": "1.8.3", 4 | "main": "underscore.js", 5 | "keywords": [ 6 | "util", 7 | "functional", 8 | "server", 9 | "client", 10 | "browser" 11 | ], 12 | "ignore": [ 13 | "docs", 14 | "test", 15 | "*.yml", 16 | "CNAME", 17 | "index.html", 18 | "favicon.ico", 19 | "CONTRIBUTING.md", 20 | ".*", 21 | "component.json", 22 | "package.json", 23 | "karma.*" 24 | ], 25 | "homepage": "https://github.com/jashkenas/underscore", 26 | "_release": "1.8.3", 27 | "_resolution": { 28 | "type": "version", 29 | "tag": "1.8.3", 30 | "commit": "e4743ab712b8ab42ad4ccb48b155034d02394e4d" 31 | }, 32 | "_source": "https://github.com/jashkenas/underscore.git", 33 | "_target": "^1.8.3", 34 | "_originalSource": "underscore", 35 | "_direct": true 36 | } -------------------------------------------------------------------------------- /src/javarepl/console/rest/RestConsoleExpressionReader.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.rest; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import com.googlecode.totallylazy.Sequence; 5 | import com.googlecode.totallylazy.Sequences; 6 | 7 | import static com.googlecode.totallylazy.Option.none; 8 | import static com.googlecode.totallylazy.Option.some; 9 | import static javarepl.ExpressionReader.expressionIsTerminated; 10 | 11 | public class RestConsoleExpressionReader { 12 | private Sequence lines = Sequences.empty(); 13 | 14 | public Option readExpression(String line) { 15 | lines = lines.append(line); 16 | if (expressionIsTerminated(lines)) { 17 | Option result = some(lines.toString("\n")); 18 | lines = Sequences.empty(); 19 | return result; 20 | } else { 21 | return none(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/ConsoleResult.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import static com.googlecode.totallylazy.Sequences.empty; 6 | 7 | public class ConsoleResult { 8 | private final String expression; 9 | private final Sequence logs; 10 | 11 | public ConsoleResult(String expression, Sequence logs) { 12 | this.expression = expression; 13 | this.logs = logs; 14 | } 15 | 16 | public String expression() { 17 | return expression; 18 | } 19 | 20 | public Sequence logs() { 21 | return logs; 22 | } 23 | 24 | public static ConsoleResult emptyResult() { 25 | return new ConsoleResult("", empty(ConsoleLog.class)); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return expression + " => " + logs.toString("(", ", ", ")"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ShowLastSource.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.Evaluator; 4 | import javarepl.completion.CommandCompleter; 5 | import javarepl.console.ConsoleLogger; 6 | 7 | import static com.googlecode.totallylazy.predicates.Predicates.equalTo; 8 | 9 | public final class ShowLastSource extends Command { 10 | private static final String COMMAND = ":src"; 11 | 12 | private final Evaluator evaluator; 13 | private final ConsoleLogger logger; 14 | 15 | public ShowLastSource(Evaluator evaluator, ConsoleLogger logger) { 16 | super(COMMAND + " - show source of last evaluated expression", equalTo(COMMAND), new CommandCompleter(COMMAND)); 17 | this.evaluator = evaluator; 18 | this.logger = logger; 19 | } 20 | 21 | public void execute(String expression) { 22 | logger.success(evaluator.lastSource().getOrElse("No source")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/wrapMap.js: -------------------------------------------------------------------------------- 1 | define( function() { 2 | 3 | // We have to close these tags to support XHTML (#13200) 4 | var wrapMap = { 5 | 6 | // Support: IE9 7 | option: [ 1, "" ], 8 | 9 | // XHTML parsers do not magically insert elements in the 10 | // same way that tag soup parsers do. So we cannot shorten 11 | // this by omitting or other required elements. 12 | thead: [ 1, "", "
" ], 13 | col: [ 2, "", "
" ], 14 | tr: [ 2, "", "
" ], 15 | td: [ 3, "", "
" ], 16 | 17 | _default: [ 0, "", "" ] 18 | }; 19 | 20 | // Support: IE9 21 | wrapMap.optgroup = wrapMap.option; 22 | 23 | wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; 24 | wrapMap.th = wrapMap.td; 25 | 26 | return wrapMap; 27 | } ); 28 | -------------------------------------------------------------------------------- /src/javarepl/reflection/ConstructorReflection.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.Constructor; 7 | 8 | import static com.googlecode.totallylazy.Sequences.sequence; 9 | 10 | public final class ConstructorReflection extends MemberReflection> { 11 | public ConstructorReflection(Constructor constructor) { 12 | super(constructor); 13 | } 14 | 15 | public Integer modifiers() { 16 | return member().getModifiers(); 17 | } 18 | 19 | public String name() { 20 | return member().getName(); 21 | } 22 | 23 | public Sequence annotations() { 24 | return sequence(member().getAnnotations()); 25 | } 26 | 27 | public Sequence declaredAnnotations() { 28 | return sequence(member().getDeclaredAnnotations()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ResetAllEvaluations.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.Evaluator; 4 | import javarepl.completion.CommandCompleter; 5 | import javarepl.console.ConsoleLogger; 6 | 7 | import static com.googlecode.totallylazy.predicates.Predicates.equalTo; 8 | 9 | public final class ResetAllEvaluations extends Command { 10 | private static final String COMMAND = ":reset"; 11 | private final Evaluator evaluator; 12 | private final ConsoleLogger logger; 13 | 14 | public ResetAllEvaluations(Evaluator evaluator, ConsoleLogger logger) { 15 | super(COMMAND + " - resets environment to initial state", equalTo(COMMAND), new CommandCompleter(COMMAND)); 16 | this.evaluator = evaluator; 17 | this.logger = logger; 18 | } 19 | 20 | public void execute(String expression) { 21 | evaluator.reset(); 22 | logger.success("All variables has been cleared"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/QuitApplication.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.Evaluator; 4 | import javarepl.completion.CommandCompleter; 5 | import javarepl.console.ConsoleLogger; 6 | 7 | import static com.googlecode.totallylazy.predicates.Predicates.equalTo; 8 | 9 | public final class QuitApplication extends Command { 10 | private static final String COMMAND = ":quit"; 11 | private final Evaluator evaluator; 12 | private final ConsoleLogger logger; 13 | 14 | public QuitApplication(Evaluator evaluator, ConsoleLogger logger) { 15 | super(COMMAND + " - quit application", equalTo(COMMAND).or(equalTo(null)), new CommandCompleter(COMMAND)); 16 | this.evaluator = evaluator; 17 | this.logger = logger; 18 | } 19 | 20 | public void execute(String expression) { 21 | logger.success("Terminating..."); 22 | evaluator.clearOutputDirectory(); 23 | System.exit(0); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/javarepl/console/rest/RestConsoleApplication.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.rest; 2 | 3 | import com.googlecode.utterlyidle.BasePath; 4 | import com.googlecode.utterlyidle.RestApplication; 5 | import javarepl.console.ui.ConsoleUiModule; 6 | 7 | import static com.googlecode.utterlyidle.annotations.AnnotatedBindings.annotatedClass; 8 | import static com.googlecode.utterlyidle.modules.Modules.applicationInstance; 9 | import static com.googlecode.utterlyidle.modules.Modules.bindingsModule; 10 | 11 | public class RestConsoleApplication extends RestApplication { 12 | public RestConsoleApplication(BasePath basePath, RestConsole console) { 13 | super(basePath, 14 | bindingsModule(annotatedClass(RestConsoleResource.class)), 15 | applicationInstance(console), 16 | applicationInstance(new RestConsoleExpressionReader())); 17 | 18 | add(new ConsoleUiModule()); 19 | add(new RestConsoleModule()); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/javarepl/completion/AggregateCompleterTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Sequences.sequence; 6 | import static javarepl.completion.CompleterTestHelper.*; 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | 9 | public class AggregateCompleterTest { 10 | 11 | @Test 12 | public void shouldAggregateCompletions() { 13 | AggregateCompleter completer = new AggregateCompleter(sequence( 14 | new StringCompleter(sequence("text", "someText", "otherText")), 15 | new CommandCompleter("someCommand", sequence("param1", "param2")))); 16 | 17 | assertThat(completer.apply("so"), completesTo(candidatesValues("someText", "someCommand"), position(0))); 18 | assertThat(completer.apply("prefix so"), completesTo(candidatesValues("someText"), position(7))); 19 | assertThat(completer.apply("invalid"), completesTo(candidatesValues(), position(0))); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ShowHelp.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.completion.CommandCompleter; 4 | import javarepl.console.ConsoleLogger; 5 | 6 | import static com.googlecode.totallylazy.functions.Callables.asString; 7 | import static com.googlecode.totallylazy.predicates.Predicates.*; 8 | import static javarepl.Utils.listValues; 9 | 10 | public final class ShowHelp extends Command { 11 | private static final String COMMAND = ":help"; 12 | private final Commands commands; 13 | private final ConsoleLogger logger; 14 | 15 | public ShowHelp(Commands commands, ConsoleLogger logger) { 16 | super(COMMAND + " - shows this help", equalTo(COMMAND), new CommandCompleter(COMMAND)); 17 | this.commands = commands; 18 | this.logger = logger; 19 | } 20 | 21 | public void execute(String expression) { 22 | logger.success(listValues("Available commands", commands.userCommands().map(asString()).filter(not(nullValue())))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-fork-ribbon-css", 3 | "version": "0.2.0", 4 | "homepage": "https://simonwhitaker.github.io/github-fork-ribbon-css/", 5 | "authors": [ 6 | "Simon Whitaker" 7 | ], 8 | "description": "\"Fork me on GitHub\" CSS ribbon", 9 | "main": [ 10 | "gh-fork-ribbon.css", 11 | "gh-fork-ribbon.ie.css" 12 | ], 13 | "keywords": [ 14 | "css", 15 | "fork", 16 | "GitHub", 17 | "ribbon" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "node_modules", 23 | "bower_components", 24 | "test", 25 | "tests" 26 | ], 27 | "_release": "0.2.0", 28 | "_resolution": { 29 | "type": "version", 30 | "tag": "0.2.0", 31 | "commit": "6a52239eb39b3aebec7da47baf2f9695f523bb11" 32 | }, 33 | "_source": "https://github.com/simonwhitaker/github-fork-ribbon-css.git", 34 | "_target": "^0.2.0", 35 | "_originalSource": "github-fork-ribbon-css", 36 | "_direct": true 37 | } -------------------------------------------------------------------------------- /test/javarepl/completion/StringCompleterTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Sequences.sequence; 6 | import static javarepl.completion.CompleterTestHelper.*; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class StringCompleterTest { 10 | @Test 11 | public void shouldCompleteStringFromGivenCandidates() { 12 | StringCompleter completer = new StringCompleter(sequence("some string", "some other", "another")); 13 | 14 | assertThat(completer.apply(""), completesTo(candidatesValues("some string", "some other", "another"), position(0))); 15 | assertThat(completer.apply("str"), completesTo(candidatesValues(), position(0))); 16 | assertThat(completer.apply("prefix "), completesTo(candidatesValues("some string", "some other", "another"), position(7))); 17 | assertThat(completer.apply("prefix some"), completesTo(candidatesValues("some string", "some other"), position(7))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/javarepl/reflection/MemberReflection.java: -------------------------------------------------------------------------------- 1 | package javarepl.reflection; 2 | 3 | public abstract class MemberReflection implements AnnotatedReflection { 4 | 5 | private final T member; 6 | 7 | MemberReflection(T member) { 8 | this.member = member; 9 | } 10 | 11 | public final T member() { 12 | return member; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return getClass().getSimpleName() + "(" + member() + ")"; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return (member() != null ? member().hashCode() : 0); 23 | } 24 | 25 | @Override 26 | public boolean equals(Object other) { 27 | return other.getClass().equals(getClass()) && 28 | member().getClass().isInstance(((MemberReflection) other).member()) && 29 | (member() != null && member().equals(((MemberReflection) other).member())); 30 | } 31 | 32 | public abstract Integer modifiers(); 33 | 34 | public abstract String name(); 35 | } 36 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/package.in: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.terminal", 3 | "version": "{{VER}}", 4 | "description": "jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications.", 5 | "main": "js/jquery.terminal.js", 6 | "keywords": [ 7 | "terminal", 8 | "emulator", 9 | "prompt", 10 | "console", 11 | "keyboard", 12 | "type", 13 | "rpc", 14 | "input", 15 | "ui" 16 | ], 17 | "author": "Jakub Jankiewicz (http://jakub.jankiewi.cz)", 18 | "license": "MIT", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/jcubic/jquery.terminal.git" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/jcubic/jquery.terminal/issues" 25 | }, 26 | "homepage": "http://terminal.jcubic.pl", 27 | "dependencies": { 28 | "jquery": "^2.1.4" 29 | }, 30 | "devDependencies": { 31 | "istanbul": "^0.4.3", 32 | "jasmine": "^2.4.1", 33 | "jasmine-node": "^1.14.5", 34 | "jsdom": "^3.1.2" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.terminal", 3 | "version": "0.11.19", 4 | "description": "jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications.", 5 | "main": "js/jquery.terminal.js", 6 | "keywords": [ 7 | "terminal", 8 | "emulator", 9 | "prompt", 10 | "console", 11 | "keyboard", 12 | "type", 13 | "rpc", 14 | "input", 15 | "ui" 16 | ], 17 | "author": "Jakub Jankiewicz (http://jakub.jankiewi.cz)", 18 | "license": "MIT", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/jcubic/jquery.terminal.git" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/jcubic/jquery.terminal/issues" 25 | }, 26 | "homepage": "http://terminal.jcubic.pl", 27 | "dependencies": { 28 | "jquery": "^2.1.4" 29 | }, 30 | "devDependencies": { 31 | "istanbul": "^0.4.3", 32 | "jasmine": "^2.4.1", 33 | "jasmine-node": "^1.14.5", 34 | "jsdom": "^3.1.2" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/terminal.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "terminal", 3 | "title": "jQuery Terminal Emulator", 4 | "description": "jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications.", 5 | "version": "0.11.19", 6 | "keywords": [ 7 | "terminal", "emulator", "prompt", "console", "keyboard", "type", "rpc", "input", "ui" 8 | ], 9 | "author": { 10 | "name": "Jakub Jankiewicz", 11 | "email": "jcubic@onet.pl", 12 | "url": "http://jcubic.pl" 13 | }, 14 | "licenses": [{ 15 | "type": "MIT", 16 | "url": "http://opensource.org/licenses/MIT" 17 | }], 18 | "homepage": "http://terminal.jcubic.pl/", 19 | "bugs": "https://github.com/jcubic/jquery.terminal/issues", 20 | "demo": "http://terminal.jcubic.pl/#demo", 21 | "docs": "http://terminal.jcubic.pl/api_reference.php", 22 | "download": "https://github.com/jcubic/jquery.terminal/releases", 23 | "dependencies": { 24 | "jquery": ">=1.5" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/js/jquery.mousewheel-min.js: -------------------------------------------------------------------------------- 1 | (function(c){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),e=0,h=0,f=0;a=c.event.fix(b);a.type="mousewheel";if(b.wheelDelta)e=b.wheelDelta/120;if(b.detail)e=-b.detail/3;f=e;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){f=0;h=-1*e}if(b.wheelDeltaY!==undefined)f=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,e,h,f);return(c.event.dispatch||c.event.handle).apply(this,i)}var d=["DOMMouseScroll","mousewheel"];if(c.event.fixHooks)for(var j=d.length;j;)c.event.fixHooks[d[--j]]= 2 | c.event.mouseHooks;c.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=d.length;a;)this.addEventListener(d[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=d.length;a;)this.removeEventListener(d[--a],g,false);else this.onmousewheel=null}};c.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery); 3 | -------------------------------------------------------------------------------- /src/javarepl/completion/Completers.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import static com.googlecode.totallylazy.Sequences.sequence; 4 | import static com.googlecode.totallylazy.comparators.Comparators.ascending; 5 | 6 | public final class Completers { 7 | public static Completer javaKeywordCompleter() { 8 | return new StringCompleter( 9 | sequence("abstract", "assert", "boolean", "break", "byte", "case", "catch", 10 | "char", "class", "continue", "default", "double", "do", "else", "enum", 11 | "extends", "false", "final", "finally", "float", "for", "if", "implements", 12 | "import", "instanceof", "int", "interface", "long", "native", "new", "null", 13 | "package", "private", "protected", "public", "return", "short", "static", 14 | "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", 15 | "transient", "true", "try", "void", "volatile", "while").sort(ascending(String.class))); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.terminal", 3 | "version": "0.11.19", 4 | "main": [ 5 | "js/jquery.terminal.min.js", 6 | "js/jquery.mousewheel-min.js", 7 | "css/jquery.terminal.min.css" 8 | ], 9 | "description": "jQuery Terminal Emulator is a plugin for creating command line interpreters in your applications.", 10 | "license": "MIT", 11 | "ignore": [ 12 | "examples", 13 | "CHANGELOG", 14 | "README.in", 15 | "bower.in", 16 | "Makefile", 17 | "manifest" 18 | ], 19 | "dependencies": { 20 | "jquery": "~2" 21 | }, 22 | "devDependencies": { 23 | "jasmine": "latest" 24 | }, 25 | "homepage": "https://github.com/jcubic/jquery.terminal", 26 | "_release": "0.11.19", 27 | "_resolution": { 28 | "type": "version", 29 | "tag": "0.11.19", 30 | "commit": "d6cff3b93ce8f863a3a8d9bab82e80159279e617" 31 | }, 32 | "_source": "https://github.com/jcubic/jquery.terminal.git", 33 | "_target": "^0.11.19", 34 | "_originalSource": "jquery.terminal", 35 | "_direct": true 36 | } -------------------------------------------------------------------------------- /src/javarepl/console/DelegatingConsole.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import javarepl.completion.CompletionResult; 4 | import javarepl.rendering.ExpressionTemplate; 5 | 6 | public abstract class DelegatingConsole implements Console { 7 | private final Console delegate; 8 | 9 | protected DelegatingConsole(Console delegate) { 10 | this.delegate = delegate; 11 | } 12 | 13 | public ConsoleResult execute(String expression) { 14 | return delegate.execute(expression); 15 | } 16 | 17 | public CompletionResult completion(String expression) { 18 | return delegate.completion(expression); 19 | } 20 | 21 | public ExpressionTemplate template(String expression) { 22 | return delegate.template(expression); 23 | } 24 | 25 | public ConsoleStatus status() { 26 | return delegate.status(); 27 | } 28 | 29 | public ConsoleHistory history() { 30 | return delegate.history(); 31 | } 32 | 33 | public void shutdown() { 34 | delegate.shutdown(); 35 | } 36 | 37 | public void start() { 38 | delegate.start(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/attributes/support.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../var/document", 3 | "../var/support" 4 | ], function( document, support ) { 5 | 6 | ( function() { 7 | var input = document.createElement( "input" ), 8 | select = document.createElement( "select" ), 9 | opt = select.appendChild( document.createElement( "option" ) ); 10 | 11 | input.type = "checkbox"; 12 | 13 | // Support: iOS<=5.1, Android<=4.2+ 14 | // Default value for a checkbox should be "on" 15 | support.checkOn = input.value !== ""; 16 | 17 | // Support: IE<=11+ 18 | // Must access selectedIndex to make default options select 19 | support.optSelected = opt.selected; 20 | 21 | // Support: Android<=2.3 22 | // Options inside disabled selects are incorrectly marked as disabled 23 | select.disabled = true; 24 | support.optDisabled = !opt.disabled; 25 | 26 | // Support: IE<=11+ 27 | // An input loses its value after becoming a radio 28 | input = document.createElement( "input" ); 29 | input.value = "t"; 30 | input.type = "radio"; 31 | support.radioValue = input.value === "t"; 32 | } )(); 33 | 34 | return support; 35 | 36 | } ); 37 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/exports/amd.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core" 3 | ], function( jQuery ) { 4 | 5 | // Register as a named AMD module, since jQuery can be concatenated with other 6 | // files that may use define, but not via a proper concatenation script that 7 | // understands anonymous AMD modules. A named AMD is safest and most robust 8 | // way to register. Lowercase jquery is used because AMD module names are 9 | // derived from file names, and jQuery is normally delivered in a lowercase 10 | // file name. Do this after creating the global so that if an AMD module wants 11 | // to call noConflict to hide this version of jQuery, it will work. 12 | 13 | // Note that for maximum portability, libraries that are not jQuery should 14 | // declare themselves as anonymous modules, and avoid setting a global if an 15 | // AMD loader is present. jQuery is a special case. For more information, see 16 | // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon 17 | 18 | if ( typeof define === "function" && define.amd ) { 19 | define( "jquery", [], function() { 20 | return jQuery; 21 | } ); 22 | } 23 | 24 | } ); 25 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Expression.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | import com.googlecode.totallylazy.functions.Function1; 4 | 5 | public abstract class Expression { 6 | private final String source; 7 | 8 | protected Expression(String source) { 9 | this.source = source; 10 | } 11 | 12 | public abstract String key(); 13 | 14 | public String source() { 15 | return source; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return getClass().getSimpleName() + "(" + source + ")"; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | return (source != null ? source.hashCode() : 0); 26 | } 27 | 28 | @Override 29 | public boolean equals(Object other) { 30 | return other instanceof Expression && 31 | other.getClass().equals(getClass()) && 32 | (source != null && source.equals(((Expression) other).source)); 33 | } 34 | 35 | public static final class functions { 36 | public static Function1 source() { 37 | return Expression::source; 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /test/javarepl/console/ConsoleHistoryTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import com.googlecode.totallylazy.Files; 4 | import org.junit.Test; 5 | 6 | import java.io.File; 7 | 8 | import static com.googlecode.totallylazy.Option.some; 9 | import static com.googlecode.totallylazy.Strings.replaceAll; 10 | import static com.googlecode.totallylazy.predicates.Predicates.never; 11 | import static javarepl.console.ConsoleHistory.emptyHistory; 12 | import static javarepl.console.ConsoleHistory.historyFromFile; 13 | import static org.hamcrest.Matchers.is; 14 | import static org.junit.Assert.assertThat; 15 | 16 | public class ConsoleHistoryTest { 17 | @Test 18 | public void savesAndLoadsMultilineHistory() { 19 | File historyFile = Files.temporaryFile(); 20 | ConsoleHistory history = emptyHistory(never(), some(historyFile)) 21 | .add("multiline\nexpression") 22 | .add("single line expression") 23 | .add("another\nmultiline\nexpression"); 24 | 25 | history.save(); 26 | 27 | assertThat(historyFromFile(never(), some(historyFile)).items(), is(history.items().map(replaceAll("\n", " ")))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/javarepl/EvaluationClassLoader.java: -------------------------------------------------------------------------------- 1 | package javarepl; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import java.net.URL; 6 | import java.net.URLClassLoader; 7 | 8 | import static com.googlecode.totallylazy.Sequences.sequence; 9 | import static com.googlecode.totallylazy.io.URLs.toURL; 10 | 11 | public class EvaluationClassLoader extends URLClassLoader { 12 | private Sequence registeredUrls = sequence(); 13 | 14 | private EvaluationClassLoader(EvaluationContext context) { 15 | super(new URL[]{toURL().apply(context.outputDirectory())}); 16 | } 17 | 18 | public static EvaluationClassLoader evaluationClassLoader(EvaluationContext context) { 19 | return new EvaluationClassLoader(context); 20 | } 21 | 22 | public void registerURL(URL url) { 23 | if (!sequence(getURLs()).contains(url)) { 24 | addURL(url); 25 | registeredUrls = registeredUrls.append(url); 26 | } 27 | } 28 | 29 | public Sequence registeredUrls() { 30 | return registeredUrls; 31 | } 32 | 33 | 34 | 35 | public boolean isClassLoaded(String name) { 36 | return findLoadedClass(name) != null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Simon Whitaker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jakub Jankiewicz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/manipulation/support.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../var/document", 3 | "../var/support" 4 | ], function( document, support ) { 5 | 6 | ( function() { 7 | var fragment = document.createDocumentFragment(), 8 | div = fragment.appendChild( document.createElement( "div" ) ), 9 | input = document.createElement( "input" ); 10 | 11 | // Support: Android 4.0-4.3, Safari<=5.1 12 | // Check state lost if the name is set (#11217) 13 | // Support: Windows Web Apps (WWA) 14 | // `name` and `type` must use .setAttribute for WWA (#14901) 15 | input.setAttribute( "type", "radio" ); 16 | input.setAttribute( "checked", "checked" ); 17 | input.setAttribute( "name", "t" ); 18 | 19 | div.appendChild( input ); 20 | 21 | // Support: Safari<=5.1, Android<4.2 22 | // Older WebKit doesn't clone checked state correctly in fragments 23 | support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked; 24 | 25 | // Support: IE<=11+ 26 | // Make sure textarea (and checkbox) defaultValue is properly cloned 27 | div.innerHTML = ""; 28 | support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; 29 | } )(); 30 | 31 | return support; 32 | 33 | } ); 34 | -------------------------------------------------------------------------------- /src/javarepl/expressions/Method.java: -------------------------------------------------------------------------------- 1 | package javarepl.expressions; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import javarepl.rendering.TypeRenderer; 5 | 6 | import static javarepl.Utils.canonicalName; 7 | 8 | public final class Method extends Expression { 9 | private final java.lang.reflect.Type type; 10 | private final String name; 11 | private final Sequence> arguments; 12 | 13 | public Method(String source, java.lang.reflect.Type type, String name, Sequence> arguments) { 14 | super(source); 15 | 16 | this.type = type; 17 | this.name = name; 18 | this.arguments = arguments; 19 | } 20 | 21 | public String name() { 22 | return name; 23 | } 24 | 25 | public java.lang.reflect.Type type() { 26 | return type; 27 | } 28 | 29 | public Sequence> arguments() { 30 | return arguments; 31 | } 32 | 33 | public String signature() { 34 | return TypeRenderer.renderType(type) + " " + name + arguments.map(canonicalName()).toString("(", ", ", ")"); 35 | } 36 | 37 | public String key() { 38 | return name + arguments.map(canonicalName()).toString(", "); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bin/docker-commands.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | docker pull albertlatacz/java-repl 4 | docker build -t albertlatacz/java-repl:308 -t albertlatacz/javarepl --build-arg JAVA_REPL_VERSION=308 . 5 | docker login -u="albertlatacz" -p=""; 6 | docker push albertlatacz/java-repl 7 | 8 | 9 | docker stop $(docker ps -q --filter ancestor=albertlatacz/java-repl) 10 | docker pull albertlatacz/java-repl 11 | docker start $(docker create -p 8090:8090 albertlatacz/java-repl) 12 | 13 | 14 | docker images --filter dangling=true #lists all images that are dangling and has no pointer to it 15 | docker rmi `docker images --filter dangling=true -q` #Removes all those images. 16 | 17 | #Kill exited containers 18 | sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm 19 | 20 | 21 | docker ps -a # all containers 22 | 23 | 24 | # clean up all exited and dangling 25 | docker rm $(docker ps -q -f status=exited) 26 | docker rmi $(docker images -q -f dangling=true) 27 | 28 | docker rmi $(docker images -q albertlatacz/java-repl) 29 | 30 | docker run --restart=always -d -p 8090:8090 albertlatacz/java-repl 31 | 32 | curl 'https://registry.hub.docker.com/v2/repositories/albertlatacz/java-repl/tags/' | jq '.results[].name' | wc -w #count tags -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/core/parseHTML.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../var/document", 4 | "./var/rsingleTag", 5 | "../manipulation/buildFragment" 6 | ], function( jQuery, document, rsingleTag, buildFragment ) { 7 | 8 | // Argument "data" should be string of html 9 | // context (optional): If specified, the fragment will be created in this context, 10 | // defaults to document 11 | // keepScripts (optional): If true, will include scripts passed in the html string 12 | jQuery.parseHTML = function( data, context, keepScripts ) { 13 | if ( !data || typeof data !== "string" ) { 14 | return null; 15 | } 16 | if ( typeof context === "boolean" ) { 17 | keepScripts = context; 18 | context = false; 19 | } 20 | context = context || document; 21 | 22 | var parsed = rsingleTag.exec( data ), 23 | scripts = !keepScripts && []; 24 | 25 | // Single tag 26 | if ( parsed ) { 27 | return [ context.createElement( parsed[ 1 ] ) ]; 28 | } 29 | 30 | parsed = buildFragment( [ data ], context, scripts ); 31 | 32 | if ( scripts && scripts.length ) { 33 | jQuery( scripts ).remove(); 34 | } 35 | 36 | return jQuery.merge( [], parsed.childNodes ); 37 | }; 38 | 39 | return jQuery.parseHTML; 40 | 41 | } ); 42 | -------------------------------------------------------------------------------- /test/javarepl/ExpressionReaderTest.java: -------------------------------------------------------------------------------- 1 | package javarepl; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Option.none; 6 | import static com.googlecode.totallylazy.Option.some; 7 | import static javarepl.ExpressionReader.lines; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class ExpressionReaderTest { 12 | 13 | @Test 14 | public void shouldTerminateCorrectlyWhenReadingTheExpression() { 15 | assertThat(new ExpressionReader(lines("int ", "x = 12;")).readExpression(), is(some("int"))); 16 | assertThat(new ExpressionReader(lines("{", "int x = 12;", "}")).readExpression(), is(some("{\nint x = 12;\n}"))); 17 | assertThat(new ExpressionReader(lines("{", "int x = 12;", "}")).readExpression(), is(some("{\nint x = 12;\n}"))); 18 | assertThat(new ExpressionReader(lines("{", "int[]", "x = new int[]{12, 22};", "}")).readExpression(), is(some("{\nint[]\nx = new int[]{12, 22};\n}"))); 19 | assertThat(new ExpressionReader(lines("{", "int", "", "", "}")).readExpression(), is(some("{\nint"))); 20 | assertThat(new ExpressionReader(lines()).readExpression(), is(none(String.class))); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/SearchHistory.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.completion.CommandCompleter; 4 | import javarepl.console.ConsoleHistory; 5 | import javarepl.console.ConsoleLogger; 6 | 7 | import static com.googlecode.totallylazy.Strings.contains; 8 | import static com.googlecode.totallylazy.Strings.startsWith; 9 | import static javarepl.Utils.listValues; 10 | import static javarepl.console.commands.ShowHistory.numberedHistory; 11 | 12 | public final class SearchHistory extends Command { 13 | private static final String COMMAND = ":h?"; 14 | private final ConsoleLogger logger; 15 | private final ConsoleHistory history; 16 | 17 | public SearchHistory(ConsoleLogger logger, ConsoleHistory history) { 18 | super(COMMAND + " - searches the history", startsWith(COMMAND), new CommandCompleter(COMMAND)); 19 | this.logger = logger; 20 | this.history = history; 21 | } 22 | 23 | public void execute(String expression) { 24 | String searchTerm = parseStringCommand(expression).second().getOrElse(""); 25 | logger.success(listValues("History search for '" + searchTerm + "'", numberedHistory(history).filter(contains(searchTerm)))); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/underscore/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative 2 | Reporters & Editors 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/README.md: -------------------------------------------------------------------------------- 1 | # "Fork me on GitHub" CSS ribbon 2 | 3 | This is a recreation of the [Fork me on GitHub ribbon](https://github.com/blog/273-github-ribbons) 4 | in CSS, hence resolution-independent. 5 | 6 | ## Using "Fork me on GitHub" CSS ribbon with a CDN 7 | 8 | You can use github-fork-ribbon-css without installation via [cdnjs.com](https://cdnjs.com/libraries/github-fork-ribbon-css). 9 | 10 | Copy the following code into the `` of your page: 11 | 12 | 13 | ```html 14 | 15 | 18 | ``` 19 | 20 | And this into the `` of your page: 21 | 22 | ```html 23 | Fork me on GitHub 24 | ``` 25 | 26 | See 'em in action! 27 | 28 | Feel free to fork, tweak and send me a pull request. 29 | 30 | Note: this project is not sponsored or in any way endorsed by GitHub. 31 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/showHide.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../data/var/dataPriv" 3 | ], function( dataPriv ) { 4 | 5 | function showHide( elements, show ) { 6 | var display, elem, 7 | values = [], 8 | index = 0, 9 | length = elements.length; 10 | 11 | // Determine new display value for elements that need to change 12 | for ( ; index < length; index++ ) { 13 | elem = elements[ index ]; 14 | if ( !elem.style ) { 15 | continue; 16 | } 17 | 18 | display = elem.style.display; 19 | if ( show ) { 20 | if ( display === "none" ) { 21 | 22 | // Restore a pre-hide() value if we have one 23 | values[ index ] = dataPriv.get( elem, "display" ) || ""; 24 | } 25 | } else { 26 | if ( display !== "none" ) { 27 | values[ index ] = "none"; 28 | 29 | // Remember the value we're replacing 30 | dataPriv.set( elem, "display", display ); 31 | } 32 | } 33 | } 34 | 35 | // Set the display of the elements in a second loop 36 | // to avoid the constant reflow 37 | for ( index = 0; index < length; index++ ) { 38 | if ( values[ index ] != null ) { 39 | elements[ index ].style.display = values[ index ]; 40 | } 41 | } 42 | 43 | return elements; 44 | } 45 | 46 | return showHide; 47 | 48 | } ); 49 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/Commands.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | 4 | import com.googlecode.totallylazy.Sequence; 5 | import com.googlecode.totallylazy.Sequences; 6 | import com.googlecode.yadic.Container; 7 | import javarepl.console.ConsoleConfig; 8 | 9 | import static com.googlecode.totallylazy.Sequences.sequence; 10 | 11 | public final class Commands { 12 | private final Container context; 13 | 14 | private Sequence> commands = Sequences.empty(); 15 | 16 | public Commands(Container context, ConsoleConfig config) { 17 | this.context = context; 18 | this.commands = config.commands; 19 | } 20 | 21 | public Sequence allCommands() { 22 | return userCommands() 23 | .join(commandInstances(sequence( 24 | NotAValidCommand.class, 25 | ShowResult.class, 26 | EvaluateExpression.class))); 27 | } 28 | 29 | Sequence userCommands() { 30 | return commandInstances(commands.cons(ShowHelp.class)); 31 | } 32 | 33 | private Sequence commandInstances(Sequence> commands) { 34 | return commands.map(context::create); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/javarepl/console/commands/CommandTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Option.none; 6 | import static com.googlecode.totallylazy.Option.some; 7 | import static com.googlecode.totallylazy.Pair.pair; 8 | import static javarepl.console.commands.Command.parseNumericCommand; 9 | import static javarepl.console.commands.Command.parseStringCommand; 10 | import static org.hamcrest.core.Is.is; 11 | import static org.junit.Assert.assertThat; 12 | 13 | public class CommandTest { 14 | 15 | @Test 16 | public void shouldParseNumericCommand() { 17 | assertThat(parseNumericCommand(":cmd 12"), is(pair(":cmd", some(12)))); 18 | assertThat(parseNumericCommand(":cmd hello"), is(pair(":cmd", none(Integer.class)))); 19 | assertThat(parseNumericCommand(":cmd"), is(pair(":cmd", none(Integer.class)))); 20 | } 21 | 22 | @Test 23 | public void shouldParseStringCommand() { 24 | assertThat(parseStringCommand(":cmd 12"), is(pair(":cmd", some("12")))); 25 | assertThat(parseStringCommand(":cmd some params "), is(pair(":cmd", some("some params")))); 26 | assertThat(parseStringCommand(":cmd"), is(pair(":cmd", none(String.class)))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/javarepl/completion/CommandCompleterTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import org.junit.Test; 4 | 5 | import static com.googlecode.totallylazy.Sequences.empty; 6 | import static com.googlecode.totallylazy.Sequences.sequence; 7 | import static javarepl.completion.CompleterTestHelper.*; 8 | import static org.junit.Assert.assertThat; 9 | 10 | public class CommandCompleterTest { 11 | @Test 12 | public void shouldCompleteCommandWithGivenCandidates() { 13 | CommandCompleter completer = new CommandCompleter("command", sequence("first", "second")); 14 | 15 | assertThat(completer.apply("invalid"), completesTo(candidatesValues(), position(0))); 16 | assertThat(completer.apply(""), completesTo(candidatesValues("command"), position(0))); 17 | assertThat(completer.apply("command "), completesTo(candidatesValues("first", "second"), position(8))); 18 | } 19 | 20 | @Test 21 | public void shouldCompleteCommandWithoutCandidates() { 22 | CommandCompleter completer = new CommandCompleter("command", empty(String.class)); 23 | 24 | assertThat(completer.apply(""), completesTo(candidatesValues("command"), position(0))); 25 | assertThat(completer.apply("command "), completesTo(candidatesValues(), position(0))); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javarepl/completion/ResolvedClass.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | 4 | public final class ResolvedClass { 5 | private final ResolvedPackage resolvedPackage; 6 | private final String className; 7 | 8 | public ResolvedClass(ResolvedPackage resolvedPackage, String className) { 9 | this.resolvedPackage = resolvedPackage; 10 | this.className = className; 11 | } 12 | 13 | 14 | public ResolvedPackage resolvedPackage() { 15 | return resolvedPackage; 16 | } 17 | 18 | public String className() { 19 | return className; 20 | } 21 | 22 | public String canonicalClassName() { 23 | return (resolvedPackage.packageName().isEmpty() ? "" : resolvedPackage.packageName() + ".") + className; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return resolvedPackage.packageName() + "." + className + " in " + resolvedPackage.file(); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return toString().hashCode(); 34 | } 35 | 36 | @Override 37 | public boolean equals(Object other) { 38 | return other instanceof CompletionResult && 39 | other.getClass().equals(getClass()) && 40 | other.toString().equals(toString()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/javarepl/console/rest/RestConsoleModule.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.rest; 2 | 3 | import com.googlecode.utterlyidle.Resources; 4 | import com.googlecode.utterlyidle.handlers.ResponseHandlers; 5 | import com.googlecode.utterlyidle.modules.ResourcesModule; 6 | import com.googlecode.utterlyidle.modules.ResponseHandlersModule; 7 | import com.googlecode.yadic.Container; 8 | 9 | import java.util.Map; 10 | 11 | import static com.googlecode.totallylazy.io.URLs.packageUrl; 12 | import static com.googlecode.totallylazy.predicates.Predicates.*; 13 | import static com.googlecode.utterlyidle.dsl.DslBindings.bindings; 14 | import static com.googlecode.utterlyidle.dsl.StaticBindingBuilder.in; 15 | import static com.googlecode.utterlyidle.handlers.HandlerRule.entity; 16 | 17 | public class RestConsoleModule implements ResourcesModule, ResponseHandlersModule { 18 | @Override 19 | public Resources addResources(Resources resources) throws Exception { 20 | return resources.add(bindings(in(packageUrl(RestConsoleResource.class)).path(""))); 21 | } 22 | 23 | @Override 24 | public ResponseHandlers addResponseHandlers(ResponseHandlers handlers, Container requestScope) throws Exception { 25 | return handlers.add(where(entity(), is(instanceOf(Map.class))), MapToJsonResponseHandler.class); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/javarepl/web/WebConsoleModule.java: -------------------------------------------------------------------------------- 1 | package javarepl.web; 2 | 3 | import com.googlecode.utterlyidle.Resources; 4 | import com.googlecode.utterlyidle.handlers.ResponseHandlers; 5 | import com.googlecode.utterlyidle.modules.ResourcesModule; 6 | import com.googlecode.utterlyidle.modules.ResponseHandlersModule; 7 | import com.googlecode.yadic.Container; 8 | import javarepl.console.rest.MapToJsonResponseHandler; 9 | 10 | import java.util.Map; 11 | 12 | import static com.googlecode.totallylazy.io.URLs.packageUrl; 13 | import static com.googlecode.totallylazy.predicates.Predicates.*; 14 | import static com.googlecode.utterlyidle.dsl.DslBindings.bindings; 15 | import static com.googlecode.utterlyidle.dsl.StaticBindingBuilder.in; 16 | import static com.googlecode.utterlyidle.handlers.HandlerRule.entity; 17 | 18 | public class WebConsoleModule implements ResourcesModule, ResponseHandlersModule { 19 | public Resources addResources(Resources resources) throws Exception { 20 | return resources.add(bindings(in(packageUrl(WebConsoleResource.class)).path(""))); 21 | } 22 | 23 | @Override 24 | public ResponseHandlers addResponseHandlers(ResponseHandlers handlers, Container requestScope) throws Exception { 25 | return handlers.add(where(entity(), is(instanceOf(Map.class))), MapToJsonResponseHandler.class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/javarepl/console/rest/RestConsole.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.rest; 2 | 3 | import com.googlecode.utterlyidle.ServerConfiguration; 4 | import com.googlecode.utterlyidle.httpserver.RestServer; 5 | import javarepl.console.Console; 6 | import javarepl.console.DelegatingConsole; 7 | 8 | import static com.googlecode.utterlyidle.BasePath.basePath; 9 | import static com.googlecode.utterlyidle.ServerConfiguration.defaultConfiguration; 10 | 11 | public class RestConsole extends DelegatingConsole { 12 | private final RestServer server; 13 | private final Integer port; 14 | 15 | public RestConsole(Console console, Integer port) throws Exception { 16 | super(console); 17 | 18 | ServerConfiguration configuration = defaultConfiguration().port(port); 19 | RestConsoleApplication application = new RestConsoleApplication(basePath("/"), this); 20 | 21 | this.server = new RestServer(application, configuration); 22 | this.port = port; 23 | } 24 | 25 | public final Integer port() { 26 | return port; 27 | } 28 | 29 | @Override 30 | public void shutdown() { 31 | try { 32 | server.close(); 33 | } catch (Exception e) { 34 | throw new RuntimeException(e); 35 | } finally { 36 | super.shutdown(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/underscore/README.md: -------------------------------------------------------------------------------- 1 | __ 2 | /\ \ __ 3 | __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____ 4 | /\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\ 5 | \ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\ 6 | \ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/ 7 | \/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/ 8 | \ \____/ 9 | \/___/ 10 | 11 | Underscore.js is a utility-belt library for JavaScript that provides 12 | support for the usual functional suspects (each, map, reduce, filter...) 13 | without extending any core JavaScript objects. 14 | 15 | For Docs, License, Tests, and pre-packed downloads, see: 16 | http://underscorejs.org 17 | 18 | Underscore is an open-sourced component of DocumentCloud: 19 | https://github.com/documentcloud 20 | 21 | Many thanks to our contributors: 22 | https://github.com/jashkenas/underscore/contributors 23 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery.terminal/SpecRunner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jasmine Spec Runner v2.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/javarepl/rendering/TypeRenderer.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | import com.googlecode.totallylazy.annotations.multimethod; 4 | import com.googlecode.totallylazy.multi; 5 | 6 | import java.lang.reflect.ParameterizedType; 7 | import java.lang.reflect.Type; 8 | import java.lang.reflect.TypeVariable; 9 | 10 | import static com.googlecode.totallylazy.Sequences.sequence; 11 | import static java.lang.String.format; 12 | import static javarepl.Utils.extractType; 13 | 14 | public class TypeRenderer { 15 | 16 | @multimethod 17 | public static String renderType(Type type) { 18 | Type extractedType = extractType(type); 19 | return new multi() { 20 | }.methodOption(extractedType) 21 | .getOrElse(extractedType.toString()); 22 | } 23 | 24 | @multimethod 25 | private static String renderType(Class type) { 26 | return type.getCanonicalName(); 27 | } 28 | 29 | @multimethod 30 | private static String renderType(TypeVariable typeVariable) { 31 | return "Object"; 32 | } 33 | 34 | @multimethod 35 | private static String renderType(ParameterizedType type) { 36 | return format("%s<%s>", 37 | renderType(type.getRawType()), 38 | sequence(type.getActualTypeArguments()).map(TypeRenderer::renderType).toString(", ")); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ReplayAllEvaluations.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import javarepl.Evaluator; 5 | import javarepl.completion.CommandCompleter; 6 | import javarepl.console.ConsoleLogger; 7 | import javarepl.expressions.Expression; 8 | 9 | import static com.googlecode.totallylazy.predicates.Predicates.equalTo; 10 | import static javarepl.EvaluationContext.defaultExpressions; 11 | import static javarepl.console.commands.EvaluateExpression.evaluate; 12 | 13 | public final class ReplayAllEvaluations extends Command { 14 | private static final String COMMAND = ":replay"; 15 | private final Evaluator evaluator; 16 | private final ConsoleLogger logger; 17 | 18 | public ReplayAllEvaluations(Evaluator evaluator, ConsoleLogger logger) { 19 | super(COMMAND + " - replay all evaluations", equalTo(COMMAND), new CommandCompleter(COMMAND)); 20 | this.evaluator = evaluator; 21 | this.logger = logger; 22 | } 23 | 24 | public void execute(String line) { 25 | logger.success("Replaying all evaluations:"); 26 | Sequence expressions = evaluator.expressions().deleteAll(defaultExpressions()); 27 | 28 | evaluator.reset(); 29 | for (Expression expression : expressions) { 30 | evaluate(evaluator, logger, expression.source()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/ShowTypeOfExpression.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import javarepl.Evaluator; 5 | import javarepl.completion.CommandCompleter; 6 | import javarepl.console.ConsoleLogger; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | import static com.googlecode.totallylazy.Strings.startsWith; 11 | import static javarepl.rendering.TypeRenderer.renderType; 12 | 13 | public final class ShowTypeOfExpression extends Command { 14 | private static final String COMMAND = ":type"; 15 | private final Evaluator evaluator; 16 | private final ConsoleLogger logger; 17 | 18 | public ShowTypeOfExpression(Evaluator evaluator, ConsoleLogger logger) { 19 | super(COMMAND + " - shows the type of an expression without affecting current context", startsWith(COMMAND), new CommandCompleter(COMMAND)); 20 | 21 | this.evaluator = evaluator; 22 | this.logger = logger; 23 | } 24 | 25 | public void execute(String expression) { 26 | Option expressionType = evaluator.typeOfExpression(parseStringCommand(expression).second().getOrElse("")); 27 | 28 | if (!expressionType.isEmpty()) { 29 | logger.success(renderType(expressionType.get())); 30 | } else { 31 | logger.error("Cannot determine the type of this expression."); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/EvaluateFromHistory.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import javarepl.completion.CommandCompleter; 5 | import javarepl.console.Console; 6 | import javarepl.console.ConsoleHistory; 7 | import javarepl.console.ConsoleLogger; 8 | 9 | import static com.googlecode.totallylazy.Strings.startsWith; 10 | 11 | public final class EvaluateFromHistory extends Command { 12 | private static final String COMMAND = ":h!"; 13 | private final Console console; 14 | private final ConsoleHistory history; 15 | private final ConsoleLogger logger; 16 | 17 | public EvaluateFromHistory(Console console, ConsoleHistory history, ConsoleLogger logger) { 18 | super(COMMAND + " num - evaluate expression from history", startsWith(COMMAND), new CommandCompleter(COMMAND)); 19 | this.console = console; 20 | this.history = history; 21 | this.logger = logger; 22 | } 23 | 24 | public void execute(String expression) { 25 | Integer historyItem = parseNumericCommand(expression).second().getOrElse(history.items().size()); 26 | Option fromHistory = history.items().drop(historyItem - 1).headOption(); 27 | 28 | if (!fromHistory.isEmpty()) { 29 | console.execute(fromHistory.get()); 30 | } else { 31 | logger.error("Expression not found.\n"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/javarepl/completion/ResolvedPackage.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import com.googlecode.totallylazy.functions.Function0; 5 | 6 | import java.io.File; 7 | 8 | import static javarepl.completion.TypeResolver.functions.classResolver; 9 | 10 | public class ResolvedPackage { 11 | private final String packageName; 12 | private final File file; 13 | private final Function0> classResolver; 14 | 15 | public ResolvedPackage(File file, String packageName) { 16 | this.packageName = packageName; 17 | this.file = file; 18 | this.classResolver = classResolver(this); 19 | } 20 | 21 | public String packageName() { 22 | return packageName; 23 | } 24 | 25 | public File file() { 26 | return file; 27 | } 28 | 29 | public Sequence classes() { 30 | return classResolver.apply(); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return packageName + " in " + file; 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return toString().hashCode(); 41 | } 42 | 43 | @Override 44 | public boolean equals(Object other) { 45 | return other instanceof CompletionResult && 46 | other.getClass().equals(getClass()) && 47 | other.toString().equals(toString()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/javarepl/web/WebConsoleServer.java: -------------------------------------------------------------------------------- 1 | package javarepl.web; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import com.googlecode.utterlyidle.ServerConfiguration; 5 | import com.googlecode.utterlyidle.httpserver.RestServer; 6 | 7 | import static com.googlecode.totallylazy.Sequences.sequence; 8 | import static com.googlecode.totallylazy.Strings.replaceAll; 9 | import static com.googlecode.totallylazy.Strings.startsWith; 10 | import static com.googlecode.totallylazy.functions.Callables.compose; 11 | import static com.googlecode.totallylazy.numbers.Numbers.intValue; 12 | import static com.googlecode.totallylazy.numbers.Numbers.valueOf; 13 | import static com.googlecode.utterlyidle.BasePath.basePath; 14 | import static com.googlecode.utterlyidle.ServerConfiguration.defaultConfiguration; 15 | import static javarepl.Utils.randomServerPort; 16 | 17 | public class WebConsoleServer { 18 | 19 | public static void main(String... args) throws Exception { 20 | ServerConfiguration configuration = defaultConfiguration().port(port(args).getOrElse(randomServerPort())); 21 | WebConsoleApplication application = new WebConsoleApplication(basePath("/")); 22 | new RestServer(application, configuration); 23 | 24 | } 25 | 26 | private static Option port(String[] args) { 27 | return sequence(args).find(startsWith("--port=")).map(compose(replaceAll("--port=", ""), compose(valueOf, intValue))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/javarepl/examples/EmbedInApplication.java: -------------------------------------------------------------------------------- 1 | package javarepl.examples; 2 | 3 | import javarepl.console.ConsoleConfig; 4 | import javarepl.console.SimpleConsole; 5 | import javarepl.console.commands.EvaluateFromHistory; 6 | import javarepl.console.commands.ListValues; 7 | import javarepl.console.commands.SearchHistory; 8 | import javarepl.console.commands.ShowHistory; 9 | import javarepl.console.rest.RestConsole; 10 | 11 | import java.io.File; 12 | import java.util.Date; 13 | 14 | import static java.lang.System.getProperty; 15 | import static javarepl.Result.result; 16 | import static javarepl.console.ConsoleConfig.consoleConfig; 17 | 18 | /** 19 | * Example shows how to embed JavaREPL inside your application. Note that your application needs to be running via JDK 20 | * for the JavaREPL to work. 21 | */ 22 | public class EmbedInApplication { 23 | public static void main(String... args) throws Exception { 24 | ConsoleConfig config = consoleConfig() 25 | .historyFile(new File(getProperty("user.home"), ".javarepl-embedded.history")) 26 | .commands( 27 | ListValues.class, 28 | ShowHistory.class, 29 | EvaluateFromHistory.class, 30 | SearchHistory.class) 31 | .results( 32 | result("date", new Date()), 33 | result("num", 42)); 34 | 35 | new RestConsole(new SimpleConsole(config), 8001).start(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/javarepl/rendering/ValueRendererTest.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | import org.junit.Test; 4 | 5 | import static javarepl.rendering.ValueRenderer.renderValue; 6 | import static org.hamcrest.Matchers.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class ValueRendererTest { 10 | 11 | @Test 12 | public void shouldRenderValuesCorrectlyForArrays() { 13 | assertThat(renderValue(new byte[]{1, 2}), is("[1, 2]")); 14 | assertThat(renderValue(new int[]{1, 2}), is("[1, 2]")); 15 | assertThat(renderValue(new short[]{1, 2}), is("[1, 2]")); 16 | assertThat(renderValue(new long[]{1, 2}), is("[1, 2]")); 17 | assertThat(renderValue(new double[]{1.5, 2.5}), is("[1.5, 2.5]")); 18 | assertThat(renderValue(new float[]{1.5f, 2.5f}), is("[1.5, 2.5]")); 19 | assertThat(renderValue(new boolean[]{true, false}), is("[true, false]")); 20 | assertThat(renderValue(new char[]{'a', 'b'}), is("[a, b]")); 21 | } 22 | 23 | 24 | @Test 25 | public void shouldRenderValuesCorrectlyForObjectArrays() { 26 | assertThat(renderValue(new Integer[]{1, 2}), is("[1, 2]")); 27 | assertThat(renderValue(new Object[][]{{42, "str1"}, {42d, "str2"}}), is("[[42, \"str1\"], [42.0, \"str2\"]]")); 28 | } 29 | 30 | @Test 31 | public void shouldRenderValuesCorrectlyForObjects() { 32 | assertThat(renderValue("test"), is("\"test\"")); 33 | assertThat(renderValue(42), is("42")); 34 | assertThat(renderValue(null), is("null")); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/core/access.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core" 3 | ], function( jQuery ) { 4 | 5 | // Multifunctional method to get and set values of a collection 6 | // The value/s can optionally be executed if it's a function 7 | var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { 8 | var i = 0, 9 | len = elems.length, 10 | bulk = key == null; 11 | 12 | // Sets many values 13 | if ( jQuery.type( key ) === "object" ) { 14 | chainable = true; 15 | for ( i in key ) { 16 | access( elems, fn, i, key[ i ], true, emptyGet, raw ); 17 | } 18 | 19 | // Sets one value 20 | } else if ( value !== undefined ) { 21 | chainable = true; 22 | 23 | if ( !jQuery.isFunction( value ) ) { 24 | raw = true; 25 | } 26 | 27 | if ( bulk ) { 28 | 29 | // Bulk operations run against the entire set 30 | if ( raw ) { 31 | fn.call( elems, value ); 32 | fn = null; 33 | 34 | // ...except when executing function values 35 | } else { 36 | bulk = fn; 37 | fn = function( elem, key, value ) { 38 | return bulk.call( jQuery( elem ), value ); 39 | }; 40 | } 41 | } 42 | 43 | if ( fn ) { 44 | for ( ; i < len; i++ ) { 45 | fn( 46 | elems[ i ], key, raw ? 47 | value : 48 | value.call( elems[ i ], i, fn( elems[ i ], key ) ) 49 | ); 50 | } 51 | } 52 | } 53 | 54 | return chainable ? 55 | elems : 56 | 57 | // Gets 58 | bulk ? 59 | fn.call( elems ) : 60 | len ? fn( elems[ 0 ], key ) : emptyGet; 61 | }; 62 | 63 | return access; 64 | 65 | } ); 66 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/github-fork-ribbon-css/gh-fork-ribbon.ie.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * "Fork me on GitHub" CSS ribbon v0.2.0 | MIT License 3 | * https://github.com/simonwhitaker/github-fork-ribbon-css 4 | */ 5 | 6 | /* IE voodoo courtesy of http://stackoverflow.com/a/4617511/263871 and 7 | * http://www.useragentman.com/IETransformsTranslator */ 8 | 9 | html { 10 | overflow: auto; 11 | } 12 | 13 | body { 14 | position: relative; 15 | width: 100%; 16 | height: auto; 17 | overflow: hidden; 18 | } 19 | 20 | .github-fork-ribbon { 21 | width: 15.38em; 22 | height: 5.62em; 23 | 24 | /* IE positioning hack (couldn't find a transform-origin alternative for IE) */ 25 | top: -3.92em; 26 | right: -4.46em; 27 | 28 | /* IE8+ */ 29 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865474, M12=-0.7071067811865477, M21=0.7071067811865477, M22=0.7071067811865474, SizingMethod='auto expand')"; 30 | } 31 | 32 | .github-fork-ribbon.left-top, .github-fork-ribbon.right-bottom { 33 | /* IE8+ */ 34 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"; 35 | } 36 | 37 | .github-fork-ribbon:before, .github-fork-ribbon:after { 38 | left: auto !important; 39 | right: auto !important; 40 | font-size: inherit; 41 | } 42 | 43 | .github-fork-ribbon.left-top, .github-fork-ribbon.left-bottom { 44 | left: -3.92em; 45 | } 46 | 47 | .github-fork-ribbon.left-bottom, .github-fork-ribbon.right-bottom { 48 | bottom: 4.77em; 49 | } 50 | -------------------------------------------------------------------------------- /src/javarepl/completion/CompletionCandidate.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import com.googlecode.totallylazy.functions.Function1; 5 | 6 | import static com.googlecode.totallylazy.Sequences.sequence; 7 | 8 | public class CompletionCandidate { 9 | private final String value; 10 | private final Sequence forms; 11 | 12 | public CompletionCandidate(String value, Sequence forms) { 13 | this.value = value; 14 | this.forms = forms; 15 | } 16 | 17 | public String value() { 18 | return value; 19 | } 20 | 21 | public Sequence forms() { 22 | return forms; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return value + forms.toString(" (", ", ", ")"); 28 | } 29 | 30 | 31 | @Override 32 | public int hashCode() { 33 | return (value != null ? value.hashCode() : 0) + 34 | (forms != null ? forms.hashCode() : 0); 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object other) { 40 | return other instanceof CompletionCandidate && 41 | other.getClass().equals(getClass()) && 42 | (value != null && value.equals(((CompletionCandidate) other).value)) && 43 | (forms != null && forms.equals(((CompletionCandidate) other).forms)); 44 | } 45 | 46 | public static Function1 asCompletionCandidate() { 47 | return candidate -> new CompletionCandidate(candidate, sequence(candidate)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/intro.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery JavaScript Library v@VERSION 3 | * http://jquery.com/ 4 | * 5 | * Includes Sizzle.js 6 | * http://sizzlejs.com/ 7 | * 8 | * Copyright jQuery Foundation and other contributors 9 | * Released under the MIT license 10 | * http://jquery.org/license 11 | * 12 | * Date: @DATE 13 | */ 14 | 15 | (function( global, factory ) { 16 | 17 | if ( typeof module === "object" && typeof module.exports === "object" ) { 18 | // For CommonJS and CommonJS-like environments where a proper `window` 19 | // is present, execute the factory and get jQuery. 20 | // For environments that do not have a `window` with a `document` 21 | // (such as Node.js), expose a factory as module.exports. 22 | // This accentuates the need for the creation of a real `window`. 23 | // e.g. var jQuery = require("jquery")(window); 24 | // See ticket #14549 for more info. 25 | module.exports = global.document ? 26 | factory( global, true ) : 27 | function( w ) { 28 | if ( !w.document ) { 29 | throw new Error( "jQuery requires a window with a document" ); 30 | } 31 | return factory( w ); 32 | }; 33 | } else { 34 | factory( global ); 35 | } 36 | 37 | // Pass this if window is not defined yet 38 | }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) { 39 | 40 | // Support: Firefox 18+ 41 | // Can't be in strict mode, several libs including ASP.NET trace 42 | // the stack via arguments.caller.callee and Firefox dies if 43 | // you try to trace through "use strict" call chains. (#13335) 44 | //"use strict"; 45 | -------------------------------------------------------------------------------- /src/javarepl/completion/AggregateCompleter.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Group; 4 | import com.googlecode.totallylazy.Option; 5 | import com.googlecode.totallylazy.Sequence; 6 | import com.googlecode.totallylazy.functions.Function1; 7 | 8 | import static com.googlecode.totallylazy.Groups.groupKey; 9 | import static com.googlecode.totallylazy.Sequences.empty; 10 | 11 | public class AggregateCompleter extends Completer { 12 | private final Sequence completers; 13 | 14 | public AggregateCompleter(Sequence completers) { 15 | this.completers = completers; 16 | } 17 | 18 | public CompletionResult call(String expression) throws Exception { 19 | Option> group = completeGroup(expression); 20 | 21 | if (group.isEmpty()) 22 | return new CompletionResult(expression, 0, empty(CompletionCandidate.class)); 23 | 24 | return new CompletionResult(expression, group.get().key(), group.get().flatMap(CompletionResult::candidates)); 25 | } 26 | 27 | private Option> completeGroup(String expression) { 28 | return completers.map(complete(expression)) 29 | .unique() 30 | .groupBy(CompletionResult::position) 31 | .sortBy(groupKey(Integer.class)) 32 | .reverse() 33 | .headOption(); 34 | } 35 | 36 | private Function1 complete(final String expression) { 37 | return completer -> completer.apply(expression); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/javarepl/rendering/ExpressionSourceRenderer.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | import com.googlecode.totallylazy.annotations.multimethod; 4 | import com.googlecode.totallylazy.multi; 5 | import javarepl.expressions.*; 6 | 7 | public class ExpressionSourceRenderer { 8 | @multimethod 9 | public static String renderExpressionSource(Expression expression) { 10 | return new multi() { 11 | }.methodOption(expression) 12 | .getOrThrow(new IllegalArgumentException(expression + " not mapped")); 13 | } 14 | 15 | @multimethod 16 | private static String renderExpressionSource(Statement expression) { 17 | return expression.source(); 18 | } 19 | 20 | @multimethod 21 | private static String renderExpressionSource(Assignment expression) { 22 | return expression.value(); 23 | } 24 | 25 | @multimethod 26 | private static String renderExpressionSource(AssignmentWithType expression) { 27 | return expression.value(); 28 | } 29 | 30 | @multimethod 31 | private static String renderExpressionSource(Value expression) { 32 | return expression.source(); 33 | } 34 | 35 | @multimethod 36 | private static String renderExpressionSource(Method expression) { 37 | return expression.source().replaceAll("\n", "\n "); 38 | } 39 | 40 | @multimethod 41 | private static String renderExpressionSource(Import expression) { 42 | return expression.source(); 43 | } 44 | 45 | @multimethod 46 | private static String renderExpressionSource(Type expression) { 47 | return expression.source(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/EvaluateFile.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Strings; 4 | import javarepl.Evaluator; 5 | import javarepl.completion.CommandCompleter; 6 | import javarepl.console.ConsoleHistory; 7 | import javarepl.console.ConsoleLogger; 8 | 9 | import static com.googlecode.totallylazy.Strings.startsWith; 10 | import static java.lang.String.format; 11 | import static javarepl.Utils.resolveURL; 12 | 13 | public final class EvaluateFile extends Command { 14 | private static final String COMMAND = ":eval"; 15 | private final ConsoleLogger logger; 16 | private final Evaluator evaluator; 17 | private final ConsoleHistory history; 18 | 19 | public EvaluateFile(ConsoleLogger logger, Evaluator evaluator, ConsoleHistory history) { 20 | super(COMMAND + " - evaluates all expressions from file (expression per line)", startsWith(COMMAND), new CommandCompleter(COMMAND)); 21 | this.logger = logger; 22 | this.evaluator = evaluator; 23 | this.history = history; 24 | } 25 | 26 | public void execute(String expression) { 27 | String path = parseStringCommand(expression).second().getOrNull(); 28 | try { 29 | for (String line : Strings.lines(resolveURL(path).openStream())) { 30 | history.add(line); 31 | EvaluateExpression.evaluate(evaluator, logger, line); 32 | } 33 | 34 | logger.success(format("Finished evaluating %s", path)); 35 | } catch (Exception e) { 36 | logger.error(format("Could evaluate %s. %s", path, e.getLocalizedMessage())); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/javarepl/completion/CommandCompleter.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | 5 | import static com.googlecode.totallylazy.Sequences.*; 6 | import static com.googlecode.totallylazy.Strings.startsWith; 7 | import static javarepl.completion.CompletionCandidate.asCompletionCandidate; 8 | 9 | public class CommandCompleter extends Completer { 10 | private final String command; 11 | private final Sequence candidates; 12 | 13 | public CommandCompleter(String command) { 14 | this(command, empty(String.class)); 15 | } 16 | 17 | public CommandCompleter(String command, Sequence candidates) { 18 | this.command = command; 19 | this.candidates = candidates; 20 | } 21 | 22 | public CompletionResult call(String expression) throws Exception { 23 | Sequence parts = sequence(expression.split(" ")); 24 | 25 | if (parts.isEmpty()) { 26 | return new CompletionResult(expression, 0, empty(CompletionCandidate.class)); 27 | } 28 | 29 | if (command.equals(parts.head())) { 30 | String nextCommandPart = parts.tail().headOption().getOrElse(""); 31 | return new CompletionResult(expression, candidates.isEmpty() ? 0 : command.length() + 1, candidates.filter(startsWith(nextCommandPart)).map(asCompletionCandidate())); 32 | } 33 | 34 | if (command.startsWith(parts.head())) { 35 | return new CompletionResult(expression, 0, one(asCompletionCandidate().apply(command))); 36 | } 37 | 38 | return new CompletionResult(expression, 0, empty(CompletionCandidate.class)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/script.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../var/document", 4 | "../ajax" 5 | ], function( jQuery, document ) { 6 | 7 | // Install script dataType 8 | jQuery.ajaxSetup( { 9 | accepts: { 10 | script: "text/javascript, application/javascript, " + 11 | "application/ecmascript, application/x-ecmascript" 12 | }, 13 | contents: { 14 | script: /\b(?:java|ecma)script\b/ 15 | }, 16 | converters: { 17 | "text script": function( text ) { 18 | jQuery.globalEval( text ); 19 | return text; 20 | } 21 | } 22 | } ); 23 | 24 | // Handle cache's special case and crossDomain 25 | jQuery.ajaxPrefilter( "script", function( s ) { 26 | if ( s.cache === undefined ) { 27 | s.cache = false; 28 | } 29 | if ( s.crossDomain ) { 30 | s.type = "GET"; 31 | } 32 | } ); 33 | 34 | // Bind script tag hack transport 35 | jQuery.ajaxTransport( "script", function( s ) { 36 | 37 | // This transport only deals with cross domain requests 38 | if ( s.crossDomain ) { 39 | var script, callback; 40 | return { 41 | send: function( _, complete ) { 42 | script = jQuery( " 18 | ``` 19 | 20 | #### Babel 21 | 22 | [Babel](http://babeljs.io/) is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively. 23 | 24 | ```js 25 | import $ from "jquery"; 26 | ``` 27 | 28 | #### Browserify/Webpack 29 | 30 | There are several ways to use [Browserify](http://browserify.org/) and [Webpack](https://webpack.github.io/). For more information on using these tools, please refer to the corresponding project's documention. In the script, including jQuery will usually look like this... 31 | 32 | ```js 33 | var $ = require("jquery"); 34 | ``` 35 | 36 | #### AMD (Asynchronous Module Definition) 37 | 38 | AMD is a module format built for the browser. For more information, we recommend [require.js' documentation](http://requirejs.org/docs/whyamd.html). 39 | 40 | ```js 41 | define(["jquery"], function($) { 42 | 43 | }); 44 | ``` 45 | 46 | ### Node 47 | 48 | To include jQuery in [Node](nodejs.org), first install with npm. 49 | 50 | ```sh 51 | npm install jquery 52 | ``` 53 | 54 | For jQuery to work in Node, a window with a document is required. Since no such window exists natively in Node, one can be mocked by tools such as [jsdom](https://github.com/tmpvar/jsdom). This can be useful for testing purposes. 55 | 56 | ```js 57 | require("jsdom").env("", function(err, window) { 58 | if (err) { 59 | console.error(err); 60 | return; 61 | } 62 | 63 | var $ = require("jquery")(window); 64 | }); 65 | ``` 66 | -------------------------------------------------------------------------------- /src/javarepl/ExpressionCompilationException.java: -------------------------------------------------------------------------------- 1 | package javarepl; 2 | 3 | import com.googlecode.totallylazy.functions.Function1; 4 | import com.googlecode.totallylazy.predicates.Predicate; 5 | 6 | import javax.tools.Diagnostic; 7 | import java.io.File; 8 | import java.util.Locale; 9 | 10 | import static com.googlecode.totallylazy.Sequences.repeat; 11 | import static com.googlecode.totallylazy.Sequences.sequence; 12 | import static com.googlecode.totallylazy.Strings.lines; 13 | import static java.lang.String.format; 14 | import static java.util.regex.Pattern.quote; 15 | import static javax.tools.Diagnostic.Kind.ERROR; 16 | 17 | public class ExpressionCompilationException extends Exception { 18 | 19 | public ExpressionCompilationException(File file, Iterable> diagnostics) { 20 | this(diagnosticsAsMessage(file, diagnostics)); 21 | } 22 | 23 | public ExpressionCompilationException(String message) { 24 | super(message); 25 | } 26 | 27 | private static String diagnosticsAsMessage(final File file, final Iterable> diagnostics) { 28 | return sequence(diagnostics) 29 | .filter(isError()) 30 | .map(diagnosticToMessage(file)) 31 | .toString("\n"); 32 | } 33 | 34 | private static Function1, String> diagnosticToMessage(final File file) { 35 | return diagnostic -> { 36 | String line = lines(file).drop((int) diagnostic.getLineNumber() - 1).head(); 37 | String marker = repeat(' ').take((int) diagnostic.getColumnNumber() - 1).toString("", "", "^"); 38 | String message = diagnostic.getMessage(Locale.getDefault()); 39 | String evaluationClass = file.getName().replaceAll("\\.java", ""); 40 | return format("%s: %s\n%s\n%s", diagnostic.getKind(), message, line, marker) 41 | .replaceAll(quote(evaluationClass), "Evaluation"); 42 | }; 43 | } 44 | 45 | private static Predicate> isError() { 46 | return diagnostic -> diagnostic.getKind() == ERROR; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/css/adjustCSS.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../var/rcssNum" 4 | ], function( jQuery, rcssNum ) { 5 | 6 | function adjustCSS( elem, prop, valueParts, tween ) { 7 | var adjusted, 8 | scale = 1, 9 | maxIterations = 20, 10 | currentValue = tween ? 11 | function() { return tween.cur(); } : 12 | function() { return jQuery.css( elem, prop, "" ); }, 13 | initial = currentValue(), 14 | unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), 15 | 16 | // Starting value computation is required for potential unit mismatches 17 | initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) && 18 | rcssNum.exec( jQuery.css( elem, prop ) ); 19 | 20 | if ( initialInUnit && initialInUnit[ 3 ] !== unit ) { 21 | 22 | // Trust units reported by jQuery.css 23 | unit = unit || initialInUnit[ 3 ]; 24 | 25 | // Make sure we update the tween properties later on 26 | valueParts = valueParts || []; 27 | 28 | // Iteratively approximate from a nonzero starting point 29 | initialInUnit = +initial || 1; 30 | 31 | do { 32 | 33 | // If previous iteration zeroed out, double until we get *something*. 34 | // Use string for doubling so we don't accidentally see scale as unchanged below 35 | scale = scale || ".5"; 36 | 37 | // Adjust and apply 38 | initialInUnit = initialInUnit / scale; 39 | jQuery.style( elem, prop, initialInUnit + unit ); 40 | 41 | // Update scale, tolerating zero or NaN from tween.cur() 42 | // Break the loop if scale is unchanged or perfect, or if we've just had enough. 43 | } while ( 44 | scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations 45 | ); 46 | } 47 | 48 | if ( valueParts ) { 49 | initialInUnit = +initialInUnit || +initial || 0; 50 | 51 | // Apply relative offset (+=/-=) if specified 52 | adjusted = valueParts[ 1 ] ? 53 | initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] : 54 | +valueParts[ 2 ]; 55 | if ( tween ) { 56 | tween.unit = unit; 57 | tween.start = initialInUnit; 58 | tween.end = adjusted; 59 | } 60 | } 61 | return adjusted; 62 | } 63 | 64 | return adjustCSS; 65 | } ); 66 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/CheckExpression.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Either; 4 | import com.googlecode.totallylazy.functions.Callables; 5 | import javarepl.Evaluation; 6 | import javarepl.Evaluator; 7 | import javarepl.completion.CommandCompleter; 8 | import javarepl.console.ConsoleLogger; 9 | import javarepl.expressions.Expression; 10 | 11 | import static com.googlecode.totallylazy.Strings.startsWith; 12 | import static java.lang.String.format; 13 | 14 | public final class CheckExpression extends Command { 15 | private static final String COMMAND = ":check"; 16 | private final Evaluator evaluator; 17 | private final ConsoleLogger logger; 18 | 19 | public CheckExpression(Evaluator evaluator, ConsoleLogger logger) { 20 | super(COMMAND + " - checks syntax of given single line expression and returns detailed report", startsWith(COMMAND), new CommandCompleter(COMMAND)); 21 | this.evaluator = evaluator; 22 | this.logger = logger; 23 | } 24 | 25 | public void execute(String expression) { 26 | String syntaxToCheck = parseStringCommand(expression).second().getOrNull(); 27 | try { 28 | Either result = evaluator.parseExpression(syntaxToCheck); 29 | 30 | if (result.isLeft()) { 31 | logger.error(format("Parsing: %s", result.left())); 32 | } else { 33 | logger.success(format("Parsing: %s", result.right())); 34 | 35 | Either evaluation = evaluator.tryEvaluate(syntaxToCheck); 36 | if (evaluation.isLeft()) { 37 | logger.error(format("Evaluation: %s", evaluation.left())); 38 | } else { 39 | logger.success(format("Evaluation: %s => %s", 40 | evaluation.right().expression(), 41 | evaluation.right().result().map(Callables.asString()).getOrElse("void"))); 42 | } 43 | 44 | } 45 | 46 | } catch (Exception e) { 47 | logger.error(format("Could not check syntax %s. %s", syntaxToCheck, e.getLocalizedMessage())); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/javarepl/web/WebConsole.java: -------------------------------------------------------------------------------- 1 | package javarepl.web; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import com.googlecode.totallylazy.Sequence; 5 | import com.googlecode.totallylazy.collections.ListMap; 6 | import com.googlecode.totallylazy.collections.PersistentMap; 7 | 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.ScheduledExecutorService; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import static com.googlecode.totallylazy.Some.some; 13 | 14 | public class WebConsole { 15 | private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); 16 | private PersistentMap clients = ListMap.emptyListMap(); 17 | 18 | public WebConsole() { 19 | executorService.scheduleAtFixedRate(clearStaleSessions(), 10, 10, TimeUnit.SECONDS); 20 | } 21 | 22 | private Runnable clearStaleSessions() { 23 | return new Runnable() { 24 | public void run() { 25 | for (WebConsoleClientHandler client : clients.values()) { 26 | if (!client.exitCode().isEmpty()) { 27 | removeClient(client.id()); 28 | } 29 | } 30 | } 31 | }; 32 | } 33 | 34 | public synchronized Option createClient(Option expression) { 35 | WebConsoleClientHandler clientHandler = new WebConsoleClientHandler(expression); 36 | clients = clients.insert(clientHandler.id(), clientHandler); 37 | return some(clientHandler); 38 | } 39 | 40 | 41 | public synchronized Option removeClient(String id) { 42 | Option clientHandler = clients.lookup(id); 43 | 44 | if (!clientHandler.isEmpty()) { 45 | clientHandler.get().shutdown(); 46 | clients = clients.delete(clientHandler.get().id()); 47 | } 48 | 49 | return clientHandler; 50 | } 51 | 52 | 53 | public Option client(String id) { 54 | return clients.lookup(id); 55 | } 56 | 57 | public Sequence clients() { 58 | return clients.values(); 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/javarepl/console/TimingOutConsole.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | 5 | import java.util.concurrent.Callable; 6 | import java.util.concurrent.ScheduledExecutorService; 7 | import java.util.concurrent.ScheduledFuture; 8 | 9 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; 10 | import static java.util.concurrent.TimeUnit.SECONDS; 11 | 12 | public class TimingOutConsole extends DelegatingConsole { 13 | public static final int EXPRESSION_TIMEOUT = 125; 14 | public static final int INACTIVITY_TIMEOUT = 126; 15 | 16 | private final ScheduledExecutorService scheduler = newSingleThreadScheduledExecutor(); 17 | private final Option expressionTimeout; 18 | private final Option inactivityTimeout; 19 | private ScheduledFuture inactivityFuture; 20 | 21 | public TimingOutConsole(Console console, Option expressionTimeout, Option inactivityTimeout) { 22 | super(console); 23 | this.expressionTimeout = expressionTimeout; 24 | this.inactivityTimeout = inactivityTimeout; 25 | 26 | scheduleInactivityTimeout(); 27 | } 28 | 29 | public ConsoleResult execute(final String expression) { 30 | scheduleInactivityTimeout(); 31 | 32 | ScheduledFuture timedOut = null; 33 | if (expressionTimeout.isDefined()) { 34 | timedOut = scheduler.schedule(exitWithCode(EXPRESSION_TIMEOUT), expressionTimeout.get(), SECONDS); 35 | } 36 | 37 | ConsoleResult result = super.execute(expression); 38 | 39 | if (!expressionTimeout.isEmpty()) { 40 | timedOut.cancel(true); 41 | } 42 | return result; 43 | } 44 | 45 | private void scheduleInactivityTimeout() { 46 | if (inactivityTimeout.isDefined()) { 47 | if (inactivityFuture != null) { 48 | inactivityFuture.cancel(true); 49 | } 50 | 51 | inactivityFuture = scheduler.schedule(exitWithCode(INACTIVITY_TIMEOUT), inactivityTimeout.get(), SECONDS); 52 | } 53 | } 54 | 55 | private Callable exitWithCode(final int code) { 56 | return () -> { 57 | System.exit(code); 58 | return null; 59 | }; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/javarepl/completion/CompleterTestHelper.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import javarepl.EvaluationContext; 5 | import javarepl.Evaluator; 6 | import org.hamcrest.Description; 7 | import org.hamcrest.Matcher; 8 | import org.hamcrest.TypeSafeMatcher; 9 | 10 | import static com.googlecode.totallylazy.Sequences.sequence; 11 | import static javarepl.EvaluationClassLoader.evaluationClassLoader; 12 | import static javarepl.EvaluationContext.evaluationContext; 13 | import static javarepl.completion.CompletionCandidate.asCompletionCandidate; 14 | 15 | public class CompleterTestHelper { 16 | 17 | public static Matcher completesTo(final Sequence candidates, final int position) { 18 | return new TypeSafeMatcher() { 19 | private CompletionResult result; 20 | 21 | protected boolean matchesSafely(CompletionResult completionResult) { 22 | result = completionResult; 23 | return completionResult.candidates().equals(candidates) && completionResult.position() == position; 24 | } 25 | 26 | public void describeTo(Description description) { 27 | description.appendText(new CompletionResult(result.expression(), position, candidates).toString()); 28 | } 29 | }; 30 | } 31 | 32 | public static Sequence candidatesValues(String... candidates) { 33 | return sequence(candidates).map(asCompletionCandidate()); 34 | } 35 | 36 | public static Sequence candidates(CompletionCandidate... candidates) { 37 | return sequence(candidates); 38 | } 39 | 40 | public static int position(int position) { 41 | return position; 42 | } 43 | 44 | public static Evaluator evaluator(String... expressions) { 45 | EvaluationContext context = evaluationContext(); 46 | Evaluator evaluator = new Evaluator(context, evaluationClassLoader(context)); 47 | for (String expression : expressions) { 48 | evaluator.evaluate(expression); 49 | } 50 | return evaluator; 51 | } 52 | 53 | public static String importMembersOf(Class aClass) { 54 | return "import " + aClass.getCanonicalName() + ".*"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/javarepl/console/commands/Command.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import com.googlecode.totallylazy.Option; 4 | import com.googlecode.totallylazy.Pair; 5 | import com.googlecode.totallylazy.Sequence; 6 | import com.googlecode.totallylazy.predicates.Predicate; 7 | import javarepl.completion.Completer; 8 | 9 | import static com.googlecode.totallylazy.Option.none; 10 | import static com.googlecode.totallylazy.Option.some; 11 | import static com.googlecode.totallylazy.Sequences.sequence; 12 | import static java.lang.Integer.parseInt; 13 | 14 | public abstract class Command { 15 | public static final String COMMAND_SEPARATOR = " "; 16 | 17 | private final String description; 18 | private final Predicate predicate; 19 | private final Completer completer; 20 | 21 | protected Command(String description, Predicate predicate, Completer completer) { 22 | this.description = description; 23 | this.predicate = predicate; 24 | this.completer = completer; 25 | } 26 | 27 | public abstract void execute(String expression); 28 | 29 | public String description() { 30 | return description; 31 | } 32 | 33 | public Predicate predicate() { 34 | return predicate; 35 | } 36 | 37 | public Completer completer() { 38 | return completer; 39 | } 40 | 41 | @Override 42 | public final String toString() { 43 | return description(); 44 | } 45 | 46 | public static final Pair> parseStringCommand(String input) { 47 | final Sequence splitInput = sequence(input.split(COMMAND_SEPARATOR)); 48 | String command = splitInput.first(); 49 | String value = splitInput.tail().toString(COMMAND_SEPARATOR); 50 | return Pair.pair(command, value.isEmpty() ? Option.none(String.class) : some(value)); 51 | } 52 | 53 | public static final Pair> parseNumericCommand(String input) { 54 | final Sequence splitInput = sequence(input.split(COMMAND_SEPARATOR)); 55 | 56 | try { 57 | return Pair.pair(splitInput.first(), some(parseInt(splitInput.tail().toString(COMMAND_SEPARATOR)))); 58 | } catch (Exception e) { 59 | return Pair.pair(splitInput.first(), none(Integer.class)); 60 | } 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /src/javarepl/console/commands/ListValues.java: -------------------------------------------------------------------------------- 1 | package javarepl.console.commands; 2 | 3 | import javarepl.Evaluator; 4 | import javarepl.completion.CommandCompleter; 5 | import javarepl.console.ConsoleLogger; 6 | import javarepl.expressions.Import; 7 | import javarepl.expressions.Method; 8 | import javarepl.expressions.Type; 9 | 10 | import static com.googlecode.totallylazy.Sequences.sequence; 11 | import static com.googlecode.totallylazy.Strings.startsWith; 12 | import static javarepl.Utils.listValues; 13 | 14 | public final class ListValues extends Command { 15 | private static final String COMMAND = ":list"; 16 | private final Evaluator evaluator; 17 | private final ConsoleLogger logger; 18 | 19 | 20 | public ListValues(Evaluator evaluator, ConsoleLogger logger) { 21 | super(COMMAND + " - list specified values", 22 | startsWith(COMMAND), new CommandCompleter(COMMAND, sequence("results", "methods", "imports", "types", "all"))); 23 | 24 | this.evaluator = evaluator; 25 | this.logger = logger; 26 | } 27 | 28 | public void execute(String expression) { 29 | String items = expression.replace(COMMAND, "").trim(); 30 | 31 | if (items.equals("results")) { 32 | listResults(); 33 | } else if (items.equals("types")) { 34 | listTypes(); 35 | } else if (items.equals("imports")) { 36 | listImports(); 37 | } else if (items.equals("methods")) { 38 | listMethods(); 39 | } else { 40 | listResults(); 41 | listTypes(); 42 | listImports(); 43 | listMethods(); 44 | } 45 | } 46 | 47 | private void listMethods() { 48 | logger.success(listValues("Methods", sequence(evaluator.expressionsOfType(Method.class)).map(Method::signature))); 49 | } 50 | 51 | private void listImports() { 52 | logger.success(listValues("Imports", sequence(evaluator.expressionsOfType(Import.class)).map(Import::typePackage))); 53 | } 54 | 55 | private void listTypes() { 56 | logger.success(listValues("Types", sequence(evaluator.expressionsOfType(Type.class)).map(Type::type))); 57 | } 58 | 59 | private void listResults() { 60 | logger.success(listValues("Results", evaluator.results())); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/javarepl/rendering/ExpressionTokenRenderer.java: -------------------------------------------------------------------------------- 1 | package javarepl.rendering; 2 | 3 | import com.googlecode.totallylazy.annotations.multimethod; 4 | import com.googlecode.totallylazy.multi; 5 | import javarepl.expressions.*; 6 | 7 | import static java.lang.String.format; 8 | 9 | public class ExpressionTokenRenderer { 10 | public static final String EXPRESSION_TOKEN = "$JAVAREPL_EXPRESSION_TOKEN$"; 11 | public static final String EXPRESSION_VALUE = "$JAVAREPL_EXPRESSION_VALUE$"; 12 | 13 | @multimethod 14 | public static String renderExpressionToken(Expression expression) { 15 | return new multi() { 16 | }.methodOption(expression) 17 | .getOrThrow(new IllegalArgumentException(expression + " not mapped")); 18 | } 19 | 20 | @multimethod 21 | private static String renderExpressionToken(Statement expression) { 22 | return " " + EXPRESSION_TOKEN + ";"; 23 | } 24 | 25 | @multimethod 26 | private static String renderExpressionToken(Assignment expression) { 27 | return expressionWithValue(expression.value()); 28 | } 29 | 30 | @multimethod 31 | private static String renderExpressionToken(AssignmentWithType expression) { 32 | return expressionWithValue(expression.value(), expression.type()); 33 | } 34 | 35 | @multimethod 36 | private static String renderExpressionToken(Value expression) { 37 | return expressionWithValue(expression.source()); 38 | } 39 | 40 | @multimethod 41 | private static String renderExpressionToken(Method expression) { 42 | return " " + EXPRESSION_TOKEN + "\n"; 43 | } 44 | 45 | @multimethod 46 | private static String renderExpressionToken(Import expression) { 47 | return EXPRESSION_TOKEN + ";"; 48 | } 49 | 50 | private static String expressionWithValue(String value) { 51 | return expressionWithValue(value, Object.class); 52 | } 53 | 54 | private static String expressionWithValue(String value, java.lang.reflect.Type returnType) { 55 | return expressionWithValue(value, TypeRenderer.renderType(returnType)); 56 | } 57 | 58 | private static String expressionWithValue(String value, String returnType) { 59 | return format(" %s %s =\n\n %s;\n\n return %s;", returnType, EXPRESSION_VALUE, EXPRESSION_TOKEN, EXPRESSION_VALUE); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/javarepl/web/embed.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | Java REPL 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 34 | 35 | 36 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/javarepl/console/ui/bower_components/jquery/src/ajax/load.js: -------------------------------------------------------------------------------- 1 | define( [ 2 | "../core", 3 | "../core/parseHTML", 4 | "../ajax", 5 | "../traversing", 6 | "../manipulation", 7 | "../selector", 8 | 9 | // Optional event/alias dependency 10 | "../event/alias" 11 | ], function( jQuery ) { 12 | 13 | // Keep a copy of the old load method 14 | var _load = jQuery.fn.load; 15 | 16 | /** 17 | * Load a url into a page 18 | */ 19 | jQuery.fn.load = function( url, params, callback ) { 20 | if ( typeof url !== "string" && _load ) { 21 | return _load.apply( this, arguments ); 22 | } 23 | 24 | var selector, type, response, 25 | self = this, 26 | off = url.indexOf( " " ); 27 | 28 | if ( off > -1 ) { 29 | selector = jQuery.trim( url.slice( off ) ); 30 | url = url.slice( 0, off ); 31 | } 32 | 33 | // If it's a function 34 | if ( jQuery.isFunction( params ) ) { 35 | 36 | // We assume that it's the callback 37 | callback = params; 38 | params = undefined; 39 | 40 | // Otherwise, build a param string 41 | } else if ( params && typeof params === "object" ) { 42 | type = "POST"; 43 | } 44 | 45 | // If we have elements to modify, make the request 46 | if ( self.length > 0 ) { 47 | jQuery.ajax( { 48 | url: url, 49 | 50 | // If "type" variable is undefined, then "GET" method will be used. 51 | // Make value of this field explicit since 52 | // user can override it through ajaxSetup method 53 | type: type || "GET", 54 | dataType: "html", 55 | data: params 56 | } ).done( function( responseText ) { 57 | 58 | // Save response for use in complete callback 59 | response = arguments; 60 | 61 | self.html( selector ? 62 | 63 | // If a selector was specified, locate the right elements in a dummy div 64 | // Exclude scripts to avoid IE 'Permission Denied' errors 65 | jQuery( "
" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : 66 | 67 | // Otherwise use the full result 68 | responseText ); 69 | 70 | // If the request succeeds, this function gets "data", "status", "jqXHR" 71 | // but they are ignored because response was set above. 72 | // If it fails, this function gets "jqXHR", "status", "error" 73 | } ).always( callback && function( jqXHR, status ) { 74 | self.each( function() { 75 | callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); 76 | } ); 77 | } ); 78 | } 79 | 80 | return this; 81 | }; 82 | 83 | } ); 84 | -------------------------------------------------------------------------------- /src/javarepl/console/ConsoleHistory.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import com.googlecode.totallylazy.Files; 4 | import com.googlecode.totallylazy.Option; 5 | import com.googlecode.totallylazy.Sequence; 6 | import com.googlecode.totallylazy.Strings; 7 | import com.googlecode.totallylazy.predicates.Predicate; 8 | 9 | import java.io.File; 10 | 11 | import static com.googlecode.totallylazy.Option.option; 12 | import static com.googlecode.totallylazy.Sequences.empty; 13 | import static com.googlecode.totallylazy.Strings.replaceAll; 14 | import static com.googlecode.totallylazy.predicates.Not.not; 15 | 16 | 17 | public final class ConsoleHistory { 18 | private final Option file; 19 | private final Predicate ignored; 20 | 21 | private Sequence history = empty(); 22 | 23 | private ConsoleHistory(Sequence history, Predicate ignored, Option file) { 24 | this.ignored = ignored; 25 | this.history = addToHistory(history); 26 | this.file = file; 27 | } 28 | 29 | public static final ConsoleHistory emptyHistory(Predicate ignored, Option file) { 30 | return new ConsoleHistory(empty(String.class), ignored, file); 31 | } 32 | 33 | public static final ConsoleHistory historyFromFile(Predicate ignored, Option file) { 34 | if (file.isEmpty()) 35 | return emptyHistory(ignored, file); 36 | 37 | try { 38 | return new ConsoleHistory(Strings.lines(file.get()), ignored, file); 39 | } catch (Exception e) { 40 | return emptyHistory(ignored, file); 41 | } 42 | } 43 | 44 | public boolean save() { 45 | if (file.isEmpty()) 46 | return false; 47 | 48 | try { 49 | Files.write(history.toString("\n").getBytes(), file.get()); 50 | return true; 51 | } catch (Exception e) { 52 | return false; 53 | } 54 | } 55 | 56 | public ConsoleHistory add(String expression) { 57 | history = addToHistory(option(expression).map(replaceAll("\n", " ")).toSequence()); 58 | return this; 59 | } 60 | 61 | public Sequence items() { 62 | return history; 63 | } 64 | 65 | private Sequence addToHistory(Sequence historyToAdd) { 66 | return history.join(historyToAdd.map(replaceAll("\n", " "))).filter(not(ignored)).reverse().take(300).reverse(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/javarepl/completion/TypeCompleter.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | 4 | import com.googlecode.totallylazy.Sequence; 5 | import com.googlecode.totallylazy.Strings; 6 | import com.googlecode.totallylazy.functions.Function1; 7 | 8 | import static com.googlecode.totallylazy.Sequences.empty; 9 | import static com.googlecode.totallylazy.Strings.startsWith; 10 | import static com.googlecode.totallylazy.comparators.Comparators.ascending; 11 | import static com.googlecode.totallylazy.predicates.Predicates.*; 12 | import static javarepl.completion.CompletionCandidate.asCompletionCandidate; 13 | 14 | public final class TypeCompleter extends Completer { 15 | private final TypeResolver typeResolver; 16 | 17 | public TypeCompleter(TypeResolver typeResolver) { 18 | this.typeResolver = typeResolver; 19 | } 20 | 21 | public CompletionResult call(String expression) throws Exception { 22 | final int lastSpace = expression.lastIndexOf(" ") + 1; 23 | final String packagePart = expression.substring(lastSpace); 24 | final int beginIndex = packagePart.lastIndexOf('.') + 1; 25 | 26 | Sequence resolvedPackages = typeResolver.packages().filter(where(ResolvedPackage::packageName, startsWith(packagePart))); 27 | 28 | Sequence classesInPackage = beginIndex > 0 29 | ? typeResolver.packages().filter(where(ResolvedPackage::packageName, equalTo(packagePart.substring(0, beginIndex - 1)))) 30 | .flatMap(ResolvedPackage::classes) 31 | .map(ResolvedClass::canonicalClassName) 32 | .filter(startsWith(packagePart)) 33 | : empty(String.class); 34 | 35 | Sequence candidates = resolvedPackages.map(ResolvedPackage::packageName).join(classesInPackage) 36 | .map(candidatePackagePrefix(beginIndex)) 37 | .filter(not(Strings.empty())) 38 | .unique() 39 | .sort(ascending(String.class)) 40 | .map(asCompletionCandidate()); 41 | 42 | return new CompletionResult(expression, lastSpace + beginIndex, candidates); 43 | } 44 | 45 | private Function1 candidatePackagePrefix(final int fromIndex) { 46 | return item -> { 47 | int toIndex = item.indexOf('.', fromIndex); 48 | 49 | if (toIndex < fromIndex) 50 | toIndex = item.length(); 51 | 52 | return item.substring(fromIndex, toIndex); 53 | }; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/javarepl/completion/ConsoleCompleter.java: -------------------------------------------------------------------------------- 1 | package javarepl.completion; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import com.googlecode.totallylazy.functions.Function1; 5 | import javarepl.Evaluator; 6 | import javarepl.Result; 7 | import javarepl.expressions.Expression; 8 | import javarepl.expressions.Import; 9 | import javarepl.expressions.Method; 10 | import javarepl.expressions.Type; 11 | 12 | import static com.googlecode.totallylazy.Strings.*; 13 | import static com.googlecode.totallylazy.predicates.Predicates.in; 14 | import static com.googlecode.totallylazy.predicates.Predicates.where; 15 | import static javarepl.completion.CompletionCandidate.asCompletionCandidate; 16 | 17 | public class ConsoleCompleter extends Completer { 18 | private final Evaluator evaluator; 19 | private final TypeResolver typeResolver; 20 | 21 | public ConsoleCompleter(Evaluator evaluator, TypeResolver typeResolver) { 22 | this.evaluator = evaluator; 23 | this.typeResolver = typeResolver; 24 | } 25 | 26 | public CompletionResult call(String expression) throws Exception { 27 | int lastSpace = expression.lastIndexOf(" ") + 1; 28 | Sequence candidates = results() 29 | .join(methods()) 30 | .join(types()) 31 | .join(imports()) 32 | .filter(startsWith(expression.substring(lastSpace))) 33 | .map(asCompletionCandidate()); 34 | 35 | return new CompletionResult(expression, lastSpace, candidates); 36 | } 37 | 38 | private Sequence results() { 39 | return evaluator.results().map(Result::key); 40 | } 41 | 42 | private Sequence methods() { 43 | return evaluator.expressionsOfType(Method.class).map(Method::name).unique().map(format("%s(")); 44 | } 45 | 46 | private Sequence types() { 47 | return evaluator.expressionsOfType(Type.class).map(Expression::key); 48 | } 49 | 50 | private Sequence imports() { 51 | Sequence importedPackages = evaluator 52 | .expressionsOfType(Import.class) 53 | .map(((Function1) Import::typePackage).then(replace(".*", "")).then(replace(" ", ""))); 54 | 55 | return typeResolver.packages() 56 | .filter(where(ResolvedPackage::packageName, in(importedPackages))) 57 | .flatMap(ResolvedPackage::classes) 58 | .map(ResolvedClass::className) 59 | .unique(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/javarepl/console/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | package javarepl.console; 2 | 3 | import com.googlecode.totallylazy.Sequence; 4 | import com.googlecode.totallylazy.Sequences; 5 | 6 | import java.io.IOException; 7 | import java.io.OutputStream; 8 | import java.io.PrintStream; 9 | 10 | public final class ConsoleLogger { 11 | private Sequence logs = Sequences.empty(); 12 | private final PrintStream infoStream; 13 | private final PrintStream errorStream; 14 | private final Boolean colored; 15 | 16 | public ConsoleLogger(PrintStream infoStream, PrintStream errorStream, Boolean colored) { 17 | this.infoStream = infoStream; 18 | this.errorStream = errorStream; 19 | this.colored = colored; 20 | } 21 | 22 | public ConsoleLogger() { 23 | infoStream = voidOutputStream(); 24 | errorStream = voidOutputStream(); 25 | colored = false; 26 | } 27 | 28 | public void info(String message) { 29 | log(ConsoleLog.info(message)); 30 | } 31 | 32 | public void control(String message) { 33 | log(ConsoleLog.control(message)); 34 | } 35 | 36 | public void success(String message) { 37 | log(ConsoleLog.success(message)); 38 | } 39 | 40 | public void error(String message) { 41 | log(ConsoleLog.error(message)); 42 | } 43 | 44 | public void log(ConsoleLog log) { 45 | switch (log.type()) { 46 | case INFO: 47 | printColored(infoStream, log.message(), "\u001B[0m"); 48 | break; 49 | case SUCCESS: 50 | printColored(infoStream, log.message(), "\u001B[32m"); 51 | break; 52 | case ERROR: 53 | printColored(errorStream, log.message(), "\u001B[31m"); 54 | break; 55 | } 56 | 57 | logs = logs.append(log); 58 | } 59 | 60 | private void printColored(PrintStream stream, String message, String color) { 61 | if (colored) 62 | stream.print(color); 63 | 64 | stream.println(message); 65 | 66 | if (colored) 67 | stream.print("\u001B[0m"); 68 | } 69 | 70 | public Sequence logs() { 71 | return logs; 72 | } 73 | 74 | public void reset() { 75 | logs = Sequences.empty(); 76 | } 77 | 78 | private PrintStream voidOutputStream() { 79 | return new PrintStream(new OutputStream() { 80 | public void write(int b) throws IOException { 81 | } 82 | }); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | env: 5 | global: 6 | - PROJECT_REPOSITORY="albertlatacz/java-repl" 7 | - PROJECT_VERSION=$TRAVIS_BUILD_NUMBER 8 | - secure: "GgktdD6R+usYtITrqJcpcgU0MjwZXI0kcL1MVwqJVH7+6dAxt2i4ddHj62lT2zjPah1EqL/OXVw3WrhI3kDgljSuG4kcFsTj/ZBDpzhFtFL6aF5SR49tHUykL5nSaIp53TVnHFnk5CuRUUVxAnlUxNLWDCNyYfD3GB2vxJnicMs=" 9 | - secure: "bIFU+VgbcIJ5DmsXkoxTaLGI40uIyWdTFnco7FaJLoJLwLJSake4jemFv5SI\nJaSFVINBXA+Xn/qqHmFfWVr2fKsAevwRfkkIuTM1QMlN2TOMkCwOrz6mYA3f\nxjh+oKXUzNutZTHSyoCyZ72uHSJ33TlPWHU+OToS4AYxf8LrTYI=" 10 | - secure: "O0xTkW+WBNWT0a44u7XRpm0vp0q04ZFv/ovmPX6nm3fRokuiHMoRaL1l7r1K\nLF9ow3n+Ncsl64XRJNv2rjKVrxb19GtZQjxnHqi6bW2FSnoTEJsfvIjgMOwh\nrOHL9MUP61idRqN15ki0qYsmZ8t3xN9rw04fJLGZn73Oy0uRSGI=" 11 | - secure: "C5j0sZWXhfOoaVYyylyM7aJsjUSBbiIkW2GpAhODIrp/E5l297TymomFOCOTZSL1xF5V4RYt6jc7db+Qri5ryeHd0IIYMNWqcmni4rChtKp4b2F4qh+eqwre8RW5hONOcByZTQDvo+m3SCTuoTWcIM/UIhQIGovSPtYmqjQlSwI=" 12 | - secure: "fpuaeSvHiDRtUGHRuCkaZOglaE8IujaCXjSShYP78kxaZUOkHCY6meGmk2YRB6nKTs80lpiQCGFOmtcdEOsCRt2kQXuzJR6NkcG8JEYbdD36G0zR/GpeZ38o3lZqd7Xy1FEGwTgMi0Wy699ZvSoBP1xtGz8A7f8G9ROV7E81gdw=" 13 | - secure: "bxZ+/YMNG5guSA4R62wsIODwvslnqh4YwzaZjCuSO8FsXzEFkRLbZlgNTJYthcKEOZK0Oq+7d0nr0Dh2hKSgOx/FM2nCNzL3kMc/D4gAi54OET8wOv21PgiZQomPlZd5v62uTdw8XDrSzdEG8tzjrA21GDGNFF+Uuz3KPfoQfc0=" 14 | - secure: "KdWNLW5VYhvGUMIB0Q4OwPfPAFLhVNi9hLRw2ZapBq245iVf7ayMXZznyOpSYgOjuXRqx/24ww+LSBFGM/rFetIiP2mA1A4RpxYpyRzJmfhxz3e4Rj71bE1JrLynY/MLIuH4NERMRdH1kZjQaY+IFkXqas5C+FD8Msj0owzlwLE=" 15 | - secure: "Z5wmAFWOUv1fV3A/iCDrz9J59vZVzAn1tQigpYKdCTsvuZMHvk7SP3+3Aak2NEtuRzzu09WuBmCE6pfES3HbvD2W0jR2iqiv0bECnt5pCptC9QjlAw9vvGhm0Tz/aR4dJwzAjWBREU4LTgjN65416jclKV1HxhJcw90CZbYBmNo=" 16 | - secure: "fovLGO44v27+u6dYAtT9zqpm/pJImgl6Bb4YqJ6VGSqx87axro3bkoeqlrw8aTThCqNxBCtoOPx7iPmQVi2l8fB5Dh7G8P50CYtT6fb9p8e7GHh9vZDBRk/UQmm5XALBX2dna1dN/UOKTyN/NFAajfCt6lAah5d9HvDpqw9E7Xs=" 17 | - secure: "BhPDDFZqVLPx5g2Tu4n2AMT9MhmnFKmK9g+D+jmOkkn9CEMPByWoJDqOZghUE/1Dw0f8wv6wmjK6WfolmxT0lTTmybN9+b/K9yTULldx1tIQ+bXToaf+cSjw+ZBkY8WSgBa5h3tHSRLpjp+zgERuJR1erWsIpU6UDVfx2RgVHeg=" 18 | - secure: "AZAE6aWnJyQvNsEL/9PFweOyVNnUxgWhdPHD4OONHr3y3D+uT7kZn6GJx0C0f4bvQGCX5ENGbDqh/NSEplD+85kwQrhW9Qi3G+zZbrENHygQUVaHi6OC+JmsIvkLS6WFe013jGAJeP3+dt8aE+VRIECtA7RvpHGS+ONCUh7YBVs=" 19 | 20 | sudo: required 21 | 22 | branches: 23 | only: 24 | - master 25 | 26 | services: 27 | - docker 28 | 29 | script: 30 | - gradle clean check shadowJar bintrayUpload githubRelease 31 | 32 | after_success: 33 | - sh bin/push-to-docker-hub.sh -------------------------------------------------------------------------------- /src/javarepl/console/ui/console.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | Java REPL 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 39 | 40 | 41 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | --------------------------------------------------------------------------------