1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +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 {
private URI filename;
public AbstractMakefile(Directive parent) {
@ -52,9 +51,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IRule[] getRules() {
IDirective[] stmts = getDirectives(true);
List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) {
if (stmts[i] instanceof IRule) {
array.add(stmts[i]);
for (IDirective stmt : stmts) {
if (stmt instanceof IRule) {
array.add(stmt);
}
}
return array.toArray(new IRule[0]);
@ -64,9 +63,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IRule[] getRules(String target) {
IRule[] rules = getRules();
List<IRule> array = new ArrayList<IRule>(rules.length);
for (int i = 0; i < rules.length; i++) {
if (rules[i].getTarget().equals(target)) {
array.add(rules[i]);
for (IRule rule : rules) {
if (rule.getTarget().equals(target)) {
array.add(rule);
}
}
return array.toArray(new IRule[0]);
@ -76,9 +75,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getInferenceRules() {
IRule[] rules = getRules();
List<IRule> array = new ArrayList<IRule>(rules.length);
for (int i = 0; i < rules.length; i++) {
if (rules[i] instanceof IInferenceRule) {
array.add(rules[i]);
for (IRule rule : rules) {
if (rule instanceof IInferenceRule) {
array.add(rule);
}
}
return array.toArray(new IInferenceRule[0]);
@ -88,9 +87,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getInferenceRules(String target) {
IInferenceRule[] irules = getInferenceRules();
List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length);
for (int i = 0; i < irules.length; i++) {
if (irules[i].getTarget().equals(target)) {
array.add(irules[i]);
for (IInferenceRule irule : irules) {
if (irule.getTarget().equals(target)) {
array.add(irule);
}
}
return array.toArray(new IInferenceRule[0]);
@ -100,9 +99,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public ITargetRule[] getTargetRules() {
IRule[] trules = getRules();
List<IRule> array = new ArrayList<IRule>(trules.length);
for (int i = 0; i < trules.length; i++) {
if (trules[i] instanceof ITargetRule) {
array.add(trules[i]);
for (IRule trule : trules) {
if (trule instanceof ITargetRule) {
array.add(trule);
}
}
return array.toArray(new ITargetRule[0]);
@ -112,9 +111,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public ITargetRule[] getTargetRules(String target) {
ITargetRule[] trules = getTargetRules();
List<ITargetRule> array = new ArrayList<ITargetRule>(trules.length);
for (int i = 0; i < trules.length; i++) {
if (trules[i].getTarget().equals(target)) {
array.add(trules[i]);
for (ITargetRule trule : trules) {
if (trule.getTarget().equals(target)) {
array.add(trule);
}
}
return array.toArray(new ITargetRule[0]);
@ -124,9 +123,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getMacroDefinitions() {
IDirective[] stmts = getDirectives(true);
List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) {
if (stmts[i] instanceof IMacroDefinition) {
array.add(stmts[i]);
for (IDirective stmt : stmts) {
if (stmt instanceof IMacroDefinition) {
array.add(stmt);
}
}
return array.toArray(new IMacroDefinition[0]);
@ -136,9 +135,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getMacroDefinitions(String name) {
IMacroDefinition[] variables = getMacroDefinitions();
List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length);
for (int i = 0; i < variables.length; i++) {
if (variables[i].getName().equals(name)) {
array.add(variables[i]);
for (IMacroDefinition variable : variables) {
if (variable.getName().equals(name)) {
array.add(variable);
}
}
return array.toArray(new IMacroDefinition[0]);
@ -148,9 +147,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getBuiltinMacroDefinitions() {
IDirective[] stmts = getBuiltins();
List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) {
if (stmts[i] instanceof IMacroDefinition) {
array.add(stmts[i]);
for (IDirective stmt : stmts) {
if (stmt instanceof IMacroDefinition) {
array.add(stmt);
}
}
return array.toArray(new IMacroDefinition[0]);
@ -160,9 +159,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IMacroDefinition[] getBuiltinMacroDefinitions(String name) {
IMacroDefinition[] variables = getBuiltinMacroDefinitions();
List<IMacroDefinition> array = new ArrayList<IMacroDefinition>(variables.length);
for (int i = 0; i < variables.length; i++) {
if (variables[i].getName().equals(name)) {
array.add(variables[i]);
for (IMacroDefinition variable : variables) {
if (variable.getName().equals(name)) {
array.add(variable);
}
}
return array.toArray(new IMacroDefinition[0]);
@ -171,9 +170,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getBuiltinInferenceRules() {
IDirective[] stmts = getBuiltins();
List<IDirective> array = new ArrayList<IDirective>(stmts.length);
for (int i = 0; i < stmts.length; i++) {
if (stmts[i] instanceof IInferenceRule) {
array.add(stmts[i]);
for (IDirective stmt : stmts) {
if (stmt instanceof IInferenceRule) {
array.add(stmt);
}
}
return array.toArray(new IInferenceRule[0]);
@ -182,9 +181,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
public IInferenceRule[] getBuiltinInferenceRules(String target) {
IInferenceRule[] irules = getBuiltinInferenceRules();
List<IInferenceRule> array = new ArrayList<IInferenceRule>(irules.length);
for (int i = 0; i < irules.length; i++) {
if (irules[i].getTarget().equals(target)) {
array.add(irules[i]);
for (IInferenceRule irule : irules) {
if (irule.getTarget().equals(target)) {
array.add(irule);
}
}
return array.toArray(new IInferenceRule[0]);

View file

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

View file

@ -72,13 +72,12 @@ import org.eclipse.core.runtime.CoreException;
*/
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 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")
IDirective[] builtins = new IDirective[]{
private IDirective[] builtins = new IDirective[]{
new AutomaticVariable(this, "@", MakefileMessages.getString("GNUMakefile.automaticVariable.at")),
new AutomaticVariable(this, "%", MakefileMessages.getString("GNUMakefile.automaticVariable.percent")),
new AutomaticVariable(this, "<", MakefileMessages.getString("GNUMakefile.automaticVariable.less")),
@ -113,8 +112,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
try {
final IFileStore store = EFS.getStore(fileURI);
final IFileInfo info = store.fetchInfo();
if (!info.exists() || info.isDirectory())
if (!info.exists() || info.isDirectory()) {
throw new IOException();
}
reader = new MakefileReader(new InputStreamReader(
store.openInputStream(EFS.NONE, null)));
@ -802,13 +802,11 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
}
IDirective[] dirs = getDirectives();
ArrayList<IDirective> list = new ArrayList<IDirective>(Arrays.asList(dirs));
for (int i = 0; i < dirs.length; ++i) {
if (dirs[i] instanceof Include) {
Include include = (Include)dirs[i];
IDirective[] includedMakefiles = include.getDirectives();
for (int j = 0; j < includedMakefiles.length; ++j) {
IMakefile includedMakefile = (IMakefile)includedMakefiles[j];
list.addAll(Arrays.asList(includedMakefile.getDirectives()));
for (IDirective dir : dirs) {
if (dir instanceof Include) {
IDirective[] includedMakefiles = ((Include)dir).getDirectives();
for (IDirective includedMakefile : includedMakefiles) {
list.addAll(Arrays.asList(((IMakefile)includedMakefile).getDirectives()));
}
}
}

View file

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

View file

@ -39,34 +39,20 @@ import org.eclipse.ui.IEditorPart;
* MakefileCompletionProcessor
*/
public class MakefileCompletionProcessor implements IContentAssistProcessor {
/**
* 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 int fInstallOffset;
/*
* @see IContextInformationValidator#isContextInformationValid(int)
*/
@Override
public boolean isContextInformationValid(int offset) {
return Math.abs(fInstallOffset - offset) < 5;
}
/*
* @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
*/
@Override
public void install(IContextInformation info, ITextViewer viewer, int offset) {
fInstallOffset = offset;
}
/*
* @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
*/
@Override
public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
return false;
@ -74,10 +60,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
}
public class DirectiveComparator implements Comparator<Object> {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Object o1, Object o2) {
String name1;
@ -117,9 +99,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
fManager = MakeUIPlugin.getDefault().getWorkingCopyManager();
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
*/
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
@ -139,16 +118,16 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
ArrayList<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(statements.length);
// iterate over all the different categories
for (int i = 0; i < statements.length; i++) {
for (IDirective statement : statements) {
String name = null;
Image image = null;
String infoString = "";//getContentInfoString(name); //$NON-NLS-1$
if (statements[i] instanceof IMacroDefinition) {
name = ((IMacroDefinition) statements[i]).getName();
if (statement instanceof IMacroDefinition) {
name = ((IMacroDefinition) statement).getName();
image = imageMacro;
infoString = ((IMacroDefinition)statements[i]).getValue().toString();
} else if (statements[i] instanceof IRule) {
name = ((IRule) statements[i]).getTarget().toString();
infoString = ((IMacroDefinition)statement).getValue().toString();
} else if (statement instanceof IRule) {
name = ((IRule) statement).getTarget().toString();
image = imageTarget;
infoString = name;
}
@ -173,9 +152,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
return proposals;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
*/
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
@ -184,11 +160,11 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
ArrayList<String> contextList = new ArrayList<String>();
if (macro) {
IDirective[] statements = makefile.getMacroDefinitions();
for (int i = 0; i < statements.length; i++) {
if (statements[i] instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statements[i]).getName();
for (IDirective statement : statements) {
if (statement instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statement).getName();
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) {
contextList.add(value);
}
@ -196,11 +172,11 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
}
}
statements = makefile.getBuiltinMacroDefinitions();
for (int i = 0; i < statements.length; i++) {
if (statements[i] instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statements[i]).getName();
for (IDirective statement : statements) {
if (statement instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statement).getName();
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) {
contextList.add(value);
}
@ -218,33 +194,21 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
*/
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
*/
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
*/
@Override
public String getErrorMessage() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
*/
@Override
public IContextInformationValidator getContextInformationValidator() {
return fValidator;