Example #1
0
  @Override
  public boolean contains(VirtualFile file) {
    if (!super.contains(file)) {
      return false;
    }

    if (includeLibraries && StdFileTypes.CLASS == file.getFileType()) {
      return index.isInLibraryClasses(file);
    }

    if (JetPluginUtil.isKtFileInGradleProjectInWrongFolder(file, getProject())) {
      return false;
    }

    return file.getFileType().equals(JetFileType.INSTANCE)
        && (index.isInSourceContent(file) || includeLibraries && index.isInLibrarySource(file));
  }
Example #2
0
 /**
  * Add import directive corresponding to a type to file when it is needed.
  *
  * @param type type to import
  * @param file file where import directive should be added
  */
 public static void addImportDirectivesIfNeeded(@NotNull JetType type, @NotNull JetFile file) {
   if (JetPluginUtil.checkTypeIsStandard(type, file.getProject())
       || ErrorUtils.isErrorType(type)) {
     return;
   }
   BindingContext bindingContext = getContextForSingleFile(file);
   PsiElement element =
       BindingContextUtils.descriptorToDeclaration(
           bindingContext, type.getMemberScope().getContainingDeclaration());
   if (element != null
       && element.getContainingFile()
           == file) { // declaration is in the same file, so no import is needed
     return;
   }
   for (ClassDescriptor clazz : TypeUtils.getAllClassDescriptors(type)) {
     addImportDirective(DescriptorUtils.getFQName(getTopLevelClass(clazz)).toSafe(), file);
   }
 }
Example #3
0
    @Override
    protected Location prepareRequestInfo() {
      if (!toolWindow.isVisible()) {
        return null;
      }

      Location location =
          Location.fromEditor(
              FileEditorManager.getInstance(myProject).getSelectedTextEditor(), myProject);
      if (location.getEditor() == null) {
        return null;
      }

      JetFile file = location.getJetFile();
      if (file == null || !JetPluginUtil.isInSource(file, false)) {
        return null;
      }

      return location;
    }