use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.
the class BuckGotoProvider method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
if (source != null && source.getLanguage() instanceof BuckLanguage) {
// The parent type of the element must be BuckValue.
BuckValue value = PsiTreeUtil.getParentOfType(source, BuckValue.class);
if (value == null) {
return null;
}
final Project project = editor.getProject();
if (project == null) {
return null;
}
String target = source.getText();
if ((target.startsWith("'") && target.endsWith("'")) || (target.startsWith("\"") && target.endsWith("\""))) {
target = target.substring(1, target.length() - 1);
}
VirtualFile targetFile = // Try to find the BUCK file
Optional.fromNullable(BuckBuildUtil.getBuckFileFromAbsoluteTarget(project, target)).or(Optional.fromNullable(source.getContainingFile().getParent().getVirtualFile().findFileByRelativePath(target))).orNull();
if (targetFile == null) {
return null;
}
project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
return PsiManager.getInstance(project).findFile(targetFile);
}
return null;
}
use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.
the class BuckToolWindowFactory method handleClickOnError.
private void handleClickOnError(BuckTreeNodeDetailError node) {
TreeNode parentNode = node.getParent();
if (parentNode instanceof BuckTreeNodeFileError) {
BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
DataContext dataContext = DataManager.getInstance().getDataContext();
Project project = DataKeys.PROJECT.getData(dataContext);
String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
openFileDescriptor.navigate(true);
}
}
use of com.intellij.openapi.vfs.VirtualFile in project buck by facebook.
the class BuckCopyPasteProcessor method referenceNameToBuckFile.
private VirtualFile referenceNameToBuckFile(Project project, String reference) {
// First test if it is a absolute path of a file.
File tryFile = new File(reference);
if (tryFile != null) {
VirtualFile file = VfsUtil.findFileByIoFile(tryFile, true);
if (file != null) {
return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
}
}
// Try class firstly.
PsiClass classElement = JavaPsiFacade.getInstance(project).findClass(reference, GlobalSearchScope.allScope(project));
if (classElement != null) {
VirtualFile file = PsiUtilCore.getVirtualFile(classElement);
return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
}
// Then try package.
PsiPackage packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
if (packageElement != null) {
PsiDirectory directory = packageElement.getDirectories()[0];
return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
}
// Extract the package from the reference.
int index = reference.lastIndexOf(".");
if (index == -1) {
return null;
}
reference = reference.substring(0, index);
// Try to find the package again.
packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
if (packageElement != null) {
PsiDirectory directory = packageElement.getDirectories()[0];
return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
}
return null;
}
use of com.intellij.openapi.vfs.VirtualFile in project qi4j-sdk by Qi4j.
the class AbstractIntention method isFileReadOnly.
protected static boolean isFileReadOnly(@NotNull Project project, @NotNull PsiFile file) {
VirtualFile virtualFile = file.getVirtualFile();
ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
ReadonlyStatusHandler.OperationStatus operationStatus = readonlyStatusHandler.ensureFilesWritable(virtualFile);
return operationStatus.hasReadonlyFiles();
}
use of com.intellij.openapi.vfs.VirtualFile in project android-selector-chapek by inmite.
the class SelectorChapekAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Log.d("---- Start - menu item clicked ----");
VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (isCorrectFolderSelected(selectedFile)) {
new SelectorDetector(e.getProject()).detectAndCreateSelectors(selectedFile);
showInfoDialog("Selectors were generated into 'drawable' folder", e);
} else {
if (selectedFile != null) {
showErrorDialog("You need to select folder with image resources, for example 'drawables-xhdpi' " + "" + selectedFile.getName(), e);
}
}
}
Aggregations