Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getCanonicalPath()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#getCanonicalPath() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Nullable
private OutputInfo addInfo(@NotNull String path, @NotNull String line, @NotNull String colStart, @NotNull String colEnd) {
    OutputInfo info = new OutputInfo();

    VirtualFile fileInError = Platform.findFileByRelativePath(m_project, path);
    if (fileInError == null) {
        return null;
    }

    info.path = fileInError.getCanonicalPath();
    info.lineStart = parseInt(line);
    info.colStart = parseInt(colStart) + 1;
    info.lineEnd = info.lineStart;
    info.colEnd = parseInt(colEnd) + 1;
    if (info.colEnd == info.colStart) {
        info.colEnd += 1;
    }

    m_bsbInfo.add(info);
    return info;
}
 
Example 2
Source Project: consulo   File: PsiFileNode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example 3
@Override
public void actionPerformed(ActionEvent e)
{
    autoDetectDojoSources.setEnabled(false);
    VirtualFile directory = SourcesLocator.getDojoSourcesDirectory(project, false);

    if(directory == null)
    {
        Messages.showInfoMessage("Could not find any dojo sources via auto-detection", "Auto-detect Dojo Sources");
        autoDetectDojoSources.setEnabled(true);
        return;
    }

    dojoSourcesText.setText(directory.getCanonicalPath());
    dojoSourceString = directory.getCanonicalPath();
    autoDetectDojoSources.setEnabled(true);

    updateModifiedState();
}
 
Example 4
public void actionPerformed(AnActionEvent e) {
    if(module == null) {
        return;
    }

    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    final NewStoryboardDialog dialog = new NewStoryboardDialog(e.getProject(), new File(file.getCanonicalPath()));
    dialog.show();
    if(dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        IBIntegratorProxy proxy = IBIntegratorManager.getInstance().getProxy(module);
        if(proxy == null) {
            RoboVmPlugin.logError(e.getProject(), "Couldn't get interface builder integrator for module %s", module.getName());
        } else {
            File resourceDir = new File(file.getCanonicalPath());
            proxy.newIOSStoryboard(dialog.getStoryboardName(), resourceDir);
            VirtualFile vsfFile = VfsUtil.findFileByIoFile(resourceDir, true);
            vsfFile.refresh(false, true);
        }
    }
}
 
