1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Adapt handle identifier API for use with Mylyn bridge

This commit is contained in:
Anton Leherbauer 2008-03-17 11:49:57 +00:00
parent 65adceff69
commit d35bf75b1c
14 changed files with 68 additions and 114 deletions

View file

@ -382,7 +382,7 @@ public interface ICElement extends IAdaptable {
* @exception CModelException if this element does not exist or if an * @exception CModelException if this element does not exist or if an
* exception occurs while accessing its resource * exception occurs while accessing its resource
*/ */
IResource getResource() ; IResource getResource();
/** /**
* Returns whether this C element is read-only. An element is read-only * Returns whether this C element is read-only. An element is read-only
* if its structure cannot be modified by the C model. * if its structure cannot be modified by the C model.
@ -417,12 +417,17 @@ public interface ICElement extends IAdaptable {
/** /**
* Returns a string representation of this element handle. The format of * Returns a string representation of this element handle. The format of the
* the string is not specified; however, the identifier is stable across * string is not specified; however, the identifier is stable across
* workspace sessions, and can be used to recreate this handle via the * workspace sessions, and can be used to recreate this handle via the
* <code>CoreModel.create(String)</code> method. * <code>CoreModel.create(String)</code> method.
* * <p>
* @return the string handle identifier * Some element types, like binaries, do not support handle identifiers and
* return <code>null</code>.
* </p>
*
* @return the string handle identifier, or <code>null</code> if the
* element type is not supported
* @see CoreModel#create(java.lang.String) * @see CoreModel#create(java.lang.String)
* *
* @since 5.0 * @since 5.0

View file

@ -126,8 +126,8 @@ public class Archive extends Openable implements IArchive {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -57,8 +57,8 @@ public class ArchiveContainer extends Openable implements IArchiveContainer {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -515,8 +515,8 @@ public class Binary extends Openable implements IBinary {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -74,8 +74,8 @@ public class BinaryContainer extends Openable implements IBinaryContainer {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -256,8 +256,8 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others. * Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -107,8 +108,8 @@ public class BinaryModule extends Parent implements IBinaryModule {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -274,13 +274,37 @@ public class CContainer extends Openable implements ICContainer {
@Override @Override
public ICElement getHandleFromMemento(String token, MementoTokenizer memento) { public ICElement getHandleFromMemento(String token, MementoTokenizer memento) {
switch (token.charAt(0)) { switch (token.charAt(0)) {
case CEM_TRANSLATIONUNIT: case CEM_SOURCEFOLDER:
if (!memento.hasMoreTokens()) return this; String name;
String tuName = memento.nextToken(); if (memento.hasMoreTokens()) {
CElement tu = (CElement) getTranslationUnit(tuName); name = memento.nextToken();
if (tu != null) { char firstChar = name.charAt(0);
return tu.getHandleFromMemento(memento); if (firstChar == CEM_TRANSLATIONUNIT) {
token = name;
name = ""; //$NON-NLS-1$
} else {
token = null;
} }
} else {
name = ""; //$NON-NLS-1$
token = null;
}
CElement folder = (CElement)getCContainer(name);
if (folder != null) {
if (token == null) {
return folder.getHandleFromMemento(memento);
} else {
return folder.getHandleFromMemento(token, memento);
}
}
break;
case CEM_TRANSLATIONUNIT:
if (!memento.hasMoreTokens()) return this;
String tuName = memento.nextToken();
CElement tu = (CElement) getTranslationUnit(tuName);
if (tu != null) {
return tu.getHandleFromMemento(memento);
}
} }
return null; return null;
} }

View file

@ -75,8 +75,8 @@ public class LibraryReference extends Parent implements ILibraryReference {
} }
@Override @Override
public void getHandleMemento(StringBuilder buff) { public String getHandleMemento() {
((CElement)getParent()).getHandleMemento(buff); return null;
} }
@Override @Override

View file

@ -17,7 +17,6 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.settings.model.ICSourceEntry; import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.internal.core.util.MementoTokenizer;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -72,40 +71,7 @@ public class SourceRoot extends CContainer implements ISourceRoot {
return false; return false;
} }
/* @Override
* @see CElement
*/
public ICElement getHandleFromMemento(String token, MementoTokenizer memento) {
switch (token.charAt(0)) {
case CEM_SOURCEFOLDER:
String name;
if (memento.hasMoreTokens()) {
name = memento.nextToken();
char firstChar = name.charAt(0);
if (firstChar == CEM_TRANSLATIONUNIT) {
token = name;
name = ""; //$NON-NLS-1$
} else {
token = null;
}
} else {
name = ""; //$NON-NLS-1$
token = null;
}
CElement folder = (CElement)getCContainer(name);
if (token == null) {
return folder.getHandleFromMemento(memento);
} else {
return folder.getHandleFromMemento(token, memento);
}
case CEM_TRANSLATIONUNIT:
return super.getHandleFromMemento(token, memento);
}
return null;
}
/**
* @see CElement#getHandleMemento(StringBuilder)
*/
public void getHandleMemento(StringBuilder buff) { public void getHandleMemento(StringBuilder buff) {
IPath path; IPath path;
IResource underlyingResource = getResource(); IResource underlyingResource = getResource();

View file

@ -299,34 +299,20 @@ abstract class CElementHandle implements ICElementHandle, ISourceReference {
* @see ICElement * @see ICElement
*/ */
public String getHandleIdentifier() { public String getHandleIdentifier() {
return getHandleMemento(); ICElement cModelElement= mapToModelElement();
} if (cModelElement != null) {
return cModelElement.getHandleIdentifier();
public String getHandleMemento(){
StringBuilder buff = new StringBuilder();
getHandleMemento(buff);
return buff.toString();
}
protected void getHandleMemento(StringBuilder buff) {
final ICElement parent= getParent();
if (parent instanceof CElement) {
((CElement)parent).getHandleMemento(buff);
} else if (parent instanceof CElementHandle) {
((CElementHandle)parent).getHandleMemento(buff);
} }
buff.append(getHandleMementoDelimiter()); return null;
CElement.escapeMementoName(buff, getElementName());
buff.append(CElement.CEM_ELEMENTTYPE);
buff.append(Integer.toString(getElementType()));
} }
/** private ICElement mapToModelElement() {
* Returns the <code>char</code> that marks the start of this handles try {
* contribution to a memento. ISourceRange range= getSourceRange();
*/ return getTranslationUnit().getElementAtOffset(range.getIdStartPos());
protected char getHandleMementoDelimiter() { } catch (CModelException exc) {
return CElement.CEM_SOURCEELEMENT; return null;
}
} }
} }

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IFunctionDeclaration; import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.FunctionDeclaration; import org.eclipse.cdt.internal.core.model.FunctionDeclaration;
public class FunctionDeclarationHandle extends CElementHandle implements org.eclipse.cdt.core.model.IFunctionDeclaration { public class FunctionDeclarationHandle extends CElementHandle implements org.eclipse.cdt.core.model.IFunctionDeclaration {
@ -64,12 +63,4 @@ public class FunctionDeclarationHandle extends CElementHandle implements org.ecl
return fIsStatic; return fIsStatic;
} }
public void getHandleMemento(StringBuilder buff) {
super.getHandleMemento(buff);
for (int i = 0; i < fParameterTypes.length; i++) {
buff.append(CElement.CEM_PARAMETER);
CElement.escapeMementoName(buff, fParameterTypes[i]);
}
}
} }

