Skip to content

Commit

Permalink
SLE-470 Restore backward compatibility with Eclipse < 2018-09
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju authored and damien-urruty-sonarsource committed Sep 28, 2021
1 parent bb3fd31 commit 3394c50
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 100 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ http://stackoverflow.com/questions/36317684/eclipse-jsdt-internal-error-noclassd
Adding a dependency
-------------------

Must be osgi bundle.
Must be an osgi bundle.

### For Maven

Expand Down
2 changes: 1 addition & 1 deletion org.sonarlint.eclipse.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Export-Package: org.sonarlint.eclipse.core,
org.sonarlint.eclipse.core.internal.resources;x-friends:="org.sonarlint.eclipse.ui,org.sonarlint.eclipse.core.tests",
org.sonarlint.eclipse.core.internal.telemetry;x-friends:="org.sonarlint.eclipse.ui,org.sonarlint.eclipse.core.tests",
org.sonarlint.eclipse.core.internal.tracking;x-friends:="org.sonarlint.eclipse.core.tests",
org.sonarlint.eclipse.core.internal.utils;x-friends:="org.sonarlint.eclipse.core.tests,org.sonarlint.eclipse.ui",
org.sonarlint.eclipse.core.internal.utils;x-friends:="org.sonarlint.eclipse.core.tests,org.sonarlint.eclipse.jdt,org.sonarlint.eclipse.ui",
org.sonarlint.eclipse.core.listener,
org.sonarlint.eclipse.core.resource
Require-Bundle: org.eclipse.equinox.security,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ private static Version platformVersion() {
return platform != null ? platform.getVersion() : Version.emptyVersion;
}

