1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45: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:
Alain Magloire 2005-01-27 03:39:09 +00:00
parent a047b603b5
commit 8df4a09141
8 changed files with 194 additions and 83 deletions

View file

@ -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
PR 38958
Part implementation of the CreateXXXOperation classes.

View file

@ -29,6 +29,8 @@ import org.eclipse.core.runtime.Path;
public class BinaryElement extends CElement implements IBinaryElement, ISourceManipulation, ISourceReference {
IAddress addr;
int fStartLine;
int fEndLine;
public BinaryElement(ICElement parent, String name, int type, IAddress a) {
super(parent, name, type);
@ -158,6 +160,64 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
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)
* @see org.eclipse.cdt.core.model.IBinaryElement#getBinary()
*/

View file

@ -38,13 +38,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
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) {
fParent= parent;
fName= name;
@ -196,45 +189,6 @@ public abstract class CElement extends PlatformObject implements ICElement {
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() {
IResource res = getResource();
if (res == null) {

View file

@ -317,13 +317,14 @@ public class CModelBuilder {
{
// Template Declaration
IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration();
if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){
if (declaration instanceof IASTAbstractTypeSpecifierDeclaration){
IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ;
CElement element = createAbstractElement(parent, abstractDeclaration , true, true);
if(element != null){
if (element instanceof SourceManipulation) {
SourceManipulation sourceRef = (SourceManipulation)element;
// set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
// set the template parameters
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
ITemplate classTemplate = (ITemplate) element;
@ -333,10 +334,11 @@ public class CModelBuilder {
// special case for Structural parse
IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ;
CElement element = createClassSpecifierElement(parent, classSpecifier , true);
if(element != null){
if (element instanceof SourceManipulation) {
SourceManipulation sourceRef = (SourceManipulation)element;
// set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
// set the template parameters
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
ITemplate classTemplate = (ITemplate) element;
@ -346,11 +348,11 @@ public class CModelBuilder {
ITemplate template = null;
template = (ITemplate) createSimpleElement(parent, declaration, true);
if(template != null){
CElement element = (CElement)template;
if (template instanceof SourceManipulation){
SourceManipulation sourceRef = (SourceManipulation)template;
// set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() );
// set the template parameters
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
template.setTemplateParameterTypes(parameterTypes);
@ -380,16 +382,16 @@ public class CModelBuilder {
private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate, boolean isDeclaration)throws ASTNotImplementedException, CModelException{
CElement element = null;
if(abstractDeclaration != null){
if (abstractDeclaration != null){
IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier();
// IASTEnumerationSpecifier
if ( typeSpec instanceof IASTEnumerationSpecifier){
if (typeSpec instanceof IASTEnumerationSpecifier) {
IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec;
IParent enumElement = createEnumeration (parent, enumSpecifier);
element = (CElement) enumElement;
}
// IASTClassSpecifier
else if (typeSpec instanceof IASTClassSpecifier){
else if (typeSpec instanceof IASTClassSpecifier) {
IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec;
element = createClassSpecifierElement (parent, classSpecifier, isTemplate);
} else if (isDeclaration && typeSpec instanceof IASTElaboratedTypeSpecifier) {

View file

@ -77,13 +77,21 @@ public class CopyElementsOperation extends MultiOperation {
* Returns the nested operation to use for processing this element
*/
protected CModelOperation getNestedOperation(ICElement element) {
ICElement dest = getDestinationParent(element);
ITranslationUnit unit = (ITranslationUnit)dest.getAncestor(ICElement.C_UNIT);
ITranslationUnit unit = getDestinationTranslationUnit(element);
String name = element.getElementName();
int type = element.getElementType();
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.
*/
@ -115,7 +123,14 @@ public class CopyElementsOperation extends MultiOperation {
if (op == null) {
return;
}
boolean isInTUOperation = op instanceof CreateElementInTUOperation;
if (isInTUOperation && isMove()) {
DeleteElementsOperation deleteOp = new DeleteElementsOperation(new ICElement[] { element }, fForce);
executeNestedOperation(deleteOp, 1);
}
if (isInTUOperation) {
CreateElementInTUOperation inTUop = (CreateElementInTUOperation)op;
ICElement sibling = (ICElement) fInsertBeforeElements.get(element);
@ -134,9 +149,9 @@ public class CopyElementsOperation extends MultiOperation {
}
executeNestedOperation(op, 1);
if (isInTUOperation && isMove()) {
DeleteElementsOperation deleteOp = new DeleteElementsOperation(new ICElement[] { element }, fForce);
executeNestedOperation(deleteOp, 1);
ITranslationUnit destUnit = getDestinationTranslationUnit(element);
if (!destUnit.isWorkingCopy()) {
destUnit.close();
}
}

View file

@ -36,15 +36,15 @@ public class Namespace extends SourceManipulation implements INamespace{
public void setTypeName(String typeName) {
this.typeName = typeName;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {
// TODO Auto-generated method stub
return (super.equals(other)
&& (this.getStartPos() == ((Namespace)other).getStartPos())
&& (this.getLength() == ((Namespace)other).getLength())
);
}
// /* (non-Javadoc)
// * @see java.lang.Object#equals(java.lang.Object)
// */
// public boolean equals(Object other) {
// return (super.equals(other)
// && (this.getStartPos() == ((Namespace)other).getStartPos())
// && (this.getLength() == ((Namespace)other).getLength())
// );
// }
}

View file

@ -185,4 +185,28 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
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) {
//
}
}
}

View file

@ -19,6 +19,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
/* package */
class SourceManipulationInfo extends CElementInfo {
protected int fStartPos;
protected int fLength;
protected int fIdStartPos;
protected int fIdLength;
protected int fStartLine;
protected int fEndLine;
int modifiers;
protected SourceManipulationInfo(CElement element) {
@ -27,13 +35,52 @@ class SourceManipulationInfo extends CElementInfo {
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() {
return new SourceRange(getElement().getStartPos(),
getElement().getLength(),
getElement().getIdStartPos(),
getElement().getIdLength(),
getElement().getStartLine(),
getElement().getEndLine());
return new SourceRange(fStartPos,
fLength,
fIdStartPos,
fIdLength,
fStartLine,
fEndLine);
}
/**
@ -45,8 +92,8 @@ class SourceManipulationInfo extends CElementInfo {
if (buffer == null) {
return null;
}
int offset = getElement().getStartPos();
int length = getElement().getLength();
int offset = fStartPos;
int length = fLength;
if (offset == -1 || length == 0 ) {
return null;
}