-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Abstract out JavadocTagsSubProcessor for extension * Abstract out SerialVersionSubProcessor * Separate core from ui for UnInitializedFinalFieldSubProcessor * Allow all subprocessors to use IInvocationContextCore Signed-off-by: Rob Stryker <stryker@redhat.com> Co-authored-by: Rob Stryker <stryker@redhat.com>
- Loading branch information
1 parent
8c6926b
commit 8e28ae0
Showing
21 changed files
with
940 additions
and
822 deletions.
There are no files selected for viewing
379 changes: 379 additions & 0 deletions
379
...ation/common/org/eclipse/jdt/internal/ui/text/correction/JavadocTagsBaseSubProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
54 changes: 54 additions & 0 deletions
54
...ion/common/org/eclipse/jdt/internal/ui/text/correction/SerialVersionBaseSubProcessor.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,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation and others. | ||
* | ||
* 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: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.ui.text.correction; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.core.runtime.Assert; | ||
|
||
import org.eclipse.jdt.internal.corext.fix.IProposableFix; | ||
import org.eclipse.jdt.internal.corext.fix.PotentialProgrammingProblemsFixCore; | ||
|
||
/** | ||
* Subprocessor for serial version quickfix proposals. | ||
* | ||
* @since 3.1 | ||
*/ | ||
public abstract class SerialVersionBaseSubProcessor<T> { | ||
public SerialVersionBaseSubProcessor() { | ||
} | ||
|
||
/** | ||
* Determines the serial version quickfix proposals. | ||
* | ||
* @param context the invocation context | ||
* @param location the problem location | ||
* @param proposals the proposal collection to extend | ||
*/ | ||
public void addSerialVersionProposals(final IInvocationContextCore context, final IProblemLocationCore location, final Collection<T> proposals) { | ||
|
||
Assert.isNotNull(context); | ||
Assert.isNotNull(location); | ||
Assert.isNotNull(proposals); | ||
|
||
IProposableFix[] fixes= PotentialProgrammingProblemsFixCore.createMissingSerialVersionFixes(context.getASTRoot(), location); | ||
if (fixes != null) { | ||
proposals.add(createSerialVersionProposal(fixes[0], IProposalRelevance.MISSING_SERIAL_VERSION_DEFAULT, context, true)); | ||
proposals.add(createSerialVersionProposal(fixes[1], IProposalRelevance.MISSING_SERIAL_VERSION, context, false)); | ||
} | ||
} | ||
|
||
protected abstract T createSerialVersionProposal(IProposableFix iProposableFix, int missingSerialVersion, IInvocationContextCore context, boolean b); | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
.../org/eclipse/jdt/internal/ui/text/correction/UnInitializedFinalFieldBaseSubProcessor.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,100 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 IBM Corporation and others. | ||
* | ||
* 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: | ||
* IBM Corporation - initial API and implementation | ||
* Renaud Waldura <renaud+eclipse@waldura.com> - New class/interface with wizard | ||
* Rabea Gransberger <rgransberger@gmx.de> - [quick fix] Fix several visibility issues - https://bugs.eclipse.org/394692 | ||
* Jens Reimann <jreimann@redhat.com> Bug 38201: [quick assist] Allow creating abstract method - https://bugs.eclipse.org/38201 | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.ui.text.correction; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.dom.ASTNode; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.IBinding; | ||
import org.eclipse.jdt.core.dom.IMethodBinding; | ||
import org.eclipse.jdt.core.dom.ITypeBinding; | ||
import org.eclipse.jdt.core.dom.IVariableBinding; | ||
import org.eclipse.jdt.core.dom.MethodDeclaration; | ||
import org.eclipse.jdt.core.dom.SimpleName; | ||
|
||
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; | ||
|
||
import org.eclipse.jdt.internal.ui.text.correction.proposals.InitializeFinalFieldProposalCore; | ||
|
||
public abstract class UnInitializedFinalFieldBaseSubProcessor<T> { | ||
|
||
public UnInitializedFinalFieldBaseSubProcessor() { | ||
} | ||
|
||
public void addProposals(IInvocationContextCore context, IProblemLocationCore problem, Collection<T> proposals) throws CoreException { | ||
ICompilationUnit cu= context.getCompilationUnit(); | ||
|
||
CompilationUnit astRoot= context.getASTRoot(); | ||
ASTNode selectedNode= problem.getCoveringNode(astRoot); | ||
|
||
if (selectedNode == null) { | ||
return; | ||
} | ||
|
||
int type= selectedNode.getNodeType(); | ||
if (type == ASTNode.METHOD_DECLARATION) { | ||
// propose add initialization to constructor | ||
IMethodBinding targetBinding= null; | ||
MethodDeclaration node= (MethodDeclaration) selectedNode; | ||
if (!node.isConstructor()) { | ||
return; | ||
} | ||
IMethodBinding binding= node.resolveBinding(); | ||
if (binding != null) { | ||
targetBinding= binding; | ||
} else { | ||
return; | ||
} | ||
ITypeBinding targetDecl= targetBinding.getDeclaringClass(); | ||
ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl); | ||
|
||
T p1 = createInitializeFinalFieldProposal(problem, targetCU, node, IProposalRelevance.CREATE_CONSTRUCTOR, InitializeFinalFieldProposalCore.UPDATE_AT_CONSTRUCTOR); | ||
if( p1 != null ) | ||
proposals.add(p1); | ||
|
||
T p2= conditionallyCreateInitializeFinalFieldProposal(problem, targetCU, node, IProposalRelevance.CREATE_CONSTRUCTOR, InitializeFinalFieldProposalCore.UPDATE_CONSTRUCTOR_NEW_PARAMETER); | ||
if( p2 != null ) { | ||
proposals.add(p2); | ||
} | ||
|
||
} else if (type == ASTNode.SIMPLE_NAME) { | ||
// propose add initialization at declaration | ||
IVariableBinding targetBinding= null; | ||
SimpleName node= (SimpleName) selectedNode; | ||
IBinding binding= node.resolveBinding(); | ||
if (binding instanceof IVariableBinding) { | ||
targetBinding= (IVariableBinding) binding; | ||
} else { | ||
return; | ||
} | ||
ITypeBinding targetDecl= targetBinding.getDeclaringClass(); | ||
ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl); | ||
|
||
T p3= createInitializeFinalFieldProposal(problem, targetCU, node, targetBinding, IProposalRelevance.CREATE_CONSTRUCTOR); | ||
if( p3 != null ) | ||
proposals.add(p3); | ||
} | ||
} | ||
|
||
protected abstract T createInitializeFinalFieldProposal(IProblemLocationCore problem, ICompilationUnit targetCU, SimpleName node, IVariableBinding targetBinding, int createConstructor); | ||
protected abstract T createInitializeFinalFieldProposal(IProblemLocationCore problem, ICompilationUnit targetCU, MethodDeclaration node, int createConstructor, int updateAtConstructor); | ||
protected abstract T conditionallyCreateInitializeFinalFieldProposal(IProblemLocationCore problem, ICompilationUnit targetCU, MethodDeclaration node, int createConstructor, int updateAtConstructor); | ||
} |
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
Oops, something went wrong.