From dd63a88e6a0c34826c14ee317250581119507d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 2 Sep 2020 10:55:28 +0200 Subject: [PATCH] Cleanup cpp --- .../pmd/internal/util/AssertionUtil.java | 2 +- .../pmd/util/document/SourceCodePositioner.java | 2 +- .../java/net/sourceforge/pmd/cpd/CPPTokenizer.java | 11 ++++++----- .../net/sourceforge/pmd/cpd/CppBlockSkipper.java | 14 +++++++------- .../pmd/lang/java/ast/FormalComment.java | 4 +--- .../pmd/lang/java/ast/InternalApiBridge.java | 5 ----- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/AssertionUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/AssertionUtil.java index 2f47421a24..4e3ad73af7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/AssertionUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/AssertionUtil.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.internal.util; import java.util.Collection; -import java.util.regex.Pattern; import java.util.function.Function; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/document/SourceCodePositioner.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/document/SourceCodePositioner.java index 4c008918cd..b3e1966208 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/document/SourceCodePositioner.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/document/SourceCodePositioner.java @@ -216,7 +216,7 @@ final class SourceCodePositioner { buf = new int[Math.max(1, bufSize)]; } - public Builder() { + Builder() { this(400); } diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java index fbb80a8f33..2dada00663 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.cpd; import java.io.IOException; import java.util.Properties; +import java.util.regex.Pattern; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; @@ -22,8 +23,8 @@ import net.sourceforge.pmd.util.document.TextDocument; public class CPPTokenizer extends JavaCCTokenizer { private boolean skipBlocks; - private String skipBlocksStart; - private String skipBlocksEnd; + private Pattern skipBlocksStart; + private Pattern skipBlocksEnd; public CPPTokenizer() { setProperties(new Properties()); // set the defaults @@ -48,11 +49,11 @@ public class CPPTokenizer extends JavaCCTokenizer { if (skipBlocks) { String skipBlocksPattern = properties.getProperty(OPTION_SKIP_BLOCKS_PATTERN, DEFAULT_SKIP_BLOCKS_PATTERN); String[] split = skipBlocksPattern.split("\\|", 2); - skipBlocksStart = split[0]; + skipBlocksStart = CppBlockSkipper.compileSkipMarker(split[0]); if (split.length == 1) { - skipBlocksEnd = split[0]; + skipBlocksEnd = skipBlocksStart; } else { - skipBlocksEnd = split[1]; + skipBlocksEnd = CppBlockSkipper.compileSkipMarker(split[1]); } } } diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CppBlockSkipper.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CppBlockSkipper.java index fa5be8ee91..4770579f60 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CppBlockSkipper.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CppBlockSkipper.java @@ -18,16 +18,16 @@ import net.sourceforge.pmd.util.document.TextDocument; class CppBlockSkipper extends EscapeTranslator { private final Pattern skipStart; - private final String skipStartMarker; private final Pattern skipEnd; - private final String skipEndMarker; - public CppBlockSkipper(TextDocument original, String skipStartMarker, String skipEndMarker) { + static Pattern compileSkipMarker(String marker) { + return Pattern.compile("^(?i)" + Pattern.quote(marker), Pattern.MULTILINE); + } + + public CppBlockSkipper(TextDocument original, Pattern skipStartMarker, Pattern skipEndMarker) { super(original); - skipStart = Pattern.compile("^(?i)" + Pattern.quote(skipStartMarker), Pattern.MULTILINE); - this.skipStartMarker = "\n" + skipStartMarker; - skipEnd = Pattern.compile("^(?i)" + Pattern.quote(skipEndMarker), Pattern.MULTILINE); - this.skipEndMarker = "\n" + skipEndMarker; + skipStart = skipStartMarker; + skipEnd = skipEndMarker; } @Override diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/FormalComment.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/FormalComment.java index c232b943c0..4f47dd5bbf 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/FormalComment.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/FormalComment.java @@ -18,9 +18,7 @@ public class FormalComment extends Comment { public FormalComment(JavaccToken t) { super(t); - -// findJavadocs(); - + findJavadocs(t); } @Override diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index 840e06c235..d7706dae6c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -26,7 +26,6 @@ import net.sourceforge.pmd.lang.java.types.JVariableSig.FieldSig; import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; import net.sourceforge.pmd.lang.symboltable.Scope; -import net.sourceforge.pmd.util.document.TextDocument; /** * Acts as a bridge between outer parts of PMD and the restricted access @@ -96,10 +95,6 @@ public final class InternalApiBridge { return methodDeclaration; } - public static JavaccTokenDocument javaTokenDoc(String fullText) { - return new JavaTokenDocument(fullText); - } - public static void setSymbol(SymbolDeclaratorNode node, JElementSymbol symbol) { if (node instanceof ASTMethodDeclaration) { ((ASTMethodDeclaration) node).setSymbol((JMethodSymbol) symbol);