Example 5
Source Project: p4ic4idea   File: MockVirtualFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildFile(Object requestor, @NotNull VirtualFile vDir, @NotNull String fileName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(fileName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + fileName);
            }
            MockVirtualFile child = new MockVirtualFile(this, fileName, mvd, "", getDefaultCharset());
            mvd.markChild(child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, fileName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    } else if (vDir instanceof IOVirtualFile) {
        return new IOVirtualFile(new File(((IOVirtualFile) vDir).getIOFile(), fileName), false);
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example 6
Source Project: p4ic4idea   File: MockVirtualFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile vDir, @NotNull String dirName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(dirName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + dirName);
            }
            MockVirtualFile child = new MockVirtualFile(this, dirName, mvd);
            mvd.markChild(child);
            registeredFiles.put(child.getPath(), child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, dirName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example 7
Source Project: intellij-haskforce   File: TypeInfoUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getTypeInfo(Module module, VisualPosition blockStart, VisualPosition blockEnd, VirtualFile projectFile) {
    final String canonicalPath = projectFile.getCanonicalPath();
    if (canonicalPath == null){
        return null;
    }
    final String workDir = ExecUtil.guessWorkDir(module);
    if (ToolKey.GHC_MODI_KEY.getPath(module.getProject()) != null) {
        GhcModi ghcModi = module.getComponent(GhcModi.class);
        if (ghcModi != null) {
            return GhcModi.getFutureType(module.getProject(), ghcModi.type(canonicalPath,
                    blockStart, blockEnd));

        } else {
            return null;
        }
    } else {
        return GhcMod.type(module, workDir, canonicalPath, blockStart, blockEnd);
    }
}
 
Example 8
Source Project: idea-gitignore   File: Utils.java    License: MIT License 6 votes vote down vote up
/**
 * Returns all Ignore files in given {@link Project} that can match current passed file.
 *
 * @param project current project
 * @param file    current file
 * @return collection of suitable Ignore files
 */
public static List<VirtualFile> getSuitableIgnoreFiles(@NotNull Project project, @NotNull IgnoreFileType fileType,
                                                       @NotNull VirtualFile file)
        throws ExternalFileException {
    VirtualFile baseDir = getModuleRootForFile(file, project);
    List<VirtualFile> files = new ArrayList<>();
    if (file.getCanonicalPath() == null || baseDir == null ||
            !VfsUtilCore.isAncestor(baseDir, file, true)) {
        throw new ExternalFileException();
    }
    if (!baseDir.equals(file)) {
        do {
            file = file.getParent();
            VirtualFile ignoreFile = file.findChild(fileType.getIgnoreLanguage().getFilename());
            ContainerUtil.addIfNotNull(files, ignoreFile);
        } while (!file.equals(baseDir));
    }
    return files;
}
 
Example 9
private static void applySettings(VirtualFile file) {
    if (file == null || !file.isInLocalFileSystem()) return;
    // Get editorconfig settings
    final String filePath = file.getCanonicalPath();
    final SettingsProviderComponent settingsProvider = SettingsProviderComponent.getInstance();
    final List<EditorConfig.OutPair> outPairs = settingsProvider.getOutPairs(filePath);
    // Apply trailing spaces setting
    final String trimTrailingWhitespace = Utils.configValueForKey(outPairs, trimTrailingWhitespaceKey);
    applyConfigValueToUserData(file, TrailingSpacesStripper.OVERRIDE_STRIP_TRAILING_SPACES_KEY,
                               trimTrailingWhitespaceKey, trimTrailingWhitespace, trimMap);
    // Apply final newline setting
    final String insertFinalNewline = Utils.configValueForKey(outPairs, insertFinalNewlineKey);
    applyConfigValueToUserData(file, TrailingSpacesStripper.OVERRIDE_ENSURE_NEWLINE_KEY,
                               insertFinalNewlineKey, insertFinalNewline, newlineMap);
}
 
Example 10
Source Project: consulo   File: FileChooserDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Defines whether file is visible in the tree
 */
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
  if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) {
    return false;
  }

  if (!file.isDirectory()) {
    if (FileElement.isArchive(file)) {
      if (!myChooseJars && !myChooseJarContents) {
        return false;
      }
    }
    else if (!myChooseFiles) {
      return false;
    }

    if (myFileFilter != null && !myFileFilter.value(file)) {
      return false;
    }
  }

  if (isHideIgnored() && FileTypeManager.getInstance().isFileIgnored(file)) {
    return false;
  }

  if (!showHiddenFiles && FileElement.isFileHidden(file)) {
    return false;
  }

  return true;
}
 
Example 11
Source Project: reasonml-idea-plugin   File: BsCompilerImpl.java    License: MIT License 5 votes vote down vote up
@Nullable
private BsConfig getOrRefreshBsConfig(@NotNull VirtualFile bsConfigFile) {
    String bsConfigPath = bsConfigFile.getCanonicalPath();
    BsConfig bsConfig = m_configs.get(bsConfigPath);
    if (bsConfig == null) {
        refresh(bsConfigFile);
        bsConfig = m_configs.get(bsConfigPath);
    }
    return bsConfig;
}
 
Example 12
@Override
public void onNewConfigurationCreated() {
    super.onNewConfigurationCreated();

    try {
        Project project = getProject();

        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        VirtualFile[] sourceRoots = rootManager.getContentSourceRoots();

        Optional<VirtualFile> webinfFile = Stream.of(sourceRoots).map(VirtualFile::getParent).distinct().flatMap(f ->
                Stream.of(f.getChildren()).filter(c -> {
                    Path path = Paths.get(c.getCanonicalPath(), "WEB-INF");
                    return path.toFile().exists();
                })).distinct().findFirst();


        if (webinfFile.isPresent()) {
            VirtualFile file = webinfFile.get();
            docBase = file.getCanonicalPath();
            moduleName = ModuleUtil.findModuleForFile(file, project).getName();
            contextPath = "/" + moduleName;
        }
    } catch (Exception e) {
        //do nothing.
    }

}
 
Example 13
Source Project: yiistorm   File: CommonHelper.java    License: MIT License 5 votes vote down vote up
public static String getFilePath(PsiFile originalFile) {

        VirtualFile vFile = originalFile.getOriginalFile().getVirtualFile();
        if (vFile != null) {
            String path = vFile.getCanonicalPath();
            if (path != null) {
                return path.replaceAll("(?im)[a-z0-9_]+\\.[a-z]+$", "");
            }
        }
        return "";
    }
 
Example 14
/**
 * Find the canonical path of the directory or file in the list which ends with the paths given
 *
 * @param vFiles files to scan
 * @param paths ending subdirectories
 * @return directory or file, null if no match
 */
