Search in sources :

Example 1 with IProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class QuickFixProcessor method getCorrections.

public List<ChangeCorrectionProposal> getCorrections(IInvocationContext context, IProblemLocationCore[] locations) throws CoreException {
    if (locations == null || locations.length == 0) {
        return Collections.emptyList();
    }
    ArrayList<ChangeCorrectionProposal> resultingCollections = new ArrayList<>();
    Set<Integer> handledProblems = new HashSet<>(locations.length);
    for (int i = 0; i < locations.length; i++) {
        IProblemLocationCore curr = locations[i];
        if (handledProblems(curr, locations, handledProblems)) {
            process(context, curr, resultingCollections);
        }
    }
    return resultingCollections;
}
Also used : IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) ArrayList(java.util.ArrayList) ChangeCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.ChangeCorrectionProposal) HashSet(java.util.HashSet)

Example 2 with IProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class QuickAssistProcessor method getTryWithResourceProposals.

public static boolean getTryWithResourceProposals(IProblemLocationCore[] locations, IInvocationContext context, ASTNode node, Collection<ChangeCorrectionProposal> resultingCollections) throws IllegalArgumentException, CoreException {
    final List<Integer> exceptionProblems = Arrays.asList(IProblem.UnclosedCloseable, IProblem.UnclosedCloseable, IProblem.PotentiallyUnclosedCloseable, IProblem.UnhandledException);
    for (IProblemLocationCore location : locations) {
        if (exceptionProblems.contains(location.getProblemId())) {
            return false;
        }
    }
    ArrayList<ASTNode> coveredNodes = QuickAssistProcessor.getFullyCoveredNodes(context, context.getCoveringNode());
    return getTryWithResourceProposals(context, node, coveredNodes, resultingCollections);
}
Also used : IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) ASTNode(org.eclipse.jdt.core.dom.ASTNode)

Example 3 with IProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class NonProjectFixProcessor method getCorrections.

public List<Either<Command, CodeAction>> getCorrections(CodeActionParams params, IInvocationContext context, IProblemLocationCore[] locations) {
    if (locations == null || locations.length == 0) {
        return Collections.emptyList();
    }
    List<Either<Command, CodeAction>> $ = new ArrayList<>();
    String uri = JDTUtils.toURI(context.getCompilationUnit());
    for (int i = 0; i < locations.length; i++) {
        IProblemLocationCore curr = locations[i];
        Integer id = Integer.valueOf(curr.getProblemId());
        if (id == DiagnosticsHandler.NON_PROJECT_JAVA_FILE || id == DiagnosticsHandler.NOT_ON_CLASSPATH) {
            if (this.nonProjectDiagnosticsState.isOnlySyntaxReported(uri)) {
                $.add(getDiagnosticsFixes(ActionMessages.ReportAllErrorsForThisFile, uri, "thisFile", false));
                $.add(getDiagnosticsFixes(ActionMessages.ReportAllErrorsForAnyNonProjectFile, uri, "anyNonProjectFile", false));
            } else {
                $.add(getDiagnosticsFixes(ActionMessages.ReportSyntaxErrorsForThisFile, uri, "thisFile", true));
                $.add(getDiagnosticsFixes(ActionMessages.ReportSyntaxErrorsForAnyNonProjectFile, uri, "anyNonProjectFile", true));
            }
        }
    }
    return $;
}
Also used : IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either)

Example 4 with IProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class SourceAssistProcessor method getSourceActionCommands.

