mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Reimplemented IndexUI.getTranslationUnit(IASTName) method.
Change-Id: Icb13f2d8d4370c670053a52aeb226d4853ce4b44
This commit is contained in:
parent
537178b4e4
commit
d4c3e42e7e
3 changed files with 14 additions and 5 deletions
|
@ -57,6 +57,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
@ -416,8 +417,10 @@ public class SelectionToDeclarationJob extends Job implements ASTRunnable {
|
||||||
IASTName astName = (IASTName) declName;
|
IASTName astName = (IASTName) declName;
|
||||||
IBinding binding = astName.resolveBinding();
|
IBinding binding = astName.resolveBinding();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
ITranslationUnit tu = IndexUI.getTranslationUnit(project, astName);
|
ITranslationUnit tu = IndexUI.getTranslationUnit(astName);
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
|
if (tu instanceof IWorkingCopy)
|
||||||
|
tu = ((IWorkingCopy) tu).getOriginalElement();
|
||||||
IASTFileLocation loc = astName.getFileLocation();
|
IASTFileLocation loc = astName.getFileLocation();
|
||||||
IRegion region = new Region(loc.getNodeOffset(), loc.getNodeLength());
|
IRegion region = new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||||
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
||||||
|
|
|
@ -84,6 +84,7 @@ import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.IStructureDeclaration;
|
import org.eclipse.cdt.core.model.IStructureDeclaration;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -501,8 +502,10 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
IASTName astName = (IASTName) declName;
|
IASTName astName = (IASTName) declName;
|
||||||
IBinding binding= astName.resolveBinding();
|
IBinding binding= astName.resolveBinding();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
ITranslationUnit tu= IndexUI.getTranslationUnit(project, astName);
|
ITranslationUnit tu= IndexUI.getTranslationUnit(astName);
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
|
if (tu instanceof IWorkingCopy)
|
||||||
|
tu = ((IWorkingCopy) tu).getOriginalElement();
|
||||||
IASTFileLocation loc= astName.getFileLocation();
|
IASTFileLocation loc= astName.getFileLocation();
|
||||||
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||||
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
||||||
|
|
|
@ -316,8 +316,10 @@ public class IndexUI {
|
||||||
assert !declName.isReference();
|
assert !declName.isReference();
|
||||||
IBinding binding= declName.resolveBinding();
|
IBinding binding= declName.resolveBinding();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
ITranslationUnit tu= getTranslationUnit(declName);
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
|
if (tu instanceof IWorkingCopy)
|
||||||
|
tu = ((IWorkingCopy) tu).getOriginalElement();
|
||||||
IFile file= (IFile) tu.getResource();
|
IFile file= (IFile) tu.getResource();
|
||||||
long timestamp= file != null ? file.getLocalTimeStamp() : 0;
|
long timestamp= file != null ? file.getLocalTimeStamp() : 0;
|
||||||
IASTFileLocation loc= declName.getFileLocation();
|
IASTFileLocation loc= declName.getFileLocation();
|
||||||
|
@ -332,8 +334,9 @@ public class IndexUI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ITranslationUnit getTranslationUnit(ICProject cproject, IASTName name) {
|
public static ITranslationUnit getTranslationUnit(IASTName name) {
|
||||||
return getTranslationUnit(cproject, name.getFileLocation());
|
IASTTranslationUnit astTranslationUnit = name.getTranslationUnit();
|
||||||
|
return astTranslationUnit == null ? null : astTranslationUnit.getOriginatingTranslationUnit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ITranslationUnit getTranslationUnit(ICProject cproject, IIndexName name) {
|
public static ITranslationUnit getTranslationUnit(ICProject cproject, IIndexName name) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue