From 8a6ca5e26126391ca9ee1f096f20e70f0e285953 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 20 Oct 2010 23:37:49 +0000 Subject: [PATCH] Cosmetics. --- .../cdt/internal/corext/util/CModelUtil.java | 234 +++++++++--------- .../refactoring/rename/CRenameProcessor.java | 1 - .../cdt/internal/ui/util/EditorUtility.java | 18 +- 3 files changed, 126 insertions(+), 127 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java index a0078a0ccf6..acc5776d15d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java @@ -1,117 +1,117 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.corext.util; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; - -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; - -import org.eclipse.cdt.internal.ui.util.EditorUtility; - -public class CModelUtil { - /** - * 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. - */ - public static ITranslationUnit toWorkingCopy(ITranslationUnit unit) { - if (!unit.isWorkingCopy()) { - ITranslationUnit workingCopy= EditorUtility.getWorkingCopy(unit); - if (workingCopy != null) { - return workingCopy; - } - } - return unit; - } - - public static ITranslationUnit toOriginal(ITranslationUnit unit){ - if (unit.isWorkingCopy()) { - return (((IWorkingCopy)unit).getOriginalElement()); - } - return unit; - } - - /** - * Returns the source root of ICElement. If the given - * element is already a source root, the element itself is returned. - */ - public static ISourceRoot getSourceRoot(ICElement element) { - ICElement root = element; - while (root != null) { - if (root instanceof ISourceRoot) - return (ISourceRoot)root; - ICElement parent = root.getAncestor(ICElement.C_CCONTAINER); - if (parent == root) - return null; - root = parent; - } - return null; - } - - /** - * Returns the source folder of ICElement. If the given - * element is already a source folder, the element itself is returned. - */ - public static ICContainer getSourceFolder(ICElement element) { - ICContainer folder = null; - if (element != null) { - boolean foundSourceRoot = false; - ICElement curr = element; - while (curr != null && !foundSourceRoot) { - if (curr instanceof ICContainer && folder == null) { - folder = (ICContainer)curr; - } - foundSourceRoot = (curr instanceof ISourceRoot); - curr = curr.getParent(); - } - if (folder == null) { - ICProject cproject = element.getCProject(); - folder = cproject.findSourceRoot(cproject.getProject()); - } - } - return folder; - } - - /** - * Returns true if the given source root is - * referenced. This means it is own by a different project but is referenced - * by the root's parent. Returns false if the given root - * doesn't have an underlying resource. - */ - public static boolean isReferenced(ISourceRoot root) { - IResource resource= root.getResource(); - if (resource != null) { - IProject project= resource.getProject(); - IProject container= root.getCProject().getProject(); - return !container.equals(project); - } - return false; - } - - /** - * Returns the translation unit the element belongs to or null if it does not. - */ - public static ITranslationUnit getTranslationUnit(ICElement elem) { - while (elem != null) { - if (elem instanceof ITranslationUnit) { - return (ITranslationUnit) elem; - } - elem= elem.getParent(); - } - return null; - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 IBM Corporation 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.internal.corext.util; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; + +import org.eclipse.cdt.core.model.ICContainer; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.IWorkingCopy; + +import org.eclipse.cdt.internal.ui.util.EditorUtility; + +public class CModelUtil { + /** + * 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. + */ + public static ITranslationUnit toWorkingCopy(ITranslationUnit unit) { + if (!unit.isWorkingCopy()) { + ITranslationUnit workingCopy= EditorUtility.getWorkingCopy(unit); + if (workingCopy != null) { + return workingCopy; + } + } + return unit; + } + + public static ITranslationUnit toOriginal(ITranslationUnit unit){ + if (unit.isWorkingCopy()) { + return (((IWorkingCopy) unit).getOriginalElement()); + } + return unit; + } + + /** + * Returns the source root of ICElement. If the given + * element is already a source root, the element itself is returned. + */ + public static ISourceRoot getSourceRoot(ICElement element) { + ICElement root = element; + while (root != null) { + if (root instanceof ISourceRoot) + return (ISourceRoot)root; + ICElement parent = root.getAncestor(ICElement.C_CCONTAINER); + if (parent == root) + return null; + root = parent; + } + return null; + } + + /** + * Returns the source folder of ICElement. If the given + * element is already a source folder, the element itself is returned. + */ + public static ICContainer getSourceFolder(ICElement element) { + ICContainer folder = null; + if (element != null) { + boolean foundSourceRoot = false; + ICElement curr = element; + while (curr != null && !foundSourceRoot) { + if (curr instanceof ICContainer && folder == null) { + folder = (ICContainer)curr; + } + foundSourceRoot = (curr instanceof ISourceRoot); + curr = curr.getParent(); + } + if (folder == null) { + ICProject cproject = element.getCProject(); + folder = cproject.findSourceRoot(cproject.getProject()); + } + } + return folder; + } + + /** + * Returns true if the given source root is + * referenced. This means it is own by a different project but is referenced + * by the root's parent. Returns false if the given root + * doesn't have an underlying resource. + */ + public static boolean isReferenced(ISourceRoot root) { + IResource resource= root.getResource(); + if (resource != null) { + IProject project= resource.getProject(); + IProject container= root.getCProject().getProject(); + return !container.equals(project); + } + return false; + } + + /** + * Returns the translation unit the element belongs to or null if it does not. + */ + public static ITranslationUnit getTranslationUnit(ICElement elem) { + while (elem != null) { + if (elem instanceof ITranslationUnit) { + return (ITranslationUnit) elem; + } + elem= elem.getParent(); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java index 1a355ea0b6d..b57b277c519 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java @@ -42,7 +42,6 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; - /** * This is the processor used for the rename. It decides which of the delegates to * use and forwards further calls to the delegate. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java index fb269ef27f8..a8025fc2e7e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java @@ -274,7 +274,7 @@ public class EditorUtility { private static IEditorInput getEditorInput(ICElement element) throws CModelException { while (element != null) { if (element instanceof ISourceReference) { - ITranslationUnit tu = ((ISourceReference)element).getTranslationUnit(); + ITranslationUnit tu = ((ISourceReference) element).getTranslationUnit(); if (tu != null) { 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) - * @return the working copy of the compilation unit, or null if not found + * @param tu the original translation unit (or another working copy) + * @return the working copy of the translation unit, or null if not found */ - public static ITranslationUnit getWorkingCopy(ITranslationUnit cu) { - if (cu == null) + public static ITranslationUnit getWorkingCopy(ITranslationUnit tu) { + if (tu == null) return null; - if (cu.isWorkingCopy()) - return cu; + if (tu.isWorkingCopy()) + return tu; - return CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(cu); + return CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu); } /**