-
Notifications
You must be signed in to change notification settings - Fork 86
/
ConvertStringConcatenationProposals.java
69 lines (57 loc) · 3 KB
/
ConvertStringConcatenationProposals.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
* Copyright (c) 2020 Julian Honnen
*
* 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:
* Julian Honnen <julian.honnen@vector.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.correction;
import java.util.Collection;
import org.eclipse.jdt.internal.corext.fix.ConvertToMessageFormatFixCore;
import org.eclipse.jdt.internal.corext.fix.ConvertToStringBufferFixCore;
import org.eclipse.jdt.internal.corext.fix.ConvertToStringFormatFixCore;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal;
import org.eclipse.jdt.ui.text.java.IInvocationContext;
import org.eclipse.jdt.ui.text.java.correction.ICommandAccess;
import org.eclipse.swt.graphics.Image;
final class ConvertStringConcatenationProposals {
private ConvertStringConcatenationProposals() {
}
public static boolean getProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) {
var compilationUnit= context.getASTRoot();
var node= context.getCoveringNode();
var convertToStringBufferFix= ConvertToStringBufferFixCore.createConvertToStringBufferFix(compilationUnit, node);
var convertToMessageFormatFix= ConvertToMessageFormatFixCore.createConvertToMessageFormatFix(compilationUnit, node);
var convertToStringFormatFix= ConvertToStringFormatFixCore.createConvertToStringFormatFix(compilationUnit, node);
if (convertToStringBufferFix == null && convertToMessageFormatFix == null && convertToStringFormatFix == null) {
return false;
}
if (resultingCollections == null) {
return true;
}
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
if (convertToStringBufferFix != null) {
FixCorrectionProposal proposal= new FixCorrectionProposal(convertToStringBufferFix, null, IProposalRelevance.CONVERT_TO_STRING_BUFFER, image, context);
proposal.setCommandId(QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
resultingCollections.add(proposal);
}
if (convertToMessageFormatFix != null) {
FixCorrectionProposal proposal= new FixCorrectionProposal(convertToMessageFormatFix, null, IProposalRelevance.CONVERT_TO_MESSAGE_FORMAT, image, context);
proposal.setCommandId(QuickAssistProcessor.CONVERT_TO_MESSAGE_FORMAT_ID);
resultingCollections.add(proposal);
}
if (convertToStringFormatFix != null) {
FixCorrectionProposal proposal= new FixCorrectionProposal(convertToStringFormatFix, null, IProposalRelevance.CONVERT_TO_MESSAGE_FORMAT, image, context);
proposal.setCommandId(QuickAssistProcessor.CONVERT_TO_MESSAGE_FORMAT_ID);
resultingCollections.add(proposal);
}
return true;
}
}