From d35f9e1a602b86a3cf22af4aeb85c24c166b17c8 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 22 Mar 2017 11:58:24 +0200 Subject: [PATCH] autotools: automake/autoconf generic editor. Reorganize code and expose things for generic editor. So far presentation reconciler only is ported. Allows to right-click/Open with/Generic editor on e.g. Makefile.am and see it in the generic editor. It is not as feature rich as the specialized editors we have now but over time it should provide all the features of them with significantly less code. Change-Id: I72324b94ce08ab762979804914adbb1982c88198 Signed-off-by: Alexander Kurtakov --- .../META-INF/MANIFEST.MF | 5 +- .../plugin.properties | 3 +- build/org.eclipse.cdt.autotools.ui/plugin.xml | 33 ++++++++---- .../editors/AutoconfMacroDamagerRepairer.java | 36 +++---------- .../AutoconfSourceViewerConfiguration.java | 21 ++------ .../AutoconfPresentationReconciler.java | 38 ++++++++++++++ .../AutomakefilePresentationReconciler.java | 50 +++++++++++++++++++ .../AutomakefileSourceConfiguration.java | 35 +------------ 8 files changed, 126 insertions(+), 95 deletions(-) create mode 100644 build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/autoconf/AutoconfPresentationReconciler.java create mode 100644 build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefilePresentationReconciler.java diff --git a/build/org.eclipse.cdt.autotools.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.autotools.ui/META-INF/MANIFEST.MF index 114c5e624e7..529690da189 100644 --- a/build/org.eclipse.cdt.autotools.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.autotools.ui/META-INF/MANIFEST.MF @@ -9,21 +9,20 @@ Bundle-Vendor: %provider Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.cdt.autotools.core;bundle-version="1.0.0", - org.eclipse.cdt.make.core;bundle-version="6.0.0", org.eclipse.cdt.core;bundle-version="5.1.0", org.eclipse.core.resources;bundle-version="3.5.0", org.eclipse.cdt.managedbuilder.core;bundle-version="6.0.0", org.eclipse.jface.text;bundle-version="3.5.0", org.eclipse.ui.editors;bundle-version="3.5.0", org.eclipse.cdt.ui;bundle-version="5.1.0", - org.eclipse.help;bundle-version="3.4.0", org.eclipse.ui.ide;bundle-version="3.5.0", org.eclipse.cdt.managedbuilder.ui;bundle-version="5.1.0", org.eclipse.core.filesystem;bundle-version="1.2.0", org.eclipse.cdt.make.ui;bundle-version="6.0.0", org.eclipse.ui.views;bundle-version="3.4.0", org.eclipse.cdt.remote.core;bundle-version="1.0.0", - org.eclipse.swt + org.eclipse.swt, + org.eclipse.ui.genericeditor;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.cdt.autotools.ui, diff --git a/build/org.eclipse.cdt.autotools.ui/plugin.properties b/build/org.eclipse.cdt.autotools.ui/plugin.properties index ab4e3a45a49..310b1d67d69 100644 --- a/build/org.eclipse.cdt.autotools.ui/plugin.properties +++ b/build/org.eclipse.cdt.autotools.ui/plugin.properties @@ -95,4 +95,5 @@ GetDefinedSymbols.label = Get Defined Symbols IncludesOption.name = includes SymbolsOption.name = symbols AutomakeEditor.name = AutomakeEditor -Automake.name = automake \ No newline at end of file +Automake.name = automake +Autoconf.name = autoconf \ No newline at end of file diff --git a/build/org.eclipse.cdt.autotools.ui/plugin.xml b/build/org.eclipse.cdt.autotools.ui/plugin.xml index 2b3f23049b6..cd15096649b 100644 --- a/build/org.eclipse.cdt.autotools.ui/plugin.xml +++ b/build/org.eclipse.cdt.autotools.ui/plugin.xml @@ -36,11 +36,14 @@ - + file-names="Makefile.in" + file-extensions="am" + priority="high"> + @@ -48,22 +51,32 @@ class="org.eclipse.cdt.autotools.ui.editors.AutoconfEditor" contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor" default="true" - filenames="configure.in,configure.ac,aclocal.m4,acinclude.m4,libtool.m4,ltversion.m4,ltsugar.m4,ltoptions.m4,ltdl.m4,ltgcc.m4,lt~obsolete.m4" icon="icons/autoconf.gif" id="org.eclipse.cdt.autotools.ui.editor.autoconf" - name="%Autoconf.editor.name"/> + name="%Autoconf.editor.name"> + + - + + + + + + + null - * and is assumed to return only token that carry text attributes. + * Creates a damager/repairer that uses the given scanner. The scanner may + * not be null and is assumed to return only token that carry + * text attributes. * - * @param scanner the token scanner to be used, may not be null + * @param scanner + * the token scanner to be used, may not be null */ public AutoconfMacroDamagerRepairer(ITokenScanner scanner) { super(scanner); } - @Override - public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) { - // In the case of a partition with multiline rules, we will punt to - // reparse the entire partition because we don't know if the line being - // edited is in the middle of an area covered by a multiline rule. In - // such a case, we need to back up and find the start sequence of the - // rule. It is easiest to just reparse the whole partition. - return partition; - } - @Override - public void createPresentation(TextPresentation presentation, ITypedRegion region) { - -// int offset = region.getOffset(); -// int length = region.getLength(); - - super.createPresentation(presentation, region); - } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfSourceViewerConfiguration.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfSourceViewerConfiguration.java index 0ace96b0685..3662c8e0da2 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfSourceViewerConfiguration.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfSourceViewerConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 Red Hat, Inc. + * Copyright (c) 2006, 2017 Red Hat, Inc. * 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.autotools.ui.editors; +import org.eclipse.cdt.internal.autotools.ui.editors.autoconf.AutoconfPresentationReconciler; import org.eclipse.cdt.internal.autotools.ui.text.hover.AutoconfTextHover; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.preference.IPreferenceStore; @@ -19,10 +20,8 @@ import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.reconciler.IReconciler; import org.eclipse.jface.text.reconciler.MonoReconciler; -import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.source.IAnnotationHover; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; @@ -91,20 +90,6 @@ public class AutoconfSourceViewerConfiguration extends } @Override public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr= new AutoconfMacroDamagerRepairer(new AutoconfMacroCodeScanner()); - reconciler.setDamager(dr, AutoconfPartitionScanner.AUTOCONF_MACRO); - reconciler.setRepairer(dr, AutoconfPartitionScanner.AUTOCONF_MACRO); - - dr= new DefaultDamagerRepairer(new AutoconfCodeScanner()); - reconciler.setDamager(dr, AutoconfPartitionScanner.AUTOCONF_COMMENT); - reconciler.setRepairer(dr, AutoconfPartitionScanner.AUTOCONF_COMMENT); - - dr= new MultilineRuleDamagerRepairer(new AutoconfCodeScanner()); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - - return reconciler; + return new AutoconfPresentationReconciler(); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/autoconf/AutoconfPresentationReconciler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/autoconf/AutoconfPresentationReconciler.java new file mode 100644 index 00000000000..7b9e08b6a72 --- /dev/null +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/autoconf/AutoconfPresentationReconciler.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * 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 + * + * Contributors: + * Red Hat Inc. - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.autotools.ui.editors.autoconf; + +import org.eclipse.cdt.autotools.ui.editors.AutoconfCodeScanner; +import org.eclipse.cdt.autotools.ui.editors.AutoconfMacroCodeScanner; +import org.eclipse.cdt.autotools.ui.editors.AutoconfMacroDamagerRepairer; +import org.eclipse.cdt.autotools.ui.editors.AutoconfPartitionScanner; +import org.eclipse.cdt.autotools.ui.editors.MultilineRuleDamagerRepairer; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; + +public class AutoconfPresentationReconciler extends PresentationReconciler { + + public AutoconfPresentationReconciler() { + DefaultDamagerRepairer dr = new AutoconfMacroDamagerRepairer(new AutoconfMacroCodeScanner()); + setDamager(dr, AutoconfPartitionScanner.AUTOCONF_MACRO); + setRepairer(dr, AutoconfPartitionScanner.AUTOCONF_MACRO); + + dr = new DefaultDamagerRepairer(new AutoconfCodeScanner()); + setDamager(dr, AutoconfPartitionScanner.AUTOCONF_COMMENT); + setRepairer(dr, AutoconfPartitionScanner.AUTOCONF_COMMENT); + + dr = new MultilineRuleDamagerRepairer(new AutoconfCodeScanner()); + setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + } + +} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefilePresentationReconciler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefilePresentationReconciler.java new file mode 100644 index 00000000000..e863cd8318a --- /dev/null +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefilePresentationReconciler.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2017 Red Hat Inc. and others. + * 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 + * + * Contributors: + * Red Hat Inc. - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.autotools.ui.editors.automake; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; + +public class AutomakefilePresentationReconciler extends PresentationReconciler { + + public AutomakefilePresentationReconciler() { + AutomakefileCodeScanner scanner = new AutomakefileCodeScanner(); + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION); + + dr = new DefaultDamagerRepairer(scanner); + setDamager(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION); + setRepairer(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION); + } + +} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileSourceConfiguration.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileSourceConfiguration.java index dd342ffcc6b..b452c9252d9 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileSourceConfiguration.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileSourceConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 QNX Software Systems and others. + * Copyright (c) 2000, 2017 QNX Software Systems and others. * 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 @@ -19,10 +19,8 @@ import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.reconciler.IReconciler; import org.eclipse.jface.text.reconciler.MonoReconciler; -import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.util.PropertyChangeEvent; @@ -82,36 +80,7 @@ public class AutomakefileSourceConfiguration extends @Override public IPresentationReconciler getPresentationReconciler(ISourceViewer v) { - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION); - - dr = new DefaultDamagerRepairer(getAutomakeCodeScanner()); - reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION); - reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION); - return reconciler; + return new AutomakefilePresentationReconciler(); } @Override