diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeReference.java')
-rw-r--r-- | core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeReference.java | 267 |
1 files changed, 0 insertions, 267 deletions
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeReference.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeReference.java deleted file mode 100644 index 0cfeb9a574b..00000000000 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/TypeReference.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.browser; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - - -public class TypeReference implements ITypeReference { - private IPath fPath; - private IProject fProject; - private IResource fResource; - private IWorkingCopy fWorkingCopy; - private int fOffset; - private int fLength; - - public TypeReference(IPath path, IProject project, int offset, int length) { - fPath = path; - fProject = project; - fWorkingCopy = null; - fResource = null; - fOffset = offset; - fLength = length; - } - - public TypeReference(IResource resource, IProject project, int offset, int length) { - fPath = null; - fProject = project; - fWorkingCopy = null; - fResource = resource; - fOffset = offset; - fLength = length; - } - - public TypeReference(IWorkingCopy workingCopy, IProject project, int offset, int length) { - fPath = null; - fProject = project; - fWorkingCopy = workingCopy; - fResource = null; - fOffset = offset; - fLength = length; - } - - public TypeReference(IPath path, IProject project) { - this(path, project, 0, 0); - } - - public TypeReference(IResource resource, IProject project) { - this(resource, project, 0, 0); - } - - public TypeReference(IWorkingCopy workingCopy, IProject project) { - this(workingCopy, project, 0, 0); - } - - public IPath getPath() { - if (fWorkingCopy != null) { - return fWorkingCopy.getPath(); - } else if (fResource != null) { - return fResource.getFullPath(); - } else { - return fPath; - } - } - - public IPath getLocation() { - if (fWorkingCopy != null) { - IResource resource = fWorkingCopy.getUnderlyingResource(); - if (resource != null) { - return resource.getLocation(); - } else { - return null; - } - } else if (fResource != null) { - return fResource.getLocation(); - } else if (fPath != null) { - return fPath; - } else if (fProject != null) { - return fProject.getLocation(); - } else { - return null; - } - } - - public IResource getResource() { - return fResource; - } - - public IWorkingCopy getWorkingCopy() { - return fWorkingCopy; - } - - public IProject getProject() { - if (fProject != null) { - return fProject; - } else { - if (fWorkingCopy != null) { - ICProject cProject = fWorkingCopy.getCProject(); - if (cProject != null) { - return cProject.getProject(); - } else { - return null; - } - } else if (fResource != null) { - return fResource.getProject(); - } else { - return null; - } - } - } - - public ITranslationUnit getTranslationUnit() { - ITranslationUnit unit = null; - if (fWorkingCopy != null) { - unit = fWorkingCopy.getTranslationUnit(); - } else if (fResource != null) { - ICElement elem = CoreModel.getDefault().create(fResource); - if (elem instanceof ITranslationUnit) - unit = (ITranslationUnit) elem; - } else { - IPath path = getLocation(); - ICElement elem = CoreModel.getDefault().create(path); - if (elem instanceof ITranslationUnit) - unit = (ITranslationUnit) elem; - } - - if (unit == null) { - IProject project = getProject(); - if (project != null) { - ICProject cProject = findCProject(project); - if (cProject != null) { - IPath path = getLocation(); - ICElement elem = CoreModel.getDefault().createTranslationUnitFrom(cProject, path); - if (elem instanceof ITranslationUnit) - unit = (ITranslationUnit) elem; - } - } - } - return unit; - } - - private ICProject findCProject(IProject project) { - try { - ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects(); - if (cProjects != null) { - for (int i = 0; i < cProjects.length; ++i) { - ICProject cProject = cProjects[i]; - if (project.equals(cProjects[i].getProject())) - return cProject; - } - } - } catch (CModelException e) { - } - return null; - } - - public ICElement[] getCElements() { - ITranslationUnit unit = getTranslationUnit(); - if (unit != null) { - try { - return unit.getElementsAtOffset(fOffset); - } catch (CModelException e) { - } - } - return null; - } - - public int getOffset() { - return fOffset; - } - - public int getLength() { - return fLength; - } - - public IPath getRelativeIncludePath(IProject project) { - IPath path = getLocation(); - if (path != null) { - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); - if (provider != null) { - IScannerInfo info = provider.getScannerInformation(project); - if (info != null) { - String[] includePaths = info.getIncludePaths(); - IPath relativePath = null; - int mostSegments = 0; - for (int i = 0; i < includePaths.length; ++i) { - IPath includePath = new Path(includePaths[i]); - if (includePath.isPrefixOf(path)) { - int segments = includePath.matchingFirstSegments(path); - if (segments > mostSegments) { - relativePath = path.removeFirstSegments(segments).setDevice(null); - mostSegments = segments; - } - } - } - if (relativePath != null) - path = relativePath; - } - } - } - return path; - } - - public IPath getRelativePath(IPath relativeToPath) { - IPath path = getPath(); - if (path != null) { - int segments = relativeToPath.matchingFirstSegments(path); - if (segments > 0) { - IPath prefix = relativeToPath.removeFirstSegments(segments).removeLastSegments(1); - IPath suffix = path.removeFirstSegments(segments); - IPath relativePath = new Path(""); //$NON-NLS-1$ - for (int i = 0; i < prefix.segmentCount(); ++i) { - relativePath = relativePath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$ - } - return relativePath.append(suffix); - } - } - return path; - } - - public String toString() { - IPath path = getLocation(); - if (path != null) { - if (fLength == 0 && fOffset == 0) { - return path.toString(); - } else { - return path.toString() + ":" + fOffset + "-" + (fOffset + fLength); //$NON-NLS-1$//$NON-NLS-2$ - } - } else { - return ""; //$NON-NLS-1$ - } - } - - public int hashCode() { - return toString().hashCode(); - } - - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ITypeReference)) { - return false; - } - ITypeReference ref = (ITypeReference)obj; - return toString().equals(ref.toString()); - } -} |