mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
More work to support gnu makefiles
This commit is contained in:
parent
9c0b2ed659
commit
e1ef9ffd9f
9 changed files with 167 additions and 78 deletions
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/include_obj.gif
Normal file
BIN
build/org.eclipse.cdt.make.ui/icons/obj16/include_obj.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 B |
|
@ -67,6 +67,9 @@ public class MakeUIImages {
|
||||||
public static final String IMG_OBJS_MAKEFILE_COMMAND = NAME_PREFIX + "command_obj.gif"; //$NON-NLS-1$
|
public static final String IMG_OBJS_MAKEFILE_COMMAND = NAME_PREFIX + "command_obj.gif"; //$NON-NLS-1$
|
||||||
public static final ImageDescriptor DESC_MAKEFILE_COMMAND = createManaged(OBJ, IMG_OBJS_MAKEFILE_COMMAND);
|
public static final ImageDescriptor DESC_MAKEFILE_COMMAND = createManaged(OBJ, IMG_OBJS_MAKEFILE_COMMAND);
|
||||||
|
|
||||||
|
public static final String IMG_OBJS_MAKEFILE_INCLUDE = NAME_PREFIX + "include_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final ImageDescriptor DESC_MAKEFILE_INCLUDE = createManaged(OBJ, IMG_OBJS_MAKEFILE_INCLUDE);
|
||||||
|
|
||||||
public static final String IMG_TOOLS_MAKEFILE_SEGMENT_EDIT= NAME_PREFIX + "segment_edit.gif";
|
public static final String IMG_TOOLS_MAKEFILE_SEGMENT_EDIT= NAME_PREFIX + "segment_edit.gif";
|
||||||
|
|
||||||
private static ImageDescriptor createManaged(String prefix, String name) {
|
private static ImageDescriptor createManaged(String prefix, String name) {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public interface IMakefileEditorActionDefinitionIds extends ITextEditorActionDefinitionIds {
|
||||||
|
|
||||||
|
String UNCOMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.comment";
|
||||||
|
|
||||||
|
String COMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.uncomment";
|
||||||
|
|
||||||
|
}
|
|
@ -13,16 +13,19 @@ package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IBadDirective;
|
||||||
import org.eclipse.cdt.make.core.makefile.ICommand;
|
import org.eclipse.cdt.make.core.makefile.ICommand;
|
||||||
import org.eclipse.cdt.make.core.makefile.IComment;
|
import org.eclipse.cdt.make.core.makefile.IComment;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||||
import org.eclipse.cdt.make.core.makefile.IEmptyLine;
|
import org.eclipse.cdt.make.core.makefile.IEmptyLine;
|
||||||
import org.eclipse.cdt.make.core.makefile.IInferenceRule;
|
import org.eclipse.cdt.make.core.makefile.IInferenceRule;
|
||||||
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
||||||
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
import org.eclipse.cdt.make.core.makefile.IParent;
|
import org.eclipse.cdt.make.core.makefile.IParent;
|
||||||
import org.eclipse.cdt.make.core.makefile.IRule;
|
import org.eclipse.cdt.make.core.makefile.IRule;
|
||||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
|
||||||
import org.eclipse.cdt.make.core.makefile.ITargetRule;
|
import org.eclipse.cdt.make.core.makefile.ITargetRule;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.gnu.IInclude;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.gnu.ITerminal;
|
||||||
import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
|
import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
|
@ -54,6 +57,7 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
protected boolean showMacroDefinition = true;
|
protected boolean showMacroDefinition = true;
|
||||||
protected boolean showTargetRule = true;
|
protected boolean showTargetRule = true;
|
||||||
protected boolean showInferenceRule = true;
|
protected boolean showInferenceRule = true;
|
||||||
|
protected boolean showIncludeChildren = false;
|
||||||
|
|
||||||
protected IMakefile makefile;
|
protected IMakefile makefile;
|
||||||
protected IMakefile nullMakefile = new NullMakefile();
|
protected IMakefile nullMakefile = new NullMakefile();
|
||||||
|
@ -63,8 +67,8 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
*/
|
*/
|
||||||
public Object[] getChildren(Object element) {
|
public Object[] getChildren(Object element) {
|
||||||
if (element == fInput) {
|
if (element == fInput) {
|
||||||
return getElements(element);
|
return getElements(makefile);
|
||||||
} else if (element instanceof IParent) {
|
} else if (element instanceof IDirective) {
|
||||||
return getElements(element);
|
return getElements(element);
|
||||||
}
|
}
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
|
@ -74,8 +78,11 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public Object getParent(Object element) {
|
public Object getParent(Object element) {
|
||||||
if (element instanceof IDirective)
|
if (element instanceof IMakefile) {
|
||||||
return fInput;
|
return fInput;
|
||||||
|
} else if (element instanceof IDirective) {
|
||||||
|
return ((IDirective)element).getParent();
|
||||||
|
}
|
||||||
return fInput;
|
return fInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +93,10 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
if (element == fInput) {
|
if (element == fInput) {
|
||||||
return true;
|
return true;
|
||||||
} else if (element instanceof IParent) {
|
} else if (element instanceof IParent) {
|
||||||
|
// Do not drill down in includes.
|
||||||
|
if (element instanceof IInclude && !showIncludeChildren) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -95,27 +106,30 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
IDirective[] statements;
|
IDirective[] directives;
|
||||||
if (inputElement == fInput) {
|
if (inputElement == fInput) {
|
||||||
statements = makefile.getStatements();
|
directives = makefile.getDirectives();
|
||||||
|
} else if (inputElement instanceof IRule) {
|
||||||
|
directives = ((IRule)inputElement).getCommands();
|
||||||
} else if (inputElement instanceof IParent) {
|
} else if (inputElement instanceof IParent) {
|
||||||
statements = ((IParent)inputElement).getStatements();
|
directives = ((IParent)inputElement).getDirectives();
|
||||||
} else {
|
} else {
|
||||||
statements = new IDirective[0];
|
directives = new IDirective[0];
|
||||||
}
|
}
|
||||||
List list = new ArrayList(statements.length);
|
List list = new ArrayList(directives.length);
|
||||||
for (int i = 0; i < statements.length; i++) {
|
for (int i = 0; i < directives.length; i++) {
|
||||||
if (showMacroDefinition && statements[i] instanceof IMacroDefinition) {
|
if (showMacroDefinition && directives[i] instanceof IMacroDefinition) {
|
||||||
list.add(statements[i]);
|
list.add(directives[i]);
|
||||||
} else if (showInferenceRule && statements[i] instanceof IInferenceRule) {
|
} else if (showInferenceRule && directives[i] instanceof IInferenceRule) {
|
||||||
list.add(statements[i]);
|
list.add(directives[i]);
|
||||||
} else if (showTargetRule && statements[i] instanceof ITargetRule) {
|
} else if (showTargetRule && directives[i] instanceof ITargetRule) {
|
||||||
list.add(statements[i]);
|
list.add(directives[i]);
|
||||||
} else {
|
} else {
|
||||||
boolean irrelevant = (statements[i] instanceof IComment ||
|
boolean irrelevant = (directives[i] instanceof IComment ||
|
||||||
statements[i] instanceof IEmptyLine);
|
directives[i] instanceof IEmptyLine ||
|
||||||
|
directives[i] instanceof ITerminal);
|
||||||
if (!irrelevant) {
|
if (!irrelevant) {
|
||||||
list.add(statements[i]);
|
list.add(directives[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,14 +156,6 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
if (makefile == null) {
|
if (makefile == null) {
|
||||||
makefile = nullMakefile;
|
makefile = nullMakefile;
|
||||||
}
|
}
|
||||||
// IDocument document= fDocumentProvider.getDocument(newInput);
|
|
||||||
// makefile = fEditor.getMakefile();
|
|
||||||
// try {
|
|
||||||
// String content = document.get();
|
|
||||||
// Reader r = new StringReader(content);
|
|
||||||
// makefile.parse(r);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,10 +173,14 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_INFERENCE_RULE);
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_INFERENCE_RULE);
|
||||||
} else if (element instanceof IMacroDefinition) {
|
} else if (element instanceof IMacroDefinition) {
|
||||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
|
||||||
} else if (element instanceof IParent) {
|
|
||||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_RELATION);
|
|
||||||
} else if (element instanceof ICommand) {
|
} else if (element instanceof ICommand) {
|
||||||
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_COMMAND);
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_COMMAND);
|
||||||
|
} else if (element instanceof IInclude) {
|
||||||
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_INCLUDE);
|
||||||
|
} else if (element instanceof IBadDirective) {
|
||||||
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_ERROR);
|
||||||
|
} else if (element instanceof IParent) {
|
||||||
|
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_RELATION);
|
||||||
}
|
}
|
||||||
return super.getImage(element);
|
return super.getImage(element);
|
||||||
}
|
}
|
||||||
|
@ -189,8 +199,8 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
if (name.length() > 20) {
|
if (name.length() > 25) {
|
||||||
name = name.substring(0, 20) + "..."; //$NON-NLS-1$
|
name = name.substring(0, 25) + " ..."; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.text.ITextOperationTarget;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
import org.eclipse.ui.editors.text.TextEditor;
|
import org.eclipse.ui.editors.text.TextEditor;
|
||||||
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
||||||
|
@ -40,40 +41,6 @@ public class MakefileEditor extends TextEditor {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public IMakefile getMakefile() {
|
|
||||||
// IDocument document = getDocumentProvider().getDocument(getEditorInput());
|
|
||||||
// if (makefile == null) {
|
|
||||||
// makefile = new GNUMakefile();
|
|
||||||
// try {
|
|
||||||
// String content = document.get();
|
|
||||||
// Reader r = new StringReader(content);
|
|
||||||
// makefile.parse(r);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// }
|
|
||||||
// IEditorInput input = getEditorInput();
|
|
||||||
// if (makefile instanceof GNUMakefile) {
|
|
||||||
// GNUMakefile gnu = (GNUMakefile)makefile;
|
|
||||||
// if (input instanceof IFileEditorInput) {
|
|
||||||
// IFile file = ((IFileEditorInput)input).getFile();
|
|
||||||
// String[] dirs = gnu.getIncludeDirectories();
|
|
||||||
// String[] includes = new String[dirs.length + 1];
|
|
||||||
// System.arraycopy(dirs, 0, includes, 0, dirs.length);
|
|
||||||
// String cwd = file.getLocation().removeLastSegments(1).toOSString();
|
|
||||||
// includes[dirs.length] = cwd;
|
|
||||||
// gnu.setIncludeDirectories(includes);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else if (isDirty()) {
|
|
||||||
// try {
|
|
||||||
// String content = document.get();
|
|
||||||
// Reader r = new StringReader(content);
|
|
||||||
// makefile.parse(r);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return makefile;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public MakefileEditor() {
|
public MakefileEditor() {
|
||||||
super();
|
super();
|
||||||
initializeEditor();
|
initializeEditor();
|
||||||
|
@ -130,6 +97,16 @@ public class MakefileEditor extends TextEditor {
|
||||||
a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||||
setAction("ContentAssistTip", a); //$NON-NLS-1$
|
setAction("ContentAssistTip", a); //$NON-NLS-1$
|
||||||
|
|
||||||
|
a = new TextOperationAction(bundle, "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
|
||||||
|
a.setActionDefinitionId(IMakefileEditorActionDefinitionIds.COMMENT);
|
||||||
|
setAction("Comment", a); //$NON-NLS-1$
|
||||||
|
markAsStateDependentAction("Comment", true); //$NON-NLS-1$
|
||||||
|
|
||||||
|
a = new TextOperationAction(bundle, "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
|
||||||
|
a.setActionDefinitionId(IMakefileEditorActionDefinitionIds.UNCOMMENT);
|
||||||
|
setAction("Uncomment", a); //$NON-NLS-1$
|
||||||
|
markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,12 +58,12 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
||||||
public String[] getConfiguredContentTypes(ISourceViewer v) {
|
public String[] getConfiguredContentTypes(ISourceViewer v) {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
IDocument.DEFAULT_CONTENT_TYPE,
|
IDocument.DEFAULT_CONTENT_TYPE,
|
||||||
MakefilePartitionScanner.MAKEFILE_COMMENT,//MakefileEditor.MAKE_COMMENT,
|
MakefilePartitionScanner.MAKEFILE_COMMENT,
|
||||||
MakefilePartitionScanner.MAKEFILE_IF_BLOCK,//MakefileEditor.MAKE_KEYWORD,
|
MakefilePartitionScanner.MAKEFILE_IF_BLOCK,
|
||||||
MakefilePartitionScanner.MAKEFILE_DEF_BLOCK,
|
MakefilePartitionScanner.MAKEFILE_DEF_BLOCK,
|
||||||
MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK,
|
MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK,
|
||||||
MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT, //MakefileEditor.MAKE_MACRO_VAR,
|
MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT,
|
||||||
};//MakefileEditor.MAKE_META_DATA };
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.eclipse.cdt.make.internal.ui.text;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||||
|
|
||||||
|
public class CompletionProposalComparator implements Comparator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CompletionProposalComparator.
|
||||||
|
*/
|
||||||
|
public CompletionProposalComparator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see Comparator#compare(Object, Object)
|
||||||
|
*/
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
ICompletionProposal c1= (ICompletionProposal) o1;
|
||||||
|
ICompletionProposal c2= (ICompletionProposal) o2;
|
||||||
|
return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -59,6 +59,6 @@ public class WordPartDetector {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isMakefileLetter(char c) {
|
boolean isMakefileLetter(char c) {
|
||||||
return Character.isLetterOrDigit(c) || c == '_';
|
return Character.isLetterOrDigit(c) || c == '_' || c == '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
||||||
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
|
@ -18,6 +20,7 @@ import org.eclipse.cdt.make.core.makefile.IRule;
|
||||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.CompletionProposalComparator;
|
||||||
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
|
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
|
||||||
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
@ -69,10 +72,41 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DirectiveComparator implements Comparator {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||||
|
*/
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
String name1;
|
||||||
|
String name2;
|
||||||
|
|
||||||
|
if (o1 instanceof IMacroDefinition) {
|
||||||
|
name1 = ((IMacroDefinition)o1).getName();
|
||||||
|
} else if (o1 instanceof IRule) {
|
||||||
|
name1 = ((IRule)o1).getTarget().toString();
|
||||||
|
} else {
|
||||||
|
name1 ="";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o2 instanceof IMacroDefinition) {
|
||||||
|
name2 = ((IMacroDefinition)o1).getName();
|
||||||
|
} else if (o2 instanceof IRule) {
|
||||||
|
name2 = ((IRule)o1).getTarget().toString();
|
||||||
|
} else {
|
||||||
|
name2 ="";
|
||||||
|
}
|
||||||
|
|
||||||
|
//return String.CASE_INSENSITIVE_ORDER.compare(name1, name2);
|
||||||
|
return name1.compareToIgnoreCase(name2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
protected IContextInformationValidator fValidator = new Validator();
|
protected IContextInformationValidator fValidator = new Validator();
|
||||||
protected Image imageMacro = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
|
protected Image imageMacro = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
|
||||||
protected Image imageTarget = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_TARGET_RULE);
|
protected Image imageTarget = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_TARGET_RULE);
|
||||||
|
|
||||||
|
protected CompletionProposalComparator comparator = new CompletionProposalComparator();
|
||||||
protected IEditorPart fEditor;
|
protected IEditorPart fEditor;
|
||||||
protected IWorkingCopyManager fManager;
|
protected IWorkingCopyManager fManager;
|
||||||
|
|
||||||
|
@ -87,13 +121,13 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
|
||||||
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
|
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
|
||||||
boolean macro = inMacro(viewer, documentOffset);
|
boolean macro = inMacro(viewer, documentOffset);
|
||||||
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
// IMakefile makefile = fEditor.getMakefile();
|
|
||||||
// String content = viewer.getDocument().get();
|
|
||||||
// Reader r = new StringReader(content);
|
|
||||||
// makefile.parse(r);
|
|
||||||
IDirective[] statements = null;
|
IDirective[] statements = null;
|
||||||
if (macro) {
|
if (macro) {
|
||||||
statements = makefile.getMacroDefinitions();
|
IDirective[] m1 = makefile.getMacroDefinitions();
|
||||||
|
IDirective[] m2 = makefile.getBuiltinMacroDefinitions();
|
||||||
|
statements = new IDirective[m1.length + m2.length];
|
||||||
|
System.arraycopy(m1, 0, statements, 0, m1.length);
|
||||||
|
System.arraycopy(m2, 0, statements, m1.length, m2.length);
|
||||||
} else {
|
} else {
|
||||||
statements = makefile.getTargetRules();
|
statements = makefile.getTargetRules();
|
||||||
}
|
}
|
||||||
|
@ -131,7 +165,9 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
|
||||||
proposalList.add(result);
|
proposalList.add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ICompletionProposal[]) proposalList.toArray(new ICompletionProposal[0]);
|
ICompletionProposal[] proposals = (ICompletionProposal[]) proposalList.toArray(new ICompletionProposal[0]);
|
||||||
|
Arrays.sort(proposals, comparator);
|
||||||
|
return proposals;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -141,8 +177,6 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
|
||||||
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
|
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
|
||||||
boolean macro = inMacro(viewer, documentOffset);
|
boolean macro = inMacro(viewer, documentOffset);
|
||||||
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
//IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
|
|
||||||
//IMakefile makefile = fEditor.getMakefile();
|
|
||||||
ArrayList contextList = new ArrayList();
|
ArrayList contextList = new ArrayList();
|
||||||
if (macro) {
|
if (macro) {
|
||||||
IDirective[] statements = makefile.getMacroDefinitions();
|
IDirective[] statements = makefile.getMacroDefinitions();
|
||||||
|
@ -157,6 +191,18 @@ 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();
|
||||||
|
if (name != null && name.equals(wordPart.getString())) {
|
||||||
|
String value = ((IMacroDefinition) statements[i]).getValue().toString();
|
||||||
|
if (value != null && value.length() > 0) {
|
||||||
|
contextList.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IContextInformation[] result = new IContextInformation[contextList.size()];
|
IContextInformation[] result = new IContextInformation[contextList.size()];
|
||||||
|
|
Loading…
Add table
Reference in a new issue