aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-02-28 16:17:24 -0800
committerTor Norbye <tnorbye@google.com>2012-02-28 16:17:46 -0800
commitf14914e59366377316c70f068347d3e34a1dea3c (patch)
tree3c9fd951e9c58347111ce367ed3124ef1b7696ff /eclipse
parent11baf5c216f12d01a147ff761389ef36a50a91b0 (diff)
downloadsdk-f14914e59366377316c70f068347d3e34a1dea3c.zip
sdk-f14914e59366377316c70f068347d3e34a1dea3c.tar.gz
sdk-f14914e59366377316c70f068347d3e34a1dea3c.tar.bz2
Make XML editors work with non-workspace files
This changeset makes the AndroidXmlEditor handle other editor inputs than just FileEditorInput. In particular, it now handles IURIEditorInput as well. This makes the "Go To Declaration" facility for @android resources work properly again, and unlike before, you can now use our editors in those files as well, so you can use Go To Declaration to jump to other @android resources within the same platform. This changeset adds checks after all the getInputFile() calls on the editor, which ensures that features which assume a file exists (such as the quickfix and visual refactoring operations) do not do anything in these files. The layout editor has a lot of file requirements, so that editor is deliberately skipped and you get a plain editor instead if you try to open layout files outside of the workspace. See http://code.google.com/p/android/issues/detail?id=26164 Change-Id: I7457494ec0bfc2eb4e6eba2e059025142c21d3ce
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java30
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java52
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java19
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationEditorDelegate.java11
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorEditorDelegate.java2
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java10
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java35
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableEditorDelegate.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java1
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java4
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java5
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/MenuEditorDelegate.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/OtherXmlEditorDelegate.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesEditorDelegate.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/CyclicDependencyValidator.java8
27 files changed, 169 insertions, 51 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
index e3fc5fe..62b6804 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtUtils.java
@@ -17,6 +17,7 @@
package com.android.ide.eclipse.adt;
import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper.IProjectFilter;
@@ -37,6 +38,7 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -419,4 +421,32 @@ public class AdtUtils {
}
});
}
+
+ /**
+ * Returns the name of the parent folder for the given editor input
+ *
+ * @param editorInput the editor input to check
+ * @return the parent folder, which is never null but may be ""
+ */
+ @NonNull
+ public static String getParentFolderName(@Nullable IEditorInput editorInput) {
+ if (editorInput instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) editorInput).getFile();
+ return file.getParent().getName();
+ }
+
+ if (editorInput instanceof IURIEditorInput) {
+ IURIEditorInput urlEditorInput = (IURIEditorInput) editorInput;
+ String path = urlEditorInput.getURI().toString();
+ int lastIndex = path.lastIndexOf('/');
+ if (lastIndex != -1) {
+ int lastLastIndex = path.lastIndexOf('/', lastIndex - 1);
+ if (lastLastIndex != -1) {
+ return path.substring(lastLastIndex + 1, lastIndex);
+ }
+ }
+ }
+
+ return "";
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
index 3a54caf..bea293e 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/AaptQuickFix.java
@@ -167,6 +167,9 @@ public class AaptQuickFix implements IMarkerResolutionGenerator2, IQuickAssistPr
AndroidXmlEditor editor = AndroidXmlEditor.fromTextViewer(sourceViewer);
if (editor != null) {
IFile file = editor.getInputFile();
+ if (file == null) {
+ return null;
+ }
IDocument document = sourceViewer.getDocument();
List<IMarker> markers = AdtUtils.findMarkersOnLine(AdtConstants.MARKER_AAPT_COMPILE,
file, document, invocationContext.getOffset());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
index a1635dc..7c57549 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
@@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.editors;
import static org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT;
+import com.android.annotations.Nullable;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
@@ -56,8 +57,8 @@ import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
@@ -474,26 +475,9 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh
}
/**
- * Initializes the editor part with a site and input.
- * <p/>
- * Checks that the input is an instance of {@link IFileEditorInput}.
- *
- * @see FormEditor
- */
- @Override
- public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
- if (!(editorInput instanceof IFileEditorInput))
- throw new PartInitException("Invalid Input: Must be IFileEditorInput");
- super.init(site, editorInput);
- }
-
- /**
* Returns the {@link IFile} matching the editor's input or null.
- * <p/>
- * By construction, the editor input has to be an {@link IFileEditorInput} so it must
- * have an associated {@link IFile}. Null can only be returned if this editor has no
- * input somehow.
*/
+ @Nullable
public IFile getInputFile() {
IEditorInput input = getEditorInput();
if (input instanceof IFileEditorInput) {
@@ -581,9 +565,15 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh
*
* @see EclipseLintRunner#startLint(java.util.List, IDocument, boolean, boolean)
*/
+ @Nullable
public Job startLintJob() {
- return EclipseLintRunner.startLint(Collections.singletonList(getInputFile()),
- getStructuredDocument(), false /*fatalOnly*/, false /*show*/);
+ IFile file = getInputFile();
+ if (file != null) {
+ return EclipseLintRunner.startLint(Collections.singletonList(file),
+ getStructuredDocument(), false /*fatalOnly*/, false /*show*/);
+ }
+
+ return null;
}
/* (non-Javadoc)
@@ -1183,6 +1173,26 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh
}
}
+ IEditorInput input = getEditorInput();
+ if (input instanceof IURIEditorInput) {
+ IURIEditorInput urlInput = (IURIEditorInput) input;
+ Sdk currentSdk = Sdk.getCurrent();
+ if (currentSdk != null) {
+ try {
+ String path = AdtUtils.getFile(urlInput.getURI().toURL()).getPath();
+ IAndroidTarget[] targets = currentSdk.getTargets();
+ for (IAndroidTarget target : targets) {
+ if (path.startsWith(target.getLocation())) {
+ return currentSdk.getTargetData(target);
+ }
+ }
+ } catch (MalformedURLException e) {
+ // File might be in some other weird random location we can't
+ // handle: Just ignore these
+ }
+ }
+ }
+
return null;
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
index 08ca60a..8ff2a34 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/Hyperlinks.java
@@ -745,6 +745,21 @@ public class Hyperlinks {
private static ResourceRepository getResources(IProject project, boolean framework) {
if (framework) {
IAndroidTarget target = getTarget(project);
+
+ if (target == null && project == null && framework) {
+ // No current project: probably jumped into some of the framework XML resource
+ // files and attempting to jump around. Attempt to figure out which target
+ // we're dealing with and continue looking within the same framework.
+ IEditorPart editor = getEditor();
+ Sdk sdk = Sdk.getCurrent();
+ if (sdk != null && editor instanceof AndroidXmlEditor) {
+ AndroidTargetData data = ((AndroidXmlEditor) editor).getTargetData();
+ if (data != null) {
+ return data.getFrameworkResources();
+ }
+ }
+ }
+
if (target == null) {
return null;
}
@@ -1081,6 +1096,10 @@ public class Hyperlinks {
String name = resource.getSecond();
boolean isFramework = url.startsWith("@android"); //$NON-NLS-1$
+ if (project == null) {
+ // Local reference *within* a framework
+ isFramework = true;
+ }
ResourceRepository resources = getResources(project, isFramework);
if (resources == null) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java
index ee0c290..476fbd9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java
@@ -23,6 +23,7 @@ import com.android.annotations.VisibleForTesting;
import com.android.ide.common.api.IAttributeInfo.Format;
import com.android.ide.common.resources.ResourceItem;
import com.android.ide.common.resources.ResourceRepository;
+import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.AndroidContentAssist;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
@@ -58,7 +59,7 @@ public final class AnimationContentAssist extends AndroidContentAssist {
@Override
protected int getRootDescriptorId() {
- String folderName = mEditor.getInputFile().getParent().getName();
+ String folderName = AdtUtils.getParentFolderName(mEditor.getEditorInput());
ResourceFolderType folderType = ResourceFolderType.getFolderType(folderName);
if (folderType == ResourceFolderType.ANIM) {
return AndroidTargetData.DESCRIPTOR_ANIM;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationEditorDelegate.java
index bd1fa3d..153bc79 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationEditorDelegate.java
@@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.editors.animator;
import static com.android.ide.eclipse.adt.AdtConstants.EDITORS_NAMESPACE;
+import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlDelegate;
import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.DocumentDescriptor;
@@ -25,8 +26,6 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescripto
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceFolderType;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -43,7 +42,6 @@ public class AnimationEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public AnimationEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.ANIM == type || ResourceFolderType.ANIMATOR == type) {
return new AnimationEditorDelegate(delegator);
@@ -152,10 +150,9 @@ public class AnimationEditorDelegate extends CommonXmlDelegate {
}
private ResourceFolderType getFolderType() {
- IFile inputFile = getEditor().getInputFile();
- if (inputFile != null) {
- String folderName = inputFile.getParent().getName();
- return ResourceFolderType.getFolderType(folderName);
+ String folderName = AdtUtils.getParentFolderName(getEditor().getEditorInput());
+ if (folderName.length() > 0) {
+ return ResourceFolderType.getFolderType(folderName);
}
return ResourceFolderType.ANIMATOR;
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorEditorDelegate.java
index 2398486..53edea9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorEditorDelegate.java
@@ -24,7 +24,6 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescripto
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceFolderType;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -41,7 +40,6 @@ public class ColorEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public ColorEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.COLOR == type) {
return new ColorEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java
index 7c454fb..a664800 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java
@@ -28,7 +28,7 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.part.FileEditorInput;
import org.w3c.dom.Document;
@@ -59,14 +59,12 @@ public abstract class CommonXmlDelegate {
* based on its resource path (e.g. ResourceManager#getResourceFolder).
*
* @param delegator The non-null instance of {@link CommonXmlEditor}.
- * @param input A non-null input file.
* @param type The {@link ResourceFolderType} of the folder containing the file,
* if it can be determined. Null otherwise.
* @return A new delegate that can handle that file or null.
*/
public @Nullable <T extends CommonXmlDelegate> T createForFile(
@NonNull CommonXmlEditor delegator,
- @NonNull IFileEditorInput input,
@Nullable ResourceFolderType type);
}
@@ -132,7 +130,11 @@ public abstract class CommonXmlDelegate {
if (input instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput) input;
IFile file = fileInput.getFile();
- getEditor().setPartName(String.format("%1$s", file.getName()));
+ getEditor().setPartName(file.getName());
+ } else if (input instanceof IURIEditorInput) {
+ IURIEditorInput uriInput = (IURIEditorInput) input;
+ String name = uriInput.getName();
+ getEditor().setPartName(name);
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java
index 3ddc115..5481456 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java
@@ -19,6 +19,7 @@ package com.android.ide.eclipse.adt.internal.editors.common;
import com.android.ide.common.resources.ResourceFolder;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
+import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.animator.AnimationEditorDelegate;
import com.android.ide.eclipse.adt.internal.editors.color.ColorEditorDelegate;
@@ -44,6 +45,7 @@ import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IShowEditorInput;
+import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.w3c.dom.Document;
@@ -135,7 +137,7 @@ public class CommonXmlEditor extends AndroidXmlEditor implements IShowEditorInpu
ResourceFolderType type = resFolder == null ? null : resFolder.getType();
for (IDelegateCreator creator : DELEGATES) {
- mDelegate = creator.createForFile(this, fileInput, type);
+ mDelegate = creator.createForFile(this, type);
if (mDelegate != null) {
break;
}
@@ -151,12 +153,39 @@ public class CommonXmlEditor extends AndroidXmlEditor implements IShowEditorInpu
type);
mDelegate = new OtherXmlEditorDelegate(this);
}
+ } else if (editorInput instanceof IURIEditorInput) {
+ String folderName = AdtUtils.getParentFolderName(editorInput);
+ ResourceFolderType type = ResourceFolderType.getFolderType(folderName);
+ if (type == ResourceFolderType.LAYOUT) {
+ // The layout editor has a lot of hardcoded requirements for real IFiles
+ // and IProjects so for now just use a plain XML editor for project-less layout
+ // files
+ mDelegate = new OtherXmlEditorDelegate(this);
+ } else {
+ for (IDelegateCreator creator : DELEGATES) {
+ mDelegate = creator.createForFile(this, type);
+ if (mDelegate != null) {
+ break;
+ }
+ }
+ }
+
+ if (mDelegate == null) {
+ // We didn't find any editor.
+ // We'll use the OtherXmlEditorDelegate as a catch-all editor.
+ AdtPlugin.log(IStatus.INFO,
+ "No valid Android XML Editor Delegate found for file %1$s [Res %2$s, type %3$s]",
+ ((IURIEditorInput) editorInput).getURI().toString(),
+ folderName,
+ type);
+ mDelegate = new OtherXmlEditorDelegate(this);
+ }
}
if (mDelegate == null) {
// We can't do anything if we don't have a valid file.
AdtPlugin.log(IStatus.INFO,
- "Android XML Editor cannot process non-file input %1$s" + //$NON-NLS-1$
+ "Android XML Editor cannot process non-file input %1$s", //$NON-NLS-1$
(editorInput == null ? "null" : editorInput.toString())); //$NON-NLS-1$
throw new PartInitException("Android XML Editor cannot process this input.");
} else {
@@ -292,7 +321,7 @@ public class CommonXmlEditor extends AndroidXmlEditor implements IShowEditorInpu
@Override
protected Job runLint() {
- if (mDelegate != null) {
+ if (mDelegate != null && getEditorInput() instanceof IFileEditorInput) {
return mDelegate.delegateRunLint();
}
return null;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableEditorDelegate.java
index d5234bd..69d82bd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableEditorDelegate.java
@@ -25,7 +25,6 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescripto
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceFolderType;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -42,7 +41,6 @@ public class DrawableEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public DrawableEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.DRAWABLE == type) {
return new DrawableEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
index 8d02bda..9c7189b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java
@@ -82,7 +82,6 @@ public class LayoutEditorDelegate extends CommonXmlDelegate
@SuppressWarnings("unchecked")
public LayoutEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.LAYOUT == type) {
return new LayoutEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
index 970a5a8..8f950b9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
@@ -461,7 +461,9 @@ public class LayoutActionBar extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
IFile file = mEditor.getEditorDelegate().getEditor().getInputFile();
- EclipseLintClient.showErrors(getShell(), file);
+ if (file != null) {
+ EclipseLintClient.showErrors(getShell(), file);
+ }
}
});
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
index b097743..e45803a 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
@@ -615,7 +615,10 @@ public class LayoutCanvas extends Canvas {
// Clear the zoom setting if it is almost identical to 1.0
String zoomValue = (Math.abs(scale - 1.0) < 0.0001) ? null : Double.toString(scale);
- AdtPlugin.setFileProperty(mEditorDelegate.getEditor().getInputFile(), NAME_ZOOM, zoomValue);
+ IFile file = mEditorDelegate.getEditor().getInputFile();
+ if (file != null) {
+ AdtPlugin.setFileProperty(file, NAME_ZOOM, zoomValue);
+ }
}
/**
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java
index 5f7222f..27c03d0 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoring.java
@@ -223,6 +223,9 @@ public class ChangeLayoutRefactoring extends VisualRefactoring {
IFile file = mDelegate.getEditor().getInputFile();
List<Change> changes = new ArrayList<Change>();
+ if (file == null) {
+ return changes;
+ }
TextFileChange change = new TextFileChange(file.getName(), file);
MultiTextEdit rootEdit = new MultiTextEdit();
change.setTextType(EXT_XML);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java
index 6e451be..b686aac 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeViewRefactoring.java
@@ -155,6 +155,9 @@ public class ChangeViewRefactoring extends VisualRefactoring {
IFile file = mDelegate.getEditor().getInputFile();
List<Change> changes = new ArrayList<Change>();
+ if (file == null) {
+ return changes;
+ }
TextFileChange change = new TextFileChange(file.getName(), file);
MultiTextEdit rootEdit = new MultiTextEdit();
change.setEdit(rootEdit);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java
index 70025cf..3b78f60 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractIncludeRefactoring.java
@@ -238,6 +238,9 @@ public class ExtractIncludeRefactoring extends VisualRefactoring {
String newFileName = mLayoutName + DOT_XML;
IProject project = mDelegate.getEditor().getProject();
IFile sourceFile = mDelegate.getEditor().getInputFile();
+ if (sourceFile == null) {
+ return changes;
+ }
// Replace extracted elements by <include> tag
handleIncludingFile(changes, sourceFile, mSelectionStart, mSelectionEnd,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java
index 8d1f7cb..48cb55b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ExtractStyleRefactoring.java
@@ -370,6 +370,9 @@ public class ExtractStyleRefactoring extends VisualRefactoring {
if (rootEdit.hasChildren()) {
IFile sourceFile = mDelegate.getEditor().getInputFile();
+ if (sourceFile == null) {
+ return changes;
+ }
TextFileChange change = new TextFileChange(sourceFile.getName(), sourceFile);
change.setTextType(EXT_XML);
changes.add(change);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
index 97cf3ec..51360e8 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringAssistant.java
@@ -87,6 +87,9 @@ public class RefactoringAssistant implements IQuickAssistProcessor {
}
IFile file = xmlEditor.getInputFile();
+ if (file == null) {
+ return null;
+ }
int offset = invocationContext.getOffset();
// Ensure that we are over a tag name (for element-based refactoring
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java
index 62b4fd7..039968d 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UnwrapRefactoring.java
@@ -175,6 +175,9 @@ public class UnwrapRefactoring extends VisualRefactoring {
IFile file = mDelegate.getEditor().getInputFile();
List<Change> changes = new ArrayList<Change>();
+ if (file == null) {
+ return changes;
+ }
MultiTextEdit rootEdit = new MultiTextEdit();
// Transfer namespace elements?
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java
index aeea328..0480cda 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/UseCompoundDrawableRefactoring.java
@@ -192,6 +192,9 @@ public class UseCompoundDrawableRefactoring extends VisualRefactoring {
String androidNsPrefix = getAndroidNamespacePrefix();
IFile file = mDelegate.getEditor().getInputFile();
List<Change> changes = new ArrayList<Change>();
+ if (file == null) {
+ return changes;
+ }
TextFileChange change = new TextFileChange(file.getName(), file);
MultiTextEdit rootEdit = new MultiTextEdit();
change.setTextType(EXT_XML);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java
index 23a4987..8e4f447 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/WrapInRefactoring.java
@@ -202,6 +202,9 @@ public class WrapInRefactoring extends VisualRefactoring {
IFile file = mDelegate.getEditor().getInputFile();
List<Change> changes = new ArrayList<Change>();
+ if (file == null) {
+ return changes;
+ }
TextFileChange change = new TextFileChange(file.getName(), file);
MultiTextEdit rootEdit = new MultiTextEdit();
change.setTextType(EXT_XML);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
index e36d988..a8ebe75 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
@@ -453,7 +453,7 @@ public final class ManifestEditor extends AndroidXmlEditor {
Node node = usesPermission.createXmlNode();
if (show && !shown) {
shown = true;
- if (node instanceof IndexedRegion) {
+ if (node instanceof IndexedRegion && getInputFile() != null) {
IndexedRegion indexedRegion = (IndexedRegion) node;
IRegion region = new Region(indexedRegion.getStartOffset(),
indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/MenuEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/MenuEditorDelegate.java
index a55d6e4..faca295 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/MenuEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/menu/MenuEditorDelegate.java
@@ -26,7 +26,6 @@ import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceFolderType;
import com.android.sdklib.xml.AndroidXPathFactory;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -45,7 +44,6 @@ public class MenuEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public MenuEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.MENU == type) {
return new MenuEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/OtherXmlEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/OtherXmlEditorDelegate.java
index f6e23de..138ff95 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/OtherXmlEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/otherxml/OtherXmlEditorDelegate.java
@@ -24,7 +24,6 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.DocumentDescript
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceFolderType;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.w3c.dom.Document;
@@ -38,7 +37,6 @@ public class OtherXmlEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public OtherXmlEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.XML == type) {
return new OtherXmlEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesEditorDelegate.java
index 6198fcd..f253b30 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesEditorDelegate.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/ValuesEditorDelegate.java
@@ -26,7 +26,6 @@ import com.android.resources.ResourceFolderType;
import com.android.sdklib.xml.AndroidXPathFactory;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -45,7 +44,6 @@ public class ValuesEditorDelegate extends CommonXmlDelegate {
@SuppressWarnings("unchecked")
public ValuesEditorDelegate createForFile(
CommonXmlEditor delegator,
- IFileEditorInput input,
ResourceFolderType type) {
if (ResourceFolderType.VALUES == type) {
return new ValuesEditorDelegate(delegator);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
index 7669ae4..478a07c 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/lint/LintFixGenerator.java
@@ -164,6 +164,9 @@ public class LintFixGenerator implements IMarkerResolutionGenerator2, IQuickAssi
AndroidXmlEditor editor = AndroidXmlEditor.fromTextViewer(sourceViewer);
if (editor != null) {
IFile file = editor.getInputFile();
+ if (file == null) {
+ return null;
+ }
IDocument document = sourceViewer.getDocument();
List<IMarker> markers = AdtUtils.findMarkersOnLine(AdtConstants.MARKER_LINT,
file, document, invocationContext.getOffset());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/CyclicDependencyValidator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/CyclicDependencyValidator.java
index 911cf3a..a2b13c6 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/CyclicDependencyValidator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/CyclicDependencyValidator.java
@@ -15,6 +15,7 @@
*/
package com.android.ide.eclipse.adt.internal.resources;
+import com.android.annotations.Nullable;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.IncludeFinder;
import org.eclipse.core.resources.IFile;
@@ -49,7 +50,12 @@ public class CyclicDependencyValidator implements IInputValidator {
* @return a validator which checks whether resource ids are valid or whether they
* could result in a cyclic dependency
*/
- public static IInputValidator create(IFile file) {
+ @Nullable
+ public static IInputValidator create(@Nullable IFile file) {
+ if (file == null) {
+ return null;
+ }
+
IProject project = file.getProject();
IncludeFinder includeFinder = IncludeFinder.get(project);
final Collection<String> invalid =