public List<Either<Command, CodeAction>> getSourceActionCommands(CodeActionParams params, IInvocationContext context, IProblemLocationCore[] locations, IProgressMonitor monitor) {
    List<Either<Command, CodeAction>> $ = new ArrayList<>();
    ICompilationUnit cu = context.getCompilationUnit();
    IType type = getSelectionType(context);
    boolean isInTypeDeclaration = isInTypeDeclaration(context);
    boolean isInImportDeclaration = isInImportDeclaration(context);
    try {
        // Generate Constructor QuickAssist
        IJavaElement element = JDTUtils.findElementAtSelection(cu, params.getRange().getEnd().getLine(), params.getRange().getEnd().getCharacter(), this.preferenceManager, new NullProgressMonitor());
        if (element instanceof IField || isInTypeDeclaration) {
            Optional<Either<Command, CodeAction>> quickAssistGenerateConstructors = getGenerateConstructorsAction(params, context, type, JavaCodeActionKind.QUICK_ASSIST, monitor);
            addSourceActionCommand($, params.getContext(), quickAssistGenerateConstructors);
        }
    } catch (JavaModelException e) {
        JavaLanguageServerPlugin.logException(e);
    }
    // Generate Constructor Source Action
    Optional<Either<Command, CodeAction>> sourceGenerateConstructors = getGenerateConstructorsAction(params, context, type, JavaCodeActionKind.SOURCE_GENERATE_CONSTRUCTORS, monitor);
    addSourceActionCommand($, params.getContext(), sourceGenerateConstructors);
    // Organize Imports
    if (preferenceManager.getClientPreferences().isAdvancedOrganizeImportsSupported()) {
        // Generate QuickAssist
        if (isInImportDeclaration) {
            Optional<Either<Command, CodeAction>> quickAssistOrganizeImports = getOrganizeImportsAction(params, JavaCodeActionKind.QUICK_ASSIST);
            addSourceActionCommand($, params.getContext(), quickAssistOrganizeImports);
        }
        // Generate Source Action
        Optional<Either<Command, CodeAction>> sourceOrganizeImports = getOrganizeImportsAction(params, CodeActionKind.SourceOrganizeImports);
        addSourceActionCommand($, params.getContext(), sourceOrganizeImports);
    } else {
        CodeActionProposal organizeImportsProposal = (pm) -> {
            TextEdit edit = getOrganizeImportsProposal(context, pm);
            return convertToWorkspaceEdit(cu, edit);
        };
        // Generate QuickAssist
        if (isInImportDeclaration) {
            Optional<Either<Command, CodeAction>> sourceOrganizeImports = getCodeActionFromProposal(params.getContext(), context.getCompilationUnit(), CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description, JavaCodeActionKind.QUICK_ASSIST, organizeImportsProposal);
            addSourceActionCommand($, params.getContext(), sourceOrganizeImports);
        }
        // Generate Source Action
        Optional<Either<Command, CodeAction>> sourceOrganizeImports = getCodeActionFromProposal(params.getContext(), context.getCompilationUnit(), CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description, CodeActionKind.SourceOrganizeImports, organizeImportsProposal);
        addSourceActionCommand($, params.getContext(), sourceOrganizeImports);
    }
    if (!UNSUPPORTED_RESOURCES.contains(cu.getResource().getName())) {
        // Override/Implement Methods QuickAssist
        if (isInTypeDeclaration) {
            Optional<Either<Command, CodeAction>> quickAssistOverrideMethods = getOverrideMethodsAction(params, JavaCodeActionKind.QUICK_ASSIST);
            addSourceActionCommand($, params.getContext(), quickAssistOverrideMethods);
        }
        // Override/Implement Methods Source Action
        Optional<Either<Command, CodeAction>> sourceOverrideMethods = getOverrideMethodsAction(params, JavaCodeActionKind.SOURCE_OVERRIDE_METHODS);
        addSourceActionCommand($, params.getContext(), sourceOverrideMethods);
    }
    // Generate Getter and Setter QuickAssist
    if (isInTypeDeclaration) {
        Optional<Either<Command, CodeAction>> quickAssistGetterSetter = getGetterSetterAction(params, context, type, JavaCodeActionKind.QUICK_ASSIST, isInTypeDeclaration);
        addSourceActionCommand($, params.getContext(), quickAssistGetterSetter);
    }
    // Generate Getter and Setter Source Action
    Optional<Either<Command, CodeAction>> sourceGetterSetter = getGetterSetterAction(params, context, type, JavaCodeActionKind.SOURCE_GENERATE_ACCESSORS, isInTypeDeclaration);
    addSourceActionCommand($, params.getContext(), sourceGetterSetter);
    // Generate hashCode() and equals()
    if (supportsHashCodeEquals(context, type, monitor)) {
        // Generate QuickAssist
        if (isInTypeDeclaration) {
            Optional<Either<Command, CodeAction>> quickAssistHashCodeEquals = getHashCodeEqualsAction(params, JavaCodeActionKind.QUICK_ASSIST);
            addSourceActionCommand($, params.getContext(), quickAssistHashCodeEquals);
        }
        // Generate Source Action
        Optional<Either<Command, CodeAction>> sourceActionHashCodeEquals = getHashCodeEqualsAction(params, JavaCodeActionKind.SOURCE_GENERATE_HASHCODE_EQUALS);
        addSourceActionCommand($, params.getContext(), sourceActionHashCodeEquals);
    }
    // Generate toString()
    if (supportsGenerateToString(type)) {
        boolean nonStaticFields = true;
        try {
            nonStaticFields = hasFields(type, false);
        } catch (JavaModelException e) {
        // do nothing.
        }
        if (nonStaticFields) {
            // Generate QuickAssist
            if (isInTypeDeclaration) {
                Optional<Either<Command, CodeAction>> generateToStringQuickAssist = getGenerateToStringAction(params, JavaCodeActionKind.QUICK_ASSIST);
                addSourceActionCommand($, params.getContext(), generateToStringQuickAssist);
            }
            // Generate Source Action
            Optional<Either<Command, CodeAction>> generateToStringCommand = getGenerateToStringAction(params, JavaCodeActionKind.SOURCE_GENERATE_TO_STRING);
            addSourceActionCommand($, params.getContext(), generateToStringCommand);
        } else {
            CodeActionProposal generateToStringProposal = (pm) -> {
                IJavaElement insertPosition = isInTypeDeclaration ? CodeGenerationUtils.findInsertElement(type, null) : CodeGenerationUtils.findInsertElement(type, context.getSelectionOffset());
                TextEdit edit = GenerateToStringHandler.generateToString(type, new LspVariableBinding[0], insertPosition, pm);
                return convertToWorkspaceEdit(cu, edit);
            };
            // Generate QuickAssist
            if (isInTypeDeclaration) {
                Optional<Either<Command, CodeAction>> generateToStringQuickAssist = getCodeActionFromProposal(params.getContext(), context.getCompilationUnit(), ActionMessages.GenerateToStringAction_label, JavaCodeActionKind.QUICK_ASSIST, generateToStringProposal);
                addSourceActionCommand($, params.getContext(), generateToStringQuickAssist);
            }
            // Generate Source Action
            Optional<Either<Command, CodeAction>> generateToStringCommand = getCodeActionFromProposal(params.getContext(), context.getCompilationUnit(), ActionMessages.GenerateToStringAction_label, JavaCodeActionKind.SOURCE_GENERATE_TO_STRING, generateToStringProposal);
            addSourceActionCommand($, params.getContext(), generateToStringCommand);
        }
    }
    // Generate Delegate Methods
    Optional<Either<Command, CodeAction>> generateDelegateMethods = getGenerateDelegateMethodsAction(params, context, type);
    addSourceActionCommand($, params.getContext(), generateDelegateMethods);
    // Add final modifiers where possible
    Optional<Either<Command, CodeAction>> generateFinalModifiers = addFinalModifierWherePossibleAction(context);
    addSourceActionCommand($, params.getContext(), generateFinalModifiers);
    return $;
}
Also used : CodeActionProposal(org.eclipse.jdt.ls.core.internal.handlers.CodeActionProposal) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Arrays(java.util.Arrays) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) CoreException(org.eclipse.core.runtime.CoreException) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) GenerateToStringHandler(org.eclipse.jdt.ls.core.internal.handlers.GenerateToStringHandler) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Statement(org.eclipse.jdt.core.dom.Statement) CodeActionHandler(org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler) DiagnosticsHelper(org.eclipse.jdt.ls.core.internal.corrections.DiagnosticsHelper) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) VariableDeclarationFixCore(org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore) CodeActionProposal(org.eclipse.jdt.ls.core.internal.handlers.CodeActionProposal) OrganizeImportsHandler(org.eclipse.jdt.ls.core.internal.handlers.OrganizeImportsHandler) ASTNodes(org.eclipse.jdt.internal.corext.dom.ASTNodes) CodeAction(org.eclipse.lsp4j.CodeAction) ASTNode(org.eclipse.jdt.core.dom.ASTNode) JDTUtils(org.eclipse.jdt.ls.core.internal.JDTUtils) IProposalRelevance(org.eclipse.jdt.ls.core.internal.corrections.proposals.IProposalRelevance) FixCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.FixCorrectionProposal) Set(java.util.Set) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter) Sets(com.google.common.collect.Sets) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GenerateDelegateMethodsHandler(org.eclipse.jdt.ls.core.internal.handlers.GenerateDelegateMethodsHandler) IType(org.eclipse.jdt.core.IType) IProposableFix(org.eclipse.jdt.internal.corext.fix.IProposableFix) IInvocationContext(org.eclipse.jdt.ls.core.internal.corrections.IInvocationContext) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) List(java.util.List) Stream(java.util.stream.Stream) Command(org.eclipse.lsp4j.Command) Modifier(java.lang.reflect.Modifier) InnovationContext(org.eclipse.jdt.ls.core.internal.corrections.InnovationContext) Optional(java.util.Optional) ChangeUtil(org.eclipse.jdt.ls.core.internal.ChangeUtil) GenerateGetterSetterOperation(org.eclipse.jdt.ls.core.internal.codemanipulation.GenerateGetterSetterOperation) IField(org.eclipse.jdt.core.IField) JavaModelException(org.eclipse.jdt.core.JavaModelException) JavaCodeActionKind(org.eclipse.jdt.ls.core.internal.JavaCodeActionKind) CodeGenerationUtils(org.eclipse.jdt.ls.core.internal.handlers.CodeGenerationUtils) CorrectionMessages(org.eclipse.jdt.ls.core.internal.corrections.CorrectionMessages) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) ArrayList(java.util.ArrayList) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) OrganizeImportsOperation(org.eclipse.jdt.core.manipulation.OrganizeImportsOperation) GenerateConstructorsHandler(org.eclipse.jdt.ls.core.internal.handlers.GenerateConstructorsHandler) ImportDeclaration(org.eclipse.jdt.core.dom.ImportDeclaration) CheckConstructorsResponse(org.eclipse.jdt.ls.core.internal.handlers.GenerateConstructorsHandler.CheckConstructorsResponse) AccessorField(org.eclipse.jdt.ls.core.internal.codemanipulation.GenerateGetterSetterOperation.AccessorField) JdtFlags(org.eclipse.jdt.internal.corext.util.JdtFlags) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) LspVariableBinding(org.eclipse.jdt.ls.core.internal.handlers.JdtDomModels.LspVariableBinding) JavaLanguageServerPlugin(org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin) TextEdit(org.eclipse.text.edits.TextEdit) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) CoreASTProvider(org.eclipse.jdt.core.manipulation.CoreASTProvider) IJavaElement(org.eclipse.jdt.core.IJavaElement) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) Collections(java.util.Collections) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) LspVariableBinding(org.eclipse.jdt.ls.core.internal.handlers.JdtDomModels.LspVariableBinding) ArrayList(java.util.ArrayList) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) TextEdit(org.eclipse.text.edits.TextEdit) Either(org.eclipse.lsp4j.jsonrpc.messages.Either)

