-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quickfix for redundant interface
Signed-off-by: Snjezana Peco <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
4 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
86 changes: 86 additions & 0 deletions
86
...tests/src/org/eclipse/jdt/ls/core/internal/correction/RedundantInterfaceQuickFixTest.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,86 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. 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: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal.correction; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.IPackageFragment; | ||
import org.eclipse.jdt.core.IPackageFragmentRoot; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.lsp4j.CodeAction; | ||
import org.eclipse.lsp4j.Command; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author snjeza | ||
* | ||
*/ | ||
public class RedundantInterfaceQuickFixTest extends AbstractQuickFixTest { | ||
|
||
private IJavaProject fJProject; | ||
private IPackageFragmentRoot fSourceFolder; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
fJProject = newEmptyProject(); | ||
Map<String, String> testProjectOptions = TestOptions.getDefaultOptions(); | ||
testProjectOptions.put(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE, JavaCore.WARNING); | ||
fJProject.setOptions(testProjectOptions); | ||
fSourceFolder = fJProject.getPackageFragmentRoot(fJProject.getProject().getFolder("src")); | ||
} | ||
|
||
@Test | ||
public void testRedundantSuperinterface() throws Exception { | ||
IPackageFragment pack = fSourceFolder.createPackageFragment("test", false, null); | ||
StringBuilder buf = new StringBuilder(); | ||
buf.append("package test;\n"); | ||
buf.append("public class RedundantInterface implements Int1, Int2 {}\n"); | ||
buf.append("interface Int1 {}\n"); | ||
buf.append("interface Int2 extends Int1 {}\n"); | ||
ICompilationUnit cu = pack.createCompilationUnit("RedundantInterface.java", buf.toString(), true, null); | ||
buf = new StringBuilder(); | ||
buf.append("package test;\n"); | ||
buf.append("public class RedundantInterface implements Int2 {}\n"); | ||
buf.append("interface Int1 {}\n"); | ||
buf.append("interface Int2 extends Int1 {}\n"); | ||
Expected e1 = new Expected("Remove super interface", buf.toString()); | ||
Range selection = new Range(new Position(1, 45), new Position(1, 45)); | ||
assertCodeActions(cu, selection, e1); | ||
} | ||
|
||
@Test | ||
public void testIgnoreRedundantSuperinterface() throws Exception { | ||
Map<String, String> testProjectOptions = fJProject.getOptions(false); | ||
testProjectOptions.put(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE, JavaCore.IGNORE); | ||
fJProject.setOptions(testProjectOptions); | ||
IPackageFragment pack = fSourceFolder.createPackageFragment("test", false, null); | ||
StringBuilder buf = new StringBuilder(); | ||
buf.append("package test;\n"); | ||
buf.append("public class RedundantInterface implements Int1, Int2 {}\n"); | ||
buf.append("interface Int1 {}\n"); | ||
buf.append("interface Int2 extends Int1 {}\n"); | ||
ICompilationUnit cu = pack.createCompilationUnit("RedundantInterface.java", buf.toString(), true, null); | ||
Range selection = new Range(new Position(1, 45), new Position(1, 45)); | ||
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, selection); | ||
assertEquals(0, codeActions.size()); | ||
} | ||
} |