private void doCompletionOnComponentDeclaration()

in ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/RutaCompletionEngine.java [241:355]


  private void doCompletionOnComponentDeclaration(IModuleSource cu, RutaModuleDeclaration parsed,
          String startPart, int type, String complString) throws Exception {
    if (type == ComponentDeclaration.SCRIPT) {
      List<String> scripts = new ArrayList<String>();

      List<IFolder> scriptFolders = RutaProjectUtils
              .getAllScriptFolders(sourceModule.getModelElement().getScriptProject());
      for (IFolder folder : scriptFolders) {
        try {
          scripts.addAll(collectScripts(folder, ""));
        } catch (CoreException e) {
        }
      }
      Resource[] resources = getFilesInClasspath(complString, "ruta");
      for (Resource resource : resources) {
        try {
          String string = getScriptRepresentation(resource, "ruta");
          if (string != null && !scripts.contains(string)) {
            scripts.add(string);
          }
        } catch (Exception e) {
          // do not report the exceptions
        }
      }

      for (String string : scripts) {
        if (match(complString, string)) {
          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
        }
      }
    } else if (type == ComponentDeclaration.UIMAFIT_ENGINE) {
      List<String> engines = new ArrayList<String>();
      ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
              true);
      ResourceLoader resourceLoader = new DefaultResourceLoader(classloader);
      provider.setResourceLoader(resourceLoader);
      provider.addIncludeFilter(new AssignableTypeFilter(AnalysisComponent.class));

      String pack = complString.replaceAll("[.]", "/");
      if (pack.endsWith("/")) {
        pack = pack.substring(0, pack.length() - 1);
      }
      Set<BeanDefinition> components = provider.findCandidateComponents(pack);
      for (BeanDefinition component : components) {
        String beanClassName = component.getBeanClassName();
        engines.add(beanClassName);
      }
      for (String string : engines) {
        if (match(complString, string)) {
          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
        }
      }
    } else if (type == ComponentDeclaration.ENGINE) {
      List<String> engines = new ArrayList<String>();
      Resource[] resources = getFilesInClasspath(complString, "xml");
      for (Resource resource : resources) {
        try {
          UIMAFramework.getXMLParser()
                  .parseAnalysisEngineDescription(new XMLInputSource(resource.getURL()));
          String string = getScriptRepresentation(resource, "xml");
          if (string != null) {
            engines.add(string);
          }
        } catch (Exception e) {
          // do not report the exceptions
        }
      }
      if (StringUtils.isAllUpperCase(complString)) {
        List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(
                sourceModule.getModelElement().getScriptProject().getProject());
        for (IFolder folder : descriptorFolders) {
          try {
            engines.addAll(collectEngines(folder, ""));
          } catch (CoreException e) {
          }
        }
      }
      for (String string : engines) {
        if (match(complString, string)) {
          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
        }
      }
    } else {
      List<String> tss = new ArrayList<String>();
      Resource[] resources = getFilesInClasspath(complString, "xml");
      for (Resource resource : resources) {
        try {
          UIMAFramework.getXMLParser()
                  .parseTypeSystemDescription(new XMLInputSource(resource.getURL()));
          String string = getScriptRepresentation(resource, "xml");
          if (string != null) {
            tss.add(string);
          }
        } catch (Exception e) {
          // do not report the exceptions
        }
      }
      if (StringUtils.isAllUpperCase(complString)) {
        // fallback for camel case
        List<IFolder> descriptorFolders = RutaProjectUtils.getAllDescriptorFolders(
                sourceModule.getModelElement().getScriptProject().getProject());
        for (IFolder folder : descriptorFolders) {
          try {
            tss.addAll(collectTypeSystems(folder, ""));
          } catch (CoreException e) {
          }
        }
      }
      for (String string : tss) {
        if (match(complString, string)) {
          addProposal(complString, string, CompletionProposal.PACKAGE_REF);
        }
      }
    }
  }