コード例 #1
0
ファイル: PyGlobalsBrowser.java プロジェクト: rcuza/Pydev
  /**
   * @param pythonNatures the natures from were we can get info
   * @param additionalInfo the additional informations
   * @param selectedText the text that should be initially set as a filter
   */
  public static void doSelect(
      List<IPythonNature> pythonNatures,
      List<AbstractAdditionalTokensInfo> additionalInfo,
      String selectedText) {

    SelectionDialog dialog =
        GlobalsDialogFactory.create(getShell(), additionalInfo, selectedText, pythonNatures);

    dialog.open();
    Object[] result = dialog.getResult();
    if (result != null && result.length > 0) {
      for (Object obj : result) {
        IInfo entry;
        if (obj instanceof AdditionalInfoAndIInfo) {
          entry = ((AdditionalInfoAndIInfo) obj).info;
        } else {
          entry = (IInfo) obj;
        }
        List<ItemPointer> pointers = new ArrayList<ItemPointer>();

        CompletionCache completionCache = new CompletionCache();
        for (IPythonNature pythonNature : pythonNatures) {
          // try to find in one of the natures...
          ICodeCompletionASTManager astManager = pythonNature.getAstManager();
          if (astManager == null) {
            continue;
          }
          AnalysisPlugin.getDefinitionFromIInfo(
              pointers, astManager, pythonNature, entry, completionCache);
          if (pointers.size() > 0) {
            new PyOpenAction().run(pointers.get(0));
            break; // don't check the other natures
          }
        }
      }
    }
  }
コード例 #2
0
ファイル: CtxParticipant.java プロジェクト: aparo/Pydev
  private void fillNatureCompletionsForConsole(
      IScriptConsoleViewer viewer,
      int requestOffset,
      List<ICompletionProposal> completions,
      String qual,
      boolean addAutoImport,
      int qlen,
      String lowerQual,
      IPythonNature nature,
      boolean getSystem) {
    AbstractAdditionalInterpreterInfo additionalInfoForProject;

    if (getSystem) {
      try {
        additionalInfoForProject =
            AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(
                PydevPlugin.getInterpreterManager(nature),
                nature.getProjectInterpreter().getExecutableOrJar());
      } catch (Exception e) {
        PydevPlugin.log(e);
        return;
      }
    } else {
      try {
        additionalInfoForProject =
            AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
      } catch (Exception e) {
        PydevPlugin.log(e);
        return;
      }
    }

    List<IInfo> tokensStartingWith =
        additionalInfoForProject.getTokensStartingWith(
            qual, AbstractAdditionalInterpreterInfo.TOP_LEVEL);

    FastStringBuffer realImportRep = new FastStringBuffer();
    FastStringBuffer displayString = new FastStringBuffer();
    FastStringBuffer tempBuf = new FastStringBuffer();
    for (IInfo info : tokensStartingWith) {
      // there always must be a declaringModuleName
      String declaringModuleName = info.getDeclaringModuleName();
      boolean hasInit = false;
      if (declaringModuleName.endsWith(".__init__")) {
        declaringModuleName =
            declaringModuleName.substring(
                0, declaringModuleName.length() - 9); // remove the .__init__
        hasInit = true;
      }

      String rep = info.getName();
      String lowerRep = rep.toLowerCase();
      if (!lowerRep.startsWith(lowerQual)) {
        continue;
      }

      if (addAutoImport) {
        realImportRep.clear();
        realImportRep.append("from ");
        realImportRep.append(
            AutoImportsPreferencesPage.removeImportsStartingWithUnderIfNeeded(
                declaringModuleName, tempBuf));
        realImportRep.append(" import ");
        realImportRep.append(rep);
      }

      displayString.clear();
      displayString.append(rep);
      displayString.append(" - ");
      displayString.append(declaringModuleName);
      if (hasInit) {
        displayString.append(".__init__");
      }

      PyConsoleCompletion proposal =
          new PyConsoleCompletion(
              rep,
              requestOffset - qlen,
              qlen,
              realImportRep.length(),
              AnalysisPlugin.getImageForAutoImportTypeInfo(info),
              displayString.toString(),
              (IContextInformation) null,
              "",
              lowerRep.equals(lowerQual)
                  ? IPyCompletionProposal.PRIORITY_LOCALS_1
                  : IPyCompletionProposal.PRIORITY_GLOBALS,
              realImportRep.toString(),
              viewer);

      completions.add(proposal);
    }
  }
コード例 #3
0
ファイル: CtxParticipant.java プロジェクト: aparo/Pydev
  private Collection<CtxInsensitiveImportComplProposal> getThem(
      CompletionRequest request, ICompletionState state, boolean addAutoImport)
      throws MisconfigurationException {

    ArrayList<CtxInsensitiveImportComplProposal> completions =
        new ArrayList<CtxInsensitiveImportComplProposal>();
    if (request.isInCalltip) {
      return completions;
    }

    HashSet<String> importedNames = getImportedNames(state);

    String qual = request.qualifier;
    if (qual.length()
        >= CodeCompletionPreferencesPage
            .getCharsForContextInsensitiveGlobalTokensCompletion()) { // at least n characters
                                                                      // required...
      String lowerQual = qual.toLowerCase();

      String initialModule = request.resolveModule();

      List<IInfo> tokensStartingWith =
          AdditionalProjectInterpreterInfo.getTokensStartingWith(
              qual, request.nature, AbstractAdditionalInterpreterInfo.TOP_LEVEL);

      FastStringBuffer realImportRep = new FastStringBuffer();
      FastStringBuffer displayString = new FastStringBuffer();
      FastStringBuffer tempBuf = new FastStringBuffer();

      for (IInfo info : tokensStartingWith) {
        // there always must be a declaringModuleName
        String declaringModuleName = info.getDeclaringModuleName();
        if (initialModule != null && declaringModuleName != null) {
          if (initialModule.equals(declaringModuleName)) {
            continue;
          }
        }
        boolean hasInit = false;
        if (declaringModuleName.endsWith(".__init__")) {
          declaringModuleName =
              declaringModuleName.substring(
                  0, declaringModuleName.length() - 9); // remove the .__init__
          hasInit = true;
        }

        String rep = info.getName();
        String lowerRep = rep.toLowerCase();
        if (!lowerRep.startsWith(lowerQual) || importedNames.contains(rep)) {
          continue;
        }

        if (addAutoImport) {
          realImportRep.clear();
          realImportRep.append("from ");
          realImportRep.append(
              AutoImportsPreferencesPage.removeImportsStartingWithUnderIfNeeded(
                  declaringModuleName, tempBuf));
          realImportRep.append(" import ");
          realImportRep.append(rep);
        }

        displayString.clear();
        displayString.append(rep);
        displayString.append(" - ");
        displayString.append(declaringModuleName);
        if (hasInit) {
          displayString.append(".__init__");
        }

        CtxInsensitiveImportComplProposal proposal =
            new CtxInsensitiveImportComplProposal(
                rep,
                request.documentOffset - request.qlen,
                request.qlen,
                realImportRep.length(),
                AnalysisPlugin.getImageForAutoImportTypeInfo(info),
                displayString.toString(),
                (IContextInformation) null,
                "",
                lowerRep.equals(lowerQual)
                    ? IPyCompletionProposal.PRIORITY_LOCALS_1
                    : IPyCompletionProposal.PRIORITY_GLOBALS,
                realImportRep.toString());

        completions.add(proposal);
      }
    }
    return completions;
  }