{"action":"created","comment":{"url":"https://api.github.com/repos/ensime/ensime-server/pulls/comments/42855393","id":42855393,"diff_hunk":"@@ -0,0 +1,178 @@\n+package org.ensime.core.javac\n+\n+import akka.actor.ActorRef\n+import akka.event.LoggingAdapter\n+import com.sun.source.tree.CompilationUnitTree\n+import com.sun.source.util.JavacTask\n+import com.sun.source.tree.Scope\n+import com.sun.source.util.TreePath\n+import com.sun.source.util.Trees\n+import java.io.{ File, FileInputStream, IOException, InputStream }\n+import java.net.URI\n+import java.nio.charset.Charset\n+import java.util.Locale\n+import javax.lang.model.`type`.TypeMirror\n+import javax.tools._\n+import org.ensime.api._\n+import org.ensime.core.DocSigPair\n+import org.ensime.util.ReportHandler\n+import org.ensime.util.{ FileUtils, ReportHandler }\n+import scala.collection.JavaConversions._\n+import scala.concurrent.Future\n+import scala.reflect.internal.util.{ BatchSourceFile, RangePosition, SourceFile }\n+import scala.tools.nsc.Settings\n+import scala.tools.nsc.interactive.CompilerControl\n+import scala.tools.nsc.io.AbstractFile\n+import scala.tools.nsc.reporters.Reporter\n+import scala.tools.refactoring.analysis.GlobalIndexes\n+\n+class JavaCompiler(\n+    val config: EnsimeConfig,\n+    val charset: Charset,\n+    val indexer: ActorRef,\n+    val reportHandler: ReportHandler\n+) extends JavaDocFinding with JavaCompletion {\n+\n+  import scala.concurrent.ExecutionContext.Implicits.{ global => exe }\n+\n+  val compiler = ToolProvider.getSystemJavaCompiler()\n+  private val listener = new JavaDiagnosticListener()\n+  private val silencer = new SilencedDiagnosticListener()\n+  val fileManager = compiler.getStandardFileManager(listener, null, charset)\n+  val cp = config.compileClasspath.mkString(File.pathSeparator)\n+\n+  def askTypecheckFiles(files: Iterable[SourceFileInfo]): Future[Boolean] = Future {\n+    reportHandler.clearAllJavaNotes()\n+    typecheckAll(files.map(getJavaFileObject))\n+    true\n+  }\n+\n+  def askTypeAtPoint(file: SourceFileInfo, offset: Int): Future[Option[TypeInfo]] = Future {\n+    pathToPoint(file, offset) flatMap {\n+      case (info: CompilationInfo, path: TreePath) =>\n+        getTypeMirror(info, offset).map(typeMirrorToTypeInfo)\n+    }\n+  }\n+\n+  def askDocSignatureAtPoint(file: SourceFileInfo, offset: Int): Future[Option[DocSigPair]] = Future {\n+    pathToPoint(file, offset) flatMap {\n+      case (info: CompilationInfo, path: TreePath) =>\n+        docSignature(info, path)\n+    }\n+  }\n+\n+  def askCompletionsAtPoint(\n+    file: SourceFileInfo, offset: Int, maxResults: Int, caseSens: Boolean\n+  ): Future[CompletionInfoList] = Future {\n+    completionsAt(file, offset, maxResults, caseSens)\n+  }\n+\n+  protected def pathToPoint(file: SourceFileInfo, offset: Int): Option[(CompilationInfo, TreePath)] = {\n+    val infos = typecheckForUnits(List(getJavaFileObject(file)))\n+    infos.headOption.flatMap { info =>\n+      val path = Option(new TreeUtilities(info).pathFor(offset))\n+      path.map { p => (info, p) }\n+    }\n+  }\n+\n+  protected def scopeForPoint(file: SourceFileInfo, offset: Int): Option[(CompilationInfo, Scope)] = {\n+    val infos = typecheckForUnits(List(getJavaFileObject(file)))\n+    infos.headOption.flatMap { info =>\n+      val path = Option(new TreeUtilities(info).scopeFor(offset))\n+      path.map { p => (info, p) }\n+    }\n+  }\n+\n+  private def typeMirrorToTypeInfo(tm: TypeMirror): TypeInfo = {\n+    BasicTypeInfo(tm.toString, -1, DeclaredAs.Class, tm.toString, List(), List(), Some(EmptySourcePosition()), None)\n+  }\n+\n+  private def getTypeMirror(info: CompilationInfo, offset: Int): Option[TypeMirror] = {\n+    val path = Option(new TreeUtilities(info).pathFor(offset))\n+    // Uncomment to debug the AST path.\n+    //for (p <- path) { for (t <- p) { System.err.println(t.toString()) } }\n+    path.flatMap { p => Option(info.getTrees().getTypeMirror(p)) }\n+  }\n+\n+  private def typecheckAll(files: Iterable[JavaFileObject]): Unit = {\n+    val task = compiler.getTask(null, fileManager, listener, List(\n+      \"-cp\", cp, \"-Xlint:all\", \"-proc:none\"\n+    ), null, asJavaIterable(files)).asInstanceOf[JavacTask]\n+    val t = System.currentTimeMillis()\n+    task.parse()\n+    task.analyze()\n+    System.err.println(\"Parsed and analyzed: \" + (System.currentTimeMillis() - t) + \"ms\")","path":"core/src/main/scala/org/ensime/core/javac/JavaCompiler.scala","position":104,"original_position":104,"commit_id":"3a23ac1bc8c4c55f86bac9b989e796fb2e8ea18a","original_commit_id":"3a23ac1bc8c4c55f86bac9b989e796fb2e8ea18a","user":{"login":"fommil","id":1914041,"avatar_url":"https://avatars.githubusercontent.com/u/1914041?v=3","gravatar_id":"","url":"https://api.github.com/users/fommil","html_url":"https://github.com/fommil","followers_url":"https://api.github.com/users/fommil/followers","following_url":"https://api.github.com/users/fommil/following{/other_user}","gists_url":"https://api.github.com/users/fommil/gists{/gist_id}","starred_url":"https://api.github.com/users/fommil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fommil/subscriptions","organizations_url":"https://api.github.com/users/fommil/orgs","repos_url":"https://api.github.com/users/fommil/repos","events_url":"https://api.github.com/users/fommil/events{/privacy}","received_events_url":"https://api.github.com/users/fommil/received_events","type":"User","site_admin":false},"body":"looks like some println debugging has been left in... move to SLF4J or remove?","created_at":"2015-10-23T11:30:52Z","updated_at":"2015-10-23T11:30:52Z","html_url":"https://github.com/ensime/ensime-server/pull/1108#discussion_r42855393","pull_request_url":"https://api.github.com/repos/ensime/ensime-server/pulls/1108","_links":{"self":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/comments/42855393"},"html":{"href":"https://github.com/ensime/ensime-server/pull/1108#discussion_r42855393"},"pull_request":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/1108"}}},"pull_request":{"url":"https://api.github.com/repos/ensime/ensime-server/pulls/1108","id":46699318,"html_url":"https://github.com/ensime/ensime-server/pull/1108","diff_url":"https://github.com/ensime/ensime-server/pull/1108.diff","patch_url":"https://github.com/ensime/ensime-server/pull/1108.patch","issue_url":"https://api.github.com/repos/ensime/ensime-server/issues/1108","number":1108,"state":"open","locked":false,"title":"First pass on java type checking, type at point, doc finding","user":{"login":"aemoncannon","id":7484,"avatar_url":"https://avatars.githubusercontent.com/u/7484?v=3","gravatar_id":"","url":"https://api.github.com/users/aemoncannon","html_url":"https://github.com/aemoncannon","followers_url":"https://api.github.com/users/aemoncannon/followers","following_url":"https://api.github.com/users/aemoncannon/following{/other_user}","gists_url":"https://api.github.com/users/aemoncannon/gists{/gist_id}","starred_url":"https://api.github.com/users/aemoncannon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aemoncannon/subscriptions","organizations_url":"https://api.github.com/users/aemoncannon/orgs","repos_url":"https://api.github.com/users/aemoncannon/repos","events_url":"https://api.github.com/users/aemoncannon/events{/privacy}","received_events_url":"https://api.github.com/users/aemoncannon/received_events","type":"User","site_admin":false},"body":"Still rough. Please give it a high level look.\r\n\r\nNote:  I had a hell of a time trying to go full netbeans. Just typechecking a file seems to require buying into their indexing framework. A walk through the debugger revealed all kinds of ide code (org.netbeans....editor??) being loaded, singletons talking to each other all over the place, etc. In the end I just used/ripped the minimum that I needed to make these tests pass (TreeUtilities is a copy paste job).","created_at":"2015-10-03T04:06:32Z","updated_at":"2015-10-23T11:30:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ae346636ef48fcfae33fa8d6e99783ee3aec87f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ensime/ensime-server/pulls/1108/commits","review_comments_url":"https://api.github.com/repos/ensime/ensime-server/pulls/1108/comments","review_comment_url":"https://api.github.com/repos/ensime/ensime-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ensime/ensime-server/issues/1108/comments","statuses_url":"https://api.github.com/repos/ensime/ensime-server/statuses/3a23ac1bc8c4c55f86bac9b989e796fb2e8ea18a","head":{"label":"aemoncannon:java-type-checking","ref":"java-type-checking","sha":"3a23ac1bc8c4c55f86bac9b989e796fb2e8ea18a","user":{"login":"aemoncannon","id":7484,"avatar_url":"https://avatars.githubusercontent.com/u/7484?v=3","gravatar_id":"","url":"https://api.github.com/users/aemoncannon","html_url":"https://github.com/aemoncannon","followers_url":"https://api.github.com/users/aemoncannon/followers","following_url":"https://api.github.com/users/aemoncannon/following{/other_user}","gists_url":"https://api.github.com/users/aemoncannon/gists{/gist_id}","starred_url":"https://api.github.com/users/aemoncannon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aemoncannon/subscriptions","organizations_url":"https://api.github.com/users/aemoncannon/orgs","repos_url":"https://api.github.com/users/aemoncannon/repos","events_url":"https://api.github.com/users/aemoncannon/events{/privacy}","received_events_url":"https://api.github.com/users/aemoncannon/received_events","type":"User","site_admin":false},"repo":{"id":21144295,"name":"ensime-server","full_name":"aemoncannon/ensime-server","owner":{"login":"aemoncannon","id":7484,"avatar_url":"https://avatars.githubusercontent.com/u/7484?v=3","gravatar_id":"","url":"https://api.github.com/users/aemoncannon","html_url":"https://github.com/aemoncannon","followers_url":"https://api.github.com/users/aemoncannon/followers","following_url":"https://api.github.com/users/aemoncannon/following{/other_user}","gists_url":"https://api.github.com/users/aemoncannon/gists{/gist_id}","starred_url":"https://api.github.com/users/aemoncannon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aemoncannon/subscriptions","organizations_url":"https://api.github.com/users/aemoncannon/orgs","repos_url":"https://api.github.com/users/aemoncannon/repos","events_url":"https://api.github.com/users/aemoncannon/events{/privacy}","received_events_url":"https://api.github.com/users/aemoncannon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aemoncannon/ensime-server","description":"ENhanced Scala Interaction Mode for Emacs","fork":true,"url":"https://api.github.com/repos/aemoncannon/ensime-server","forks_url":"https://api.github.com/repos/aemoncannon/ensime-server/forks","keys_url":"https://api.github.com/repos/aemoncannon/ensime-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aemoncannon/ensime-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aemoncannon/ensime-server/teams","hooks_url":"https://api.github.com/repos/aemoncannon/ensime-server/hooks","issue_events_url":"https://api.github.com/repos/aemoncannon/ensime-server/issues/events{/number}","events_url":"https://api.github.com/repos/aemoncannon/ensime-server/events","assignees_url":"https://api.github.com/repos/aemoncannon/ensime-server/assignees{/user}","branches_url":"https://api.github.com/repos/aemoncannon/ensime-server/branches{/branch}","tags_url":"https://api.github.com/repos/aemoncannon/ensime-server/tags","blobs_url":"https://api.github.com/repos/aemoncannon/ensime-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aemoncannon/ensime-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aemoncannon/ensime-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/aemoncannon/ensime-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aemoncannon/ensime-server/statuses/{sha}","languages_url":"https://api.github.com/repos/aemoncannon/ensime-server/languages","stargazers_url":"https://api.github.com/repos/aemoncannon/ensime-server/stargazers","contributors_url":"https://api.github.com/repos/aemoncannon/ensime-server/contributors","subscribers_url":"https://api.github.com/repos/aemoncannon/ensime-server/subscribers","subscription_url":"https://api.github.com/repos/aemoncannon/ensime-server/subscription","commits_url":"https://api.github.com/repos/aemoncannon/ensime-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/aemoncannon/ensime-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/aemoncannon/ensime-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/aemoncannon/ensime-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/aemoncannon/ensime-server/contents/{+path}","compare_url":"https://api.github.com/repos/aemoncannon/ensime-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aemoncannon/ensime-server/merges","archive_url":"https://api.github.com/repos/aemoncannon/ensime-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aemoncannon/ensime-server/downloads","issues_url":"https://api.github.com/repos/aemoncannon/ensime-server/issues{/number}","pulls_url":"https://api.github.com/repos/aemoncannon/ensime-server/pulls{/number}","milestones_url":"https://api.github.com/repos/aemoncannon/ensime-server/milestones{/number}","notifications_url":"https://api.github.com/repos/aemoncannon/ensime-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aemoncannon/ensime-server/labels{/name}","releases_url":"https://api.github.com/repos/aemoncannon/ensime-server/releases{/id}","created_at":"2014-06-23T22:21:53Z","updated_at":"2015-09-11T21:05:58Z","pushed_at":"2015-10-22T21:37:08Z","git_url":"git://github.com/aemoncannon/ensime-server.git","ssh_url":"git@github.com:aemoncannon/ensime-server.git","clone_url":"https://github.com/aemoncannon/ensime-server.git","svn_url":"https://github.com/aemoncannon/ensime-server","homepage":"","size":55068,"stargazers_count":1,"watchers_count":1,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"ensime:master","ref":"master","sha":"e60e3b354a262ad2275fe37fe7818442eda1a727","user":{"login":"ensime","id":5089042,"avatar_url":"https://avatars.githubusercontent.com/u/5089042?v=3","gravatar_id":"","url":"https://api.github.com/users/ensime","html_url":"https://github.com/ensime","followers_url":"https://api.github.com/users/ensime/followers","following_url":"https://api.github.com/users/ensime/following{/other_user}","gists_url":"https://api.github.com/users/ensime/gists{/gist_id}","starred_url":"https://api.github.com/users/ensime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ensime/subscriptions","organizations_url":"https://api.github.com/users/ensime/orgs","repos_url":"https://api.github.com/users/ensime/repos","events_url":"https://api.github.com/users/ensime/events{/privacy}","received_events_url":"https://api.github.com/users/ensime/received_events","type":"Organization","site_admin":false},"repo":{"id":578384,"name":"ensime-server","full_name":"ensime/ensime-server","owner":{"login":"ensime","id":5089042,"avatar_url":"https://avatars.githubusercontent.com/u/5089042?v=3","gravatar_id":"","url":"https://api.github.com/users/ensime","html_url":"https://github.com/ensime","followers_url":"https://api.github.com/users/ensime/followers","following_url":"https://api.github.com/users/ensime/following{/other_user}","gists_url":"https://api.github.com/users/ensime/gists{/gist_id}","starred_url":"https://api.github.com/users/ensime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ensime/subscriptions","organizations_url":"https://api.github.com/users/ensime/orgs","repos_url":"https://api.github.com/users/ensime/repos","events_url":"https://api.github.com/users/ensime/events{/privacy}","received_events_url":"https://api.github.com/users/ensime/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ensime/ensime-server","description":"ENhanced Scala Interaction Mode for text Editors (especially Emacs) Server Component","fork":false,"url":"https://api.github.com/repos/ensime/ensime-server","forks_url":"https://api.github.com/repos/ensime/ensime-server/forks","keys_url":"https://api.github.com/repos/ensime/ensime-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ensime/ensime-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ensime/ensime-server/teams","hooks_url":"https://api.github.com/repos/ensime/ensime-server/hooks","issue_events_url":"https://api.github.com/repos/ensime/ensime-server/issues/events{/number}","events_url":"https://api.github.com/repos/ensime/ensime-server/events","assignees_url":"https://api.github.com/repos/ensime/ensime-server/assignees{/user}","branches_url":"https://api.github.com/repos/ensime/ensime-server/branches{/branch}","tags_url":"https://api.github.com/repos/ensime/ensime-server/tags","blobs_url":"https://api.github.com/repos/ensime/ensime-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ensime/ensime-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ensime/ensime-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/ensime/ensime-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ensime/ensime-server/statuses/{sha}","languages_url":"https://api.github.com/repos/ensime/ensime-server/languages","stargazers_url":"https://api.github.com/repos/ensime/ensime-server/stargazers","contributors_url":"https://api.github.com/repos/ensime/ensime-server/contributors","subscribers_url":"https://api.github.com/repos/ensime/ensime-server/subscribers","subscription_url":"https://api.github.com/repos/ensime/ensime-server/subscription","commits_url":"https://api.github.com/repos/ensime/ensime-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/ensime/ensime-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/ensime/ensime-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/ensime/ensime-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/ensime/ensime-server/contents/{+path}","compare_url":"https://api.github.com/repos/ensime/ensime-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ensime/ensime-server/merges","archive_url":"https://api.github.com/repos/ensime/ensime-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ensime/ensime-server/downloads","issues_url":"https://api.github.com/repos/ensime/ensime-server/issues{/number}","pulls_url":"https://api.github.com/repos/ensime/ensime-server/pulls{/number}","milestones_url":"https://api.github.com/repos/ensime/ensime-server/milestones{/number}","notifications_url":"https://api.github.com/repos/ensime/ensime-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ensime/ensime-server/labels{/name}","releases_url":"https://api.github.com/repos/ensime/ensime-server/releases{/id}","created_at":"2010-03-25T00:57:54Z","updated_at":"2015-10-17T18:39:06Z","pushed_at":"2015-10-23T10:34:29Z","git_url":"git://github.com/ensime/ensime-server.git","ssh_url":"git@github.com:ensime/ensime-server.git","clone_url":"https://github.com/ensime/ensime-server.git","svn_url":"https://github.com/ensime/ensime-server","homepage":"","size":65535,"stargazers_count":900,"watchers_count":900,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":182,"mirror_url":null,"open_issues_count":98,"forks":182,"open_issues":98,"watchers":900,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/1108"},"html":{"href":"https://github.com/ensime/ensime-server/pull/1108"},"issue":{"href":"https://api.github.com/repos/ensime/ensime-server/issues/1108"},"comments":{"href":"https://api.github.com/repos/ensime/ensime-server/issues/1108/comments"},"review_comments":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/1108/comments"},"review_comment":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ensime/ensime-server/pulls/1108/commits"},"statuses":{"href":"https://api.github.com/repos/ensime/ensime-server/statuses/3a23ac1bc8c4c55f86bac9b989e796fb2e8ea18a"}}}}