View file

@ -19,7 +19,6 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IMethodDeclaration; import org.eclipse.cdt.core.model.IMethodDeclaration;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.FunctionDeclaration; import org.eclipse.cdt.internal.core.model.FunctionDeclaration;
import org.eclipse.cdt.internal.core.model.MethodDeclaration; import org.eclipse.cdt.internal.core.model.MethodDeclaration;
@ -84,11 +83,4 @@ public class MethodDeclarationHandle extends CElementHandle implements IMethodDe
return fIsDestructor; return fIsDestructor;
} }
public void getHandleMemento(StringBuilder buff) {
super.getHandleMemento(buff);
for (int i = 0; i < fParameterTypes.length; i++) {
buff.append(CElement.CEM_PARAMETER);
CElement.escapeMementoName(buff, fParameterTypes[i]);
}
}
} }

View file

@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IStructureTemplate; import org.eclipse.cdt.core.model.IStructureTemplate;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.Template; import org.eclipse.cdt.internal.core.model.Template;
public class StructureTemplateHandle extends StructureHandle implements IStructureTemplate { public class StructureTemplateHandle extends StructureHandle implements IStructureTemplate {
@ -53,14 +52,4 @@ public class StructureTemplateHandle extends StructureHandle implements IStructu
return fTemplate.getTemplateSignature(); return fTemplate.getTemplateSignature();
} }
public void getHandleMemento(StringBuilder buff) {
super.getHandleMemento(buff);
if (fTemplate.getNumberOfTemplateParameters() > 0) {
final String[] parameterTypes= fTemplate.getTemplateParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
buff.append(CElement.CEM_PARAMETER);
CElement.escapeMementoName(buff, parameterTypes[i]);
}
}
}
} }