Format via embedded eclipse formatter & add determiner
This commit is contained in:
parent
93b2c6d59b
commit
c6921030f4
37
pom.xml
37
pom.xml
@ -12,10 +12,31 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>eclipse-formatter</artifactId>
|
||||
<version>3.14.0-spigotmc-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>./src</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>determiner</artifactId>
|
||||
<version>0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
@ -38,6 +59,22 @@
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -85,7 +85,7 @@ public class Fernflower implements IDecompiledData {
|
||||
TextBuffer buffer = new TextBuffer(ClassesProcessor.AVERAGE_CLASS_SIZE);
|
||||
buffer.append(DecompilerContext.getProperty(IFernflowerPreferences.BANNER).toString());
|
||||
classesProcessor.writeClass(cl, buffer);
|
||||
return buffer.toString();
|
||||
return org.spigotmc.fernflower.EclipseFormatter.format(buffer.toString()); // Spigot
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", ex);
|
||||
|
40
src/org/spigotmc/fernflower/EclipseFormatter.java
Normal file
40
src/org/spigotmc/fernflower/EclipseFormatter.java
Normal file
@ -0,0 +1,40 @@
|
||||
package org.spigotmc.fernflower;
|
||||
|
||||
import org.eclipse.jdt.core.formatter.CodeFormatter;
|
||||
import org.eclipse.jdt.internal.core.util.SimpleDocument;
|
||||
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
|
||||
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
|
||||
public class EclipseFormatter {
|
||||
|
||||
private static final CodeFormatter formatter;
|
||||
|
||||
static {
|
||||
DefaultCodeFormatterOptions options = new DefaultCodeFormatterOptions(null);
|
||||
options.setJavaConventionsSettings();
|
||||
|
||||
options.tab_char = DefaultCodeFormatterOptions.SPACE;
|
||||
options.page_width = 0;
|
||||
|
||||
options.insert_new_line_after_label = true;
|
||||
options.insert_new_line_in_empty_method_body = false;
|
||||
options.insert_new_line_in_empty_type_declaration = false;
|
||||
|
||||
options.insert_space_before_closing_brace_in_array_initializer = false; // Compatability
|
||||
// options.blank_lines_before_first_class_body_declaration = 1; // Needed later
|
||||
|
||||
formatter = new DefaultCodeFormatter(options);
|
||||
}
|
||||
|
||||
public static String format(String contents) throws BadLocationException {
|
||||
TextEdit formatted = formatter.format(CodeFormatter.K_COMPILATION_UNIT, contents, 0, contents.length(), 0, "\n");
|
||||
|
||||
IDocument doc = new SimpleDocument(contents);
|
||||
formatted.apply(doc);
|
||||
|
||||
return doc.get();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user