mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
file path completion on class name (ctrl+alt+space)
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceOwner;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
public class ConvertAbsolutePathToRelativeIntentionAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
protected boolean isConvertToRelative() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
|
||||
if (element == null) return false;
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile == null) return false;
|
||||
|
||||
final PsiReference reference = containingFile.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
final FileReference fileReference = reference == null ? null : findFileReference(reference);
|
||||
|
||||
if (fileReference != null) {
|
||||
final FileReferenceSet set = fileReference.getFileReferenceSet();
|
||||
final FileReference lastReference = set.getLastReference();
|
||||
return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null &&
|
||||
(!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) &&
|
||||
lastReference.resolve() != null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static FileReference findFileReference(@NotNull final PsiReference original) {
|
||||
if (original instanceof PsiMultiReference) {
|
||||
final PsiMultiReference multiReference = (PsiMultiReference)original;
|
||||
for (PsiReference reference : multiReference.getReferences()) {
|
||||
if (reference instanceof FileReference) {
|
||||
return (FileReference)reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (original instanceof FileReferenceOwner) {
|
||||
final FileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
|
||||
if (fileReference != null) {
|
||||
return fileReference;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return "Convert " + (isConvertToRelative() ? "absolute" : "relative") + " path to " + (isConvertToRelative() ? "relative" : "absolute");
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
final FileReference fileReference = reference == null ? null : findFileReference(reference);
|
||||
if (fileReference != null) {
|
||||
final FileReference lastReference = fileReference.getFileReferenceSet().getLastReference();
|
||||
if (lastReference != null) lastReference.bindToElement(lastReference.resolve(), !isConvertToRelative());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Convert path to " + (isConvertToRelative() ? "relative" : "absolute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
public class ConvertRelativePathToAbsoluteIntentionAction extends ConvertAbsolutePathToRelativeIntentionAction {
|
||||
|
||||
@Override
|
||||
protected boolean isConvertToRelative() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+11
@@ -45,6 +45,17 @@ public class FilePathReferenceProvider extends PsiReferenceProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeConvertedTo(boolean relative) {
|
||||
return !relative;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean absoluteUrlNeedsStartSlash() {
|
||||
final String s = getPathString();
|
||||
return s != null && s.length() > 0 && s.charAt(0) == '/';
|
||||
}
|
||||
|
||||
@NotNull public Collection<PsiFileSystemItem> computeDefaultContexts() {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(getElement());
|
||||
return getRoots(module, true);
|
||||
|
||||
@@ -28,8 +28,12 @@ import java.util.EventListener;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* // TODO: merge with FileReferenceHelper & drop
|
||||
*
|
||||
* @author spleaner
|
||||
* @deprecated Use FileReferenceHelper instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class LogicalRootsManager {
|
||||
|
||||
public static LogicalRootsManager getLogicalRootsManager(@NotNull final Project project) {
|
||||
@@ -54,7 +58,7 @@ public abstract class LogicalRootsManager {
|
||||
|
||||
public abstract <T extends LogicalRoot> void registerLogicalRootProvider(@NotNull final LogicalRootType<T> rootType, @NotNull NotNullFunction<Module,List<T>> provider);
|
||||
|
||||
public static interface LogicalRootListener extends EventListener {
|
||||
public interface LogicalRootListener extends EventListener {
|
||||
void logicalRootsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
+99
-87
@@ -27,29 +27,31 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileInfoManager;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceOwner;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileSystemItemUtil;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.*;
|
||||
import com.intellij.psi.search.FilenameIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
@@ -62,11 +64,6 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull CompletionResultSet result) {
|
||||
final String prefix = result.getPrefixMatcher().getPrefix();
|
||||
if (prefix.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiReference psiReference = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
|
||||
if (getReference(psiReference) != null) {
|
||||
final String shortcut = getActionShortcut(IdeActions.ACTION_CLASS_NAME_COMPLETION);
|
||||
@@ -83,96 +80,108 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
protected void addCompletions(@NotNull final CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull final CompletionResultSet _result) {
|
||||
final String prefix = _result.getPrefixMatcher().getPrefix();
|
||||
if (prefix.length() == 0) { // todo[spL]: no prefix no completion
|
||||
return;
|
||||
}
|
||||
|
||||
@NotNull final CompletionResultSet result = _result.caseInsensitive();
|
||||
|
||||
final PsiElement e = parameters.getPosition();
|
||||
|
||||
final Project project = e.getProject();
|
||||
|
||||
final PsiReference psiReference = ApplicationManager.getApplication().runReadAction(new Computable<PsiReference>() {
|
||||
public PsiReference compute() {
|
||||
//noinspection ConstantConditions
|
||||
return parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
|
||||
return parameters.getPosition().getContainingFile().getOriginalFile().findReferenceAt(parameters.getOffset());
|
||||
}
|
||||
});
|
||||
|
||||
if (getReference(psiReference) != null) {
|
||||
final Project project = e.getProject();
|
||||
final String[] fileNames = getAllNames(project);
|
||||
final List<String> resultNames = new ArrayList<String>();
|
||||
for (String fileName : fileNames) {
|
||||
if (StringUtil.startsWithIgnoreCase(fileName, prefix)) {
|
||||
resultNames.add(fileName);
|
||||
}
|
||||
final Pair<FileReference, Boolean> fileReferencePair = getReference(psiReference);
|
||||
if (fileReferencePair != null) {
|
||||
final FileReference first = fileReferencePair.getFirst();
|
||||
if (first == null) return;
|
||||
|
||||
final FileReferenceSet set = first.getFileReferenceSet();
|
||||
String prefix = set.getPathString();
|
||||
|
||||
final List<String>[] pathPrefixParts = new List[] {null};
|
||||
int lastSlashIndex;
|
||||
if ((lastSlashIndex = prefix.lastIndexOf('/')) != -1) {
|
||||
pathPrefixParts[0] = StringUtil.split(prefix.substring(0, lastSlashIndex), "/");
|
||||
prefix = prefix.substring(lastSlashIndex + 1);
|
||||
}
|
||||
|
||||
final LogicalRootsManager logicalRootsManager = LogicalRootsManager.getLogicalRootsManager(project);
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
|
||||
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
|
||||
final VirtualFile contextFile = parameters.getOriginalFile().getVirtualFile();
|
||||
final PsiFile originalFile = parameters.getOriginalFile();
|
||||
final VirtualFile contextFile = originalFile.getVirtualFile();
|
||||
if (contextFile != null) {
|
||||
final String[] fileNames = getAllNames(project);
|
||||
final Set<String> resultNames = new TreeSet<String>();
|
||||
for (String fileName : fileNames) {
|
||||
if (prefix.length() == 0 || StringUtil.startsWithIgnoreCase(fileName, prefix)) {
|
||||
resultNames.add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
|
||||
final Module contextModule = index.getModuleForFile(contextFile);
|
||||
if (contextModule != null) {
|
||||
final Module[] dependencies = ModuleRootManager.getInstance(contextModule).getDependencies();
|
||||
final FileReferenceHelper contextHelper = FileReferenceHelperRegistrar.getNotNullHelper(originalFile);
|
||||
|
||||
final Set<Module> modules = new HashSet<Module>(dependencies.length + 1);
|
||||
modules.addAll(Arrays.asList(dependencies));
|
||||
modules.add(contextModule);
|
||||
final GlobalSearchScope scope = ProjectScope.getProjectScope(project);
|
||||
for (final String name : resultNames) {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
final LogicalRoot contextRoot = logicalRootsManager.findLogicalRoot(contextFile);
|
||||
if (contextRoot != null) {
|
||||
final VirtualFile contextRootFile = contextRoot.getVirtualFile();
|
||||
final LogicalRootType contextRootType = contextRoot.getType();
|
||||
final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {
|
||||
public PsiFile[] compute() {
|
||||
return FilenameIndex.getFilesByName(project, name, scope);
|
||||
}
|
||||
});
|
||||
|
||||
final GlobalSearchScope scope = ProjectScope.getProjectScope(project);
|
||||
for (final String name : resultNames) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (files.length > 0) {
|
||||
for (final PsiFile file : files) {
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
final PsiFile[] files = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile[]>() {
|
||||
public PsiFile[] compute() {
|
||||
return FilenameIndex.getFilesByName(project, name, scope);
|
||||
}
|
||||
});
|
||||
|
||||
if (files.length > 0) {
|
||||
for (final PsiFile file : files) {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null && virtualFile.isValid()) {
|
||||
final Module module = index.getModuleForFile(virtualFile);
|
||||
if (modules.contains(module)) {
|
||||
final LogicalRoot logicalRoot = logicalRootsManager.findLogicalRoot(virtualFile);
|
||||
if (logicalRoot != null && contextRootType == logicalRoot.getType()) {
|
||||
final VirtualFile _context = contextRoot == logicalRoot ? contextRootFile : project.getBaseDir();
|
||||
if (_context != null) {
|
||||
final PsiDirectory psiFile = psiManager.findDirectory(_context);
|
||||
if (psiFile != null) {
|
||||
result.addElement(new FilePathLookupItem(file, psiFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) {
|
||||
if (contextHelper.isMine(project, virtualFile)) {
|
||||
if (pathPrefixParts[0] == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts[0])) {
|
||||
result.addElement(new FilePathLookupItem(file, contextHelper));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileReferencePair.getSecond()) result.stopHere();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean fileMatchesPathPrefix(@Nullable final PsiFileSystemItem file, @NotNull final List<String> pathPrefix) {
|
||||
if (file == null) return false;
|
||||
|
||||
final List<String> contextParts = new ArrayList<String>();
|
||||
PsiFileSystemItem parentFile = file;
|
||||
PsiFileSystemItem parent;
|
||||
while ((parent = parentFile.getParent()) != null) {
|
||||
if (parent.getName().length() > 0) contextParts.add(0, parent.getName().toLowerCase());
|
||||
parentFile = parent;
|
||||
}
|
||||
|
||||
final String path = StringUtil.join(contextParts, "/");
|
||||
|
||||
int nextIndex = 0;
|
||||
for (final String s : pathPrefix) {
|
||||
if ((nextIndex = path.indexOf(s.toLowerCase(), nextIndex)) == -1) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String[] getAllNames(@NotNull final Project project) {
|
||||
Set<String> names = new HashSet<String>();
|
||||
final ChooseByNameContributor[] nameContributors = ChooseByNameContributor.FILE_EP_NAME.getExtensions();
|
||||
@@ -196,7 +205,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiReference getReference(final PsiReference original) {
|
||||
private static Pair<FileReference, Boolean> getReference(final PsiReference original) {
|
||||
if (original == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -205,14 +214,14 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
final PsiMultiReference multiReference = (PsiMultiReference)original;
|
||||
for (PsiReference reference : multiReference.getReferences()) {
|
||||
if (reference instanceof FileReference) {
|
||||
return reference;
|
||||
return Pair.create((FileReference) reference, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (original instanceof FileReferenceOwner) {
|
||||
final FileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
|
||||
if (fileReference != null) {
|
||||
return fileReference;
|
||||
return Pair.create(fileReference, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,20 +229,18 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
public class FilePathLookupItem extends LookupElement {
|
||||
private final String myRelativePath;
|
||||
private final String myName;
|
||||
private final String myPath;
|
||||
private final String myInfo;
|
||||
private final Icon myIcon;
|
||||
private final PsiFile myFile;
|
||||
private FileReferenceHelper myReferenceHelper;
|
||||
|
||||
public FilePathLookupItem(@NotNull final PsiFile file, @NotNull final PsiFileSystemItem context) {
|
||||
public FilePathLookupItem(@NotNull final PsiFile file, @NotNull final FileReferenceHelper referenceHelper) {
|
||||
myName = file.getName();
|
||||
myPath = file.getVirtualFile().getPath();
|
||||
|
||||
final String relative = PsiFileSystemItemUtil.getRelativePath(context, file);
|
||||
|
||||
myRelativePath = relative == null ? null : relative.equals(myName) ? null : relative;
|
||||
myReferenceHelper = referenceHelper;
|
||||
|
||||
myInfo = FileInfoManager.getFileAdditionalInfo(file);
|
||||
myIcon = file.getFileType().getIcon();
|
||||
@@ -244,14 +251,14 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s (%s, %s)", myName, myInfo == null ? "" : myInfo, myRelativePath == null ? "" : myRelativePath);
|
||||
return String.format("%s (%s, %s)", myName, myInfo == null ? "" : myInfo, myPath == null ? "" : myPath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return myFile;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLookupString() {
|
||||
@@ -262,21 +269,26 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
public void handleInsert(InsertionContext context) {
|
||||
if (myFile.isValid()) {
|
||||
final PsiReference psiReference = context.getFile().findReferenceAt(context.getStartOffset());
|
||||
final PsiReference fileReference = getReference(psiReference);
|
||||
LOG.assertTrue(fileReference != null);
|
||||
final Pair<FileReference, Boolean> fileReferencePair = getReference(psiReference);
|
||||
LOG.assertTrue(fileReferencePair != null);
|
||||
|
||||
fileReference.bindToElement(myFile);
|
||||
fileReferencePair.getFirst().bindToElement(myFile, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
final VirtualFile virtualFile = myFile.getVirtualFile();
|
||||
LOG.assertTrue(virtualFile != null);
|
||||
final PsiFileSystemItem root = myReferenceHelper.findRoot(myFile.getProject(), virtualFile);
|
||||
final String relativePath = PsiFileSystemItemUtil.getRelativePath(root, myReferenceHelper.getPsiFileSystemItem(myFile.getProject(), virtualFile));
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
if (myInfo != null) {
|
||||
sb.append(" (").append(myInfo);
|
||||
}
|
||||
|
||||
if (myRelativePath != null) {
|
||||
if (relativePath != null && !relativePath.equals(myName)) {
|
||||
if (myInfo != null) {
|
||||
sb.append(", ");
|
||||
}
|
||||
@@ -284,7 +296,7 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
sb.append(" (");
|
||||
}
|
||||
|
||||
sb.append(myRelativePath);
|
||||
sb.append(relativePath);
|
||||
}
|
||||
|
||||
if (sb.length() > 0) {
|
||||
|
||||
+8
-6
@@ -336,9 +336,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
throw new IncorrectOperationException("Manipulator for this element is not defined: " + getElement());
|
||||
}
|
||||
|
||||
/* Happens when it's been moved to another folder */
|
||||
public PsiElement bindToElement(@NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
|
||||
public PsiElement bindToElement(@NotNull final PsiElement element, final boolean absolute) throws IncorrectOperationException {
|
||||
if (!(element instanceof PsiFileSystemItem)) throw new IncorrectOperationException("Cannot bind to element, should be instanceof PsiFileSystemItem: " + element);
|
||||
|
||||
final PsiFileSystemItem fileSystemItem = (PsiFileSystemItem)element;
|
||||
@@ -354,8 +352,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
|
||||
String newName;
|
||||
|
||||
if (myFileReferenceSet.isAbsolutePathReference()) {
|
||||
boolean hasSlash = myFileReferenceSet.getPathString().startsWith("/");
|
||||
if (absolute) {
|
||||
PsiFileSystemItem root = null;
|
||||
PsiFileSystemItem dstItem = null;
|
||||
for (final FileReferenceHelper helper : FileReferenceHelperRegistrar.getHelpers()) {
|
||||
@@ -375,7 +372,7 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
if (relativePath == null) {
|
||||
return element;
|
||||
}
|
||||
newName = hasSlash ? "/" + relativePath : relativePath ;
|
||||
newName = myFileReferenceSet.absoluteUrlNeedsStartSlash() ? "/" + relativePath : relativePath ;
|
||||
|
||||
} else { // relative path
|
||||
PsiFileSystemItem curItem = null;
|
||||
@@ -427,6 +424,11 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
return rename(newName);
|
||||
}
|
||||
|
||||
/* Happens when it's been moved to another folder */
|
||||
public PsiElement bindToElement(@NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
return bindToElement(element, myFileReferenceSet.isAbsolutePathReference());
|
||||
}
|
||||
|
||||
protected PsiElement rename(final String newName) throws IncorrectOperationException {
|
||||
final TextRange range = new TextRange(myFileReferenceSet.getStartInElement(), getRangeInElement().getEndOffset());
|
||||
final ElementManipulator<PsiElement> manipulator = CachingReference.getManipulator(getElement());
|
||||
|
||||
+11
-3
@@ -17,18 +17,18 @@
|
||||
package com.intellij.psi.impl.source.resolve.reference.impl.providers;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -364,4 +364,12 @@ public class FileReferenceSet {
|
||||
}
|
||||
myOptions.put(key, value);
|
||||
}
|
||||
|
||||
public boolean couldBeConvertedTo(final boolean relative) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean absoluteUrlNeedsStartSlash() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,7 +442,8 @@ i18nize.empty.file.path=Please specify properties file path
|
||||
choose.type.popup.title=Choose Type
|
||||
cast.expression=Cast expression
|
||||
cast.to.0=Cast to ''{0}''
|
||||
class.completion.file.path=Press {0} to search for all project files
|
||||
class.completion.file.path=Press {0} to search for all matching project files
|
||||
class.completion.absolute.path=Press / to insert absolute path
|
||||
property.has.more.parameters.than.passed=Property ''{0}'' expected {1} {1, choice, 1#parameter|2#parameters}, passed {2}
|
||||
create.file.family=Create File
|
||||
rename.file.reference.family=Rename File Reference
|
||||
|
||||
@@ -342,7 +342,7 @@
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.ComboEditorCompletionContributor" id="comboEditor" order="first"/>
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.WordCompletionContributor" id="wordCompletion" order="last"/>
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.LegacyCompletionContributor" id="legacy" order="last"/>
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.FilePathCompletionContributor" id="filePath" order="last"/>
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.FilePathCompletionContributor" id="filePath" order="before default"/>
|
||||
|
||||
<lookup.charFilter implementation="com.intellij.codeInsight.completion.CompletionCharFilter" order="last" id="completion"/>
|
||||
<lookup.charFilter implementation="com.intellij.refactoring.IdentifierCharFilter" id="identifier"/>
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="<spot>section1.xml</spot>"/>
|
||||
</book>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="<spot>/org/jetbrains/section1.xml</spot>"/>
|
||||
</book>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<font face="verdana" size="-1">This intention converts absolute path to relative (if applicable).</font>
|
||||
</body>
|
||||
</html>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="<spot>/org/jetbrains/section1.xml</spot>"/>
|
||||
</book>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="<spot>section1.xml</spot>"/>
|
||||
</book>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<font face="verdana" size="-1">This intention converts relative path to absolute (if applicable).</font>
|
||||
</body>
|
||||
</html>
|
||||
@@ -540,6 +540,16 @@
|
||||
<category>Declaration</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.intention.impl.ConvertAbsolutePathToRelativeIntentionAction</className>
|
||||
<category>Other</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.intention.impl.ConvertRelativePathToAbsoluteIntentionAction</className>
|
||||
<category>Other</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>com.intellij.testIntegration.createTest.CreateTestAction</className>
|
||||
</intentionAction>
|
||||
|
||||
Reference in New Issue
Block a user