Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"permissions": {
"allow": [
"Bash(./gradlew:*)",
"Bash(java:*)",
"Bash(/usr/libexec/java_home:*)",
"Bash(JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home ./gradlew build)",
"WebSearch",
"WebFetch(domain:github.com)",
"Bash(unzip:*)",
"Bash(./bin/palantir-java-format:*)",
"Bash(./palantir-java-format/build/distributions/palantir-java-format-2.49.0-2-g78818d3.dirty/bin/palantir-java-format:*)",
"Bash(/Users/bodo.teichmann/dev/learning/palantir-java-format/palantir-java-format/build/distributions/palantir-java-format-2.49.0-2-g78818d3.dirty/bin/palantir-java-format --help)"
],
"deny": [],
"ask": []
}
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
}
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1113.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: "fix issue #975: last character not a \n after format in Intellij"
links:
- https://github.com/palantir/palantir-java-format/pull/1113
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run() {
String formattedText = applyReplacements(
request.getDocumentText(),
formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request)));
request.onTextReady(formattedText);
request.onTextReady(formattedText.trim() + "\n");
} catch (FormatterException e) {
request.onError(
Notifications.PARSING_ERROR_TITLE,
Expand Down
5 changes: 3 additions & 2 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ def exports = [
]

def jvmArgList = exports.collect { value -> "--add-exports=${value}=ALL-UNNAMED".toString() }
def opensArgList = exports.collect { value -> "--add-opens=${value}=ALL-UNNAMED".toString() }

tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'StrictUnusedVariable'

// Allow access to internal javac apis
options.compilerArgs += jvmArgList
options.compilerArgs += jvmArgList + opensArgList

if (JavaVersion.current() < JavaVersion.VERSION_14) {
excludes = ['**/Java14InputAstVisitor.java']
}
}

tasks.withType(Test).configureEach {
jvmArgs = jvmArgList
jvmArgs = jvmArgList + opensArgList
}

tasks.withType(Javadoc).configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.tools.javac.parser.Tokens.TokenKind;
import com.sun.tools.javac.parser.UnicodeReader;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic;
import java.util.Set;

/** A wrapper around javac's lexer. */
Expand Down Expand Up @@ -200,6 +201,11 @@ public boolean isDeprecated() {
return false;
}

@Override
public JCDiagnostic.DiagnosticPosition getPos() {
return new JCDiagnostic.SimpleDiagnosticPosition(pos);
}

@Override
public String toString() {
return String.format("Comment: '%s'", getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCImport;
import com.sun.tools.javac.tree.JCTree.JCImportBase;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -221,7 +222,12 @@ private static RangeMap<Integer, String> buildReplacements(
Set<String> usedNames,
Multimap<String, Range<Integer>> usedInJavadoc) {
RangeMap<Integer, String> replacements = TreeRangeMap.create();
for (JCImport importTree : unit.getImports()) {
for (JCImportBase importBase : unit.getImports()) {
// Skip module imports for now - only handle traditional imports
if (!(importBase instanceof JCImport)) {
continue;
}
JCImport importTree = (JCImport) importBase;
String simpleName = getSimpleName(importTree);
if (!isUnused(unit, usedNames, usedInJavadoc, importTree, simpleName)) {
continue;
Expand Down