Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: formatter indentation change #1933

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion misc/eclipse_formatting_nowrap.xml
Original file line number Diff line number Diff line change
@@ -207,7 +207,7 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="82"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you just remove this line (and use default value)?

Copy link
Contributor Author

@quintesse quintesse Mar 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, this is what Eclipse exported for me when I changed the option to the default.

Are you expecting some other behaviour?

<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="84"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_code_block_on_one_line" value="one_line_never"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
12 changes: 6 additions & 6 deletions src/main/java/dev/jbang/Main.java
Original file line number Diff line number Diff line change
@@ -48,16 +48,16 @@ private static String[] handleDefaultRun(CommandLine.Model.CommandSpec spec, Str
private static boolean hasRunOpts(List<String> opts) {
boolean res = opts.contains("-i") || opts.contains("--interactive")
|| opts.contains("-c") || opts.contains("--code") || opts.contains("--build-dir");
res = res || opts .stream()
.anyMatch(o -> o.startsWith("-i=") || o.startsWith("--interactive=")
|| o.startsWith("-c=") || o.startsWith("--code=") || o.startsWith("--build-dir="));
res = res || opts.stream()
.anyMatch(o -> o.startsWith("-i=") || o.startsWith("--interactive=")
|| o.startsWith("-c=") || o.startsWith("--code=") || o.startsWith("--build-dir="));
return res;
}

private static List<String> stripNonInheritedJBangOpts(List<String> opts) {
List<String> jbangOpts = opts .stream()
.filter(o -> "--preview".equals(o) || o.startsWith("--preview="))
.collect(Collectors.toList());
List<String> jbangOpts = opts.stream()
.filter(o -> "--preview".equals(o) || o.startsWith("--preview="))
.collect(Collectors.toList());
opts.removeAll(jbangOpts);
return jbangOpts;
}
8 changes: 4 additions & 4 deletions src/main/java/dev/jbang/catalog/CatalogUtil.java
Original file line number Diff line number Diff line change
@@ -151,10 +151,10 @@ public static Template addTemplate(Path catalogFile, String name, Map<String, St
Path cwd = Util.getCwd();
catalogFile = cwd.resolve(catalogFile);
Catalog catalog = Catalog.get(catalogFile);
Map<String, String> relFileRefs = fileRefs .entrySet()
.stream()
.map(e -> entry(e.getKey(), catalog.relativize(e.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, String> relFileRefs = fileRefs.entrySet()
.stream()
.map(e -> entry(e.getKey(), catalog.relativize(e.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Template template = new Template(relFileRefs, description, properties, catalog);
catalog.templates.put(name, template);
try {
8 changes: 4 additions & 4 deletions src/main/java/dev/jbang/catalog/ImplicitCatalogRef.java
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ public static Optional<String> resolveImplicitCatalogUrl(String catalogName) {
() -> icr.isPresent() ? tryDownload(icr.get().repoUrl(GITHUB_URL, "/blob/")) : Optional.empty(),
() -> icr.isPresent() ? tryDownload(icr.get().repoUrl(GITLAB_URL, "/-/blob/")) : Optional.empty(),
() -> icr.isPresent() ? tryDownload(icr.get().repoUrl(BITBUCKET_URL, "/src/")) : Optional.empty())
.findFirst();
.findFirst();
return url;
}

@@ -108,9 +108,9 @@ public static ImplicitCatalogRef extract(String catalogRef) {

@SafeVarargs
public static <T> Stream<T> chain(Supplier<Optional<T>>... suppliers) {
return Arrays .stream(suppliers)
.map(Supplier::get)
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty));
return Arrays.stream(suppliers)
.map(Supplier::get)
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty));
}

@Override
72 changes: 36 additions & 36 deletions src/main/java/dev/jbang/cli/Alias.java
Original file line number Diff line number Diff line change
@@ -135,21 +135,21 @@ public Integer doCall() {

ProjectBuilder createProjectBuilder() {
ProjectBuilder pb = Project
.builder()
.setProperties(dependencyInfoMixin.getProperties())
.additionalDependencies(dependencyInfoMixin.getDependencies())
.additionalRepositories(dependencyInfoMixin.getRepositories())
.additionalClasspaths(dependencyInfoMixin.getClasspaths())
.additionalSources(scriptMixin.sources)
.additionalResources(scriptMixin.resources)
.forceType(scriptMixin.forceType)
.javaVersion(buildMixin.javaVersion)
.moduleName(buildMixin.module)
.compileOptions(buildMixin.compileOptions)
.nativeImage(nativeMixin.nativeImage)
.nativeOptions(nativeMixin.nativeOptions)
.integrations(buildMixin.integrations)
.enablePreview(enablePreviewRequested);
.builder()
.setProperties(dependencyInfoMixin.getProperties())
.additionalDependencies(dependencyInfoMixin.getDependencies())
.additionalRepositories(dependencyInfoMixin.getRepositories())
.additionalClasspaths(dependencyInfoMixin.getClasspaths())
.additionalSources(scriptMixin.sources)
.additionalResources(scriptMixin.resources)
.forceType(scriptMixin.forceType)
.javaVersion(buildMixin.javaVersion)
.moduleName(buildMixin.module)
.compileOptions(buildMixin.compileOptions)
.nativeImage(nativeMixin.nativeImage)
.nativeOptions(nativeMixin.nativeOptions)
.integrations(buildMixin.integrations)
.enablePreview(enablePreviewRequested);
Path cat = getCatalog(false);
if (cat != null) {
pb.catalog(cat.toFile());
@@ -161,10 +161,10 @@ private List<JavaAgent> createJavaAgents() {
if (runMixin.javaAgentSlots == null) {
return Collections.emptyList();
}
return runMixin.javaAgentSlots .entrySet()
.stream()
.map(e -> new JavaAgent(e.getKey(), e.getValue()))
.collect(Collectors.toList());
return runMixin.javaAgentSlots.entrySet()
.stream()
.map(e -> new JavaAgent(e.getKey(), e.getValue()))
.collect(Collectors.toList());
}
}

@@ -204,11 +204,11 @@ public Integer doCall() {

static void printAliases(PrintStream out, String catalogName, Catalog catalog, FormatMixin.Format format) {
List<AliasOut> aliases = catalog.aliases
.keySet()
.stream()
.sorted()
.map(name -> getAliasOut(catalogName, catalog, name))
.collect(Collectors.toList());
.keySet()
.stream()
.sorted()
.map(name -> getAliasOut(catalogName, catalog, name))
.collect(Collectors.toList());

if (format == FormatMixin.Format.json) {
Gson parser = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
@@ -220,18 +220,18 @@ static void printAliases(PrintStream out, String catalogName, Catalog catalog, F

static List<CatalogList.CatalogOut> getAliasesWithOrigin(String catalogName, Catalog catalog) {
Map<ResourceRef, List<AliasOut>> groups = catalog.aliases
.keySet()
.stream()
.sorted()
.map(name -> getAliasOut(catalogName, catalog,
name))
.collect(Collectors.groupingBy(
a -> a._catalogRef));
return groups .entrySet()
.stream()
.map(e -> new CatalogList.CatalogOut(null, e.getKey(),
e.getValue(), null, null))
.collect(Collectors.toList());
.keySet()
.stream()
.sorted()
.map(name -> getAliasOut(catalogName, catalog,
name))
.collect(Collectors.groupingBy(
a -> a._catalogRef));
return groups.entrySet()
.stream()
.map(e -> new CatalogList.CatalogOut(null, e.getKey(),
e.getValue(), null, null))
.collect(Collectors.toList());
}

static void printAliasesWithOrigin(PrintStream out, String catalogName, Catalog catalog,
54 changes: 27 additions & 27 deletions src/main/java/dev/jbang/cli/App.java
Original file line number Diff line number Diff line change
@@ -38,9 +38,9 @@ public class App {

public static void deleteCommandFiles(String name) {
try (Stream<Path> files = Files.list(Settings.getConfigBinDir())) {
files .filter(f -> f.getFileName().toString().equals(name)
|| f.getFileName().toString().startsWith(name + "."))
.forEach(f -> Util.deletePath(f, true));
files.filter(f -> f.getFileName().toString().equals(name)
|| f.getFileName().toString().startsWith(name + "."))
.forEach(f -> Util.deletePath(f, true));
} catch (IOException e) {
// Ignore
}
@@ -267,26 +267,26 @@ public static boolean installJBang(boolean force) throws IOException {

private static void copyJBangFiles(Path from, Path to) throws IOException {
to.toFile().mkdirs();
Stream .of("jbang", "jbang.cmd", "jbang.ps1", "jbang.jar")
.map(Paths::get)
.forEach(f -> {
try {
Path fromp = from.resolve(f);
Path top = to.resolve(f);
if (f.endsWith("jbang.jar")) {
if (!Files.isReadable(fromp)) {
fromp = from.resolve(".jbang/jbang.jar");
}
if (Util.isWindows() && Files.isRegularFile(top)) {
top = to.resolve("jbang.jar.new");
}
Stream.of("jbang", "jbang.cmd", "jbang.ps1", "jbang.jar")
.map(Paths::get)
.forEach(f -> {
try {
Path fromp = from.resolve(f);
Path top = to.resolve(f);
if (f.endsWith("jbang.jar")) {
if (!Files.isReadable(fromp)) {
fromp = from.resolve(".jbang/jbang.jar");
}
if (Util.isWindows() && Files.isRegularFile(top)) {
top = to.resolve("jbang.jar.new");
}
Files.copy(fromp, top, StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
} catch (IOException e) {
throw new ExitException(EXIT_GENERIC_ERROR, "Could not copy " + f.toString(), e);
}
});
Files.copy(fromp, top, StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
} catch (IOException e) {
throw new ExitException(EXIT_GENERIC_ERROR, "Could not copy " + f.toString(), e);
}
});
}
}

@@ -322,11 +322,11 @@ public AppOut(Path file) {
private static List<AppOut> listCommandFiles() {
try (Stream<Path> files = Files.list(Settings.getConfigBinDir())) {
return files
.filter(Files::isExecutable)
.sorted()
.map(AppOut::new)
.filter(distinctByKey(AppOut::getName))
.collect(Collectors.toList());
.filter(Files::isExecutable)
.sorted()
.map(AppOut::new)
.filter(distinctByKey(AppOut::getName))
.collect(Collectors.toList());
} catch (IOException e) {
return Collections.emptyList();
}
@@ -502,7 +502,7 @@ private static boolean changeScript(Path binDir, Path javaHome, Path bashFile) {
// Detect if JBang has already been set up before
boolean jbangFound = Files.exists(bashFile)
&& Files.lines(bashFile)
.anyMatch(ln -> ln.trim().startsWith("#") && ln.toLowerCase().contains("jbang"));
.anyMatch(ln -> ln.trim().startsWith("#") && ln.toLowerCase().contains("jbang"));
if (!jbangFound) {
// Add lines to add JBang to PATH
String lines = "\n# Add JBang to environment\n" +
34 changes: 17 additions & 17 deletions src/main/java/dev/jbang/cli/BaseBuildCommand.java
Original file line number Diff line number Diff line change
@@ -37,23 +37,23 @@ public abstract class BaseBuildCommand extends BaseCommand {

protected ProjectBuilder createBaseProjectBuilder() {
return Project
.builder()
.setProperties(dependencyInfoMixin.getProperties())
.additionalDependencies(dependencyInfoMixin.getDependencies())
.additionalRepositories(dependencyInfoMixin.getRepositories())
.additionalClasspaths(dependencyInfoMixin.getClasspaths())
.additionalSources(scriptMixin.sources)
.additionalResources(scriptMixin.resources)
.forceType(scriptMixin.forceType)
.catalog(scriptMixin.catalog)
.javaVersion(buildMixin.javaVersion)
.moduleName(buildMixin.module)
.compileOptions(buildMixin.compileOptions)
.manifestOptions(buildMixin.manifestOptions)
.nativeImage(nativeMixin.nativeImage)
.nativeOptions(nativeMixin.nativeOptions)
.integrations(buildMixin.integrations)
.enablePreview(enablePreviewRequested);
.builder()
.setProperties(dependencyInfoMixin.getProperties())
.additionalDependencies(dependencyInfoMixin.getDependencies())
.additionalRepositories(dependencyInfoMixin.getRepositories())
.additionalClasspaths(dependencyInfoMixin.getClasspaths())
.additionalSources(scriptMixin.sources)
.additionalResources(scriptMixin.resources)
.forceType(scriptMixin.forceType)
.catalog(scriptMixin.catalog)
.javaVersion(buildMixin.javaVersion)
.moduleName(buildMixin.module)
.compileOptions(buildMixin.compileOptions)
.manifestOptions(buildMixin.manifestOptions)
.nativeImage(nativeMixin.nativeImage)
.nativeOptions(nativeMixin.nativeOptions)
.integrations(buildMixin.integrations)
.enablePreview(enablePreviewRequested);

// NB: Do not put `.mainClass(buildMixin.main)` here
}
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/cli/Build.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,6 @@ public Integer doCall() throws IOException {

ProjectBuilder createProjectBuilderForBuild() {
return createBaseProjectBuilder()
.mainClass(buildMixin.main);
.mainClass(buildMixin.main);
}
}
36 changes: 18 additions & 18 deletions src/main/java/dev/jbang/cli/Catalog.java
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ protected Path getCatalog(boolean strict) {
if (catalogFile != null && Files.isDirectory(catalogFile)) {
Path defaultCatalog = catalogFile.resolve(dev.jbang.catalog.Catalog.JBANG_CATALOG_JSON);
Path hiddenCatalog = catalogFile.resolve(Settings.JBANG_DOT_DIR)
.resolve(dev.jbang.catalog.Catalog.JBANG_CATALOG_JSON);
.resolve(dev.jbang.catalog.Catalog.JBANG_CATALOG_JSON);
if (!Files.exists(defaultCatalog) && Files.exists(hiddenCatalog)) {
cat = hiddenCatalog;
} else {
@@ -212,11 +212,11 @@ public Integer doCall() {
static void printCatalogs(PrintStream out, String catalogName, dev.jbang.catalog.Catalog catalog,
FormatMixin.Format format) {
List<CatalogRefOut> catalogs = catalog.catalogs
.keySet()
.stream()
.sorted()
.map(name -> getCatalogRefOut(catalogName, catalog, name))
.collect(Collectors.toList());
.keySet()
.stream()
.sorted()
.map(name -> getCatalogRefOut(catalogName, catalog, name))
.collect(Collectors.toList());

if (format == FormatMixin.Format.json) {
Gson parser = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
@@ -228,18 +228,18 @@ static void printCatalogs(PrintStream out, String catalogName, dev.jbang.catalog

static List<CatalogOut> getCatalogsWithOrigin(String catalogName, dev.jbang.catalog.Catalog catalog) {
Map<ResourceRef, List<CatalogRefOut>> groups = catalog.catalogs
.keySet()
.stream()
.sorted()
.map(name -> getCatalogRefOut(catalogName,
catalog, name))
.collect(Collectors.groupingBy(
c -> c._catalogRef));
return groups .entrySet()
.stream()
.map(e -> new CatalogOut(null, e.getKey(),
null, null, e.getValue()))
.collect(Collectors.toList());
.keySet()
.stream()
.sorted()
.map(name -> getCatalogRefOut(catalogName,
catalog, name))
.collect(Collectors.groupingBy(
c -> c._catalogRef));
return groups.entrySet()
.stream()
.map(e -> new CatalogOut(null, e.getKey(),
null, null, e.getValue()))
.collect(Collectors.toList());
}

static void printCatalogsWithOrigin(PrintStream out, String catalogName, dev.jbang.catalog.Catalog catalog,
Loading