diff --git a/org.sf.feeling.decompiler.cfr/src/org/sf/feeling/decompiler/cfr/decompiler/CfrDecompiler.java b/org.sf.feeling.decompiler.cfr/src/org/sf/feeling/decompiler/cfr/decompiler/CfrDecompiler.java
index 243682b7..ff810a20 100644
--- a/org.sf.feeling.decompiler.cfr/src/org/sf/feeling/decompiler/cfr/decompiler/CfrDecompiler.java
+++ b/org.sf.feeling.decompiler.cfr/src/org/sf/feeling/decompiler/cfr/decompiler/CfrDecompiler.java
@@ -1,211 +1,193 @@
-/*******************************************************************************
- * Copyright (c) 2017 Chen Chao and other ECD project contributors.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.sf.feeling.decompiler.cfr.decompiler;
-
-import java.io.File;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang3.time.StopWatch;
-import org.benf.cfr.reader.apiunreleased.ClassFileSource2;
-import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
-import org.benf.cfr.reader.entities.ClassFile;
-import org.benf.cfr.reader.entities.Method;
-import org.benf.cfr.reader.state.ClassFileSourceImpl;
-import org.benf.cfr.reader.state.DCCommonState;
-import org.benf.cfr.reader.state.TypeUsageCollectingDumper;
-import org.benf.cfr.reader.state.TypeUsageInformation;
-import org.benf.cfr.reader.util.CannotLoadClassException;
-import org.benf.cfr.reader.util.getopt.GetOptParser;
-import org.benf.cfr.reader.util.getopt.Options;
-import org.benf.cfr.reader.util.getopt.OptionsImpl;
-import org.benf.cfr.reader.util.output.IllegalIdentifierDump;
-import org.benf.cfr.reader.util.output.MethodErrorCollector;
-import org.benf.cfr.reader.util.output.StringStreamDumper;
-import org.sf.feeling.decompiler.JavaDecompilerConstants;
-import org.sf.feeling.decompiler.JavaDecompilerPlugin;
-import org.sf.feeling.decompiler.cfr.CfrDecompilerPlugin;
-import org.sf.feeling.decompiler.editor.BaseDecompiler;
-import org.sf.feeling.decompiler.editor.IDecompiler;
-import org.sf.feeling.decompiler.util.FileUtil;
-import org.sf.feeling.decompiler.util.JarClassExtractor;
-import org.sf.feeling.decompiler.util.UnicodeUtil;
-
-public class CfrDecompiler extends BaseDecompiler {
-
- private String source = ""; //$NON-NLS-1$
- private long time;
- private String log = ""; //$NON-NLS-1$
-
- /**
- * Performs a Runtime.exec()
on CFR with selected options.
- *
- * @see IDecompiler#decompile(String, String, String)
- */
- @Override
- public void decompile(String root, String packege, String className) {
- StopWatch stopWatch = new StopWatch();
- stopWatch.start();
- log = ""; //$NON-NLS-1$
- source = ""; //$NON-NLS-1$
- File workingDir = new File(root + "/" + packege); //$NON-NLS-1$
-
- String classPathStr = new File(workingDir, className).getAbsolutePath();
-
- GetOptParser getOptParser = new GetOptParser();
-
- try {
- Pair, Options> options = getOptParser.parse(new String[] { classPathStr },
- OptionsImpl.getFactory());
- Options namedOptions = options.getSecond();
- ClassFileSource2 classFileSource = new ClassFileSourceImpl(namedOptions);
- classFileSource.informAnalysisRelativePathDetail(null, null);
- DCCommonState dcCommonState = new DCCommonState(namedOptions, classFileSource);
-
- IllegalIdentifierDump illegalIdentifierDump = IllegalIdentifierDump.Factory.get(namedOptions);
-
- ClassFile classFile = dcCommonState.getClassFileMaybePath(classPathStr);
- dcCommonState.configureWith(classFile);
- try {
- classFile = dcCommonState.getClassFile(classFile.getClassType());
- } catch (CannotLoadClassException e) {
- throw new RuntimeException(e);
- }
- if (namedOptions.getOption(OptionsImpl.DECOMPILE_INNER_CLASSES).booleanValue()) {
- classFile.loadInnerClasses(dcCommonState);
- }
- TypeUsageCollectingDumper typeUsageCollectingDumper = new TypeUsageCollectingDumper(namedOptions,
- classFile);
-
- classFile.analyseTop(dcCommonState, typeUsageCollectingDumper);
-
- TypeUsageInformation typeUsageInfo = typeUsageCollectingDumper.getRealTypeUsageInformation();
-
- MethodErrorCollector methodErrorCollector = new MethodErrorCollector() {
-
- @Override
- public void addSummaryError(Method paramMethod, String msg) {
- log += String.format("\n%s: %s", paramMethod.toString(), msg);
- }
-
- };
-
- StringBuilder stringBuilder = new StringBuilder(4096);
- StringStreamDumper dumper = new StringStreamDumper(methodErrorCollector, stringBuilder, typeUsageInfo,
- namedOptions, illegalIdentifierDump);
- classFile.dump(dumper);
- source = UnicodeUtil.decode(stringBuilder.toString().trim());
-
- Pattern wp = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL); //$NON-NLS-1$
- Matcher m = wp.matcher(source);
- while (m.find()) {
- if (m.group().matches("/\\*\\s+\\d*\\s+\\*/")) {//$NON-NLS-1$
- continue;
- }
- String group = m.group();
- group = group.replace("/*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*/", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (log.length() > 0) {
- log += "\n"; //$NON-NLS-1$
- }
- log += group;
-
- source = source.replace(m.group(), "").trim(); //$NON-NLS-1$
- }
-
- } catch (Exception e) {
- exceptions.add(e);
- JavaDecompilerPlugin.logError(e, e.getMessage());
- }
-
- time = stopWatch.getTime();
- }
-
- /**
- * Cfr doesn't support decompilation from archives. This methods extracts
- * request class file from the specified archive into temp directory and then
- * calls decompile
.
- *
- * @see IDecompiler#decompileFromArchive(String, String, String)
- */
- @Override
- public void decompileFromArchive(String archivePath, String packege, String className) {
- StopWatch stopWatch = new StopWatch();
- stopWatch.start();
- String tempDir = JavaDecompilerPlugin.getDefault().getPreferenceStore()
- .getString(JavaDecompilerConstants.TEMP_DIR);
- File workingDir = new File(tempDir + "/ecd_cfr_" + System.currentTimeMillis()); //$NON-NLS-1$
- try {
- workingDir.mkdirs();
- JarClassExtractor.extract(archivePath, packege, className, true, workingDir.getAbsolutePath());
- decompile(workingDir.getAbsolutePath(), "", className); //$NON-NLS-1$
- time = stopWatch.getTime();
- } catch (Exception e) {
- exceptions.add(e);
- JavaDecompilerPlugin.logError(e, e.getMessage());
- return;
- } finally {
- FileUtil.deltree(workingDir);
- }
- }
-
- @Override
- public long getDecompilationTime() {
- return time;
- }
-
- /**
- * @see IDecompiler#getLog()
- */
- @Override
- public String getLog() {
- return log;
- }
-
- /**
- * @see IDecompiler#getSource()
- */
- @Override
- public String getSource() {
- return source;
- }
-
- @Override
- public String getDecompilerType() {
- return CfrDecompilerPlugin.decompilerType;
- }
-
- @Override
- public String removeComment(String source) {
- return source;
- }
-
- @Override
- public boolean supportLevel(int level) {
- return true;
- }
-
- @Override
- public boolean supportDebugLevel(int level) {
- return false; // CFR does not seem to have an option to create code that matche sthe original
- // line numbers
- }
-
- @Override
- public String getDecompilerName() {
- return CfrDecompilerPlugin.decompilerType;
- }
-
- @Override
- public String getDecompilerVersion() {
- return CfrDecompilerPlugin.decompilerVersion;
- }
+/*******************************************************************************
+ * Copyright (c) 2017 Chen Chao and other ECD project contributors.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.sf.feeling.decompiler.cfr.decompiler;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.commons.lang3.time.StopWatch;
+import org.benf.cfr.reader.apiunreleased.ClassFileSource2;
+import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
+import org.benf.cfr.reader.entities.ClassFile;
+import org.benf.cfr.reader.entities.Method;
+import org.benf.cfr.reader.state.ClassFileSourceImpl;
+import org.benf.cfr.reader.state.DCCommonState;
+import org.benf.cfr.reader.state.TypeUsageCollectingDumper;
+import org.benf.cfr.reader.state.TypeUsageInformation;
+import org.benf.cfr.reader.util.CannotLoadClassException;
+import org.benf.cfr.reader.util.getopt.GetOptParser;
+import org.benf.cfr.reader.util.getopt.Options;
+import org.benf.cfr.reader.util.getopt.OptionsImpl;
+import org.benf.cfr.reader.util.output.IllegalIdentifierDump;
+import org.benf.cfr.reader.util.output.MethodErrorCollector;
+import org.benf.cfr.reader.util.output.StringStreamDumper;
+import org.sf.feeling.decompiler.JavaDecompilerConstants;
+import org.sf.feeling.decompiler.JavaDecompilerPlugin;
+import org.sf.feeling.decompiler.cfr.CfrDecompilerPlugin;
+import org.sf.feeling.decompiler.editor.BaseDecompiler;
+import org.sf.feeling.decompiler.editor.IDecompiler;
+import org.sf.feeling.decompiler.util.CommentUtil;
+import org.sf.feeling.decompiler.util.FileUtil;
+import org.sf.feeling.decompiler.util.JarClassExtractor;
+import org.sf.feeling.decompiler.util.UnicodeUtil;
+
+public class CfrDecompiler extends BaseDecompiler {
+
+ private String source = ""; //$NON-NLS-1$
+ private long time;
+ private String log = ""; //$NON-NLS-1$
+
+ /**
+ * Performs a Runtime.exec()
on CFR with selected options.
+ *
+ * @see IDecompiler#decompile(String, String, String)
+ */
+ @Override
+ public void decompile(String root, String packege, String className) {
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+ log = ""; //$NON-NLS-1$
+ source = ""; //$NON-NLS-1$
+ File workingDir = new File(root + "/" + packege); //$NON-NLS-1$
+
+ String classPathStr = new File(workingDir, className).getAbsolutePath();
+
+ GetOptParser getOptParser = new GetOptParser();
+
+ try {
+ Pair, Options> options = getOptParser.parse(new String[] { classPathStr },
+ OptionsImpl.getFactory());
+ Options namedOptions = options.getSecond();
+ ClassFileSource2 classFileSource = new ClassFileSourceImpl(namedOptions);
+ classFileSource.informAnalysisRelativePathDetail(null, null);
+ DCCommonState dcCommonState = new DCCommonState(namedOptions, classFileSource);
+
+ IllegalIdentifierDump illegalIdentifierDump = IllegalIdentifierDump.Factory.get(namedOptions);
+
+ ClassFile classFile = dcCommonState.getClassFileMaybePath(classPathStr);
+ dcCommonState.configureWith(classFile);
+ try {
+ classFile = dcCommonState.getClassFile(classFile.getClassType());
+ } catch (CannotLoadClassException e) {
+ throw new RuntimeException(e);
+ }
+ if (namedOptions.getOption(OptionsImpl.DECOMPILE_INNER_CLASSES).booleanValue()) {
+ classFile.loadInnerClasses(dcCommonState);
+ }
+ TypeUsageCollectingDumper typeUsageCollectingDumper = new TypeUsageCollectingDumper(namedOptions,
+ classFile);
+
+ classFile.analyseTop(dcCommonState, typeUsageCollectingDumper);
+
+ TypeUsageInformation typeUsageInfo = typeUsageCollectingDumper.getRealTypeUsageInformation();
+
+ MethodErrorCollector methodErrorCollector = new MethodErrorCollector() {
+
+ @Override
+ public void addSummaryError(Method paramMethod, String msg) {
+ log += String.format("\n%s: %s", paramMethod.toString(), msg);
+ }
+
+ };
+
+ StringBuilder stringBuilder = new StringBuilder(4096);
+ StringStreamDumper dumper = new StringStreamDumper(methodErrorCollector, stringBuilder, typeUsageInfo,
+ namedOptions, illegalIdentifierDump);
+ classFile.dump(dumper);
+ source = UnicodeUtil.decode(stringBuilder.toString().trim());
+
+ source = CommentUtil.clearComments(source);
+ } catch (Exception e) {
+ exceptions.add(e);
+ JavaDecompilerPlugin.logError(e, e.getMessage());
+ }
+
+ time = stopWatch.getTime();
+ }
+
+ /**
+ * Cfr doesn't support decompilation from archives. This methods extracts
+ * request class file from the specified archive into temp directory and then
+ * calls decompile
.
+ *
+ * @see IDecompiler#decompileFromArchive(String, String, String)
+ */
+ @Override
+ public void decompileFromArchive(String archivePath, String packege, String className) {
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+ String tempDir = JavaDecompilerPlugin.getDefault().getPreferenceStore()
+ .getString(JavaDecompilerConstants.TEMP_DIR);
+ File workingDir = new File(tempDir + "/ecd_cfr_" + System.currentTimeMillis()); //$NON-NLS-1$
+ try {
+ workingDir.mkdirs();
+ JarClassExtractor.extract(archivePath, packege, className, true, workingDir.getAbsolutePath());
+ decompile(workingDir.getAbsolutePath(), "", className); //$NON-NLS-1$
+ time = stopWatch.getTime();
+ } catch (Exception e) {
+ exceptions.add(e);
+ JavaDecompilerPlugin.logError(e, e.getMessage());
+ return;
+ } finally {
+ FileUtil.deltree(workingDir);
+ }
+ }
+
+ @Override
+ public long getDecompilationTime() {
+ return time;
+ }
+
+ /**
+ * @see IDecompiler#getLog()
+ */
+ @Override
+ public String getLog() {
+ return log;
+ }
+
+ /**
+ * @see IDecompiler#getSource()
+ */
+ @Override
+ public String getSource() {
+ return source;
+ }
+
+ @Override
+ public String getDecompilerType() {
+ return CfrDecompilerPlugin.decompilerType;
+ }
+
+ @Override
+ public String removeComment(String source) {
+ return source;
+ }
+
+ @Override
+ public boolean supportLevel(int level) {
+ return true;
+ }
+
+ @Override
+ public boolean supportDebugLevel(int level) {
+ return false; // CFR does not seem to have an option to create code that matche sthe original
+ // line numbers
+ }
+
+ @Override
+ public String getDecompilerName() {
+ return CfrDecompilerPlugin.decompilerType;
+ }
+
+ @Override
+ public String getDecompilerVersion() {
+ return CfrDecompilerPlugin.decompilerVersion;
+ }
}
\ No newline at end of file
diff --git a/org.sf.feeling.decompiler.fernflower/src/org/sf/feeling/decompiler/fernflower/decompiler/FernFlowerDecompiler.java b/org.sf.feeling.decompiler.fernflower/src/org/sf/feeling/decompiler/fernflower/decompiler/FernFlowerDecompiler.java
index 78ff1234..bead8ec1 100644
--- a/org.sf.feeling.decompiler.fernflower/src/org/sf/feeling/decompiler/fernflower/decompiler/FernFlowerDecompiler.java
+++ b/org.sf.feeling.decompiler.fernflower/src/org/sf/feeling/decompiler/fernflower/decompiler/FernFlowerDecompiler.java
@@ -14,8 +14,6 @@
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.lang3.time.StopWatch;
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
@@ -27,6 +25,7 @@
import org.sf.feeling.decompiler.editor.BaseDecompiler;
import org.sf.feeling.decompiler.editor.IDecompiler;
import org.sf.feeling.decompiler.util.ClassUtil;
+import org.sf.feeling.decompiler.util.CommentUtil;
import org.sf.feeling.decompiler.util.FileUtil;
import org.sf.feeling.decompiler.util.JarClassExtractor;
import org.sf.feeling.decompiler.util.UnicodeUtil;
@@ -127,22 +126,7 @@ public boolean accept(File dir, String name) {
FileUtil.deltree(tmpDir);
- Pattern wp = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL); //$NON-NLS-1$
- Matcher m = wp.matcher(source);
- while (m.find()) {
- if (m.group().matches("/\\*\\s*\\d*\\s*\\*/")) //$NON-NLS-1$
- continue;
- String group = m.group();
- group = group.replace("/*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*/", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (log.length() > 0) {
- log += "\n"; //$NON-NLS-1$
- }
- log += group;
-
- source = source.replace(m.group(), ""); //$NON-NLS-1$
- }
+ source = CommentUtil.clearComments(source);
time = stopWatch.getTime();
}
diff --git a/org.sf.feeling.decompiler.procyon/src/org/sf/feeling/decompiler/procyon/decompiler/ProcyonDecompiler.java b/org.sf.feeling.decompiler.procyon/src/org/sf/feeling/decompiler/procyon/decompiler/ProcyonDecompiler.java
index bccb9e77..69b10474 100644
--- a/org.sf.feeling.decompiler.procyon/src/org/sf/feeling/decompiler/procyon/decompiler/ProcyonDecompiler.java
+++ b/org.sf.feeling.decompiler.procyon/src/org/sf/feeling/decompiler/procyon/decompiler/ProcyonDecompiler.java
@@ -16,8 +16,6 @@
import java.io.Writer;
import java.util.EnumSet;
import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.lang3.time.StopWatch;
import org.sf.feeling.decompiler.JavaDecompilerConstants;
@@ -27,6 +25,7 @@
import org.sf.feeling.decompiler.procyon.ProcyonDecompilerPlugin;
import org.sf.feeling.decompiler.procyon.decompiler.LineNumberFormatter.LineNumberOption;
import org.sf.feeling.decompiler.util.ClassUtil;
+import org.sf.feeling.decompiler.util.CommentUtil;
import org.sf.feeling.decompiler.util.FileUtil;
import org.sf.feeling.decompiler.util.JarClassExtractor;
import org.sf.feeling.decompiler.util.Logger;
@@ -139,21 +138,7 @@ public void decompile(String root, String packege, String className) {
classFile.delete();
- Pattern wp = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL); //$NON-NLS-1$
- Matcher m = wp.matcher(source);
- while (m.find()) {
- if (m.group().matches("/\\*\\s*\\d*\\s*\\*/")) //$NON-NLS-1$
- continue;
- String group = m.group();
- group = group.replace("/*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*/", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (log.length() > 0)
- log += "\n"; //$NON-NLS-1$
- log += group;
-
- source = source.replace(m.group(), ""); //$NON-NLS-1$
- }
+ source = CommentUtil.clearComments(source);
time = stopWatch.getTime();
}
diff --git a/org.sf.feeling.decompiler.vineflower/src/org/sf/feeling/decompiler/vineflower/decompiler/VineflowerDecompiler.java b/org.sf.feeling.decompiler.vineflower/src/org/sf/feeling/decompiler/vineflower/decompiler/VineflowerDecompiler.java
index fb252984..7cd87239 100644
--- a/org.sf.feeling.decompiler.vineflower/src/org/sf/feeling/decompiler/vineflower/decompiler/VineflowerDecompiler.java
+++ b/org.sf.feeling.decompiler.vineflower/src/org/sf/feeling/decompiler/vineflower/decompiler/VineflowerDecompiler.java
@@ -16,8 +16,6 @@
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger;
@@ -28,6 +26,7 @@
import org.sf.feeling.decompiler.editor.BaseDecompiler;
import org.sf.feeling.decompiler.editor.IDecompiler;
import org.sf.feeling.decompiler.util.ClassUtil;
+import org.sf.feeling.decompiler.util.CommentUtil;
import org.sf.feeling.decompiler.util.FileUtil;
import org.sf.feeling.decompiler.util.JarClassExtractor;
import org.sf.feeling.decompiler.util.UnicodeUtil;
@@ -126,23 +125,7 @@ public boolean accept(File dir, String name) {
FileUtil.deltree(tmpDir);
}
- Pattern wp = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL); //$NON-NLS-1$
- Matcher m = wp.matcher(source);
- while (m.find()) {
- if (m.group().matches("/\\*\\s*\\d*\\s*\\*/")) {//$NON-NLS-1$
- continue;
- }
- String group = m.group();
- group = group.replace("/*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*/", ""); //$NON-NLS-1$ //$NON-NLS-2$
- group = group.replace("*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (log.length() > 0) {
- log += "\n"; //$NON-NLS-1$
- }
- log += group;
-
- source = source.replace(m.group(), ""); //$NON-NLS-1$
- }
+ source = CommentUtil.clearComments(source);
time = System.currentTimeMillis() - start;
}
diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/CommentUtil.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/CommentUtil.java
new file mode 100644
index 00000000..cbff65dd
--- /dev/null
+++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/CommentUtil.java
@@ -0,0 +1,63 @@
+package org.sf.feeling.decompiler.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.BlockComment;
+import org.eclipse.jdt.core.dom.Comment;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.TextEdit;
+import org.sf.feeling.decompiler.JavaDecompilerPlugin;
+
+public final class CommentUtil {
+
+ public static final String LINE_NUMBER_COMMENT = "/\\*\\s*\\d+\\s*\\*/";
+
+ private CommentUtil() {
+ }
+
+ public static String clearComments(String input) {
+ ASTParser parser = ASTParser.newParser(DecompilerOutputUtil.getMaxJSLLevel()); // AST.JLS3
+ CompilerOptions option = new CompilerOptions();
+ Map options = option.getMap();
+ options.put(CompilerOptions.OPTION_Compliance, DecompilerOutputUtil.getMaxDecompileLevel()); // $NON-NLS-1$
+ options.put(CompilerOptions.OPTION_Source, DecompilerOutputUtil.getMaxDecompileLevel()); // $NON-NLS-1$
+ parser.setCompilerOptions(options);
+ parser.setSource(input.toCharArray());
+ CompilationUnit unit = (CompilationUnit) parser.createAST(null);
+ AST ast = unit.getAST();
+ ASTRewrite rewriter = ASTRewrite.create(ast);
+ Document document = new Document(input);
+ TextEdit edits = rewriter.rewriteAST(document, null);
+ List textEdits = new ArrayList<>();
+ List commentList = unit.getCommentList();
+ for (Comment comment : commentList) {
+ if (comment.isBlockComment()) {
+ BlockComment blockComment = (BlockComment) comment;
+ int commentStart = blockComment.getStartPosition();
+ int commentLength = blockComment.getLength();
+ int commentEnd = commentStart + commentLength;
+ String commentText = input.substring(commentStart, commentEnd);
+ if (!commentText.trim().matches(LINE_NUMBER_COMMENT)) {
+ textEdits.add(new DeleteEdit(commentStart, commentLength));
+ }
+ }
+ }
+ edits.addChildren(textEdits.toArray(TextEdit[]::new));
+ try {
+ edits.apply(document);
+ } catch (MalformedTreeException | BadLocationException e) {
+ JavaDecompilerPlugin.logError(e, e.getMessage());
+ }
+ return document.get();
+ }
+}
diff --git a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompilerOutputUtil.java b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompilerOutputUtil.java
index adec7e35..d7019040 100644
--- a/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompilerOutputUtil.java
+++ b/org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/util/DecompilerOutputUtil.java
@@ -374,7 +374,7 @@ private void fillOutputList() {
}
public static int parseJavaLineNumber(String decompilerType, String line) {
- String regex = "/\\*\\s*\\d+\\s*\\*/"; //$NON-NLS-1$
+ String regex = CommentUtil.LINE_NUMBER_COMMENT;
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(line.trim());
if (matcher.find()) {
@@ -384,7 +384,7 @@ public static int parseJavaLineNumber(String decompilerType, String line) {
}
public static int parseJavaLineNumber(String line) {
- String regex = "/\\*\\s*\\d+\\s*\\*/"; //$NON-NLS-1$
+ String regex = CommentUtil.LINE_NUMBER_COMMENT;
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(line.trim());
if (matcher.find()) {
@@ -401,7 +401,7 @@ public static int parseJavaLineNumber(String line) {
}
private String removeJavaLineNumber(String line, boolean generageEmptyString, int leftTrimSpace) {
- String regex = "/\\*\\s*\\d+\\s*\\*/"; //$NON-NLS-1$
+ String regex = CommentUtil.LINE_NUMBER_COMMENT;
// if (DecompilerType.FernFlower.equals(decompilerType)) {
// regex = "//\\s+\\d+(\\s*\\d*)*"; //$NON-NLS-1$
// }