1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 16:05:25 +02:00

Bug 298758: Errors when hovering includes in makefile.

This commit is contained in:
Markus Schorn 2010-01-27 13:50:22 +00:00
parent 852f5e9d31
commit a799c0c964

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others. * Copyright (c) 2000, 2010 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -48,6 +48,8 @@ import org.eclipse.cdt.make.internal.core.makefile.TargetRule;
import org.eclipse.cdt.make.internal.core.makefile.Util; import org.eclipse.cdt.make.internal.core.makefile.Util;
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefileUtil; import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefileUtil;
import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -100,8 +102,13 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
MakefileReader reader; MakefileReader reader;
if (makefileReaderProvider == null) { if (makefileReaderProvider == null) {
try { try {
final IFileStore store = EFS.getStore(fileURI);
final IFileInfo info = store.fetchInfo();
if (!info.exists() || info.isDirectory())
throw new IOException();
reader = new MakefileReader(new InputStreamReader( reader = new MakefileReader(new InputStreamReader(
EFS.getStore(fileURI).openInputStream(EFS.NONE, null))); store.openInputStream(EFS.NONE, null)));
} catch (CoreException e) { } catch (CoreException e) {
MakeCorePlugin.log(e); MakeCorePlugin.log(e);
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
@ -120,8 +127,8 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
protected void parse(URI fileURI, MakefileReader reader) throws IOException { protected void parse(URI fileURI, MakefileReader reader) throws IOException {
String line; String line;
Rule[] rules = null; Rule[] rules = null;
Stack conditions = new Stack(); Stack<Directive> conditions = new Stack<Directive>();
Stack defines = new Stack(); Stack<VariableDefinition> defines = new Stack<VariableDefinition>();
int startLine = 0; int startLine = 0;
int endLine = 0; int endLine = 0;
@ -138,7 +145,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
if (GNUMakefileUtil.isEndef(line)) { if (GNUMakefileUtil.isEndef(line)) {
// We should have a "define" for a "endef". // We should have a "define" for a "endef".
if (!defines.empty()) { if (!defines.empty()) {
VariableDefinition def = (VariableDefinition) defines.pop(); VariableDefinition def = defines.pop();
def.setEndLine(endLine); def.setEndLine(endLine);
} }
Endef endef = new Endef(this); Endef endef = new Endef(this);
@ -161,7 +168,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
// We still in a define. // We still in a define.
if (!defines.empty()) { if (!defines.empty()) {
VariableDefinition def = (VariableDefinition) defines.peek(); VariableDefinition def = defines.peek();
StringBuffer sb = def.getValue(); StringBuffer sb = def.getValue();
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append('\n'); sb.append('\n');
@ -179,9 +186,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
continue; continue;
} else if (rules != null) { } else if (rules != null) {
// The command is added to the rules // The command is added to the rules
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;
} }
@ -196,9 +203,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
cmt.setLines(startLine, endLine); cmt.setLines(startLine, endLine);
if (rules != null) { if (rules != null) {
// The comment is added to the rules. // The comment is added to the rules.
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(conditions, cmt); addDirective(conditions, cmt);
@ -218,9 +225,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
empty.setLines(startLine, endLine); empty.setLines(startLine, endLine);
if (rules != null) { if (rules != null) {
// The EmptyLine is added to the rules. // The EmptyLine is added to the rules.
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(conditions, empty); addDirective(conditions, empty);
@ -304,9 +311,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
// - GNU Static Target rule ? // - GNU Static Target rule ?
if (GNUMakefileUtil.isStaticTargetRule(line)) { if (GNUMakefileUtil.isStaticTargetRule(line)) {
StaticTargetRule[] srules = parseStaticTargetRule(line); StaticTargetRule[] srules = parseStaticTargetRule(line);
for (int i = 0; i < srules.length; i++) { for (StaticTargetRule srule : srules) {
srules[i].setLines(startLine, endLine); srule.setLines(startLine, endLine);
addDirective(conditions, srules[i]); addDirective(conditions, srule);
} }
rules = srules; rules = srules;
continue; continue;
@ -315,9 +322,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
// - Target Rule ? // - Target Rule ?
if (GNUMakefileUtil.isGNUTargetRule(line)) { if (GNUMakefileUtil.isGNUTargetRule(line)) {
TargetRule[] trules = parseGNUTargetRules(line); TargetRule[] trules = parseGNUTargetRules(line);
for (int i = 0; i < trules.length; i++) { for (TargetRule trule : trules) {
trules[i].setLines(startLine, endLine); trule.setLines(startLine, endLine);
addDirective(conditions, trules[i]); addDirective(conditions, trule);
} }
rules = trules; rules = trules;
continue; continue;
@ -335,7 +342,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
//validator.validateDirectives(null, getDirectives()); //validator.validateDirectives(null, getDirectives());
} }
private void addDirective(Stack conditions, Directive directive) { private void addDirective(Stack<Directive> conditions, Directive directive) {
if (conditions.empty()) { if (conditions.empty()) {
addDirective(directive); addDirective(directive);
} else { } else {
@ -538,7 +545,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
String[] directories; String[] directories;
StringTokenizer st = new StringTokenizer(line); StringTokenizer st = new StringTokenizer(line);
int count = st.countTokens(); int count = st.countTokens();
List dirs = new ArrayList(count); List<String> dirs = new ArrayList<String>(count);
if (count > 0) { if (count > 0) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (count == 0) { if (count == 0) {
@ -554,7 +561,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
} }
} }
} }
directories = (String[]) dirs.toArray(new String[0]); directories = dirs.toArray(new String[0]);
if (pattern == null) { if (pattern == null) {
pattern = new String(); pattern = new String();
} }
@ -788,12 +795,13 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
return new InferenceRule(this, new Target(tgt)); return new InferenceRule(this, new Target(tgt));
} }
@Override
public IDirective[] getDirectives(boolean expand) { public IDirective[] getDirectives(boolean expand) {
if (!expand) { if (!expand) {
return getDirectives(); return getDirectives();
} }
IDirective[] dirs = getDirectives(); IDirective[] dirs = getDirectives();
ArrayList list = new ArrayList(Arrays.asList(dirs)); ArrayList<IDirective> list = new ArrayList<IDirective>(Arrays.asList(dirs));
for (int i = 0; i < dirs.length; ++i) { for (int i = 0; i < dirs.length; ++i) {
if (dirs[i] instanceof Include) { if (dirs[i] instanceof Include) {
Include include = (Include)dirs[i]; Include include = (Include)dirs[i];
@ -804,12 +812,13 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
} }
} }
} }
return (IDirective[]) list.toArray(new IDirective[list.size()]); return list.toArray(new IDirective[list.size()]);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.internal.core.makefile.AbstractMakefile#getBuiltins() * @see org.eclipse.cdt.make.internal.core.makefile.AbstractMakefile#getBuiltins()
*/ */
@Override
public IDirective[] getBuiltins() { public IDirective[] getBuiltins() {
return builtins; return builtins;
} }