mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
cleanup/refactor
This commit is contained in:
parent
46d6c6dca7
commit
564881b2ed
15 changed files with 71 additions and 740 deletions
|
@ -1,3 +1,29 @@
|
|||
2003-02-06 David Inglis
|
||||
* src/org/eclipse/cdt/internal/core/DocumentInputStream.java (Removed)
|
||||
* src/org/eclipse/cdt/internal/ui/DocumentInputStream.java (Added)
|
||||
cleanup - moved to ui package
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/CContentProvider.java (Removed)
|
||||
* src/org/eclipse/cdt/internal/ui/CElementImageDescriptor.java (Removed)
|
||||
* src/org/eclipse/cdt/internal/ui/CElementLabelProvider.java (Removed)
|
||||
* src/org/eclipse/cdt/ui/CElementContentProvider.java (Added)
|
||||
* src/org/eclipse/cdt/ui/CElementImageDescriptor.java (Added)
|
||||
* src/org/eclipse/cdt/ui/CElementLabelProvider.java (Added)
|
||||
* src/org/eclipse/cdt/internal/ui/CFileElementWorkingCopy.java
|
||||
* src/org/eclipse/cdt/internal/ui/CWorkbenchAdapter.java
|
||||
* src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java
|
||||
* src/org/eclipse/cdt/internal/ui/cview/CView.java
|
||||
* src/org/eclipse/cdt/internal/ui/dialogs/SelectionStatusDialog.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
|
||||
* src/org/eclipse/cdt/internal/ui/editor/CEditorErrorTickUpdater.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
|
||||
cleanup - moved CElementContentProvider/LableProvider/ImageDescrptor out of internal package
|
||||
to ui so it can be cleanly used by others.
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/text/eclipse2/CRuleBasedDamagerRepairer.java (Removed)
|
||||
* src/org/eclipse/cdt/internal/ui/text/eclipse2/CRuleBasedPartitioner.java (Removed)
|
||||
cleanup - No longer needed.
|
||||
|
||||
2003-02-04 Alain Magloire
|
||||
|
||||
Cleanup of the annoying error generate by the JDT 2.1 compiler
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.core.runtime.Path;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.DocumentInputStream;
|
||||
|
||||
public class CFileElementWorkingCopy extends TranslationUnit {
|
||||
|
||||
|
|
|
@ -4,26 +4,34 @@ package org.eclipse.cdt.internal.ui;
|
|||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.model.IWorkbenchAdapter;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
|
||||
/**
|
||||
* An imlementation of the IWorkbenchAdapter for CElements.
|
||||
*/
|
||||
public class CWorkbenchAdapter implements IWorkbenchAdapter {
|
||||
|
||||
private static final Object[] fgEmptyArray= new Object[0];
|
||||
|
||||
private static final Object[] fgEmptyArray = new Object[0];
|
||||
private CElementImageProvider fImageProvider;
|
||||
private CElementLabelProvider fLabelProvider;
|
||||
|
||||
public CWorkbenchAdapter() {
|
||||
fImageProvider = new CElementImageProvider();
|
||||
fLabelProvider = new CElementLabelProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IWorkbenchAdapter#getChildren
|
||||
*/
|
||||
*/
|
||||
public Object[] getChildren(Object o) {
|
||||
if (o instanceof IParent) {
|
||||
Object[] members= ((IParent)o).getChildren();
|
||||
Object[] members = ((IParent) o).getChildren();
|
||||
if (members != null) {
|
||||
return members;
|
||||
}
|
||||
|
@ -34,7 +42,12 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
|
|||
/**
|
||||
* @see IWorkbenchAdapter#getImageDescriptor
|
||||
*/
|
||||
public ImageDescriptor getImageDescriptor(Object object) {
|
||||
public ImageDescriptor getImageDescriptor(Object element) {
|
||||
if (element instanceof ICElement) {
|
||||
return fImageProvider.getCImageDescriptor(
|
||||
(ICElement) element,
|
||||
CElementImageProvider.OVERLAY_ICONS | CElementImageProvider.SMALL_ICONS);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -43,7 +56,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
|
|||
*/
|
||||
public String getLabel(Object o) {
|
||||
if (o instanceof ICElement) {
|
||||
return ((ICElement)o).getElementName();
|
||||
return fLabelProvider.getText((ICElement) o);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -53,7 +66,7 @@ public class CWorkbenchAdapter implements IWorkbenchAdapter {
|
|||
*/
|
||||
public Object getParent(Object o) {
|
||||
if (o instanceof ICElement) {
|
||||
return ((ICElement)o).getParent();
|
||||
return ((ICElement) o).getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.eclipse.cdt.internal.core;
|
||||
package org.eclipse.cdt.internal.ui;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
|
@ -6,7 +6,7 @@ package org.eclipse.cdt.internal.core;
|
|||
*/
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
/**
|
|
@ -27,10 +27,10 @@ import org.eclipse.jface.text.IDocument;
|
|||
import org.eclipse.jface.text.Position;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.core.DocumentInputStream;
|
||||
import org.eclipse.cdt.internal.parser.CStructurizer;
|
||||
import org.eclipse.cdt.internal.parser.IStructurizerCallback;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.DocumentInputStream;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ICFile;
|
|||
import org.eclipse.cdt.core.model.ICRoot;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.resources.MakeUtil;
|
||||
import org.eclipse.cdt.internal.ui.CContentProvider;
|
||||
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction;
|
||||
|
@ -28,6 +27,7 @@ import org.eclipse.cdt.internal.ui.makeview.MakeTargetAction;
|
|||
import org.eclipse.cdt.internal.ui.preferences.CPluginPreferencePage;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
|
||||
import org.eclipse.cdt.ui.CElementContentProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -368,7 +368,7 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
|
|||
viewer= new ProblemTreeViewer (parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
boolean showCUChildren= CPluginPreferencePage.showCompilationUnitChildren();
|
||||
viewer.setUseHashlookup (true);
|
||||
viewer.setContentProvider(new CContentProvider (showCUChildren, true));
|
||||
viewer.setContentProvider(new CElementContentProvider (showCUChildren, true));
|
||||
viewer.setLabelProvider (new DecoratingLabelProvider(
|
||||
new StandardCElementLabelProvider (),
|
||||
PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
|
||||
|
@ -583,8 +583,7 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
|
|||
propertyDialogAction.selectionChanged(selection);
|
||||
renameResourceAction.selectionChanged(selection);
|
||||
//sortByTypeAction.selectionChanged(selection);
|
||||
//sortByNameAction.selectionChanged(selection);
|
||||
updateGlobalActions(selection);
|
||||
//sortByNameAction.selectionChanged(selection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -983,7 +982,7 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
|
|||
|
||||
if (event.getProperty() == CPluginPreferencePage.PREF_SHOW_CU_CHILDREN) {
|
||||
boolean showCUChildren= CPluginPreferencePage.showCompilationUnitChildren();
|
||||
((CContentProvider)viewer.getContentProvider()).setProvideMembers(showCUChildren);
|
||||
((CElementContentProvider)viewer.getContentProvider()).setProvideMembers(showCUChildren);
|
||||
refreshViewer= true;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public abstract class SelectionStatusDialog extends SelectionDialog {
|
|||
* @return the first element of the initial selection.
|
||||
*/
|
||||
protected Object getPrimaryInitialSelection() {
|
||||
List result= getInitialSelections();
|
||||
List result= getInitialElementSelections();
|
||||
if (result == null || result.size() == 0)
|
||||
return null;
|
||||
return result.get(0);
|
||||
|
@ -124,7 +124,7 @@ public abstract class SelectionStatusDialog extends SelectionDialog {
|
|||
fImage= image;
|
||||
}
|
||||
protected void setInitialSelection(int position, Object element) {
|
||||
List l= getInitialSelections();
|
||||
List l= getInitialElementSelections();
|
||||
l.set(position, element);
|
||||
fInitialSelectionSet= true;
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ import org.eclipse.core.runtime.IStatus;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.CFileElementWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.CContentProvider;
|
||||
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
|
||||
import org.eclipse.cdt.ui.CElementContentProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
public class CContentOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener {
|
||||
|
@ -132,7 +132,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
treeViewer.addSelectionChangedListener(this);
|
||||
|
||||
//treeViewer.setContentProvider(new CModelContentProvider());
|
||||
treeViewer.setContentProvider(new CContentProvider(true, true));
|
||||
treeViewer.setContentProvider(new CElementContentProvider(true, true));
|
||||
treeViewer.setLabelProvider(new StandardCElementLabelProvider());
|
||||
treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
||||
treeViewer.addSelectionChangedListener(this);
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.eclipse.swt.widgets.Shell;
|
|||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.IAnnotationModelListener;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.eclipse.cdt.core.index.TagFlags;
|
|||
import org.eclipse.cdt.internal.corext.template.ContextType;
|
||||
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
|
||||
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
||||
import org.eclipse.cdt.internal.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
|
||||
|
|
|
@ -1,210 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.text.eclipse2;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DocumentEvent;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.TextAttribute;
|
||||
import org.eclipse.jface.text.TextPresentation;
|
||||
import org.eclipse.jface.text.presentation.IPresentationDamager;
|
||||
import org.eclipse.jface.text.presentation.IPresentationRepairer;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* A standard implementation of a syntax driven presentation damager
|
||||
* and presentation repairer. It uses a rule based scanner to scan
|
||||
* the document and to determine its damage and new text presentation.
|
||||
* The tokens returned by the rules the scanner is configured with
|
||||
* are supposed to return text attributes as their data.
|
||||
*
|
||||
* @see IRule
|
||||
* @see RuleBasedScanner
|
||||
*/
|
||||
public class CRuleBasedDamagerRepairer implements IPresentationDamager, IPresentationRepairer {
|
||||
|
||||
/** The document this object works on */
|
||||
protected IDocument fDocument;
|
||||
/** The scanner it uses */
|
||||
protected RuleBasedScanner fScanner;
|
||||
/** The default text attribute if non is returned as data by the current token */
|
||||
protected TextAttribute fDefaultTextAttribute;
|
||||
|
||||
/**
|
||||
* Creates a damager/repairer that uses the given scanner and returns the given default
|
||||
* text attribute if the current token does not carry a text attribute.
|
||||
*
|
||||
* @param scanner the rule based scanner to be used
|
||||
* @param defaultTextAttribute the text attribute to be returned if non is specified by the current token,
|
||||
* may not be <code>null</code>
|
||||
*
|
||||
* @deprecated use RuleBasedDamagerRepairer(RuleBasedScanner) instead
|
||||
*/
|
||||
public CRuleBasedDamagerRepairer(RuleBasedScanner scanner, TextAttribute defaultTextAttribute) {
|
||||
|
||||
Assert.isNotNull(defaultTextAttribute);
|
||||
|
||||
fScanner= scanner;
|
||||
fDefaultTextAttribute= defaultTextAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a damager/repairer that uses the given scanner. The scanner may not be <code>null</code>
|
||||
* and is assumed to return only token that carry text attributes.
|
||||
*
|
||||
* @param scanner the rule based scanner to be used, may not be <code>null</code>
|
||||
*/
|
||||
public CRuleBasedDamagerRepairer(RuleBasedScanner scanner) {
|
||||
|
||||
Assert.isNotNull(scanner);
|
||||
|
||||
fScanner= scanner;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPresentationDamager#setDocument
|
||||
* @see IPresentationRepairer#setDocument
|
||||
*/
|
||||
public void setDocument(IDocument document) {
|
||||
fDocument= document;
|
||||
}
|
||||
|
||||
|
||||
//---- IPresentationDamager
|
||||
|
||||
/**
|
||||
* Returns the end offset of the line that contains the specified offset or
|
||||
* if the offset is inside a line delimiter, the end offset of the next line.
|
||||
*
|
||||
* @param offset the offset whose line end offset must be computed
|
||||
* @return the line end offset for the given offset
|
||||
* @exception BadLocationException if offset is invalid in the current document
|
||||
*/
|
||||
protected int endOfLineOf(int offset) throws BadLocationException {
|
||||
|
||||
IRegion info= fDocument.getLineInformationOfOffset(offset);
|
||||
if (offset <= info.getOffset() + info.getLength())
|
||||
return info.getOffset() + info.getLength();
|
||||
|
||||
int line= fDocument.getLineOfOffset(offset);
|
||||
try {
|
||||
info= fDocument.getLineInformation(line + 1);
|
||||
return info.getOffset() + info.getLength();
|
||||
} catch (BadLocationException x) {
|
||||
return fDocument.getLength();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPresentationDamager#getDamageRegion
|
||||
*/
|
||||
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {
|
||||
|
||||
if (!documentPartitioningChanged) {
|
||||
try {
|
||||
|
||||
IRegion info= fDocument.getLineInformationOfOffset(e.getOffset());
|
||||
int start= Math.max(partition.getOffset(), info.getOffset());
|
||||
|
||||
int end= e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
|
||||
|
||||
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
|
||||
// optimize the case of the same line
|
||||
end= info.getOffset() + info.getLength();
|
||||
} else
|
||||
end= endOfLineOf(end);
|
||||
|
||||
end= Math.min(partition.getOffset() + partition.getLength(), end);
|
||||
return new Region(start, end - start);
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
}
|
||||
|
||||
return partition;
|
||||
}
|
||||
|
||||
//---- IPresentationRepairer
|
||||
|
||||
/*
|
||||
* @see IPresentationRepairer#createPresentation
|
||||
*/
|
||||
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
|
||||
|
||||
if (fScanner == null) {
|
||||
// will be removed if deprecated constructor will be removed
|
||||
addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute);
|
||||
return;
|
||||
}
|
||||
|
||||
int lastStart= region.getOffset();
|
||||
int length= 0;
|
||||
IToken lastToken= Token.UNDEFINED;
|
||||
TextAttribute lastAttribute= getTokenTextAttribute(lastToken);
|
||||
|
||||
fScanner.setRange(fDocument, lastStart, region.getLength());
|
||||
|
||||
while (true) {
|
||||
IToken token= fScanner.nextToken();
|
||||
if (token.isEOF())
|
||||
break;
|
||||
|
||||
TextAttribute attribute= getTokenTextAttribute(token);
|
||||
if (lastAttribute != null && lastAttribute.equals(attribute)) {
|
||||
length += fScanner.getTokenLength();
|
||||
} else {
|
||||
addRange(presentation, lastStart, length, lastAttribute);
|
||||
lastToken= token;
|
||||
lastAttribute= attribute;
|
||||
lastStart= fScanner.getTokenOffset();
|
||||
length= fScanner.getTokenLength();
|
||||
}
|
||||
}
|
||||
|
||||
addRange(presentation, lastStart, length, lastAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text attribute encoded in the given token. If the token's
|
||||
* data is not <code>null</code> and a text attribute it is assumed that
|
||||
* it is the encoded text attribute. It returns the default text attribute
|
||||
* if there is no encoded text attribute found.
|
||||
*
|
||||
* @param token the token whose text attribute is to be determined
|
||||
* @return the token's text attribute
|
||||
*/
|
||||
protected TextAttribute getTokenTextAttribute(IToken token) {
|
||||
Object data= token.getData();
|
||||
if (data instanceof TextAttribute)
|
||||
return (TextAttribute) data;
|
||||
return fDefaultTextAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds style information to the given text presentation.
|
||||
*
|
||||
* @param presentation the text presentation to be extended
|
||||
* @param offset the offset of the range to be styled
|
||||
* @param length the length of the range to be styled
|
||||
* @param attr the attribute describing the style of the range to be styled
|
||||
*/
|
||||
protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) {
|
||||
if (attr != null)
|
||||
presentation.addStyleRange(new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), attr.getStyle()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,501 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.text.eclipse2;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.BadPositionCategoryException;
|
||||
import org.eclipse.jface.text.DefaultPositionUpdater;
|
||||
import org.eclipse.jface.text.DocumentEvent;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||
import org.eclipse.jface.text.IDocumentPartitionerExtension;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.jface.text.TypedPosition;
|
||||
import org.eclipse.jface.text.TypedRegion;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A standard implementation of a syntax driven document partitioner.
|
||||
* It uses a rule based scanner to scan the document and to determine
|
||||
* the document's partitioning. The tokens returned by the rules the
|
||||
* scanner is configured with are supposed to return the partition type
|
||||
* as their data. The partitoner remembers the document's partitions
|
||||
* in the document itself rather than maintaining its own data structure.
|
||||
*
|
||||
* @see IRule
|
||||
* @see RuleBasedScanner
|
||||
*/
|
||||
public class CRuleBasedPartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension {
|
||||
|
||||
/** The position category this partitioner uses to store the document's partitioning information */
|
||||
public final static String CONTENT_TYPES_CATEGORY= "__content_types_category"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/** The partitioner's scanner */
|
||||
protected RuleBasedScanner fScanner;
|
||||
/** The legal content types of this partitioner */
|
||||
protected String[] fLegalContentTypes;
|
||||
/** The partitioner's document */
|
||||
protected IDocument fDocument;
|
||||
/** The document length before a document change occured */
|
||||
protected int fPreviousDocumentLength;
|
||||
/** The position updater used to for the default updating of partitions */
|
||||
protected DefaultPositionUpdater fPositionUpdater= new DefaultPositionUpdater(CONTENT_TYPES_CATEGORY);
|
||||
/** The offset at which the first changed partition starts */
|
||||
protected int fStartOffset;
|
||||
/** The offset at which the last changed partition ends */
|
||||
protected int fEndOffset;
|
||||
/**The offset at which a partition has been deleted */
|
||||
protected int fDeleteOffset;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new partitioner that uses the given scanner and may return
|
||||
* partitions of the given legal content types.
|
||||
*
|
||||
* @param scanner the scanner this partitioner is supposed to use
|
||||
* @param legalContentTypes the legal content types of this partitioner
|
||||
*/
|
||||
public CRuleBasedPartitioner(RuleBasedScanner scanner, String[] legalContentTypes) {
|
||||
fScanner= scanner;
|
||||
fLegalContentTypes= legalContentTypes;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#connect
|
||||
*/
|
||||
public void connect(IDocument document) {
|
||||
Assert.isNotNull(document);
|
||||
Assert.isTrue(!document.containsPositionCategory(CONTENT_TYPES_CATEGORY));
|
||||
|
||||
fDocument= document;
|
||||
fDocument.addPositionCategory(CONTENT_TYPES_CATEGORY);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the initial partitioning of the partitioner's document.
|
||||
*/
|
||||
protected void initialize() {
|
||||
|
||||
fScanner.setRange(fDocument, 0, fDocument.getLength());
|
||||
|
||||
try {
|
||||
IToken token= fScanner.nextToken();
|
||||
while (!token.isEOF()) {
|
||||
|
||||
String contentType= getTokenContentType(token);
|
||||
|
||||
if (isSupportedContentType(contentType)) {
|
||||
TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
|
||||
fDocument.addPosition(CONTENT_TYPES_CATEGORY, p);
|
||||
}
|
||||
|
||||
token= fScanner.nextToken();
|
||||
}
|
||||
} catch (BadLocationException x) {
|
||||
// cannot happen as offsets come from scanner
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// cannot happen if document has been connected before
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#disconnect
|
||||
*/
|
||||
public void disconnect() {
|
||||
|
||||
Assert.isTrue(fDocument.containsPositionCategory(CONTENT_TYPES_CATEGORY));
|
||||
|
||||
try {
|
||||
fDocument.removePositionCategory(CONTENT_TYPES_CATEGORY);
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// can not happen because of Assert
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#documentAboutToBeChanged
|
||||
*/
|
||||
public void documentAboutToBeChanged(DocumentEvent e) {
|
||||
|
||||
Assert.isTrue(e.getDocument() == fDocument);
|
||||
|
||||
fPreviousDocumentLength= e.getDocument().getLength();
|
||||
fStartOffset= -1;
|
||||
fEndOffset= -1;
|
||||
fDeleteOffset= -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#documentChanged
|
||||
*/
|
||||
public boolean documentChanged(DocumentEvent e) {
|
||||
IRegion region= documentChanged2(e);
|
||||
return (region != null);
|
||||
}
|
||||
|
||||
private void rememberRegion(int offset, int length) {
|
||||
// remember start offset
|
||||
if (fStartOffset == -1)
|
||||
fStartOffset= offset;
|
||||
else if (offset < fStartOffset)
|
||||
fStartOffset= offset;
|
||||
|
||||
// remember end offset
|
||||
int endOffset= offset + length;
|
||||
if (fEndOffset == -1)
|
||||
fEndOffset= endOffset;
|
||||
else if (endOffset > fEndOffset)
|
||||
fEndOffset= endOffset;
|
||||
}
|
||||
|
||||
private void rememberDeletedOffset(int offset) {
|
||||
fDeleteOffset= offset;
|
||||
}
|
||||
|
||||
private IRegion createRegion() {
|
||||
if (fDeleteOffset == -1) {
|
||||
if (fStartOffset == -1 || fEndOffset == -1)
|
||||
return null;
|
||||
return new Region(fStartOffset, fEndOffset - fStartOffset);
|
||||
} else if (fStartOffset == -1 || fEndOffset == -1) {
|
||||
return new Region(fDeleteOffset, 0);
|
||||
} else {
|
||||
int offset= Math.min(fDeleteOffset, fStartOffset);
|
||||
int endOffset= Math.max(fDeleteOffset, fEndOffset);
|
||||
return new Region(offset, endOffset - offset);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitionerExtension#documentChanged2(DocumentEvent)
|
||||
*/
|
||||
public IRegion documentChanged2(DocumentEvent e) {
|
||||
|
||||
try {
|
||||
|
||||
IDocument d= e.getDocument();
|
||||
Position[] category= d.getPositions(CONTENT_TYPES_CATEGORY);
|
||||
int first= 0;
|
||||
int reparseStart= 0;
|
||||
int originalSize= category.length;
|
||||
|
||||
if (originalSize > 0) {
|
||||
|
||||
/*
|
||||
* determine character position at which the scanner starts:
|
||||
* first position behind the last non-default partition the actual position is not involved with
|
||||
*/
|
||||
|
||||
first= d.computeIndexInCategory(CONTENT_TYPES_CATEGORY, e.getOffset());
|
||||
|
||||
Position p= null;
|
||||
do {
|
||||
--first;
|
||||
if (first < 0)
|
||||
break;
|
||||
|
||||
p= category[first];
|
||||
|
||||
} while (p.overlapsWith(e.getOffset(), e.getLength()) ||
|
||||
(e.getOffset() == fPreviousDocumentLength &&
|
||||
(p.getOffset() + p.getLength() == fPreviousDocumentLength)));
|
||||
|
||||
fPositionUpdater.update(e);
|
||||
for (int i= 0; i < category.length; i++) {
|
||||
p= category[i];
|
||||
if (p.isDeleted) {
|
||||
rememberDeletedOffset(e.getOffset());
|
||||
break;
|
||||
}
|
||||
}
|
||||
category= d.getPositions(CONTENT_TYPES_CATEGORY);
|
||||
|
||||
if (first >= 0) {
|
||||
p= category[first];
|
||||
reparseStart= p.getOffset() + p.getLength();
|
||||
}
|
||||
|
||||
++first;
|
||||
}
|
||||
|
||||
fScanner.setRange(d, reparseStart, d.getLength());
|
||||
|
||||
int lastScannedPosition= reparseStart;
|
||||
IToken token= fScanner.nextToken();
|
||||
|
||||
while (!token.isEOF()) {
|
||||
|
||||
|
||||
String contentType= getTokenContentType(token);
|
||||
|
||||
if (!isSupportedContentType(contentType)) {
|
||||
token= fScanner.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
int start= fScanner.getTokenOffset();
|
||||
int length= fScanner.getTokenLength();
|
||||
|
||||
lastScannedPosition= start + length - 1;
|
||||
|
||||
// remove all affected positions
|
||||
while (first < category.length) {
|
||||
TypedPosition p= (TypedPosition) category[first];
|
||||
if (lastScannedPosition >= p.offset + p.length ||
|
||||
(p.overlapsWith(start, length) &&
|
||||
(!d.containsPosition(CONTENT_TYPES_CATEGORY, start, length) ||
|
||||
!contentType.equals(p.getType())))) {
|
||||
|
||||
rememberRegion(p.offset, p.length);
|
||||
d.removePosition(CONTENT_TYPES_CATEGORY, p);
|
||||
++ first;
|
||||
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
// if position already exists we are done
|
||||
if (d.containsPosition(CONTENT_TYPES_CATEGORY, start, length))
|
||||
return createRegion();
|
||||
|
||||
// insert the new type position
|
||||
try {
|
||||
d.addPosition(CONTENT_TYPES_CATEGORY, new TypedPosition(start, length, contentType));
|
||||
rememberRegion(start, length);
|
||||
} catch (BadPositionCategoryException x) {
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
token= fScanner.nextToken();
|
||||
}
|
||||
|
||||
|
||||
// remove all positions behind lastScannedPosition since there aren't any further types
|
||||
TypedPosition p;
|
||||
first= d.computeIndexInCategory(CONTENT_TYPES_CATEGORY, lastScannedPosition);
|
||||
while (first < category.length) {
|
||||
p= (TypedPosition) category[first++];
|
||||
d.removePosition(CONTENT_TYPES_CATEGORY, p);
|
||||
rememberRegion(p.offset, p.length);
|
||||
}
|
||||
|
||||
} catch (BadPositionCategoryException x) {
|
||||
// should never happen on connected documents
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return createRegion();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the position in the partitoner's position category which is
|
||||
* close to the given offset. This is, the position has either an offset which
|
||||
* is the same as the given offset or an offset which is smaller than the given
|
||||
* offset. This method profits from the knowledge that a partitioning is
|
||||
* a ordered set of disjoint position.
|
||||
*
|
||||
* @param offset the offset for which to search the closest position
|
||||
* @return the closest position in the partitioner's category
|
||||
*/
|
||||
protected TypedPosition findClosestPosition(int offset) {
|
||||
|
||||
try {
|
||||
|
||||
int index= fDocument.computeIndexInCategory(CONTENT_TYPES_CATEGORY, offset);
|
||||
Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY);
|
||||
|
||||
if (category.length == 0)
|
||||
return null;
|
||||
|
||||
if (index < category.length) {
|
||||
if (offset == category[index].offset)
|
||||
return (TypedPosition) category[index];
|
||||
}
|
||||
|
||||
if (index > 0)
|
||||
index--;
|
||||
|
||||
return (TypedPosition) category[index];
|
||||
|
||||
} catch (BadPositionCategoryException x) {
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#getContentType
|
||||
*/
|
||||
public String getContentType(int offset) {
|
||||
|
||||
TypedPosition p= findClosestPosition(offset);
|
||||
if (p != null && p.includes(offset))
|
||||
return p.getType();
|
||||
|
||||
return IDocument.DEFAULT_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#getPartition
|
||||
*/
|
||||
public ITypedRegion getPartition(int offset) {
|
||||
|
||||
try {
|
||||
|
||||
Position[] category = fDocument.getPositions(CONTENT_TYPES_CATEGORY);
|
||||
|
||||
if (category == null || category.length == 0)
|
||||
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
|
||||
|
||||
int index= fDocument.computeIndexInCategory(CONTENT_TYPES_CATEGORY, offset);
|
||||
|
||||
if (index < category.length) {
|
||||
|
||||
TypedPosition next= (TypedPosition) category[index];
|
||||
|
||||
if (offset == next.offset)
|
||||
return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
|
||||
|
||||
if (index == 0)
|
||||
return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
|
||||
|
||||
TypedPosition previous= (TypedPosition) category[index - 1];
|
||||
if (previous.includes(offset))
|
||||
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
|
||||
|
||||
int endOffset= previous.getOffset() + previous.getLength();
|
||||
return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
TypedPosition previous= (TypedPosition) category[category.length - 1];
|
||||
if (previous.includes(offset))
|
||||
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
|
||||
|
||||
int endOffset= previous.getOffset() + previous.getLength();
|
||||
return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
|
||||
|
||||
} catch (BadPositionCategoryException x) {
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#computePartitioning
|
||||
*/
|
||||
public ITypedRegion[] computePartitioning(int offset, int length) {
|
||||
|
||||
List list= new ArrayList();
|
||||
|
||||
try {
|
||||
|
||||
int endOffset= offset + length;
|
||||
|
||||
Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY);
|
||||
|
||||
TypedPosition previous= null, current= null;
|
||||
int start, end, gapOffset;
|
||||
Position gap= null;
|
||||
|
||||
for (int i= 0; i < category.length; i++) {
|
||||
|
||||
current= (TypedPosition) category[i];
|
||||
|
||||
gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0;
|
||||
gap= new Position(gapOffset, current.getOffset() - gapOffset);
|
||||
if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
|
||||
start= Math.max(offset, gapOffset);
|
||||
end= Math.min(endOffset, gap.getOffset() + gap.getLength());
|
||||
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
|
||||
}
|
||||
|
||||
if (current.overlapsWith(offset, length)) {
|
||||
start= Math.max(offset, current.getOffset());
|
||||
end= Math.min(endOffset, current.getOffset() + current.getLength());
|
||||
list.add(new TypedRegion(start, end - start, current.getType()));
|
||||
}
|
||||
|
||||
previous= current;
|
||||
}
|
||||
|
||||
if (previous != null) {
|
||||
gapOffset= previous.getOffset() + previous.getLength();
|
||||
gap= new Position(gapOffset, fDocument.getLength() - gapOffset);
|
||||
if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
|
||||
start= Math.max(offset, gapOffset);
|
||||
end= Math.min(endOffset, fDocument.getLength());
|
||||
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty())
|
||||
list.add(new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE));
|
||||
|
||||
} catch (BadPositionCategoryException x) {
|
||||
}
|
||||
|
||||
TypedRegion[] result= new TypedRegion[list.size()];
|
||||
list.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IDocumentPartitioner#getLegalContentTypes
|
||||
*/
|
||||
public String[] getLegalContentTypes() {
|
||||
return fLegalContentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given type is one of the legal content types.
|
||||
*
|
||||
* @param contentType the content type to check
|
||||
* @return <code>true</code> if the content type is a legal content type
|
||||
*/
|
||||
protected boolean isSupportedContentType(String contentType) {
|
||||
if (contentType != null) {
|
||||
for (int i= 0; i < fLegalContentTypes.length; i++) {
|
||||
if (fLegalContentTypes[i].equals(contentType))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a content type encoded in the given token. If the token's
|
||||
* data is not <code>null</code> and a string it is assumed that
|
||||
* it is the encoded content type.
|
||||
*
|
||||
* @param token the token whose content type is to be determined
|
||||
* @return the token's content type
|
||||
*/
|
||||
protected String getTokenContentType(IToken token) {
|
||||
Object data= token.getData();
|
||||
if (data instanceof String)
|
||||
return (String) data;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.eclipse.cdt.internal.ui;
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
|
@ -26,9 +26,10 @@ import org.eclipse.cdt.core.model.IBinary;
|
|||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ICRoot;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.internal.ui.BaseCElementContentProvider;
|
||||
import org.eclipse.cdt.ui.*;
|
||||
|
||||
public class CContentProvider extends BaseCElementContentProvider implements ITreeContentProvider, IElementChangedListener {
|
||||
public class CElementContentProvider extends BaseCElementContentProvider implements ITreeContentProvider, IElementChangedListener {
|
||||
|
||||
protected StructuredViewer fViewer;
|
||||
protected Object fInput;
|
||||
|
@ -62,13 +63,13 @@ public class CContentProvider extends BaseCElementContentProvider implements ITr
|
|||
/**
|
||||
* Creates a new content provider for C elements.
|
||||
*/
|
||||
public CContentProvider() {
|
||||
public CElementContentProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new content provider for C elements.
|
||||
*/
|
||||
public CContentProvider(boolean provideMembers, boolean provideWorkingCopy) {
|
||||
public CElementContentProvider(boolean provideMembers, boolean provideWorkingCopy) {
|
||||
super(provideMembers, provideWorkingCopy);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.eclipse.cdt.internal.ui;
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
|
@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.ui;
|
|||
import org.eclipse.swt.graphics.ImageData;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.jface.resource.CompositeImageDescriptor;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.util.Assert;
|
|
@ -1,4 +1,4 @@
|
|||
package org.eclipse.cdt.internal.ui;
|
||||
package org.eclipse.cdt.ui;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
|
@ -15,6 +15,9 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICFile;
|
||||
import org.eclipse.cdt.core.model.IBinary;
|
||||
import org.eclipse.cdt.internal.ui.CElementImageProvider;
|
||||
import org.eclipse.cdt.internal.ui.ErrorTickAdornmentProvider;
|
||||
import org.eclipse.cdt.internal.ui.IAdornmentProvider;
|
||||
import org.eclipse.cdt.ui.*;
|
||||
|
||||
/**
|
Loading…
Add table
Reference in a new issue