mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
2005-01-26 Alain Magloire
The line and offset information should be cache in the SourceManipulationInfo * model/org/eclipse/cdt/iternal/core/BinaryElement.java * model/org/eclipse/cdt/iternal/core/CElement.java * model/org/eclipse/cdt/iternal/core/CModelBuilder.java * model/org/eclipse/cdt/iternal/core/Namespace.java * model/org/eclipse/cdt/iternal/core/SourceManipulation.java * model/org/eclipse/cdt/iternal/core/SourceManipulationInfo.java
This commit is contained in:
parent
a047b603b5
commit
8df4a09141
8 changed files with 194 additions and 83 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2005-01-26 Alain Magloire
|
||||||
|
The line and offset information should be cache in the SourceManipulationInfo
|
||||||
|
* model/org/eclipse/cdt/iternal/core/BinaryElement.java
|
||||||
|
* model/org/eclipse/cdt/iternal/core/CElement.java
|
||||||
|
* model/org/eclipse/cdt/iternal/core/CModelBuilder.java
|
||||||
|
* model/org/eclipse/cdt/iternal/core/Namespace.java
|
||||||
|
* model/org/eclipse/cdt/iternal/core/SourceManipulation.java
|
||||||
|
* model/org/eclipse/cdt/iternal/core/SourceManipulationInfo.java
|
||||||
|
|
||||||
2005-01-22 Alain Magloire
|
2005-01-22 Alain Magloire
|
||||||
PR 38958
|
PR 38958
|
||||||
Part implementation of the CreateXXXOperation classes.
|
Part implementation of the CreateXXXOperation classes.
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.eclipse.core.runtime.Path;
|
||||||
public class BinaryElement extends CElement implements IBinaryElement, ISourceManipulation, ISourceReference {
|
public class BinaryElement extends CElement implements IBinaryElement, ISourceManipulation, ISourceReference {
|
||||||
|
|
||||||
IAddress addr;
|
IAddress addr;
|
||||||
|
int fStartLine;
|
||||||
|
int fEndLine;
|
||||||
|
|
||||||
public BinaryElement(ICElement parent, String name, int type, IAddress a) {
|
public BinaryElement(ICElement parent, String name, int type, IAddress a) {
|
||||||
super(parent, name, type);
|
super(parent, name, type);
|
||||||
|
@ -158,6 +160,64 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This should be in the info
|
||||||
|
* @param line
|
||||||
|
*/
|
||||||
|
public void setLines(int startline, int endLine) {
|
||||||
|
fStartLine = startline;
|
||||||
|
fEndLine = endLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This should be in the info
|
||||||
|
* @param line
|
||||||
|
*/
|
||||||
|
public int getStartLine() {
|
||||||
|
return fStartLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This should be in the info
|
||||||
|
* @param line
|
||||||
|
*/
|
||||||
|
public int getEndLine() {
|
||||||
|
return fEndLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getLength() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getStartPos() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getIdLength() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getIdStartPos() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.model.IBinaryElement#getBinary()
|
* @see org.eclipse.cdt.core.model.IBinaryElement#getBinary()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -38,13 +38,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
||||||
|
|
||||||
protected String fName;
|
protected String fName;
|
||||||
|
|
||||||
protected int fStartPos;
|
|
||||||
protected int fLength;
|
|
||||||
protected int fIdStartPos;
|
|
||||||
protected int fIdLength;
|
|
||||||
protected int fStartLine;
|
|
||||||
protected int fEndLine;
|
|
||||||
|
|
||||||
protected CElement(ICElement parent, String name, int type) {
|
protected CElement(ICElement parent, String name, int type) {
|
||||||
fParent= parent;
|
fParent= parent;
|
||||||
fName= name;
|
fName= name;
|
||||||
|
@ -196,45 +189,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
||||||
protected void addChild(ICElement e) throws CModelException {
|
protected void addChild(ICElement e) throws CModelException {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPos(int startPos, int length) {
|
|
||||||
fStartPos = startPos;
|
|
||||||
fLength = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartPos() {
|
|
||||||
return fStartPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLength() {
|
|
||||||
return fLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdPos(int startPos, int length) {
|
|
||||||
fIdStartPos= startPos;
|
|
||||||
fIdLength= length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdStartPos() {
|
|
||||||
return fIdStartPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdLength() {
|
|
||||||
return fIdLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartLine() {
|
|
||||||
return fStartLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndLine() {
|
|
||||||
return fEndLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLines(int startLine, int endLine) {
|
|
||||||
fStartLine = startLine;
|
|
||||||
fEndLine = endLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IResource getUnderlyingResource() {
|
public IResource getUnderlyingResource() {
|
||||||
IResource res = getResource();
|
IResource res = getResource();
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
|
|
|
@ -317,13 +317,14 @@ public class CModelBuilder {
|
||||||
{
|
{
|
||||||
// Template Declaration
|
// Template Declaration
|
||||||
IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration();
|
IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration();
|
||||||
if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){
|
if (declaration instanceof IASTAbstractTypeSpecifierDeclaration){
|
||||||
IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ;
|
IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ;
|
||||||
CElement element = createAbstractElement(parent, abstractDeclaration , true, true);
|
CElement element = createAbstractElement(parent, abstractDeclaration , true, true);
|
||||||
if(element != null){
|
if (element instanceof SourceManipulation) {
|
||||||
|
SourceManipulation sourceRef = (SourceManipulation)element;
|
||||||
// set the element position
|
// set the element position
|
||||||
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
||||||
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
||||||
// set the template parameters
|
// set the template parameters
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
||||||
ITemplate classTemplate = (ITemplate) element;
|
ITemplate classTemplate = (ITemplate) element;
|
||||||
|
@ -333,10 +334,11 @@ public class CModelBuilder {
|
||||||
// special case for Structural parse
|
// special case for Structural parse
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ;
|
IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ;
|
||||||
CElement element = createClassSpecifierElement(parent, classSpecifier , true);
|
CElement element = createClassSpecifierElement(parent, classSpecifier , true);
|
||||||
if(element != null){
|
if (element instanceof SourceManipulation) {
|
||||||
|
SourceManipulation sourceRef = (SourceManipulation)element;
|
||||||
// set the element position
|
// set the element position
|
||||||
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
||||||
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
||||||
// set the template parameters
|
// set the template parameters
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
||||||
ITemplate classTemplate = (ITemplate) element;
|
ITemplate classTemplate = (ITemplate) element;
|
||||||
|
@ -346,11 +348,11 @@ public class CModelBuilder {
|
||||||
ITemplate template = null;
|
ITemplate template = null;
|
||||||
template = (ITemplate) createSimpleElement(parent, declaration, true);
|
template = (ITemplate) createSimpleElement(parent, declaration, true);
|
||||||
|
|
||||||
if(template != null){
|
if (template instanceof SourceManipulation){
|
||||||
CElement element = (CElement)template;
|
SourceManipulation sourceRef = (SourceManipulation)template;
|
||||||
// set the element position
|
// set the element position
|
||||||
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
||||||
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
|
||||||
// set the template parameters
|
// set the template parameters
|
||||||
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
|
||||||
template.setTemplateParameterTypes(parameterTypes);
|
template.setTemplateParameterTypes(parameterTypes);
|
||||||
|
@ -380,16 +382,16 @@ public class CModelBuilder {
|
||||||
|
|
||||||
private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate, boolean isDeclaration)throws ASTNotImplementedException, CModelException{
|
private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate, boolean isDeclaration)throws ASTNotImplementedException, CModelException{
|
||||||
CElement element = null;
|
CElement element = null;
|
||||||
if(abstractDeclaration != null){
|
if (abstractDeclaration != null){
|
||||||
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier();
|
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier();
|
||||||
// IASTEnumerationSpecifier
|
// IASTEnumerationSpecifier
|
||||||
if ( typeSpec instanceof IASTEnumerationSpecifier){
|
if (typeSpec instanceof IASTEnumerationSpecifier) {
|
||||||
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
|
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
|
||||||
IParent enumElement = createEnumeration (parent, enumSpecifier);
|
IParent enumElement = createEnumeration (parent, enumSpecifier);
|
||||||
element = (CElement) enumElement;
|
element = (CElement) enumElement;
|
||||||
}
|
}
|
||||||
// IASTClassSpecifier
|
// IASTClassSpecifier
|
||||||
else if (typeSpec instanceof IASTClassSpecifier){
|
else if (typeSpec instanceof IASTClassSpecifier) {
|
||||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
|
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
|
||||||
element = createClassSpecifierElement (parent, classSpecifier, isTemplate);
|
element = createClassSpecifierElement (parent, classSpecifier, isTemplate);
|
||||||
} else if (isDeclaration && typeSpec instanceof IASTElaboratedTypeSpecifier) {
|
} else if (isDeclaration && typeSpec instanceof IASTElaboratedTypeSpecifier) {
|
||||||
|
|
|
@ -77,13 +77,21 @@ public class CopyElementsOperation extends MultiOperation {
|
||||||
* Returns the nested operation to use for processing this element
|
* Returns the nested operation to use for processing this element
|
||||||
*/
|
*/
|
||||||
protected CModelOperation getNestedOperation(ICElement element) {
|
protected CModelOperation getNestedOperation(ICElement element) {
|
||||||
ICElement dest = getDestinationParent(element);
|
ITranslationUnit unit = getDestinationTranslationUnit(element);
|
||||||
ITranslationUnit unit = (ITranslationUnit)dest.getAncestor(ICElement.C_UNIT);
|
|
||||||
String name = element.getElementName();
|
String name = element.getElementName();
|
||||||
int type = element.getElementType();
|
int type = element.getElementType();
|
||||||
return new CreateSourceReferenceOperation(unit, name, type, getSourceFor(element));
|
return new CreateSourceReferenceOperation(unit, name, type, getSourceFor(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ITranslationUnit getDestinationTranslationUnit(ICElement element) {
|
||||||
|
ICElement dest = getDestinationParent(element);
|
||||||
|
return (ITranslationUnit)dest.getAncestor(ICElement.C_UNIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITranslationUnit getSourceTranslationUnit(ICElement element) {
|
||||||
|
return (ITranslationUnit)element.getAncestor(ICElement.C_UNIT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cached source for this element or compute it if not already cached.
|
* Returns the cached source for this element or compute it if not already cached.
|
||||||
*/
|
*/
|
||||||
|
@ -115,7 +123,14 @@ public class CopyElementsOperation extends MultiOperation {
|
||||||
if (op == null) {
|
if (op == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInTUOperation = op instanceof CreateElementInTUOperation;
|
boolean isInTUOperation = op instanceof CreateElementInTUOperation;
|
||||||
|
|
||||||
|
if (isInTUOperation && isMove()) {
|
||||||
|
DeleteElementsOperation deleteOp = new DeleteElementsOperation(new ICElement[] { element }, fForce);
|
||||||
|
executeNestedOperation(deleteOp, 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (isInTUOperation) {
|
if (isInTUOperation) {
|
||||||
CreateElementInTUOperation inTUop = (CreateElementInTUOperation)op;
|
CreateElementInTUOperation inTUop = (CreateElementInTUOperation)op;
|
||||||
ICElement sibling = (ICElement) fInsertBeforeElements.get(element);
|
ICElement sibling = (ICElement) fInsertBeforeElements.get(element);
|
||||||
|
@ -134,9 +149,9 @@ public class CopyElementsOperation extends MultiOperation {
|
||||||
}
|
}
|
||||||
executeNestedOperation(op, 1);
|
executeNestedOperation(op, 1);
|
||||||
|
|
||||||
if (isInTUOperation && isMove()) {
|
ITranslationUnit destUnit = getDestinationTranslationUnit(element);
|
||||||
DeleteElementsOperation deleteOp = new DeleteElementsOperation(new ICElement[] { element }, fForce);
|
if (!destUnit.isWorkingCopy()) {
|
||||||
executeNestedOperation(deleteOp, 1);
|
destUnit.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,15 +36,15 @@ public class Namespace extends SourceManipulation implements INamespace{
|
||||||
public void setTypeName(String typeName) {
|
public void setTypeName(String typeName) {
|
||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
// /* (non-Javadoc)
|
||||||
*/
|
// * @see java.lang.Object#equals(java.lang.Object)
|
||||||
public boolean equals(Object other) {
|
// */
|
||||||
// TODO Auto-generated method stub
|
// public boolean equals(Object other) {
|
||||||
return (super.equals(other)
|
// return (super.equals(other)
|
||||||
&& (this.getStartPos() == ((Namespace)other).getStartPos())
|
// && (this.getStartPos() == ((Namespace)other).getStartPos())
|
||||||
&& (this.getLength() == ((Namespace)other).getLength())
|
// && (this.getLength() == ((Namespace)other).getLength())
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,4 +185,28 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
|
||||||
newElements.put(this, info);
|
newElements.put(this, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPos(int startPos, int length) {
|
||||||
|
try {
|
||||||
|
getSourceManipulationInfo().setPos(startPos, length);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdPos(int startPos, int length) {
|
||||||
|
try {
|
||||||
|
getSourceManipulationInfo().setIdPos(startPos, length);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLines(int startLine, int endLine) {
|
||||||
|
try {
|
||||||
|
getSourceManipulationInfo().setLines(startLine, endLine);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
/* package */
|
/* package */
|
||||||
class SourceManipulationInfo extends CElementInfo {
|
class SourceManipulationInfo extends CElementInfo {
|
||||||
|
|
||||||
|
protected int fStartPos;
|
||||||
|
protected int fLength;
|
||||||
|
protected int fIdStartPos;
|
||||||
|
protected int fIdLength;
|
||||||
|
protected int fStartLine;
|
||||||
|
protected int fEndLine;
|
||||||
|
|
||||||
|
|
||||||
int modifiers;
|
int modifiers;
|
||||||
|
|
||||||
protected SourceManipulationInfo(CElement element) {
|
protected SourceManipulationInfo(CElement element) {
|
||||||
|
@ -27,13 +35,52 @@ class SourceManipulationInfo extends CElementInfo {
|
||||||
modifiers = 0;
|
modifiers = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPos(int startPos, int length) {
|
||||||
|
fStartPos = startPos;
|
||||||
|
fLength = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartPos() {
|
||||||
|
return fStartPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return fLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdPos(int startPos, int length) {
|
||||||
|
fIdStartPos= startPos;
|
||||||
|
fIdLength= length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdStartPos() {
|
||||||
|
return fIdStartPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdLength() {
|
||||||
|
return fIdLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartLine() {
|
||||||
|
return fStartLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndLine() {
|
||||||
|
return fEndLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLines(int startLine, int endLine) {
|
||||||
|
fStartLine = startLine;
|
||||||
|
fEndLine = endLine;
|
||||||
|
}
|
||||||
|
|
||||||
protected ISourceRange getSourceRange() {
|
protected ISourceRange getSourceRange() {
|
||||||
return new SourceRange(getElement().getStartPos(),
|
return new SourceRange(fStartPos,
|
||||||
getElement().getLength(),
|
fLength,
|
||||||
getElement().getIdStartPos(),
|
fIdStartPos,
|
||||||
getElement().getIdLength(),
|
fIdLength,
|
||||||
getElement().getStartLine(),
|
fStartLine,
|
||||||
getElement().getEndLine());
|
fEndLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,8 +92,8 @@ class SourceManipulationInfo extends CElementInfo {
|
||||||
if (buffer == null) {
|
if (buffer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int offset = getElement().getStartPos();
|
int offset = fStartPos;
|
||||||
int length = getElement().getLength();
|
int length = fLength;
|
||||||
if (offset == -1 || length == 0 ) {
|
if (offset == -1 || length == 0 ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue