private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
    try {
      DartElement enclosingElement = null;
      if (getContext().isExtended()) {
        enclosingElement = getContext().getEnclosingElement();
      } else if (fCompilationUnit != null) {
        enclosingElement = fCompilationUnit.getElementAt(proposal.getCompletionLocation() + 1);
      }
      if (enclosingElement == null) {
        return;
      }
      Type type = enclosingElement.getAncestor(Type.class);
      if (type != null) {
        String prefix = String.valueOf(proposal.getName());
        int completionStart = proposal.getReplaceStart();
        int completionEnd = proposal.getReplaceEnd();
        int relevance = computeRelevance(proposal);

        GetterSetterCompletionProposal.evaluateProposals(
            type,
            prefix,
            completionStart,
            completionEnd - completionStart,
            proposal.getReplaceEndIdentifier() - completionStart,
            relevance + 2,
            fSuggestedMethodNames,
            fDartProposals);
        MethodDeclarationCompletionProposal.evaluateProposals(
            type,
            prefix,
            completionStart,
            completionEnd - completionStart,
            proposal.getReplaceEndIdentifier() - completionStart,
            relevance,
            fSuggestedMethodNames,
            fDartProposals);
      }
    } catch (CoreException e) {
      DartToolsPlugin.log(e);
    }
  }
Exemplo n.º 2
0
  /** Map from the source language to the target language (Dart to Javascript). */
  public SourceLocation mapDartToJavascript(IFile file, int line) {
    // given the file, find the dart element
    DartElement dartElement = DartCore.create(file);

    if (dartElement == null) {
      return SourceLocation.UNKNOWN_LOCATION;
    }

    // given that, find the dart application / library
    DartLibraryImpl dartLibrary = (DartLibraryImpl) dartElement.getAncestor(DartLibrary.class);

    if (dartLibrary == null) {
      return SourceLocation.UNKNOWN_LOCATION;
    }

    try {
      // [out/DartAppFileName.app.js.map]

      IPath outputLocation = getMainDartProject().getOutputLocation();

      List<LibraryConfigurationFileImpl> libraryConfigurationFiles =
          dartLibrary.getChildrenOfType(LibraryConfigurationFileImpl.class);

      //      if (libraryConfigurationFiles.size() > 0) {
      //        String libraryName = libraryConfigurationFiles.get(0).getFile().getName();
      //
      //        IPath sourceMapPath = outputLocation.append(libraryName + ".js.map");
      //
      //        SourceMapping mapping = getCachedSourceMappingPath(sourceMapPath);
      //
      //        if (mapping != null && mapping instanceof SourceMappingReversable) {
      //          SourceMappingReversable revMapping = (SourceMappingReversable) mapping;
      //
      //          String sourcePath = findMatchingSourcePath(file, revMapping);
      //
      //          if (sourcePath != null) {
      //            Collection<OriginalMapping> mappings = revMapping.getReverseMapping(sourcePath,
      // line, 1);
      //
      //            // TODO(devoncarew): We need to handle the case where there are more then one
      // mappings
      //            // returned; this will probably involve setting one breakpoint per mapping. More
      // then
      //            // one mapping ==> something like a function that's been inlined into multiple
      // places.
      //            if (mappings.size() > 0) {
      //              OriginalMapping map = mappings.iterator().next();
      //
      //              String fileName = map.getOriginalFile();
      //              int lineNumber = map.getLineNumber();
      //
      //              return new SourceLocation(new Path(fileName), lineNumber);
      //            }
      //          }
      //        }
      //      }
    } catch (DartModelException exception) {
      DartCore.logError(exception);
    }

    return SourceLocation.UNKNOWN_LOCATION;
  }