Skip to content

Commit 9213517

Browse files
Neha Burnwalgireeshpunathil
authored andcommitted
Quick fix for adding a space after the header colon
1 parent 5aa1d30 commit 9213517

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDECoreMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public class PDECoreMessages extends NLS {
181181
public static String BundleErrorReporter_noMainSection;
182182
public static String BundleErrorReporter_duplicateHeader;
183183
public static String BundleErrorReporter_noColon;
184+
public static String BundleErrorReporter_noSpaceAfterColon;
184185
public static String BundleErrorReporter_noSpaceValue;
185186
public static String BundleErrorReporter_nameHeaderInMain;
186187
public static String BundleErrorReporter_noNameHeader;

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/JarManifestErrorReporter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ protected void parseManifest(IDocument document, IProgressMonitor monitor) {
195195
PDEMarkerFactory.CAT_FATAL);
196196
return;
197197
}
198+
if (line.length() >= colon + 2 && line.charAt(colon + 1) != ' ') {
199+
report(PDECoreMessages.BundleErrorReporter_noSpaceAfterColon, lineNumber, CompilerFlags.ERROR,
200+
PDEMarkerFactory.M_NO_SPACE_AFTER_COLON, PDEMarkerFactory.CAT_FATAL);
201+
return;
202+
}
198203
if (line.length() < colon + 2 || line.charAt(colon + 1) != ' ') {
199204
report(PDECoreMessages.BundleErrorReporter_noSpaceValue, lineNumber, CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
200205
return;

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/PDEMarkerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class PDEMarkerFactory {
7676
public static final int M_EXEC_ENV_TOO_LOW = 0x1029; // other problem
7777
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other problem
7878
public static final int M_HEADER_INCORRECT = 0x1031; // other problem
79+
public static final int M_NO_SPACE_AFTER_COLON = 0x1032; // other problem
7980
public static final int M_SINGLETON_DIR_CHANGE = 0x1033; // other problem
8081
public static final int M_MISSINGVERSION_REQ_BUNDLE = 0x1034; // other
8182
// problem

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/pderesources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ BundleErrorReporter_lineTooLong = The line is too long
139139
BundleErrorReporter_noMainSection = Manifest has no main section
140140
BundleErrorReporter_duplicateHeader = Header already defined
141141
BundleErrorReporter_noColon = ':' is required after the header name
142+
BundleErrorReporter_noSpaceAfterColon=Single space is required after the colon
142143
BundleErrorReporter_noSpaceValue = Single space and a value is required after the header name
143144
BundleErrorReporter_nameHeaderInMain = 'Name' header is not allowed in the main section
144145
BundleErrorReporter_noNameHeader = Extraneous empty line causes the file to be invalid

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,8 @@ public class PDEUIMessages extends NLS {
32383238

32393239
public static String AddSourceBuildEntryResolution_label;
32403240

3241+
public static String AddSpaceAfterColon_add;
3242+
32413243
public static String RemoveSeperatorBuildEntryResolution_label;
32423244

32433245
public static String ExternalizeStringsResolution_desc;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.pde.internal.ui.correction;
15+
16+
import java.util.logging.Level;
17+
import java.util.logging.Logger;
18+
19+
import org.eclipse.core.resources.IMarker;
20+
import org.eclipse.jface.text.BadLocationException;
21+
import org.eclipse.jface.text.IDocument;
22+
import org.eclipse.jface.text.IRegion;
23+
import org.eclipse.pde.internal.core.text.bundle.BundleModel;
24+
import org.eclipse.pde.internal.ui.PDEUIMessages;
25+
26+
/**
27+
* Resolution to add a space after the colon when not present in a manifest
28+
* header
29+
*/
30+
public class AddSpaceBeforeValue extends AbstractManifestMarkerResolution {
31+
32+
private static final Logger logger = Logger.getLogger(AddSpaceBeforeValue.class.getName());
33+
34+
public AddSpaceBeforeValue(int type, IMarker marker) {
35+
super(type, marker);
36+
}
37+
38+
@Override
39+
public String getLabel() {
40+
return PDEUIMessages.AddSpaceAfterColon_add;
41+
}
42+
43+
@Override
44+
protected void createChange(BundleModel model) {
45+
try {
46+
IDocument doc = model.getDocument();
47+
int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, -1);
48+
IRegion lineInfo = doc.getLineInformation(lineNum - 1);
49+
int offset = lineInfo.getOffset();
50+
int length = lineInfo.getLength();
51+
52+
String getLine = doc.get(offset, length);
53+
int colonInd = getLine.indexOf(':');
54+
55+
if (colonInd > 0 && getLine.charAt(colonInd + 1) != ' ') {
56+
String userHeader = getLine.substring(0, colonInd + 1);
57+
userHeader = userHeader + " "; //$NON-NLS-1$
58+
doc.replace(offset, colonInd + 1, userHeader);
59+
}
60+
} catch (BadLocationException e) {
61+
logger.log(Level.SEVERE, "Failed to apply AddSpaceBeforeValue quick fix, unexpected location in the doc", //$NON-NLS-1$
62+
e);
63+
}
64+
65+
}
66+
67+
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ResolutionGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
155155
case PDEMarkerFactory.M_MISSINGVERSION_REQ_BUNDLE:
156156
return new IMarkerResolution[] {
157157
new VersionMatchResolution(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
158+
case PDEMarkerFactory.M_NO_SPACE_AFTER_COLON:
159+
return new IMarkerResolution[] {
160+
new AddSpaceBeforeValue(AbstractPDEMarkerResolution.CREATE_TYPE, marker) };
158161
}
159162
return NO_RESOLUTIONS;
160163
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ AdvancedPluginExportPage_signButton=Si&gn the JAR archives using a keystore (a p
591591
AdvancedPluginExportPage_noKeystore=Keystore location is not set
592592
AdvancedPluginExportPage_noPassword=Password is not set
593593
AddSourceBuildEntryResolution_label=Add a {0} entry.
594+
AddSpaceAfterColon_add=Add a space after the colon
594595
AdvancedFeatureExportPage_createJNLP=&Create JNLP manifests for the JAR archives
595596
AdvancedFeatureExportPage_jreVersion=&JRE version:
596597
AdvancedPluginExportPage_qualifier = &Qualifier replacement (default value is today's date):

0 commit comments

Comments
 (0)