public static boolean supportMarkerResolutionRelevance() {
Bundle eclipseUiIde = Platform.getBundle("org.eclipse.ui.ide");
return eclipseUiIde != null && eclipseUiIde.getVersion().compareTo(Version.parseVersion("3.14")) >= 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IMarkerResolution2;
import org.sonarlint.eclipse.core.analysis.IAnalysisConfigurator;
import org.sonarlint.eclipse.core.analysis.IFileTypeProvider;
import org.sonarlint.eclipse.core.analysis.IPreAnalysisContext;
import org.sonarlint.eclipse.core.resource.ISonarLintFile;
import org.sonarlint.eclipse.core.resource.ISonarLintFileAdapterParticipant;
import org.sonarlint.eclipse.core.resource.ISonarLintProject;
import org.sonarlint.eclipse.ui.quickfixes.IMarkerResolutionEnhancer;
import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver;
import org.sonarsource.sonarlint.core.client.api.common.Language;

public class JavaProjectConfiguratorExtension implements IAnalysisConfigurator, ISonarLintFileAdapterParticipant, IFileTypeProvider, IMarkerResolutionEnhancer {
Expand Down Expand Up @@ -90,7 +90,7 @@ public ISonarLintFileType qualify(ISonarLintFile file) {
}

@Override
public IMarkerResolution2 enhance(IMarkerResolution2 resolution, IMarker marker) {
public ISonarLintMarkerResolver enhance(ISonarLintMarkerResolver resolution, IMarker marker) {
if (jdtPresent) {
return JdtUtils.enhance(resolution, marker);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.text.correction.IProposalRelevance;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IMarkerResolution2;
import org.eclipse.ui.IMarkerResolutionRelevance;
import org.osgi.framework.Version;
import org.sonarlint.eclipse.core.SonarLintLogger;
import org.sonarlint.eclipse.core.analysis.IFileTypeProvider.ISonarLintFileType;
import org.sonarlint.eclipse.core.analysis.IPreAnalysisContext;
import org.sonarlint.eclipse.core.internal.utils.CompatibilityUtils;
import org.sonarlint.eclipse.core.resource.ISonarLintFile;
import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver;

public class JdtUtils {

Expand Down Expand Up @@ -358,85 +352,11 @@ public static ISonarLintFileType qualify(ISonarLintFile slFile) {
return ISonarLintFileType.UNKNOWN;
}

public static IMarkerResolution2 enhance(IMarkerResolution2 resolution, IMarker marker) {
return new EnhancedMarkerResolution(resolution, marker);
}

/**
* Inspired by MarkerResolutionProposal
*/
private static class EnhancedMarkerResolution implements IMarkerResolution2, IMarkerResolutionRelevance, IJavaCompletionProposal {

private final IMarkerResolution2 wrapped;
private final IMarker marker;

public EnhancedMarkerResolution(IMarkerResolution2 resolution, IMarker marker) {
this.wrapped = resolution;
this.marker = marker;
}

@Override
public String getLabel() {
return wrapped.getLabel();
}

@Override
public void run(IMarker marker) {
wrapped.run(marker);
}

@Override
public void apply(IDocument document) {
wrapped.run(marker);
}

@Nullable
@Override
public Point getSelection(IDocument document) {
return null;
}

@Override
public String getAdditionalProposalInfo() {
return wrapped.getDescription();
}

@Override
public String getDisplayString() {
return getLabel();
}

@Nullable
@Override
public IContextInformation getContextInformation() {
return null;
}

@Override
public int getRelevance() {
if (wrapped instanceof IMarkerResolutionRelevance) {
return ((IMarkerResolutionRelevance) wrapped).getRelevanceForResolution();
}
return IProposalRelevance.MARKER_RESOLUTION;
}

@Override
public String getDescription() {
return wrapped.getDescription();
}

@Override
public Image getImage() {
return wrapped.getImage();
}

@Override
public int getRelevanceForResolution() {
if (wrapped instanceof IMarkerResolutionRelevance) {
return ((IMarkerResolutionRelevance) wrapped).getRelevanceForResolution();
}
return IMarkerResolutionRelevance.super.getRelevanceForResolution();
public static ISonarLintMarkerResolver enhance(ISonarLintMarkerResolver resolution, IMarker marker) {
if (CompatibilityUtils.supportMarkerResolutionRelevance()) {
return new MarkerResolverRelevanceJdtAdapter(resolution, marker);
} else {
return new MarkerResolverJdtAdapter(resolution, marker);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* SonarLint for Eclipse
* Copyright (C) 2015-2021 SonarSource SA
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarlint.eclipse.jdt.internal;

import org.eclipse.core.resources.IMarker;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver;

/**
* Inspired by MarkerResolutionProposal
*/
class MarkerResolverJdtAdapter implements ISonarLintMarkerResolver, IJavaCompletionProposal {

private final ISonarLintMarkerResolver wrapped;
private final IMarker marker;

public MarkerResolverJdtAdapter(ISonarLintMarkerResolver resolution, IMarker marker) {
this.wrapped = resolution;
this.marker = marker;
}

@Override
public String getLabel() {
return wrapped.getLabel();
}

@Override
public void run(IMarker marker) {
wrapped.run(marker);
}

@Override
public void apply(IDocument document) {
wrapped.run(marker);
}

@Nullable
@Override
public Point getSelection(IDocument document) {
return null;
}

@Override
public String getAdditionalProposalInfo() {
return wrapped.getDescription();
}

@Override
public String getDisplayString() {
return getLabel();
}

@Nullable
@Override
public IContextInformation getContextInformation() {
return null;
}

@Override
public int getRelevance() {
return wrapped.getRelevanceForResolution();
}

@Override
public String getDescription() {
return wrapped.getDescription();
}

@Override
public Image getImage() {
return wrapped.getImage();
}

@Override
public int getRelevanceForResolution() {
return wrapped.getRelevanceForResolution();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SonarLint for Eclipse
* Copyright (C) 2015-2021 SonarSource SA
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarlint.eclipse.jdt.internal;

import org.eclipse.core.resources.IMarker;
import org.eclipse.ui.IMarkerResolutionRelevance;
import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver;

class MarkerResolverRelevanceJdtAdapter extends MarkerResolverJdtAdapter implements IMarkerResolutionRelevance {
public MarkerResolverRelevanceJdtAdapter(ISonarLintMarkerResolver resolution, IMarker marker) {
super(resolution, marker);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SonarLint for Eclipse
* Copyright (C) 2015-2021 SonarSource SA
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarlint.eclipse.ui.internal.markers;

import org.eclipse.core.resources.IMarker;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMarkerResolutionRelevance;
import org.sonarlint.eclipse.ui.quickfixes.ISonarLintMarkerResolver;

public class MarkerResolutionRelevanceAdapter implements ISonarLintMarkerResolver, IMarkerResolutionRelevance {

private final ISonarLintMarkerResolver wrapped;

public MarkerResolutionRelevanceAdapter(ISonarLintMarkerResolver wrapped) {
this.wrapped = wrapped;
}

@Override
public String getLabel() {
return wrapped.getLabel();
}

@Override
public void run(IMarker marker) {
wrapped.run(marker);
}

@Override
public String getDescription() {
return wrapped.getDescription();
}

@Override
public Image getImage() {
return wrapped.getImage();
}

@Override
public int getRelevanceForResolution() {
return wrapped.getRelevanceForResolution();
}

}
Loading

0 comments on commit 3394c50

Please sign in to comment.