private static String findFile(VirtualFile[] vFiles, String... paths) {
    String result = null;
    for (VirtualFile file : vFiles) {
        String filePath = file.getCanonicalPath();
        if (filePath != null && filePath.contains(buildPath(paths))) {
            result = filePath;
            break;
        }
    }
    return result;
}
 
Example 15
@Override
protected void doOKAction() {
    String inputText = inputPanel.getTextPixel();

    if (inputText == null || inputText.isEmpty()) {
        showMessageDialog("输入的内容为空\nText is empty");
        return;
    }

    List<Values> valuesList = parseInputText(inputText);
    if (valuesList == null) {
        return;
    }

    String firstOutput = "";
    VirtualFile baseFile = project.getBaseDir();

    VirtualFile[] childFiles = baseFile.getChildren();

    if (childFiles.length > 0) {
        firstOutput = getOutputPath(childFiles);
        if (firstOutput == null) {
            firstOutput = baseFile.getCanonicalPath();
        }
    } else {
        firstOutput = baseFile.getCanonicalPath();
    }

    int positiveEnd = 1000;
    int negativeEnd = -100;

    try {
        positiveEnd = Integer.valueOf(inputPanel.getPositiveNumber());
        negativeEnd = Integer.valueOf(inputPanel.getNegativeNumber());
    } catch (NumberFormatException ignored) {
    }

    genValuesFiles(valuesList, positiveEnd, negativeEnd, firstOutput);

    super.doOKAction();
}
 
