Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2018-10-20 00:19:09 -0400
committerMarc-André Laperle2018-10-29 01:11:07 -0400
commit08721bdf8e27cc461ae9dd2dfaa2216ddd46334e (patch)
treeccefdc4f40328b840898d4ac8462ae8e0c9d422c
parent8404a76e6eb4f428eab1db8509a885ba50a1a29c (diff)
downloadorg.eclipse.cdt-08721bdf8e27cc461ae9dd2dfaa2216ddd46334e.tar.gz
org.eclipse.cdt-08721bdf8e27cc461ae9dd2dfaa2216ddd46334e.tar.xz
org.eclipse.cdt-08721bdf8e27cc461ae9dd2dfaa2216ddd46334e.zip
Bug 540257 - "Align Const" save action causes NPE when saving Assembler files
Change-Id: Ie3a086ddc7bc79eaef259a570327408e098bef51 Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AsmTextEditorTest.java59
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java1
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AlignConstAction.java6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/saveactions/AlignConstSaveAction.java4
4 files changed, 67 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AsmTextEditorTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AsmTextEditorTest.java
new file mode 100644
index 00000000000..3184683b61a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AsmTextEditorTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Marc-Andre Laperle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.text;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.testplugin.CProjectHelper;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
+
+import org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the AsmTextEditor
+ */
+public class AsmTextEditorTest extends TestCase {
+ private static final String ASM_EDITOR_ID = "org.eclipse.cdt.ui.editor.asm.AsmEditor";
+ private ICProject fCProject;
+
+ @Override
+ protected void setUp() throws Exception {
+ fCProject = CProjectHelper.createCCProject("AsmTextEditorTestProject", "");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (fCProject != null)
+ CProjectHelper.delete(fCProject);
+ }
+
+ public void testAlignConstSaveAction_Bug11111() throws Exception {
+ IEclipsePreferences prefs = DefaultScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
+ boolean oldValue = prefs.getBoolean(PreferenceConstants.ALIGN_ALL_CONST, false);
+ prefs.putBoolean(PreferenceConstants.ALIGN_ALL_CONST, true);
+ ByteArrayInputStream stream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
+ String filename = "test.asm";
+ IFile file = fCProject.getProject().getFile(filename);
+ file.create(stream, true, null);
+ AsmTextEditor editor = (AsmTextEditor) EditorTestHelper.openInEditor(file, ASM_EDITOR_ID, true);
+ editor.doSave(null);
+ EditorTestHelper.closeEditor(editor);
+ prefs.putBoolean(PreferenceConstants.ALIGN_ALL_CONST, oldValue);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java
index 5e9ee52e523..70e6e654eab 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/TextTestSuite.java
@@ -28,6 +28,7 @@ import org.eclipse.cdt.ui.tests.text.doctools.DocCommentTestSuite;
// partitioning tests
PartitionTokenScannerTest.class,
CPartitionerTest.class,
+ AsmTextEditorTest.class,
AsmPartitionerTest.class,
// smart edit tests
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AlignConstAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AlignConstAction.java
index 048c38acbd3..28a5f8c4a1b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AlignConstAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AlignConstAction.java
@@ -141,8 +141,10 @@ public class AlignConstAction extends TextEditorAction {
try {
IASTTranslationUnit ast = translationUnit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
- IASTNode enclosingNode = ast.getNodeSelector(null).findEnclosingNode(offset, length);
- rewriteMisalignedConstSpecifiers(enclosingNode, new NullProgressMonitor());
+ if (ast != null) {
+ IASTNode enclosingNode = ast.getNodeSelector(null).findEnclosingNode(offset, length);
+ rewriteMisalignedConstSpecifiers(enclosingNode, new NullProgressMonitor());
+ }
} catch (CoreException e) {
CUIPlugin.log(e);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/saveactions/AlignConstSaveAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/saveactions/AlignConstSaveAction.java
index eb05708c4cf..6676daf34c6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/saveactions/AlignConstSaveAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/saveactions/AlignConstSaveAction.java
@@ -32,7 +32,9 @@ public class AlignConstSaveAction {
private void alignConstInActiveEditor(ITranslationUnit translationUnit, IProgressMonitor monitor) {
try {
IASTTranslationUnit ast = translationUnit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
- AlignConstAction.rewriteMisalignedConstSpecifiers(ast, monitor);
+ if (ast != null) {
+ AlignConstAction.rewriteMisalignedConstSpecifiers(ast, monitor);
+ }
} catch (CoreException e) {
CUIPlugin.log(e);
}

Back to the top