Skip to content

Commit

Permalink
Fix IndexOutOfBoundsException when running on mismatched Eclipse
Browse files Browse the repository at this point in the history
Update `spring-javaformat-formatter-elcipse` so that all of
`org.eclipse.jdt` is shaded into `io.spring.javaformat.eclipse.jdt`.

This update ensures that the version of the AST parsing classes are
aligned with the version of the formatter. Prior to this commit the
misalignment would cause `IndexOutOfBounds` exceptions.

Fixes gh-288
  • Loading branch information
philwebb committed Sep 28, 2021
1 parent 492d2f5 commit 9a07516
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 399 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,8 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import io.spring.javaformat.eclipse.jdt.core.JavaCore;

/**
* The activator class controls the plug-in life cycle.
*
Expand All @@ -33,17 +35,22 @@ public class Activator extends AbstractUIPlugin {

private static Activator plugin;

private JavaCore javaCore;

public Activator() {
this.javaCore = new JavaCore();
}

@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
this.javaCore.start(context);
}

@Override
public void stop(BundleContext context) throws Exception {
this.javaCore.stop(context);
plugin = null;
super.stop(context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,8 +40,8 @@
import org.junit.runners.model.Statement;
import org.xml.sax.InputSource;

import io.spring.javaformat.eclipse.jdt.internal.formatter.Preparator;
import io.spring.javaformat.formatter.Formatter;
import io.spring.javaformat.formatter.eclipse.Preparator;
import io.spring.javaformat.org.eclipse.jdt.core.formatter.CodeFormatter;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -110,8 +110,8 @@ private void recordLevel(AuditEvent event) {
}

private void recordLocalizedMessage(String message, String... args) {
recordMessage(new Violation(0, Definitions.CHECKSTYLE_BUNDLE, message, args, null,
Violation.class, null).getViolation());
recordMessage(new Violation(0, Definitions.CHECKSTYLE_BUNDLE, message, args, null, Violation.class, null)
.getViolation());
}

private void recordMessage(String message) {
Expand Down
6 changes: 3 additions & 3 deletions spring-javaformat/spring-javaformat-formatter-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
<filter>
<artifact>io.spring.javaformat:spring-javaformat-formatter-eclipse-runtime</artifact>
<includes>
<include>org/eclipse/jdt/internal/formatter/**</include>
<include>org/eclipse/jdt/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.eclipse.jdt.internal.formatter</pattern>
<shadedPattern>io.spring.javaformat.formatter.eclipse</shadedPattern>
<pattern>org.eclipse.jdt</pattern>
<shadedPattern>io.spring.javaformat.eclipse.jdt</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.util.Map;
import java.util.Properties;

import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jface.text.IRegion;
import org.eclipse.text.edits.TextEdit;

import io.spring.javaformat.config.IndentationStyle;
import io.spring.javaformat.config.JavaFormatConfig;
import io.spring.javaformat.formatter.eclipse.ExtendedCodeFormatter;
import io.spring.javaformat.formatter.eclipse.Preparator;
import io.spring.javaformat.eclipse.jdt.core.formatter.CodeFormatter;
import io.spring.javaformat.eclipse.jdt.internal.formatter.ExtendedCodeFormatter;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Preparator;
import io.spring.javaformat.formatter.preparator.Preparators;

/**
Expand Down Expand Up @@ -195,7 +195,7 @@ private static Map<String, String> loadOptions(JavaFormatConfig javaFormatConfig

private static void applyConfig(Properties properties, JavaFormatConfig javaFormatConfig) {
if (javaFormatConfig.getIndentationStyle() == IndentationStyle.SPACES) {
properties.put("org.eclipse.jdt.core.formatter.tabulation.char", "space");
properties.put("io.spring.javaformat.eclipse.jdt.core.formatter.tabulation.char", "space");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,20 +16,19 @@

package io.spring.javaformat.formatter.preparator;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;

import io.spring.javaformat.formatter.eclipse.Preparator;
import io.spring.javaformat.formatter.eclipse.Token;
import io.spring.javaformat.formatter.eclipse.TokenManager;
import io.spring.javaformat.eclipse.jdt.core.dom.ASTNode;
import io.spring.javaformat.eclipse.jdt.core.dom.ASTVisitor;
import io.spring.javaformat.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import io.spring.javaformat.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import io.spring.javaformat.eclipse.jdt.core.dom.EnumDeclaration;
import io.spring.javaformat.eclipse.jdt.core.dom.FieldDeclaration;
import io.spring.javaformat.eclipse.jdt.core.dom.SimpleName;
import io.spring.javaformat.eclipse.jdt.core.dom.TypeDeclaration;
import io.spring.javaformat.eclipse.jdt.core.formatter.CodeFormatter;
import io.spring.javaformat.eclipse.jdt.internal.compiler.parser.TerminalTokens;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Preparator;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Token;
import io.spring.javaformat.eclipse.jdt.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune curly-brace line breaks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,20 +20,19 @@
import java.util.Collections;
import java.util.List;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TextElement;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;

import io.spring.javaformat.formatter.eclipse.Preparator;
import io.spring.javaformat.formatter.eclipse.Token;
import io.spring.javaformat.formatter.eclipse.TokenManager;
import io.spring.javaformat.eclipse.jdt.core.dom.ASTNode;
import io.spring.javaformat.eclipse.jdt.core.dom.ASTVisitor;
import io.spring.javaformat.eclipse.jdt.core.dom.Comment;
import io.spring.javaformat.eclipse.jdt.core.dom.CompilationUnit;
import io.spring.javaformat.eclipse.jdt.core.dom.Javadoc;
import io.spring.javaformat.eclipse.jdt.core.dom.TagElement;
import io.spring.javaformat.eclipse.jdt.core.dom.TextElement;
import io.spring.javaformat.eclipse.jdt.core.dom.TypeDeclaration;
import io.spring.javaformat.eclipse.jdt.core.formatter.CodeFormatter;
import io.spring.javaformat.eclipse.jdt.internal.compiler.parser.TerminalTokens;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Preparator;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Token;
import io.spring.javaformat.eclipse.jdt.internal.formatter.TokenManager;

/**
* {@link Preparator} to fine tune Javadoc whitespace.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@

import java.util.function.Consumer;

import io.spring.javaformat.formatter.eclipse.Preparator;
import io.spring.javaformat.eclipse.jdt.internal.formatter.Preparator;

/**
* {@link Preparator} instances that can be added.
Expand Down
Loading

0 comments on commit 9a07516

Please sign in to comment.