Example 16
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    String elname = element.getClass().getName();
    properties = PropertiesComponent.getInstance(project);
    VirtualFile baseDir = project.getBaseDir();
    projectPath = baseDir.getCanonicalPath();
    if (elname.endsWith("StringLiteralExpressionImpl")) {

        try {
            PsiFile file = element.getContainingFile();
            VirtualFile vfile = file.getVirtualFile();
            if (vfile != null) {
                String path = vfile.getPath();
                String basePath = project.getBasePath();
                if (basePath != null) {

                    String themeName = properties.getValue("themeName");
                    Class elementClass = element.getClass();
                    String protectedPath = YiiRefsHelper.getCurrentProtected(path);
                    path = path.replace(projectPath, "");

                    String viewPathTheme = YiiRefsHelper.getRenderViewPath(path, themeName);
                    String viewPath = YiiRefsHelper.getRenderViewPath(path, null);

                    protectedPath = protectedPath.replace(projectPath, "")
                            .replaceAll("/controllers/[a-zA-Z0-9_]+?.(php|tpl)+", "");

                    Method method = elementClass.getMethod("getValueRange");
                    Object obj = method.invoke(element);
                    TextRange textRange = (TextRange) obj;
                    Class _PhpPsiElement = elementClass.getSuperclass().getSuperclass().getSuperclass();
                    Method phpPsiElementGetText = _PhpPsiElement.getMethod("getText");
                    Object obj2 = phpPsiElementGetText.invoke(element);
                    String str = obj2.toString();
                    String uri = str.substring(textRange.getStartOffset(), textRange.getEndOffset());
                    int start = textRange.getStartOffset();
                    int len = textRange.getLength();
                    String controllerName = YiiRefsHelper.getControllerClassName(path);


                    if (controllerName != null) {
                        if (baseDir != null) {
                            String inThemeFullPath = viewPathTheme + controllerName + "/" + uri
                                    + (uri.endsWith(".tpl") ? "" : ".php");
                            if (baseDir.findFileByRelativePath(inThemeFullPath) != null) {
                                viewPath = viewPathTheme;
                            }
                            VirtualFile appDir = baseDir.findFileByRelativePath(viewPath);
                            VirtualFile protectedPathDir = (!protectedPath.equals("")) ?
                                    baseDir.findFileByRelativePath(protectedPath) : null;
                            if (appDir != null) {
                                PsiReference ref = new ViewsReference(controllerName, uri, element,
                                        new TextRange(start, start + len), project, protectedPathDir, appDir);
                                return new PsiReference[]{ref};
                            }
                        }
                        return PsiReference.EMPTY_ARRAY;
                    }
                }
            }
        } catch (Exception e) {
            System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 17
Source Project: consulo   File: WinPathChooserDialog.java    License: Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public AsyncResult<VirtualFile[]> chooseAsync(@Nullable VirtualFile toSelect) {
  if (toSelect != null && toSelect.getParent() != null) {

    String directoryName;
    String fileName = null;
    if (toSelect.isDirectory()) {
      directoryName = toSelect.getCanonicalPath();
    }
    else {
      directoryName = toSelect.getParent().getCanonicalPath();
      fileName = toSelect.getPath();
    }
    myFileDialog.setDirectory(directoryName);
    myFileDialog.setFile(fileName);
  }


  myFileDialog.setFilenameFilter((dir, name) -> {
    File file = new File(dir, name);
    return myFileChooserDescriptor.isFileSelectable(fileToVirtualFile(file));
  });

  myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple());

  AsyncResult<VirtualFile[]> result = AsyncResult.undefined();
  SwingUtilities.invokeLater(() -> {
    final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null;
    final boolean appStarted = commandProcessor != null;

    if (appStarted) {
      commandProcessor.enterModal();
      LaterInvocator.enterModal(myFileDialog);
    }

    Component parent = myParent.get();
    try {
      myFileDialog.setVisible(true);
    }
    finally {
      if (appStarted) {
        commandProcessor.leaveModal();
        LaterInvocator.leaveModal(myFileDialog);
        if (parent != null) parent.requestFocus();
      }
    }

    File[] files = myFileDialog.getFiles();
    List<VirtualFile> virtualFileList = getChosenFiles(Stream.of(files));
    virtualFiles = virtualFileList.toArray(VirtualFile.EMPTY_ARRAY);

    if (!virtualFileList.isEmpty()) {
      try {
        if (virtualFileList.size() == 1) {
          myFileChooserDescriptor.isFileSelectable(virtualFileList.get(0));
        }
        myFileChooserDescriptor.validateSelectedFiles(virtualFiles);
      }
      catch (Exception e) {
        if (parent == null) {
          Messages.showErrorDialog(myProject, e.getMessage(), myTitle);
        }
        else {
          Messages.showErrorDialog(parent, e.getMessage(), myTitle);
        }

        result.setRejected();
        return;
      }

      if (!ArrayUtil.isEmpty(files)) {
        result.setDone(VfsUtil.toVirtualFileArray(virtualFileList));
      }
      else {
        result.setRejected();
      }
    }
  });
  return result;
}
 
Example 18
@Override
public void onWizardFinished() throws CommitStepException {
    Sdk odk = null;

    if (c_rdSelectExisting.isSelected()) {
        JdkComboBox.JdkComboBoxItem selectedItem = c_selExistingSdk.getSelectedItem();
        odk = selectedItem == null ? null : selectedItem.getJdk();
    } else if (c_rdDownloadSdk.isSelected()) {
        String selectedSdk = (String) c_selDownload.getSelectedItem();
        String sdkHomeValue = PropertiesComponent.getInstance().getValue(SDK_HOME);
        if (sdkHomeValue != null) {
            VirtualFileSystem fileSystem = LocalFileSystem.getInstance();
            VirtualFile sdkHome = fileSystem.findFileByPath(sdkHomeValue);

            if (selectedSdk != null && sdkHome != null) {
                int pos = selectedSdk.lastIndexOf('.');
                String patch = selectedSdk.substring(pos + 1);
                String majorMinor = selectedSdk.substring(0, pos);
                pos = majorMinor.lastIndexOf('.');
                String major = majorMinor.substring(0, pos);
                String minor = majorMinor.substring(pos + 1);

                // Download SDK from distribution site
                LOG.debug("Download SDK", selectedSdk);
                ProgressManager.getInstance().run(SdkDownloader.modalTask(major, minor, patch, sdkHome, m_context.getProject()));

                // Create SDK
                LOG.debug("Create SDK", selectedSdk);
                File targetSdkLocation = new File(sdkHome.getCanonicalPath(), "ocaml-" + selectedSdk);
                odk = SdkConfigurationUtil.createAndAddSDK(targetSdkLocation.getAbsolutePath(), new OCamlSdkType());
                if (odk != null) {
                    SdkModificator odkModificator = odk.getSdkModificator();

                    odkModificator.setVersionString(selectedSdk);  // must be set after home path, otherwise setting home path clears the version string
                    odkModificator.setName("OCaml (sources only) " + major);
                    try {
                        addSdkSources(odkModificator, targetSdkLocation);
                    } catch (IOException e) {
                        throw new CommitStepException(e.getMessage());
                    }

                    odkModificator.commitChanges();
                }
            }
        }
    }

    // update selected sdk in builder
    ProjectBuilder builder = m_context.getProjectBuilder();
    if (odk != null && builder instanceof DuneProjectImportBuilder) {
        ((DuneProjectImportBuilder) builder).setModuleSdk(odk);
    }
}
 
Example 19
Source Project: consulo   File: WinPathChooserDialog.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void choose(@Nullable VirtualFile toSelect, @Nonnull Consumer<List<VirtualFile>> callback) {
  if (toSelect != null && toSelect.getParent() != null) {

    String directoryName;
    String fileName = null;
    if (toSelect.isDirectory()) {
      directoryName = toSelect.getCanonicalPath();
    }
    else {
      directoryName = toSelect.getParent().getCanonicalPath();
      fileName = toSelect.getPath();
    }
    myFileDialog.setDirectory(directoryName);
    myFileDialog.setFile(fileName);
  }


  myFileDialog.setFilenameFilter((dir, name) -> {
    File file = new File(dir, name);
    return myFileChooserDescriptor.isFileSelectable(fileToVirtualFile(file));
  });

  myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple());

  final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null;
  final boolean appStarted = commandProcessor != null;


  if (appStarted) {
    commandProcessor.enterModal();
    LaterInvocator.enterModal(myFileDialog);
  }

  Component parent = myParent.get();
  try {
    myFileDialog.setVisible(true);
  }
  finally {
    if (appStarted) {
      commandProcessor.leaveModal();
      LaterInvocator.leaveModal(myFileDialog);
      if (parent != null) parent.requestFocus();
    }
  }

  File[] files = myFileDialog.getFiles();
  List<VirtualFile> virtualFileList = getChosenFiles(Stream.of(files));
  virtualFiles = virtualFileList.toArray(VirtualFile.EMPTY_ARRAY);

  if (!virtualFileList.isEmpty()) {
    try {
      if (virtualFileList.size() == 1) {
        myFileChooserDescriptor.isFileSelectable(virtualFileList.get(0));
      }
      myFileChooserDescriptor.validateSelectedFiles(virtualFiles);
    }
    catch (Exception e) {
      if (parent == null) {
        Messages.showErrorDialog(myProject, e.getMessage(), myTitle);
      }
      else {
        Messages.showErrorDialog(parent, e.getMessage(), myTitle);
      }

      return;
    }

    if (!ArrayUtil.isEmpty(files)) {
      callback.consume(virtualFileList);
    }
    else if (callback instanceof FileChooser.FileChooserConsumer) {
      ((FileChooser.FileChooserConsumer)callback).cancelled();
    }
  }
}
 
