mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-04 22:23:28 +02:00
Cosmetics.
This commit is contained in:
parent
0672757bc6
commit
8a6ca5e261
3 changed files with 126 additions and 127 deletions
|
@ -1,117 +1,117 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
* Copyright (c) 2004, 2007 IBM Corporation 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
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.corext.util;
|
package org.eclipse.cdt.internal.corext.util;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
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.model.IWorkingCopy;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
|
||||||
public class CModelUtil {
|
public class CModelUtil {
|
||||||
/**
|
/**
|
||||||
* Returns the working copy CU of the given CU. If the CU is already a
|
* Returns the working copy CU of the given CU. If the CU is already a
|
||||||
* working copy or the CU has no working copy the input CU is returned.
|
* working copy or the CU has no working copy the input CU is returned.
|
||||||
*/
|
*/
|
||||||
public static ITranslationUnit toWorkingCopy(ITranslationUnit unit) {
|
public static ITranslationUnit toWorkingCopy(ITranslationUnit unit) {
|
||||||
if (!unit.isWorkingCopy()) {
|
if (!unit.isWorkingCopy()) {
|
||||||
ITranslationUnit workingCopy= EditorUtility.getWorkingCopy(unit);
|
ITranslationUnit workingCopy= EditorUtility.getWorkingCopy(unit);
|
||||||
if (workingCopy != null) {
|
if (workingCopy != null) {
|
||||||
return workingCopy;
|
return workingCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ITranslationUnit toOriginal(ITranslationUnit unit){
|
public static ITranslationUnit toOriginal(ITranslationUnit unit){
|
||||||
if (unit.isWorkingCopy()) {
|
if (unit.isWorkingCopy()) {
|
||||||
return (((IWorkingCopy)unit).getOriginalElement());
|
return (((IWorkingCopy) unit).getOriginalElement());
|
||||||
}
|
}
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the source root of <code>ICElement</code>. If the given
|
* Returns the source root of <code>ICElement</code>. If the given
|
||||||
* element is already a source root, the element itself is returned.
|
* element is already a source root, the element itself is returned.
|
||||||
*/
|
*/
|
||||||
public static ISourceRoot getSourceRoot(ICElement element) {
|
public static ISourceRoot getSourceRoot(ICElement element) {
|
||||||
ICElement root = element;
|
ICElement root = element;
|
||||||
while (root != null) {
|
while (root != null) {
|
||||||
if (root instanceof ISourceRoot)
|
if (root instanceof ISourceRoot)
|
||||||
return (ISourceRoot)root;
|
return (ISourceRoot)root;
|
||||||
ICElement parent = root.getAncestor(ICElement.C_CCONTAINER);
|
ICElement parent = root.getAncestor(ICElement.C_CCONTAINER);
|
||||||
if (parent == root)
|
if (parent == root)
|
||||||
return null;
|
return null;
|
||||||
root = parent;
|
root = parent;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the source folder of <code>ICElement</code>. If the given
|
* Returns the source folder of <code>ICElement</code>. If the given
|
||||||
* element is already a source folder, the element itself is returned.
|
* element is already a source folder, the element itself is returned.
|
||||||
*/
|
*/
|
||||||
public static ICContainer getSourceFolder(ICElement element) {
|
public static ICContainer getSourceFolder(ICElement element) {
|
||||||
ICContainer folder = null;
|
ICContainer folder = null;
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
boolean foundSourceRoot = false;
|
boolean foundSourceRoot = false;
|
||||||
ICElement curr = element;
|
ICElement curr = element;
|
||||||
while (curr != null && !foundSourceRoot) {
|
while (curr != null && !foundSourceRoot) {
|
||||||
if (curr instanceof ICContainer && folder == null) {
|
if (curr instanceof ICContainer && folder == null) {
|
||||||
folder = (ICContainer)curr;
|
folder = (ICContainer)curr;
|
||||||
}
|
}
|
||||||
foundSourceRoot = (curr instanceof ISourceRoot);
|
foundSourceRoot = (curr instanceof ISourceRoot);
|
||||||
curr = curr.getParent();
|
curr = curr.getParent();
|
||||||
}
|
}
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
ICProject cproject = element.getCProject();
|
ICProject cproject = element.getCProject();
|
||||||
folder = cproject.findSourceRoot(cproject.getProject());
|
folder = cproject.findSourceRoot(cproject.getProject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the given source root is
|
* Returns <code>true</code> if the given source root is
|
||||||
* referenced. This means it is own by a different project but is referenced
|
* referenced. This means it is own by a different project but is referenced
|
||||||
* by the root's parent. Returns <code>false</code> if the given root
|
* by the root's parent. Returns <code>false</code> if the given root
|
||||||
* doesn't have an underlying resource.
|
* doesn't have an underlying resource.
|
||||||
*/
|
*/
|
||||||
public static boolean isReferenced(ISourceRoot root) {
|
public static boolean isReferenced(ISourceRoot root) {
|
||||||
IResource resource= root.getResource();
|
IResource resource= root.getResource();
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
IProject project= resource.getProject();
|
IProject project= resource.getProject();
|
||||||
IProject container= root.getCProject().getProject();
|
IProject container= root.getCProject().getProject();
|
||||||
return !container.equals(project);
|
return !container.equals(project);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the translation unit the element belongs to or <code>null</code> if it does not.
|
* Returns the translation unit the element belongs to or <code>null</code> if it does not.
|
||||||
*/
|
*/
|
||||||
public static ITranslationUnit getTranslationUnit(ICElement elem) {
|
public static ITranslationUnit getTranslationUnit(ICElement elem) {
|
||||||
while (elem != null) {
|
while (elem != null) {
|
||||||
if (elem instanceof ITranslationUnit) {
|
if (elem instanceof ITranslationUnit) {
|
||||||
return (ITranslationUnit) elem;
|
return (ITranslationUnit) elem;
|
||||||
}
|
}
|
||||||
elem= elem.getParent();
|
elem= elem.getParent();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the processor used for the rename. It decides which of the delegates to
|
* This is the processor used for the rename. It decides which of the delegates to
|
||||||
* use and forwards further calls to the delegate.
|
* use and forwards further calls to the delegate.
|
||||||
|
|
|
@ -274,7 +274,7 @@ public class EditorUtility {
|
||||||
private static IEditorInput getEditorInput(ICElement element) throws CModelException {
|
private static IEditorInput getEditorInput(ICElement element) throws CModelException {
|
||||||
while (element != null) {
|
while (element != null) {
|
||||||
if (element instanceof ISourceReference) {
|
if (element instanceof ISourceReference) {
|
||||||
ITranslationUnit tu = ((ISourceReference)element).getTranslationUnit();
|
ITranslationUnit tu = ((ISourceReference) element).getTranslationUnit();
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
element = tu;
|
element = tu;
|
||||||
}
|
}
|
||||||
|
@ -548,18 +548,18 @@ public class EditorUtility {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the working copy of an compilation unit opened in an editor
|
* Gets the working copy of an translation unit opened in an editor
|
||||||
*
|
*
|
||||||
* @param cu the original compilation unit (or another working copy)
|
* @param tu the original translation unit (or another working copy)
|
||||||
* @return the working copy of the compilation unit, or null if not found
|
* @return the working copy of the translation unit, or null if not found
|
||||||
*/
|
*/
|
||||||
public static ITranslationUnit getWorkingCopy(ITranslationUnit cu) {
|
public static ITranslationUnit getWorkingCopy(ITranslationUnit tu) {
|
||||||
if (cu == null)
|
if (tu == null)
|
||||||
return null;
|
return null;
|
||||||
if (cu.isWorkingCopy())
|
if (tu.isWorkingCopy())
|
||||||
return cu;
|
return tu;
|
||||||
|
|
||||||
return CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(cu);
|
return CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue