diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 4186f1b748c..08558934f9f 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java index 507dfae57e5..8e72f94560e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java @@ -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() */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index 4d35e8f1fb1..cb9047daf35 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java index db01b25ecec..d4ba2b48369 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java index 853cd68c900..b0a01f9b4e4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java @@ -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(); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java index 6a43ed8f126..f92697667ee 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java @@ -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()) +// ); +// } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java index ec708c0ef10..f4d1d291580 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java @@ -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) { + // + } + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java index 9c5232e1960..f0c0b098a40 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java @@ -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; }