Example 20
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    project = element.getProject();
    String elname = element.getClass().getName();
    properties = PropertiesComponent.getInstance(project);
    if (elname.endsWith("StringLiteralExpressionImpl")) {
        try {
            PsiFile file = element.getContainingFile();
            VirtualFile vfile = file.getVirtualFile();
            if (vfile != null) {
                String path = vfile.getPath();
                VirtualFile baseDir = project.getBaseDir();
                if (baseDir == null) {
                    return PsiReference.EMPTY_ARRAY;
                }
                String basePath = baseDir.getCanonicalPath();
                if (basePath != null) {
                    String viewPath = path.replace(basePath, "")
                            .replaceAll("/[a-zA-Z0-9_]+?.(php|tpl)+", "");
                    String viewAbsolutePath = YiiRefsHelper.getViewParentPath(path
                            .replace(basePath, ""));
                    String protectedPath = YiiRefsHelper.getCurrentProtected(path);
                    protectedPath = protectedPath.replace(basePath, "");

                    String str = element.getText();
                    TextRange textRange = CommonHelper.getTextRange(element, str);
                    String uri = str.substring(textRange.getStartOffset(), textRange.getEndOffset());
                    int start = textRange.getStartOffset();
                    int len = textRange.getLength();

                    if (!uri.endsWith(".tpl") && !uri.startsWith("smarty:")) {
                        uri += ".php";
                    }

                    VirtualFile appDir = baseDir.findFileByRelativePath(viewPath);
                    VirtualFile protectedPathDir = (!protectedPath.equals(""))
                            ? baseDir.findFileByRelativePath(protectedPath) : null;

                    String filepath = viewPath + "/" + uri;
                    if (uri.matches("^//.+")) {
                        filepath = viewAbsolutePath + "/" + uri.replace("//", "");
                    }
                    VirtualFile viewfile = baseDir.findFileByRelativePath(filepath);

                    if (viewfile != null && appDir != null) {
                        PsiReference ref = new FileReference(
                                viewfile,
                                uri,
                                element,
                                new TextRange(start, start + len),
                                project,
                                protectedPathDir,
                                appDir);
                        return new PsiReference[]{ref};
                    }

                }
            }
        } catch (Exception e) {
            System.err.println("error" + e.getMessage());
        }
    }
    return PsiReference.EMPTY_ARRAY;
}