Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7553)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ResourceUtil.java

Issue 9834028: Initial implementation of "Rename Local Variable" refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: LInked/inline mode for rename Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ResourceUtil.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ResourceUtil.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ResourceUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..2c30db1d76399d07f87e038896aa214d00f19520
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ResourceUtil.java
@@ -0,0 +1,59 @@
+package com.google.dart.tools.internal.corext.refactoring.util;
+
+import com.google.dart.tools.core.model.CompilationUnit;
+import com.google.dart.tools.core.model.DartElement;
+import com.google.dart.tools.core.model.OpenableElement;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ResourceUtil {
+
+ public static IFile getFile(CompilationUnit cu) {
+ IResource resource = cu.getResource();
+ if (resource != null && resource.getType() == IResource.FILE) {
+ return (IFile) resource;
+ } else {
+ return null;
+ }
+ }
+
+ public static IFile[] getFiles(CompilationUnit[] cus) {
+ List<IResource> files = new ArrayList<IResource>(cus.length);
+ for (int i = 0; i < cus.length; i++) {
+ IResource resource = cus[i].getResource();
+ if (resource != null && resource.getType() == IResource.FILE) {
+ files.add(resource);
+ }
+ }
+ return files.toArray(new IFile[files.size()]);
+ }
+
+ public static IResource getResource(Object o) {
+ if (o instanceof IResource) {
+ return (IResource) o;
+ }
+ if (o instanceof DartElement) {
+ return getResource((DartElement) o);
+ }
+ return null;
+ }
+
+ //----- other ------------------------------
+
+ private static IResource getResource(DartElement element) {
+ if (element.getElementType() == DartElement.COMPILATION_UNIT) {
+ return ((CompilationUnit) element).getResource();
+ } else if (element instanceof OpenableElement) {
+ return element.getResource();
+ } else {
+ return null;
+ }
+ }
+
+ private ResourceUtil() {
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698