Skip to content

Commit

Permalink
Merge pull request #485 from magento/fixed-null-pointer-copy-path
Browse files Browse the repository at this point in the history
Fixed null pointer on the copy path action
  • Loading branch information
eduard13 authored Feb 12, 2021
2 parents 39381dc + c8c3611 commit 8fc2a8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).

## 3.1.1

### Fixed

- Fixed null pointer exception on the copy path action

## 3.1.0

### Added
Expand Down
21 changes: 17 additions & 4 deletions src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import org.jetbrains.annotations.NotNull;
Expand All @@ -30,7 +31,8 @@ public class CopyMagentoPath extends CopyPathProvider {
@Override
public void update(@NotNull final AnActionEvent event) {
final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
if (virtualFile != null && virtualFile.isDirectory()) {
if (virtualFile != null && virtualFile.isDirectory()
|| virtualFile != null && !PHTML.equals(virtualFile.getExtension())) {
event.getPresentation().setVisible(false);
}
}
Expand All @@ -42,11 +44,22 @@ public String getPathToElement(
@Nullable final VirtualFile virtualFile,
@Nullable final Editor editor
) {
final PsiDirectory directory
= PsiManager.getInstance(project).findFile(virtualFile).getContainingDirectory();
if (virtualFile == null) {
return null;
}
final PsiFile file
= PsiManager.getInstance(project).findFile(virtualFile);
if (file == null) {
return null;
}
final PsiDirectory directory = file.getContainingDirectory();
final String moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
if (moduleName == null) {
return null;
}
final StringBuilder fullPath = new StringBuilder(virtualFile.getPath());
final StringBuilder magentoPath
= new StringBuilder(GetModuleNameByDirectoryUtil.execute(directory, project));
= new StringBuilder(moduleName);
String path = fullPath.toString();

if (PHTML.equals(virtualFile.getExtension())) {
Expand Down

0 comments on commit 8fc2a8a

Please sign in to comment.