-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support quickfix for gradle jpms projects
Signed-off-by: Shi Chen <chenshi@microsoft.com>
- Loading branch information
Showing
8 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../org/eclipse/jdt/ls/core/internal/corrections/proposals/GradleCompatibilityProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal.corrections.proposals; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import org.eclipse.buildship.core.internal.CorePlugin; | ||
import org.eclipse.buildship.core.internal.preferences.PersistentModel; | ||
import org.eclipse.buildship.core.internal.util.gradle.GradleVersion; | ||
import org.eclipse.core.internal.resources.Workspace; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore; | ||
import org.eclipse.jdt.ls.core.internal.ProjectUtils; | ||
import org.eclipse.jdt.ls.core.internal.corrections.CorrectionMessages; | ||
import org.eclipse.jdt.ls.core.internal.corrections.IInvocationContext; | ||
import org.eclipse.jdt.ls.core.internal.managers.GradleUtils; | ||
import org.eclipse.jdt.ls.core.internal.text.correction.CUCorrectionCommandProposal; | ||
import org.eclipse.lsp4j.CodeActionKind; | ||
|
||
public class GradleCompatibilityProcessor { | ||
public static void getGradleCompatibilityProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) { | ||
IJavaProject javaProject = context.getCompilationUnit().getJavaProject(); | ||
IProject project = javaProject.getProject(); | ||
if (!ProjectUtils.isGradleProject(project)) { | ||
return; | ||
} | ||
PersistentModel model = CorePlugin.modelPersistence().loadModel(project); | ||
if (!model.isPresent()) { | ||
return; | ||
} | ||
GradleVersion gradleVersion = model.getGradleVersion(); | ||
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version(GradleUtils.JPMS_SUPPORTED_VERSION)) < 0) { | ||
IResource resource = javaProject.getResource(); | ||
if (resource == null) { | ||
return; | ||
} | ||
URI uri = resource.getLocationURI(); | ||
if (uri == null) { | ||
return; | ||
} | ||
proposals.add(new CUCorrectionCommandProposal(CorrectionMessages.NotAccessibleType_upgrade_Gradle_label, CodeActionKind.QuickFix, context.getCompilationUnit(), IProposalRelevance.CONFIGURE_BUILD_PATH, "java.project.upgradeGradle", Arrays.asList(uri.toString(), GradleUtils.JPMS_SUPPORTED_VERSION))); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters