Esempio n. 1
0
 /**
  * Locates a PHPDoc comment above the offset in the document specified. In case the given entry is
  * a parameter variable, the search for the documentation will include the documentation of the
  * parameter's wrapping function.
  *
  * @param entry
  * @param document
  * @param offset
  * @return A {@link PHPDocBlock}, or <code>null</code>.
  */
 public static PHPDocBlock findFunctionPHPDocComment(
     IElementEntry entry, IDocument document, int offset) {
   boolean isParameter =
       ((entry.getValue() instanceof VariablePHPEntryValue)
           && ((VariablePHPEntryValue) entry.getValue()).isParameter());
   if (entry.getModule() != null) {
     return findFunctionPHPDocComment(entry.getModule(), document, offset, isParameter);
   }
   // In case that the entry module is null, it's probably a PHP API documentation item, so
   // parse the right item.
   try {
     String entryPath = entry.getEntryPath();
     if (entryPath != null) {
       InputStream stream = PHPBuiltins.getInstance().getBuiltinResourceStream(entryPath);
       if (stream != null) {
         BufferedReader reader =
             new BufferedReader(new InputStreamReader(stream)); // $codepro.audit.disable
         // closeWhereCreated
         return innerParsePHPDoc(offset, reader, isParameter);
       }
     }
   } catch (Exception ex) {
     IdeLog.logError(
         PHPEditorPlugin.getDefault(), "Failed locating the PHP function doc", ex); // $NON-NLS-1$
     return null;
   }
   return null;
 }
  /**
   * Gets all the values of the entries that include the module specified.
   *
   * @param index - index to use.
   * @param module - module.
   * @return map from module to the list of entries defined in that module
   */
  public static Map<IModule, List<IncludePHPEntryValue>> getIncludes(
      IElementsIndex index, IModule module) {
    Map<IModule, List<IncludePHPEntryValue>> candidates =
        new HashMap<IModule, List<IncludePHPEntryValue>>();

    String moduleShortName = module.getShortName();

    // collecting initial candidates
    Set<IModule> modules = index.getModules();
    for (IModule currentModule : modules) {
      List<IElementEntry> moduleEntries = index.getModuleEntries(currentModule);
      for (IElementEntry entry : moduleEntries) {
        Object entryValue = entry.getValue();
        if (entryValue instanceof IncludePHPEntryValue) {
          IncludePHPEntryValue includeValue = (IncludePHPEntryValue) entryValue;
          if (includeValue.getIncludePath().endsWith(moduleShortName)) {
            List<IncludePHPEntryValue> moduleValues = candidates.get(currentModule);
            if (moduleValues == null) {
              moduleValues = new ArrayList<IncludePHPEntryValue>(1);
              candidates.put(currentModule, moduleValues);
            }

            moduleValues.add(includeValue);
          }
        }
      }
    }

    Map<IModule, List<IncludePHPEntryValue>> result =
        new HashMap<IModule, List<IncludePHPEntryValue>>();

    // filtering candidates
    for (Entry<IModule, List<IncludePHPEntryValue>> entry : candidates.entrySet()) {
      IModule currentModule = entry.getKey();
      List<IncludePHPEntryValue> values = entry.getValue();
      for (IncludePHPEntryValue value : values) {
        String includePathString = value.getIncludePath();
        IPath includePath = new Path(includePathString);
        IModule resolvedModule =
            currentModule.getBuildPath().resolveRelativePath(currentModule, includePath);
        if (resolvedModule != null && resolvedModule.equals(module)) {
          List<IncludePHPEntryValue> moduleValues = result.get(currentModule);
          if (moduleValues == null) {
            moduleValues = new ArrayList<IncludePHPEntryValue>(1);
            result.put(currentModule, moduleValues);
          }

          moduleValues.add(value);
        }
      }
    }

    return result;
  }
  /**
   * Gets module includes.
   *
   * @param module - module
   * @param index - index to use.
   * @return module includes list
   */
  public static List<IncludePHPEntryValue> getModuleIncludes(IModule module, IElementsIndex index) {
    List<IncludePHPEntryValue> result = new ArrayList<IncludePHPEntryValue>();

    List<IElementEntry> moduleEntries = index.getModuleEntries(module);
    for (IElementEntry entry : moduleEntries) {
      Object entryValue = entry.getValue();
      if (entryValue instanceof IncludePHPEntryValue) {
        result.add((IncludePHPEntryValue) entryValue);
      }
    }

    return result;
  }