diff --git a/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java b/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java index e9ce320a0f..860e8b0b0f 100644 --- a/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java +++ b/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.cpd; import java.io.StringReader; +import org.codehaus.groovy.antlr.SourceInfo; import org.codehaus.groovy.antlr.parser.GroovyLexer; import net.sourceforge.pmd.lang.ast.TokenMgrError; @@ -31,8 +32,16 @@ public class GroovyTokenizer implements Tokenizer { while (token.getType() != Token.EOF_TYPE) { String tokenText = token.getText(); - TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine(), - token.getColumn(), tokenText.length()); + + + int lastCol; + if (token instanceof SourceInfo) { + lastCol = ((SourceInfo) token).getColumnLast(); + } else { + // fallback + lastCol = token.getColumn() + tokenText.length(); + } + TokenEntry tokenEntry = new TokenEntry(tokenText, sourceCode.getFileName(), token.getLine(), token.getColumn(), lastCol); tokenEntries.add(tokenEntry); token = tokenStream.nextToken(); diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java index 169d546c46..81c9eec95c 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java @@ -87,7 +87,7 @@ public class ScalaTokenizer implements Tokenizer { pos.endColumn() + 1); tokenEntries.add(cpdToken); } - } catch (Throwable e) { + } catch (@SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause") Exception e) { if (e instanceof TokenizeException) { // cannot catch it as it's a checked exception and Scala sneaky throws TokenizeException tokE = (TokenizeException) e;