mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 407169: Highlight of automatic variables in Makefile Editor
This commit is contained in:
parent
98e64e6975
commit
ac94a39422
3 changed files with 58 additions and 1 deletions
|
@ -12,7 +12,7 @@ Export-Package: org.eclipse.cdt.make.core,
|
||||||
org.eclipse.cdt.make.core.scannerconfig,
|
org.eclipse.cdt.make.core.scannerconfig,
|
||||||
org.eclipse.cdt.make.internal.core;x-internal:=true,
|
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;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.makefile.posix;x-internal:=true,
|
||||||
org.eclipse.cdt.make.internal.core.scannerconfig;x-internal:=true,
|
org.eclipse.cdt.make.internal.core.scannerconfig;x-internal:=true,
|
||||||
org.eclipse.cdt.make.internal.core.scannerconfig.gnu;x-internal:=true,
|
org.eclipse.cdt.make.internal.core.scannerconfig.gnu;x-internal:=true,
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -91,6 +91,7 @@ public class MakefileCodeScanner extends AbstractMakefileCodeScanner {
|
||||||
|
|
||||||
rules.add(new FunctionReferenceRule(function));
|
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$
|
||||||
rules.add(new MacroReferenceRule(macroRef, "${", "}")); //$NON-NLS-1$ //$NON-NLS-2$
|
rules.add(new MacroReferenceRule(macroRef, "${", "}")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue