From 9392239c45c85d9039ff34b80ae5ba8b9052076f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 18 Feb 2018 20:23:32 +0100 Subject: [PATCH] scala update, part 2 * Update to new scala API * remove comments support which was not used anyway * Use scala-maven-plugin to generate javadoc --- pmd-scala/pom.xml | 25 ++++++- .../sonar/plugins/scala/compiler/Lexer.scala | 70 ++----------------- 2 files changed, 26 insertions(+), 69 deletions(-) diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index 1b54f49cb9..55d3bd86ef 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -41,9 +41,7 @@ net.alchim31.maven scala-maven-plugin - - -Dscalac.patmat.analysisBudget=off - + -deprecation ${scala.version} @@ -55,6 +53,12 @@ compile + + attach-javadocs + + doc-jar + + @@ -65,6 +69,21 @@ pmd-scala-checkstyle-suppressions.xml + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + none + + jar + + + + diff --git a/pmd-scala/src/main/scala/org/sonar/plugins/scala/compiler/Lexer.scala b/pmd-scala/src/main/scala/org/sonar/plugins/scala/compiler/Lexer.scala index e6a58f1b18..2ff98040ae 100644 --- a/pmd-scala/src/main/scala/org/sonar/plugins/scala/compiler/Lexer.scala +++ b/pmd-scala/src/main/scala/org/sonar/plugins/scala/compiler/Lexer.scala @@ -19,7 +19,7 @@ */ package org.sonar.plugins.scala.compiler -import collection.mutable.ListBuffer +import scala.collection.mutable.Buffer import org.sonar.plugins.scala.language.{Comment, CommentType} import scala.reflect.io.AbstractFile @@ -34,7 +34,7 @@ import scala.reflect.internal.util.BatchSourceFile */ class Lexer { - import scala.collection.JavaConversions._ + import scala.collection.JavaConverters._ import Compiler._ def getTokens(code: String): java.util.List[Token] = { @@ -49,7 +49,7 @@ class Lexer { private def tokenize(unit: CompilationUnit): java.util.List[Token] = { val scanner = new syntaxAnalyzer.UnitScanner(unit) - val tokens = ListBuffer[Token]() + val tokens = Buffer[Token]() scanner.init() while (scanner.token != scala.tools.nsc.ast.parser.Tokens.EOF) { @@ -60,69 +60,7 @@ class Lexer { tokens += Token(scanner.token, linenr, tokenVal) scanner.nextToken() } - tokens + tokens.asJava } - def getComments(code: String): java.util.List[Comment] = { - val unit = new CompilationUnit(new BatchSourceFile("", code.toCharArray)) - tokenizeComments(unit) - } - - def getCommentsOfFile(path: String): java.util.List[Comment] = { - val unit = new CompilationUnit(new BatchSourceFile(AbstractFile.getFile(path))) - tokenizeComments(unit) - } - - private def tokenizeComments(unit: CompilationUnit): java.util.List[Comment] = { - val comments = ListBuffer[Comment]() - val scanner = new syntaxAnalyzer.UnitScanner(unit) { - - private var lastDocCommentRange: Option[Range] = None - - private var foundToken = false - - override def nextToken() { - super.nextToken() - foundToken = token != 0 - } - - override def foundComment(value: String, start: Int, end: Int) = { - super.foundComment(value, start, end) - - def isHeaderComment(value: String) = { - !foundToken && comments.isEmpty && value.trim().startsWith("/*") - } - - lastDocCommentRange match { - - case Some(r: Range) => { - if (r.start != start || r.end != end) { - comments += new Comment(value, CommentType.NORMAL) - } - } - - case None => { - if (isHeaderComment(value)) { - comments += new Comment(value, CommentType.HEADER) - } else { - comments += new Comment(value, CommentType.NORMAL) - } - } - } - } - - override def foundDocComment(value: String, start: Int, end: Int) = { - super.foundDocComment(value, start, end) - comments += new Comment(value, CommentType.DOC) - lastDocCommentRange = Some(Range(start, end)) - } - } - - scanner.init() - while (scanner.token != scala.tools.nsc.ast.parser.Tokens.EOF) { - scanner.nextToken() - } - - comments - } } \ No newline at end of file