diff --git a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF index 3a2cbd5d68b..fb8700a967e 100644 --- a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Export-Package: org.eclipse.cdt.make.core, org.eclipse.cdt.make.core.scannerconfig, org.eclipse.cdt.make.internal.core;x-internal:=true, org.eclipse.cdt.make.internal.core.makefile;x-internal:=true, - org.eclipse.cdt.make.internal.core.makefile.gnu;x-internal:=true, + org.eclipse.cdt.make.internal.core.makefile.gnu;x-friends:="org.eclipse.cdt.make.ui", org.eclipse.cdt.make.internal.core.makefile.posix;x-internal:=true, org.eclipse.cdt.make.internal.core.scannerconfig;x-internal:=true, org.eclipse.cdt.make.internal.core.scannerconfig.gnu;x-internal:=true, diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/AutomaticVariableReferenceRule.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/AutomaticVariableReferenceRule.java new file mode 100644 index 00000000000..f5662433e12 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/AutomaticVariableReferenceRule.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2013, 2013 Andrew Gvozdev 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: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.make.internal.ui.text.makefile; + +import org.eclipse.cdt.make.core.makefile.IDirective; +import org.eclipse.cdt.make.core.makefile.gnu.IVariableDefinition; +import org.eclipse.cdt.make.internal.core.makefile.gnu.GNUMakefile; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.WordRule; + +/** + * Rule used to highlight automatic variables in the editor. + */ +public class AutomaticVariableReferenceRule extends WordRule { + private static final char DOLLAR_SIGN = '$'; + + /** + * Constructor. + * @param token - the token to be returned by the rule. + */ + public AutomaticVariableReferenceRule(IToken token) { + super(new IWordDetector() { + int count = 0; + @Override + public boolean isWordPart(char c) { + count++; + return count <= 2; + } + @Override + public boolean isWordStart(char c) { + count = 1; + return c == DOLLAR_SIGN; + } + }); + // Add automatic variables + for (IDirective var : new GNUMakefile().getBuiltins()) { + if (var instanceof IVariableDefinition) { + addWord(DOLLAR_SIGN + ((IVariableDefinition) var).getName(), token); + } + } + // Add also $0-$9 variables + for (int n = 0; n <= 9; n++) { + addWord(Character.toString(DOLLAR_SIGN) + n, token); + } + } + +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java index a11c29ab1c5..c7d45c07866 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java @@ -91,6 +91,7 @@ public class MakefileCodeScanner extends AbstractMakefileCodeScanner { rules.add(new FunctionReferenceRule(function)); + rules.add(new AutomaticVariableReferenceRule(macroRef)); rules.add(new MacroReferenceRule(macroRef, "$(", ")")); //$NON-NLS-1$ //$NON-NLS-2$ rules.add(new MacroReferenceRule(macroRef, "${", "}")); //$NON-NLS-1$ //$NON-NLS-2$