1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Cosmetics

This commit is contained in:
Andrew Gvozdev 2013-05-05 07:05:22 -04:00
parent e35e32e8b0
commit 5c400704fb
5 changed files with 166 additions and 230 deletions

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.make.core.makefile.ITargetRule;
*/ */
public abstract class AbstractMakefile extends Parent implements IMakefile { public abstract class AbstractMakefile extends Parent implements IMakefile {
private URI filename; private URI filename;
public AbstractMakefile(Directive parent) { public AbstractMakefile(Directive parent) {
@ -52,9 +51,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IRule[] getRules() { public IRule[] getRules() {
IDirective[] stmts = getDirectives(true); IDirective[] stmts = getDirectives(true);
List<IDirective> array = new ArrayList<IDirective>(stmts.length); List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) { for (IDirective stmt : stmts) {
if (stmts[i] instanceof IRule) { if (stmt instanceof IRule) {
array.add(stmts[i]); array.add(stmt);
} }
} }
return array.toArray(new IRule[0]); return array.toArray(new IRule[0]);
@ -64,9 +63,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IRule[] getRules(String target) { public IRule[] getRules(String target) {
IRule[] rules = getRules(); IRule[] rules = getRules();
List<IRule> array = new ArrayList<IRule>(rules.length); List<IRule> array = new ArrayList<IRule>(rules.length);
for (int i = 0; i < rules.length; i++) { for (IRule rule : rules) {
if (rules[i].getTarget().equals(target)) { if (rule.getTarget().equals(target)) {
array.add(rules[i]); array.add(rule);
} }
} }
return array.toArray(new IRule[0]); return array.toArray(new IRule[0]);
@ -76,9 +75,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getInferenceRules() { public IInferenceRule[] getInferenceRules() {
IRule[] rules = getRules(); IRule[] rules = getRules();
List<IRule> array = new ArrayList<IRule>(rules.length); List<IRule> array = new ArrayList<IRule>(rules.length);
for (int i = 0; i < rules.length; i++) { for (IRule rule : rules) {
if (rules[i] instanceof IInferenceRule) { if (rule instanceof IInferenceRule) {
array.add(rules[i]); array.add(rule);
} }
} }
return array.toArray(new IInferenceRule[0]); return array.toArray(new IInferenceRule[0]);
@ -88,9 +87,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getInferenceRules(String target) { public IInferenceRule[] getInferenceRules(String target) {
IInferenceRule[] irules = getInferenceRules(); IInferenceRule[] irules = getInferenceRules();
List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length); List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length);
for (int i = 0; i < irules.length; i++) { for (IInferenceRule irule : irules) {
if (irules[i].getTarget().equals(target)) { if (irule.getTarget().equals(target)) {
array.add(irules[i]); array.add(irule);
} }
} }
return array.toArray(new IInferenceRule[0]); return array.toArray(new IInferenceRule[0]);
@ -100,9 +99,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public ITargetRule[] getTargetRules() { public ITargetRule[] getTargetRules() {
IRule[] trules = getRules(); IRule[] trules = getRules();
List<IRule> array = new ArrayList<IRule>(trules.length); List<IRule> array = new ArrayList<IRule>(trules.length);
for (int i = 0; i < trules.length; i++) { for (IRule trule : trules) {
if (trules[i] instanceof ITargetRule) { if (trule instanceof ITargetRule) {
array.add(trules[i]); array.add(trule);
} }
} }
return array.toArray(new ITargetRule[0]); return array.toArray(new ITargetRule[0]);
@ -112,9 +111,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public ITargetRule[] getTargetRules(String target) { public ITargetRule[] getTargetRules(String target) {
ITargetRule[] trules = getTargetRules(); ITargetRule[] trules = getTargetRules();
List<ITargetRule> array = new ArrayList<ITargetRule>(trules.length); List<ITargetRule> array = new ArrayList<ITargetRule>(trules.length);
for (int i = 0; i < trules.length; i++) { for (ITargetRule trule : trules) {
if (trules[i].getTarget().equals(target)) { if (trule.getTarget().equals(target)) {
array.add(trules[i]); array.add(trule);
} }
} }
return array.toArray(new ITargetRule[0]); return array.toArray(new ITargetRule[0]);
@ -124,9 +123,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getMacroDefinitions() { public IMacroDefinition[] getMacroDefinitions() {
IDirective[] stmts = getDirectives(true); IDirective[] stmts = getDirectives(true);
List<IDirective> array = new ArrayList<IDirective>(stmts.length); List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) { for (IDirective stmt : stmts) {
if (stmts[i] instanceof IMacroDefinition) { if (stmt instanceof IMacroDefinition) {
array.add(stmts[i]); array.add(stmt);
} }
} }
return array.toArray(new IMacroDefinition[0]); return array.toArray(new IMacroDefinition[0]);
@ -136,9 +135,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getMacroDefinitions(String name) { public IMacroDefinition[] getMacroDefinitions(String name) {
IMacroDefinition[] variables = getMacroDefinitions(); IMacroDefinition[] variables = getMacroDefinitions();
List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length); List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length);
for (int i = 0; i < variables.length; i++) { for (IMacroDefinition variable : variables) {
if (variables[i].getName().equals(name)) { if (variable.getName().equals(name)) {
array.add(variables[i]); array.add(variable);
} }
} }
return array.toArray(new IMacroDefinition[0]); return array.toArray(new IMacroDefinition[0]);
@ -148,9 +147,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getBuiltinMacroDefinitions() { public IMacroDefinition[] getBuiltinMacroDefinitions() {
IDirective[] stmts = getBuiltins(); IDirective[] stmts = getBuiltins();
List<IDirective> array = new ArrayList<IDirective>(stmts.length); List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) { for (IDirective stmt : stmts) {
if (stmts[i] instanceof IMacroDefinition) { if (stmt instanceof IMacroDefinition) {
array.add(stmts[i]); array.add(stmt);
} }
} }
return array.toArray(new IMacroDefinition[0]); return array.toArray(new IMacroDefinition[0]);
@ -160,9 +159,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getBuiltinMacroDefinitions(String name) { public IMacroDefinition[] getBuiltinMacroDefinitions(String name) {
IMacroDefinition[] variables = getBuiltinMacroDefinitions(); IMacroDefinition[] variables = getBuiltinMacroDefinitions();
List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length); List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length);
for (int i = 0; i < variables.length; i++) { for (IMacroDefinition variable : variables) {
if (variables[i].getName().equals(name)) { if (variable.getName().equals(name)) {
array.add(variables[i]); array.add(variable);
} }
} }
return array.toArray(new IMacroDefinition[0]); return array.toArray(new IMacroDefinition[0]);
@ -171,9 +170,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getBuiltinInferenceRules() { public IInferenceRule[] getBuiltinInferenceRules() {
IDirective[] stmts = getBuiltins(); IDirective[] stmts = getBuiltins();
List<IDirective> array = new ArrayList<IDirective>(stmts.length); List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) { for (IDirective stmt : stmts) {
if (stmts[i] instanceof IInferenceRule) { if (stmt instanceof IInferenceRule) {
array.add(stmts[i]); array.add(stmt);
} }
} }
return array.toArray(new IInferenceRule[0]); return array.toArray(new IInferenceRule[0]);
@ -182,9 +181,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getBuiltinInferenceRules(String target) { public IInferenceRule[] getBuiltinInferenceRules(String target) {
IInferenceRule[] irules = getBuiltinInferenceRules(); IInferenceRule[] irules = getBuiltinInferenceRules();
List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length); List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length);
for (int i = 0; i < irules.length; i++) { for (IInferenceRule irule : irules) {
if (irules[i].getTarget().equals(target)) { if (irule.getTarget().equals(target)) {
array.add(irules[i]); array.add(irule);
} }
} }
return array.toArray(new IInferenceRule[0]); return array.toArray(new IInferenceRule[0]);
@ -205,53 +204,28 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
char c = line.charAt(i); char c = line.charAt(i);
switch(c) { switch(c) {
case '$': case '$':
// '$$' --> '$' // '$$' --> '$'
if (foundDollar) { if (foundDollar) {
buffer.append(c); buffer.append(c);
foundDollar = false; foundDollar = false;
} else { } else {
foundDollar = true; foundDollar = true;
} }
break; break;
case '(': case '(':
case '{': case '{':
if (foundDollar) { if (foundDollar) {
inMacro = true; inMacro = true;
} else { } else {
buffer.append(c); buffer.append(c);
} }
break; break;
case ')': case ')':
case '}': case '}':
if (inMacro) { if (inMacro) {
String name = macroName.toString(); String name = macroName.toString();
if (name.length() > 0) { if (name.length() > 0) {
IMacroDefinition[] defs = getMacroDefinitions(name);
if (defs.length == 0) {
defs = getBuiltinMacroDefinitions(name);
}
if (defs.length > 0) {
String result = defs[0].getValue().toString();
if (result.indexOf('$') != -1 && recursive) {
result = expandString(result, recursive);
}
buffer.append(result);
} else { // Do not expand
buffer.append('$').append('(').append(name).append(')');
}
}
macroName.setLength(0);
inMacro = false;
} else {
buffer.append(c);
}
break;
default:
if (inMacro) {
macroName.append(c);
} else if (foundDollar) {
String name = String.valueOf(c);
IMacroDefinition[] defs = getMacroDefinitions(name); IMacroDefinition[] defs = getMacroDefinitions(name);
if (defs.length == 0) { if (defs.length == 0) {
defs = getBuiltinMacroDefinitions(name); defs = getBuiltinMacroDefinitions(name);
@ -262,16 +236,41 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
result = expandString(result, recursive); result = expandString(result, recursive);
} }
buffer.append(result); buffer.append(result);
} else { } else { // Do not expand
// nothing found buffer.append('$').append('(').append(name).append(')');
buffer.append('$').append(c);
} }
inMacro = false;
} else {
buffer.append(c);
} }
foundDollar = false; macroName.setLength(0);
break; inMacro = false;
} else {
buffer.append(c);
}
break;
default:
if (inMacro) {
macroName.append(c);
} else if (foundDollar) {
String name = String.valueOf(c);
IMacroDefinition[] defs = getMacroDefinitions(name);
if (defs.length == 0) {
defs = getBuiltinMacroDefinitions(name);
}
if (defs.length > 0) {
String result = defs[0].getValue().toString();
if (result.indexOf('$') != -1 && recursive) {
result = expandString(result, recursive);
}
buffer.append(result);
} else {
// nothing found
buffer.append('$').append(c);
}
inMacro = false;
} else {
buffer.append(c);
}
foundDollar = false;
break;
} }
} }
return buffer.toString(); return buffer.toString();
@ -283,8 +282,8 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
} }
public void setFileURI(URI filename) { public void setFileURI(URI filename) {
this.filename = filename; this.filename = filename;
} }
@Override @Override
public IMakefile getMakefile() { public IMakefile getMakefile() {

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.make.core.makefile.IMakefileReaderProvider;
*/ */
public class NullMakefile extends AbstractMakefile { public class NullMakefile extends AbstractMakefile {
public final static IDirective[] EMPTY_DIRECTIVES = new IDirective[0]; public final static IDirective[] EMPTY_DIRECTIVES = new IDirective[0];
public NullMakefile() { public NullMakefile() {
@ -59,36 +58,22 @@ public class NullMakefile extends AbstractMakefile {
return new String(); return new String();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IMakefile#parse(java.io.Reader)
*/
@Override @Override
public void parse(String name, Reader makefile) throws IOException { public void parse(String name, Reader makefile) throws IOException {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IMakefile#getMakefileReaderProvider()
*/
@Override @Override
public IMakefileReaderProvider getMakefileReaderProvider() { public IMakefileReaderProvider getMakefileReaderProvider() {
return null; return null;
} }
/* (non-Javadoc) public void parse(String name, IMakefileReaderProvider makefileReaderProvider) throws IOException {
* @see org.eclipse.cdt.make.core.makefile.IMakefile#parse(java.lang.String, org.eclipse.cdt.make.core.makefile.IMakefileReaderProvider)
*/
public void parse(String name,
IMakefileReaderProvider makefileReaderProvider) throws IOException {
} }
@Override @Override
public void parse(URI fileURI, Reader makefile) throws IOException { public void parse(URI fileURI, Reader makefile) throws IOException {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IMakefile#parse(java.net.URI, org.eclipse.cdt.make.core.makefile.IMakefileReaderProvider)
*/
@Override @Override
public void parse(URI fileURI, public void parse(URI fileURI, IMakefileReaderProvider makefileReaderProvider) throws IOException {
IMakefileReaderProvider makefileReaderProvider) throws IOException {
} }
} }

View file

@ -72,21 +72,20 @@ import org.eclipse.core.runtime.CoreException;
*/ */
public class GNUMakefile extends AbstractMakefile implements IGNUMakefile { public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
public static String PATH_SEPARATOR = System.getProperty("path.separator", ":"); //$NON-NLS-1$ //$NON-NLS-2$ public static String PATH_SEPARATOR = System.getProperty("path.separator", ":"); //$NON-NLS-1$ //$NON-NLS-2$
public static String FILE_SEPARATOR = System.getProperty("file.separator", "/"); //$NON-NLS-1$ //$NON-NLS-2$ public static String FILE_SEPARATOR = System.getProperty("file.separator", "/"); //$NON-NLS-1$ //$NON-NLS-2$
String[] includeDirectories = new String[0]; private String[] includeDirectories = new String[0];
@SuppressWarnings("nls") @SuppressWarnings("nls")
IDirective[] builtins = new IDirective[]{ private IDirective[] builtins = new IDirective[]{
new AutomaticVariable(this, "@", MakefileMessages.getString("GNUMakefile.automaticVariable.at")), new AutomaticVariable(this, "@", MakefileMessages.getString("GNUMakefile.automaticVariable.at")),
new AutomaticVariable(this, "%", MakefileMessages.getString("GNUMakefile.automaticVariable.percent")), new AutomaticVariable(this, "%", MakefileMessages.getString("GNUMakefile.automaticVariable.percent")),
new AutomaticVariable(this, "<", MakefileMessages.getString("GNUMakefile.automaticVariable.less")), new AutomaticVariable(this, "<", MakefileMessages.getString("GNUMakefile.automaticVariable.less")),
new AutomaticVariable(this, "?", MakefileMessages.getString("GNUMakefile.automaticVariable.question")), new AutomaticVariable(this, "?", MakefileMessages.getString("GNUMakefile.automaticVariable.question")),
new AutomaticVariable(this, "^", MakefileMessages.getString("GNUMakefile.automaticVariable.carrot")), new AutomaticVariable(this, "^", MakefileMessages.getString("GNUMakefile.automaticVariable.carrot")),
new AutomaticVariable(this, "+", MakefileMessages.getString("GNUMakefile.automaticVariable.plus")), new AutomaticVariable(this, "+", MakefileMessages.getString("GNUMakefile.automaticVariable.plus")),
new AutomaticVariable(this, "|", MakefileMessages.getString("GNUMakefile.automaticVariable.pipe")), new AutomaticVariable(this, "|", MakefileMessages.getString("GNUMakefile.automaticVariable.pipe")),
new AutomaticVariable(this, "*", MakefileMessages.getString("GNUMakefile.automaticVariable.star")), new AutomaticVariable(this, "*", MakefileMessages.getString("GNUMakefile.automaticVariable.star")),
}; };
private IMakefileReaderProvider makefileReaderProvider; private IMakefileReaderProvider makefileReaderProvider;
@ -113,8 +112,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
try { try {
final IFileStore store = EFS.getStore(fileURI); final IFileStore store = EFS.getStore(fileURI);
final IFileInfo info = store.fetchInfo(); final IFileInfo info = store.fetchInfo();
if (!info.exists() || info.isDirectory()) if (!info.exists() || info.isDirectory()) {
throw new IOException(); throw new IOException();
}
reader = new MakefileReader(new InputStreamReader( reader = new MakefileReader(new InputStreamReader(
store.openInputStream(EFS.NONE, null))); store.openInputStream(EFS.NONE, null)));
@ -534,20 +534,20 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
} }
/** /**
* There are three forms of the "vpath" directive: * There are three forms of the "vpath" directive:
* "vpath PATTERN DIRECTORIES" * "vpath PATTERN DIRECTORIES"
* Specify the search path DIRECTORIES for file names that match PATTERN. * Specify the search path DIRECTORIES for file names that match PATTERN.
* *
* The search path, DIRECTORIES, is a list of directories to be * The search path, DIRECTORIES, is a list of directories to be
* searched, separated by colons (semi-colons on MS-DOS and * searched, separated by colons (semi-colons on MS-DOS and
* MS-Windows) or blanks, just like the search path used in the `VPATH' variable. * MS-Windows) or blanks, just like the search path used in the `VPATH' variable.
* *
* "vpath PATTERN" * "vpath PATTERN"
* Clear out the search path associated with PATTERN. * Clear out the search path associated with PATTERN.
* *
* "vpath" * "vpath"
* Clear all search paths previously specified with `vpath' directives. * Clear all search paths previously specified with `vpath' directives.
*/ */
protected VPath parseVPath(String line) { protected VPath parseVPath(String line) {
String pattern = null; String pattern = null;
String[] directories; String[] directories;
@ -717,8 +717,8 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
if (index > 0) { if (index > 0) {
type = line.charAt(index - 1); type = line.charAt(index - 1);
if (type == VariableDefinition.TYPE_SIMPLE_EXPAND if (type == VariableDefinition.TYPE_SIMPLE_EXPAND
|| type == VariableDefinition.TYPE_APPEND || type == VariableDefinition.TYPE_APPEND
|| type == VariableDefinition.TYPE_CONDITIONAL) { || type == VariableDefinition.TYPE_CONDITIONAL) {
separator = index - 1; separator = index - 1;
} else { } else {
type = VariableDefinition.TYPE_RECURSIVE_EXPAND; type = VariableDefinition.TYPE_RECURSIVE_EXPAND;
@ -802,13 +802,11 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
} }
IDirective[] dirs = getDirectives(); IDirective[] dirs = getDirectives();
ArrayList<IDirective> list = new ArrayList<IDirective>(Arrays.asList(dirs)); ArrayList<IDirective> list = new ArrayList<IDirective>(Arrays.asList(dirs));
for (int i = 0; i < dirs.length; ++i) { for (IDirective dir : dirs) {
if (dirs[i] instanceof Include) { if (dir instanceof Include) {
Include include = (Include)dirs[i]; IDirective[] includedMakefiles = ((Include)dir).getDirectives();
IDirective[] includedMakefiles = include.getDirectives(); for (IDirective includedMakefile : includedMakefiles) {
for (int j = 0; j < includedMakefiles.length; ++j) { list.addAll(Arrays.asList(((IMakefile)includedMakefile).getDirectives()));
IMakefile includedMakefile = (IMakefile)includedMakefiles[j];
list.addAll(Arrays.asList(includedMakefile.getDirectives()));
} }
} }
} }

View file

@ -63,17 +63,13 @@ import org.eclipse.core.runtime.CoreException;
*/ */
public class PosixMakefile extends AbstractMakefile { public class PosixMakefile extends AbstractMakefile {
private IDirective[] builtins = new IDirective[0];
IDirective[] builtins = new IDirective[0];
private IMakefileReaderProvider makefileReaderProvider; private IMakefileReaderProvider makefileReaderProvider;
public PosixMakefile() { public PosixMakefile() {
super(null); super(null);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IMakefile#getMakefileReaderProvider()
*/
@Override @Override
public IMakefileReaderProvider getMakefileReaderProvider() { public IMakefileReaderProvider getMakefileReaderProvider() {
return makefileReaderProvider; return makefileReaderProvider;
@ -84,9 +80,6 @@ public class PosixMakefile extends AbstractMakefile {
parse(URIUtil.toURI(name), new MakefileReader(reader)); parse(URIUtil.toURI(name), new MakefileReader(reader));
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IMakefile#parse(java.net.URI, org.eclipse.cdt.make.core.makefile.IMakefileReaderProvider)
*/
@Override @Override
public void parse(URI fileURI, public void parse(URI fileURI,
IMakefileReaderProvider makefileReaderProvider) throws IOException { IMakefileReaderProvider makefileReaderProvider) throws IOException {
@ -133,9 +126,9 @@ public class PosixMakefile extends AbstractMakefile {
cmd.setLines(startLine, endLine); cmd.setLines(startLine, endLine);
// The command is added to the rules // The command is added to the rules
if (rules != null) { if (rules != null) {
for (int i = 0; i < rules.length; i++) { for (Rule rule : rules) {
rules[i].addDirective(cmd); rule.addDirective(cmd);
rules[i].setEndLine(endLine); rule.setEndLine(endLine);
} }
continue; continue;
} }
@ -149,9 +142,9 @@ public class PosixMakefile extends AbstractMakefile {
Comment cmt = new Comment(this, line.substring(pound + 1)); Comment cmt = new Comment(this, line.substring(pound + 1));
cmt.setLines(startLine, endLine); cmt.setLines(startLine, endLine);
if (rules != null) { if (rules != null) {
for (int i = 0; i < rules.length; i++) { for (Rule rule : rules) {
rules[i].addDirective(cmt); rule.addDirective(cmt);
rules[i].setEndLine(endLine); rule.setEndLine(endLine);
} }
} else { } else {
addDirective(cmt); addDirective(cmt);
@ -170,9 +163,9 @@ public class PosixMakefile extends AbstractMakefile {
Directive empty = new EmptyLine(this); Directive empty = new EmptyLine(this);
empty.setLines(startLine, endLine); empty.setLines(startLine, endLine);
if (rules != null) { if (rules != null) {
for (int i = 0; i < rules.length; i++) { for (Rule rule : rules) {
rules[i].addDirective(empty); rule.addDirective(empty);
rules[i].setEndLine(endLine); rule.setEndLine(endLine);
} }
} else { } else {
addDirective(empty); addDirective(empty);
@ -214,9 +207,9 @@ public class PosixMakefile extends AbstractMakefile {
// 8- Target Rule ? // 8- Target Rule ?
if (PosixMakefileUtil.isTargetRule(line)) { if (PosixMakefileUtil.isTargetRule(line)) {
TargetRule[] trules = parseTargetRule(line); TargetRule[] trules = parseTargetRule(line);
for (int i = 0; i < trules.length; i++) { for (TargetRule trule : trules) {
trules[i].setLines(startLine, endLine); trule.setLines(startLine, endLine);
addDirective(trules[i]); addDirective(trule);
} }
rules = trules; rules = trules;
continue; continue;
@ -233,9 +226,6 @@ public class PosixMakefile extends AbstractMakefile {
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.make.internal.core.makefile.AbstractMakefile#getBuiltins()
*/
@Override @Override
public IDirective[] getBuiltins() { public IDirective[] getBuiltins() {
return builtins; return builtins;

View file

@ -39,34 +39,20 @@ import org.eclipse.ui.IEditorPart;
* MakefileCompletionProcessor * MakefileCompletionProcessor
*/ */
public class MakefileCompletionProcessor implements IContentAssistProcessor { public class MakefileCompletionProcessor implements IContentAssistProcessor {
/** /**
* Simple content assist tip closer. The tip is valid in a range * Simple content assist tip closer. The tip is valid in a range
* of 5 characters around its popup location. * of 5 characters around its pop-up location.
*/ */
protected static class Validator implements IContextInformationValidator, IContextInformationPresenter { protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
protected int fInstallOffset; protected int fInstallOffset;
/*
* @see IContextInformationValidator#isContextInformationValid(int)
*/
@Override @Override
public boolean isContextInformationValid(int offset) { public boolean isContextInformationValid(int offset) {
return Math.abs(fInstallOffset - offset) < 5; return Math.abs(fInstallOffset - offset) < 5;
} }
/*
* @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
*/
@Override @Override
public void install(IContextInformation info, ITextViewer viewer, int offset) { public void install(IContextInformation info, ITextViewer viewer, int offset) {
fInstallOffset = offset; fInstallOffset = offset;
} }
/*
* @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
*/
@Override @Override
public boolean updatePresentation(int documentPosition, TextPresentation presentation) { public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
return false; return false;
@ -74,10 +60,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
} }
public class DirectiveComparator implements Comparator<Object> { public class DirectiveComparator implements Comparator<Object> {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override @Override
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
String name1; String name1;
@ -117,9 +99,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
fManager = MakeUIPlugin.getDefault().getWorkingCopyManager(); fManager = MakeUIPlugin.getDefault().getWorkingCopyManager();
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
*/
@Override @Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset); WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
@ -139,16 +118,16 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
ArrayList<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(statements.length); ArrayList<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(statements.length);
// iterate over all the different categories // iterate over all the different categories
for (int i = 0; i < statements.length; i++) { for (IDirective statement : statements) {
String name = null; String name = null;
Image image = null; Image image = null;
String infoString = "";//getContentInfoString(name); //$NON-NLS-1$ String infoString = "";//getContentInfoString(name); //$NON-NLS-1$
if (statements[i] instanceof IMacroDefinition) { if (statement instanceof IMacroDefinition) {
name = ((IMacroDefinition) statements[i]).getName(); name = ((IMacroDefinition) statement).getName();
image = imageMacro; image = imageMacro;
infoString = ((IMacroDefinition)statements[i]).getValue().toString(); infoString = ((IMacroDefinition)statement).getValue().toString();
} else if (statements[i] instanceof IRule) { } else if (statement instanceof IRule) {
name = ((IRule) statements[i]).getTarget().toString(); name = ((IRule) statement).getTarget().toString();
image = imageTarget; image = imageTarget;
infoString = name; infoString = name;
} }
@ -156,15 +135,15 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
IContextInformation info = new ContextInformation(name, infoString); IContextInformation info = new ContextInformation(name, infoString);
String displayString = (name.equals(infoString) ? name : name + " - " + infoString); //$NON-NLS-1$ String displayString = (name.equals(infoString) ? name : name + " - " + infoString); //$NON-NLS-1$
ICompletionProposal result = ICompletionProposal result =
new CompletionProposal( new CompletionProposal(
name, name,
wordPart.getOffset(), wordPart.getOffset(),
wordPart.toString().length(), wordPart.toString().length(),
name.length(), name.length(),
image, image,
displayString, displayString,
info, info,
infoString); infoString);
proposalList.add(result); proposalList.add(result);
} }
} }
@ -173,9 +152,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
return proposals; return proposals;
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
*/
@Override @Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset); WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
@ -184,11 +160,11 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
ArrayList<String> contextList = new ArrayList<String>(); ArrayList<String> contextList = new ArrayList<String>();
if (macro) { if (macro) {
IDirective[] statements = makefile.getMacroDefinitions(); IDirective[] statements = makefile.getMacroDefinitions();
for (int i = 0; i < statements.length; i++) { for (IDirective statement : statements) {
if (statements[i] instanceof IMacroDefinition) { if (statement instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statements[i]).getName(); String name = ((IMacroDefinition) statement).getName();
if (name != null && name.equals(wordPart.toString())) { if (name != null && name.equals(wordPart.toString())) {
String value = ((IMacroDefinition) statements[i]).getValue().toString(); String value = ((IMacroDefinition) statement).getValue().toString();
if (value != null && value.length() > 0) { if (value != null && value.length() > 0) {
contextList.add(value); contextList.add(value);
} }
@ -196,11 +172,11 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
} }
} }
statements = makefile.getBuiltinMacroDefinitions(); statements = makefile.getBuiltinMacroDefinitions();
for (int i = 0; i < statements.length; i++) { for (IDirective statement : statements) {
if (statements[i] instanceof IMacroDefinition) { if (statement instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statements[i]).getName(); String name = ((IMacroDefinition) statement).getName();
if (name != null && name.equals(wordPart.toString())) { if (name != null && name.equals(wordPart.toString())) {
String value = ((IMacroDefinition) statements[i]).getValue().toString(); String value = ((IMacroDefinition) statement).getValue().toString();
if (value != null && value.length() > 0) { if (value != null && value.length() > 0) {
contextList.add(value); contextList.add(value);
} }
@ -218,33 +194,21 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
*/
@Override @Override
public char[] getCompletionProposalAutoActivationCharacters() { public char[] getCompletionProposalAutoActivationCharacters() {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
*/
@Override @Override
public char[] getContextInformationAutoActivationCharacters() { public char[] getContextInformationAutoActivationCharacters() {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
*/
@Override @Override
public String getErrorMessage() { public String getErrorMessage() {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
*/
@Override @Override
public IContextInformationValidator getContextInformationValidator() { public IContextInformationValidator getContextInformationValidator() {
return fValidator; return fValidator;