Example 5 with IProblemLocationCore

use of org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore in project eclipse.jdt.ls by eclipse.

the class GetRefactorEditHandler method getEditsForRefactor.

public static RefactorWorkspaceEdit getEditsForRefactor(GetRefactorEditParams params) {
    final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.context.getTextDocument().getUri());
    if (unit == null) {
        return null;
    }
    int start = DiagnosticsHelper.getStartOffset(unit, params.context.getRange());
    int end = DiagnosticsHelper.getEndOffset(unit, params.context.getRange());
    InnovationContext context = new InnovationContext(unit, start, end - start);
    context.setASTRoot(CodeActionHandler.getASTRoot(unit));
    IProblemLocationCore[] locations = CodeActionHandler.getProblemLocationCores(unit, params.context.getContext().getDiagnostics());
    boolean problemsAtLocation = locations.length != 0;
    String positionKey = DEFAULT_POSITION_KEY;
    try {
        Map formatterOptions = params.options == null ? null : FormatterHandler.getOptions(params.options, unit);
        LinkedCorrectionProposal proposal = null;
        if (RefactorProposalUtility.EXTRACT_VARIABLE_COMMAND.equals(params.command) || RefactorProposalUtility.EXTRACT_VARIABLE_ALL_OCCURRENCE_COMMAND.equals(params.command) || RefactorProposalUtility.EXTRACT_CONSTANT_COMMAND.equals(params.command)) {
            SelectionInfo info = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) getExtractVariableProposal(params.context, context, problemsAtLocation, params.command, formatterOptions);
        } else if (RefactorProposalUtility.ASSIGN_VARIABLE_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) getAssignVariableProposal(params, context, problemsAtLocation, params.command, formatterOptions, locations);
        } else if (RefactorProposalUtility.ASSIGN_FIELD_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getAssignFieldProposal(params.context, context, problemsAtLocation, formatterOptions, false, locations);
        } else if (RefactorProposalUtility.EXTRACT_METHOD_COMMAND.equals(params.command)) {
            SelectionInfo info = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) getExtractMethodProposal(params.context, context, context.getCoveringNode(), problemsAtLocation, formatterOptions);
        } else if (RefactorProposalUtility.CONVERT_VARIABLE_TO_FIELD_COMMAND.equals(params.command)) {
            String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getConvertVariableToFieldProposal(params.context, context, problemsAtLocation, formatterOptions, initializeIn, false);
        } else if (RefactorProposalUtility.EXTRACT_FIELD_COMMAND.equals(params.command)) {
            String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            SelectionInfo info = (params.commandArguments != null && params.commandArguments.size() > 1) ? JSONUtility.toModel(params.commandArguments.get(1), SelectionInfo.class) : null;
            if (info != null) {
                context = new InnovationContext(unit, info.offset, info.length);
            }
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getExtractFieldProposal(params.context, context, problemsAtLocation, formatterOptions, initializeIn, false);
        } else if (InvertBooleanUtility.INVERT_VARIABLE_COMMAND.equals(params.command)) {
            proposal = (LinkedCorrectionProposal) InvertBooleanUtility.getInvertVariableProposal(params.context, context, context.getCoveringNode(), false);
        } else if (RefactorProcessor.CONVERT_ANONYMOUS_CLASS_TO_NESTED_COMMAND.equals(params.command)) {
            proposal = RefactorProcessor.getConvertAnonymousToNestedProposal(params.context, context, context.getCoveringNode(), false);
            positionKey = "type_name";
        } else if (RefactorProposalUtility.INTRODUCE_PARAMETER_COMMAND.equals(params.command)) {
            // String initializeIn = (params.commandArguments != null && !params.commandArguments.isEmpty()) ? JSONUtility.toModel(params.commandArguments.get(0), String.class) : null;
            proposal = (LinkedCorrectionProposal) RefactorProposalUtility.getIntroduceParameterRefactoringProposals(params.context, context, context.getCoveringNode(), false, locations);
            positionKey = null;
            if (proposal instanceof RefactoringCorrectionProposal) {
                RefactoringCorrectionProposal rcp = (RefactoringCorrectionProposal) proposal;
                IntroduceParameterRefactoring refactoring = (IntroduceParameterRefactoring) rcp.getRefactoring();
                ParameterInfo parameterInfo = refactoring.getAddedParameterInfo();
                if (parameterInfo != null) {
                    positionKey = parameterInfo.getNewName();
                }
            }
        }
        if (proposal == null) {
            return null;
        }
        Change change = proposal.getChange();
        WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(change);
        LinkedProposalModelCore linkedProposalModel = proposal.getLinkedProposalModel();
        Command additionalCommand = null;
        if (linkedProposalModel != null) {
            LinkedProposalPositionGroupCore linkedPositionGroup = linkedProposalModel.getPositionGroup(positionKey, false);
            if (linkedPositionGroup == null) {
                Iterator<LinkedProposalPositionGroupCore> iter = linkedProposalModel.getPositionGroupCoreIterator();
                while (iter.hasNext()) {
                    LinkedProposalPositionGroupCore lppgc = iter.next();
                    if (lppgc.getGroupId().startsWith(positionKey)) {
                        linkedPositionGroup = lppgc;
                        break;
                    }
                }
            }
            PositionInformation highlightPosition = getFirstTrackedNodePositionBySequenceRank(linkedPositionGroup);
            if (highlightPosition != null) {
                int offset = highlightPosition.getOffset();
                int length = highlightPosition.getLength();
                RenamePosition renamePosition = new RenamePosition(JDTUtils.toURI(unit), offset, length);
                additionalCommand = new Command("Rename", RENAME_COMMAND, Arrays.asList(renamePosition));
            }
        }
        return new RefactorWorkspaceEdit(edit, additionalCommand);
    } catch (CoreException e) {
    // do nothing.
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IntroduceParameterRefactoring(org.eclipse.jdt.ls.core.internal.corext.refactoring.code.IntroduceParameterRefactoring) PositionInformation(org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroupCore.PositionInformation) LinkedProposalPositionGroupCore(org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroupCore) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) InnovationContext(org.eclipse.jdt.ls.core.internal.corrections.InnovationContext) ParameterInfo(org.eclipse.jdt.ls.core.internal.corext.refactoring.ParameterInfo) Change(org.eclipse.ltk.core.refactoring.Change) RefactoringCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.RefactoringCorrectionProposal) LinkedProposalModelCore(org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore) IProblemLocationCore(org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore) SelectionInfo(org.eclipse.jdt.ls.core.internal.handlers.InferSelectionHandler.SelectionInfo) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.lsp4j.Command) LinkedCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.LinkedCorrectionProposal) Map(java.util.Map)

Aggregations

IProblemLocationCore (org.eclipse.jdt.internal.ui.text.correction.IProblemLocationCore)8 ArrayList (java.util.ArrayList)5 CoreException (org.eclipse.core.runtime.CoreException)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 CoreASTProvider (org.eclipse.jdt.core.manipulation.CoreASTProvider)2 ProblemLocationCore (org.eclipse.jdt.internal.ui.text.correction.ProblemLocationCore)2 ChangeUtil (org.eclipse.jdt.ls.core.internal.ChangeUtil)2 JDTUtils (org.eclipse.jdt.ls.core.internal.JDTUtils)2 JavaCodeActionKind (org.eclipse.jdt.ls.core.internal.JavaCodeActionKind)2