1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +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 occurs while accessing its resource
*/
IResource getResource() ;
IResource getResource();
/**
* Returns whether this C element is read-only. An element is read-only
* 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
* the string is not specified; however, the identifier is stable across
* Returns a string representation of this element handle. The format of the
* string is not specified; however, the identifier is stable across
* workspace sessions, and can be used to recreate this handle via the
* <code>CoreModel.create(String)</code> method.
*
* @return the string handle identifier
* <p>
* 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)
*
* @since 5.0

View file

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

View file

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

View file

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

View file

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

View file

@ -256,8 +256,8 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
}
@Override
public void getHandleMemento(StringBuilder buff) {
((CElement)getParent()).getHandleMemento(buff);
public String getHandleMemento() {
return null;
}
@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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@ -107,8 +108,8 @@ public class BinaryModule extends Parent implements IBinaryModule {
}
@Override
public void getHandleMemento(StringBuilder buff) {
((CElement)getParent()).getHandleMemento(buff);
public String getHandleMemento() {
return null;
}
@Override

View file

@ -274,13 +274,37 @@ public class CContainer extends Openable implements ICContainer {
@Override
public ICElement getHandleFromMemento(String token, MementoTokenizer memento) {
switch (token.charAt(0)) {
case CEM_TRANSLATIONUNIT:
if (!memento.hasMoreTokens()) return this;
String tuName = memento.nextToken();
CElement tu = (CElement) getTranslationUnit(tuName);
if (tu != null) {
return tu.getHandleFromMemento(memento);
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 (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;
}

View file

@ -75,8 +75,8 @@ public class LibraryReference extends Parent implements ILibraryReference {
}
@Override
public void getHandleMemento(StringBuilder buff) {
((CElement)getParent()).getHandleMemento(buff);
public String getHandleMemento() {
return null;
}
@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.ISourceRoot;
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.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -72,40 +71,7 @@ public class SourceRoot extends CContainer implements ISourceRoot {
return false;
}
/*
* @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)
*/
@Override
public void getHandleMemento(StringBuilder buff) {
IPath path;
IResource underlyingResource = getResource();

View file

@ -299,34 +299,20 @@ abstract class CElementHandle implements ICElementHandle, ISourceReference {
* @see ICElement
*/
public String getHandleIdentifier() {
return getHandleMemento();
}
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);
ICElement cModelElement= mapToModelElement();
if (cModelElement != null) {
return cModelElement.getHandleIdentifier();
}
buff.append(getHandleMementoDelimiter());
CElement.escapeMementoName(buff, getElementName());
buff.append(CElement.CEM_ELEMENTTYPE);
buff.append(Integer.toString(getElementType()));
return null;
}
/**
* Returns the <code>char</code> that marks the start of this handles
* contribution to a memento.
*/
protected char getHandleMementoDelimiter() {
return CElement.CEM_SOURCEELEMENT;
private ICElement mapToModelElement() {
try {
ISourceRange range= getSourceRange();
return getTranslationUnit().getElementAtOffset(range.getIdStartPos());
} catch (CModelException exc) {
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.ICElement;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.FunctionDeclaration;
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;
}
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.IMethodDeclaration;
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.MethodDeclaration;
@ -84,11 +83,4 @@ public class MethodDeclarationHandle extends CElementHandle implements IMethodDe
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.ICElement;
import org.eclipse.cdt.core.model.IStructureTemplate;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.Template;
public class StructureTemplateHandle extends StructureHandle implements IStructureTemplate {
@ -53,14 +52,4 @@ public class StructureTemplateHandle extends StructureHandle implements IStructu
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]);
}
}
}
}