private static THashSet<String> collectFoldersToExclude(
      final Module module, final VirtualFile pubspecYamlFile) {
    final THashSet<String> newExcludedPackagesUrls = new THashSet<String>();
    final ProjectFileIndex fileIndex =
        ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final VirtualFile root = pubspecYamlFile.getParent();

    final VirtualFile binFolder = root.findChild("bin");
    if (binFolder != null && binFolder.isDirectory() && fileIndex.isInContent(binFolder)) {
      newExcludedPackagesUrls.add(binFolder.getUrl() + "/packages");
    }

    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("benchmark"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("example"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("test"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("tool"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("web"), fileIndex);

    // Folder packages/ThisProject (where ThisProject is the name specified in pubspec.yaml) is a
    // symlink to local 'lib' folder. Exclude it in order not to have duplicates. Resolve goes to
    // local 'lib' folder.
    // Empty 'ThisProject (link to 'lib' folder)' node is added to Project Structure by
    // DartTreeStructureProvider
    final VirtualFile libFolder = root.findChild("lib");
    if (libFolder != null && libFolder.isDirectory()) {
      final String pubspecName = PubspecYamlUtil.getPubspecName(pubspecYamlFile);
      if (pubspecName != null) {
        newExcludedPackagesUrls.add(root.getUrl() + "/packages/" + pubspecName);
      }
    }

    return newExcludedPackagesUrls;
  }
예제 #2
0
  private void mergeWithDefaultConfiguration() {
    final ArrayList<Configuration> cfgList = new ArrayList<Configuration>();
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
      final String config = support.getDefaultConfigUrl();
      final URL url = config == null ? null : support.getClass().getResource(config);
      if (url != null) {
        try {
          cfgList.add(load(url.openStream()));
        } catch (Exception e) {
          LOG.warn(e);
        }
      }
    }
    final THashSet<Object> visited = new THashSet<Object>();
    for (IdeaPluginDescriptor pluginDescriptor : PluginManager.getPlugins()) {
      if (pluginDescriptor instanceof IdeaPluginDescriptorImpl
          && !((IdeaPluginDescriptorImpl) pluginDescriptor).isEnabled()) continue;
      final ClassLoader loader = pluginDescriptor.getPluginClassLoader();
      if (!visited.add(loader)) continue;
      if (loader instanceof PluginClassLoader && ((PluginClassLoader) loader).getUrls().isEmpty())
        continue;
      try {
        final Enumeration<URL> enumeration = loader.getResources("META-INF/languageInjections.xml");
        if (enumeration == null) continue;
        while (enumeration.hasMoreElements()) {
          URL url = enumeration.nextElement();
          if (!visited.add(url.getFile())) continue; // for DEBUG mode
          try {
            cfgList.add(load(url.openStream()));
          } catch (Exception e) {
            LOG.warn(e);
          }
        }
      } catch (Exception e) {
        LOG.warn(e);
      }
    }

    final ArrayList<BaseInjection> originalInjections = new ArrayList<BaseInjection>();
    final ArrayList<BaseInjection> newInjections = new ArrayList<BaseInjection>();
    myDefaultInjections = new ArrayList<BaseInjection>();
    for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
      for (Configuration cfg : cfgList) {
        final List<BaseInjection> imported = cfg.getInjections(supportId);
        myDefaultInjections.addAll(imported);
        importInjections(getInjections(supportId), imported, originalInjections, newInjections);
      }
    }
    replaceInjections(newInjections, originalInjections);
  }
예제 #3
0
  private void addIntermediateGroovyClasses(
      Set<VirtualFile> allToCompile, final Set<VirtualFile> groovyFiles) {
    final Set<VirtualFile> initialFiles = new THashSet<VirtualFile>(allToCompile);

    final THashSet<VirtualFile> visited = new THashSet<VirtualFile>();
    for (VirtualFile aClass : initialFiles) {
      if (visited.add(aClass)) {
        goForIntermediateFiles(
            aClass,
            allToCompile,
            new FactoryMap<VirtualFile, Set<VirtualFile>>() {
              @Override
              protected Set<VirtualFile> create(final VirtualFile key) {
                AccessToken accessToken =
                    ApplicationManager.getApplication().acquireReadActionLock();
                try {
                  return calcCodeReferenceDependencies(key, groovyFiles);
                } finally {
                  accessToken.finish();
                }
              }
            },
            visited);
      }
    }
  }
예제 #4
0
 public DelimFieldTermProcessor(
     String[] _delims, boolean _indexDelimiters, boolean _countDelimiters) {
   blockDelimiterTerms = new THashSet<String>();
   for (String t : _delims) blockDelimiterTerms.add(t);
   indexDelimiters = _indexDelimiters;
   countDelimiters = _countDelimiters;
 }
예제 #5
0
  /**
   * Loads the specified stopwords file. Used internally by Stopwords(TermPipeline, String[]).
   *
   * @param stopwordsFilename The filename of the file to use as the stopwords list.
   */
  public void loadStopwordsList(String stopwordsFilename) {
    // determine encoding to use when reading the stopwords files

    // String stopwordsEncoding =  null;

    try {
      // use sys default encoding if none specified
      BufferedReader br = new BufferedReader(new FileReader(stopwordsFilename));
      String word;
      while ((word = br.readLine()) != null) {
        word = word.trim();
        if (word.length() > 0) {
          stopWords.add(word);
        }
      }
      br.close();
    } catch (IOException ioe) {
      System.err.println(
          "Errror: Input/Output Exception while reading stopword list ("
              + stopwordsFilename
              + ") :  Stack trace follows.");
      ioe.printStackTrace();
    }
    if (stopWords.size() == 0)
      System.err.println("Error: Empty stopwords file was used (" + stopwordsFilename + ")");
  }
 @Override
 public Set<String> getAllLookupStrings() {
   final Set<String> strings = getDelegate().getAllLookupStrings();
   final THashSet<String> result = new THashSet<String>();
   result.addAll(strings);
   result.add(getLookupString());
   return result;
 }
예제 #7
0
 @Nullable
 @Override
 public Set<String> fromString(@NotNull String value) {
   final THashSet<String> result = new THashSet<String>();
   for (String closingTag : StringUtil.split(value, ",")) {
     result.add(closingTag.trim());
   }
   return result;
 }
예제 #8
0
 public void addTypeReference(RefJavaElement from) {
   if (from != null) {
     if (myInTypeReferences == null) {
       myInTypeReferences = new THashSet<RefElement>(1);
     }
     myInTypeReferences.add(from);
     ((RefJavaElementImpl) from).addOutTypeRefernce(this);
     getRefManager().fireNodeMarkedReferenced(this, from, false, false, false);
   }
 }
예제 #9
0
 private String createNameForClass(ClassDescriptor descriptor) {
   String suggestedName = descriptor.getName().asString();
   String name = suggestedName;
   DeclarationDescriptor containing = descriptor;
   while (!nameClashGuard.add(name)) {
     containing = containing.getContainingDeclaration();
     assert containing != null;
     name = suggestedName + '_' + containing.getName().asString();
   }
   return name;
 }
 private static boolean defaultFunctionalityWorked(final PsiLanguageInjectionHost host) {
   final THashSet<String> languages = new THashSet<String>();
   final List<Pair<PsiElement, TextRange>> files = InjectedLanguageUtil.getInjectedPsiFiles(host);
   if (files == null) return false;
   for (Pair<PsiElement, TextRange> pair : files) {
     for (Language lang = pair.first.getLanguage(); lang != null; lang = lang.getBaseLanguage()) {
       languages.add(lang.getID());
     }
   }
   // todo there is a problem: host i.e. literal expression is confused with "target" i.e.
   // parameter
   // todo therefore this part doesn't work for java
   return Configuration.getInstance().setHostInjectionEnabled(host, languages, false);
 }
예제 #11
0
  private static List<BaseInjection> loadDefaultInjections() {
    final ArrayList<Configuration> cfgList = new ArrayList<Configuration>();
    final THashSet<Object> visited = new THashSet<Object>();
    for (LanguageInjectionConfigBean configBean :
        Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) {
      PluginDescriptor descriptor = configBean.getPluginDescriptor();
      final ClassLoader loader = descriptor.getPluginClassLoader();
      try {
        final Enumeration<URL> enumeration = loader.getResources(configBean.getConfigUrl());
        if (enumeration == null || !enumeration.hasMoreElements()) {
          LOG.warn(descriptor.getPluginId() + ": " + configBean.getConfigUrl() + " was not found");
        } else {
          while (enumeration.hasMoreElements()) {
            URL url = enumeration.nextElement();
            if (!visited.add(url.getFile())) continue; // for DEBUG mode
            try {
              cfgList.add(load(url.openStream()));
            } catch (Exception e) {
              LOG.warn(e);
            }
          }
        }
      } catch (Exception e) {
        LOG.warn(e);
      }
    }

    final ArrayList<BaseInjection> defaultInjections = new ArrayList<BaseInjection>();
    for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
      for (Configuration cfg : cfgList) {
        final List<BaseInjection> imported = cfg.getInjections(supportId);
        defaultInjections.addAll(imported);
      }
    }
    return defaultInjections;
  }
예제 #12
0
 public void addInstanceReference(RefElement from) {
   if (myInstanceReferences == null) {
     myInstanceReferences = new THashSet<RefElement>(1);
   }
   myInstanceReferences.add(from);
 }