/**
   * FIXME This is a holy hell of a mess! We map from IFiles to IFileStores, then filter on that,
   * then map back! Can't we make the IIndexFilterParticipants also operate on IFiles? It seems like
   * the only impl does anyways.
   *
   * @return
   */
  private Collection<IFile> filterFiles(Collection<IFile> files, IProgressMonitor monitor) {
    SubMonitor sub = SubMonitor.convert(monitor, 100);
    // First filter out files that don't exist, are derived, or are team-private
    files =
        CollectionsUtil.filter(
            files,
            new IFilter<IFile>() {
              public boolean include(IFile item) {
                return !ResourceUtil.shouldIgnore(item);
              }
            });
    sub.worked(10);

    // Next map IFiles to IFileStores for filter participants' sake
    Set<IFileStore> fileStores =
        new HashSet<IFileStore>(
            CollectionsUtil.map(
                files,
                new IMap<IFile, IFileStore>() {

                  public IFileStore map(IFile item) {
                    IPath path = item.getLocation();
                    return (path == null) ? null : EFS.getLocalFileSystem().getStore(path);
                  }
                }));
    sub.worked(15);

    if (!CollectionsUtil.isEmpty(fileStores)) {
      // Now let filters run
      IndexManager manager = getIndexManager();
      if (manager != null) {
        for (IIndexFilterParticipant filterParticipant : manager.getFilterParticipants()) {
          fileStores = filterParticipant.applyFilter(fileStores);
        }
      }
      sub.worked(60);

      // Now we need to map back to IFiles again. UGH!
      return CollectionsUtil.map(
          fileStores,
          new IMap<IFileStore, IFile>() {

            public IFile map(IFileStore fileStore) {
              IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
              IFile[] iFiles = workspaceRoot.findFilesForLocationURI(fileStore.toURI());
              if (ArrayUtil.isEmpty(iFiles)) {
                return null;
              }
              return iFiles[0];
            }
          });
    }

    return files;
  }
  @Test
  public void testIdentifier() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            CollectionsUtil.newList("_", "$", "a", "A"),
            CollectionsUtil.newList("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.IDENTIFIER);
  }
Exemple #3
0
  @Test
  public void testFunctionParameterWithConstantValues() {
    String typeName = "MyClass";
    String eventName = "event";
    String propertyName = "eventProperty";

    // create type
    TypeElement type = new TypeElement();
    type.setName(typeName);

    EventElement ee = new EventElement();
    ee.setName(eventName);
    EventPropertyElement epe = new EventPropertyElement();
    epe.fromJSON(
        CollectionsUtil.newTypedMap(
            String.class,
            Object.class,
            IHasPredefinedValues.CONSTANTS_PROPERTY,
            CollectionsUtil.newList("Titanium.UI.FILL", "Titanium.UI.ALIGN")));
    epe.setName(propertyName);
    ee.addProperty(epe);

    type.addEvent(ee);

    // write type to index
    this.writeType(type);

    // then retrieve it
    List<TypeElement> retrievedTypes = this.getType(typeName);
    TypeElement retrievedType = retrievedTypes.get(0);

    assertNotNull(retrievedType);
    assertEquals(typeName, retrievedType.getName());

    EventElement retrievedEvent = retrievedType.getEvent(eventName);
    assertNotNull(retrievedEvent);

    List<EventPropertyElement> retrievedProps = retrievedEvent.getProperties();
    assertNotNull(retrievedProps);
    assertEquals(1, retrievedProps.size());

    // make sure the name is correct
    EventPropertyElement retrievedProperty = retrievedProps.get(0);
    assertEquals(propertyName, retrievedProperty.getName());
    // Check constants
    List<String> constants = retrievedProperty.getConstants();
    assertEquals(2, constants.size());
    assertTrue(constants.contains("Titanium.UI.FILL"));
    assertTrue(constants.contains("Titanium.UI.ALIGN"));
  }
Exemple #4
0
    public IStatus call() throws Exception {
      // index vs filesystem
      List<String> args = CollectionsUtil.newList("diff-files", "-z"); // $NON-NLS-1$ //$NON-NLS-2$
      if (!CollectionsUtil.isEmpty(filePaths)) {
        args.add("--"); // $NON-NLS-1$
        args.addAll(filePaths);
      }

      IStatus result =
          repo.execute(GitRepository.ReadWrite.READ, args.toArray(new String[args.size()]));
      if (result != null && result.isOK()) {
        readUnstagedFiles(result.getMessage());
      }
      return Status.OK_STATUS;
    }
  private void buildFile(
      BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(participants)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size());
    for (IBuildParticipant participant : participants) {
      long startTime = System.nanoTime();
      participant.buildFile(context, sub.newChild(1));
      if (traceParticipantsEnabled) {
        double endTime = ((double) System.nanoTime() - startTime) / 1000000;
        IdeLog.logTrace(
            BuildPathCorePlugin.getDefault(),
            MessageFormat.format(
                "Executed build participant ''{0}'' on ''{1}'' in {2} ms.",
                participant.getName(), context.getURI(), endTime),
            IDebugScopes.BUILDER_PARTICIPANTS); // $NON-NLS-1$
      }

      // stop building if it has been canceled
      if (sub.isCanceled()) {
        break;
      }
    }
    updateMarkers(context, sub.newChild(participants.size()));
    sub.done();
  }
  @Test
  public void testScientificNotation() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            // { "+", "-", "" },	// TODO: apparently the scanner can't differentiate between 5 + 10
            // and 5 + +10?
            CollectionsUtil.newList("1", "1.", ".9", "1.9"),
            CollectionsUtil.newList("e", "E"),
            CollectionsUtil.newList("+", "-", ""),
            CollectionsUtil.newList("10"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.NUMBER);
  }
  private void buildFiles(
      List<IBuildParticipant> participants, Collection<IFile> files, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(participants) || CollectionsUtil.isEmpty(files)) {
      return;
    }
    SubMonitor sub = SubMonitor.convert(monitor, 100);

    // Filter
    files = filterFiles(files, sub.newChild(10));

    // Then build
    doBuildFiles(participants, files, sub.newChild(90));

    sub.done();
  }
  private void doBuildFiles(
      List<IBuildParticipant> participants, Collection<IFile> files, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(files)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 15 * files.size());
    for (IFile file : files) {
      BuildContext context = new BuildContext(file);
      sub.worked(1);

      IBuildParticipantManager manager = getBuildParticipantManager();
      if (manager == null) {
        return;
      }
      List<IBuildParticipant> filteredParticipants =
          manager.filterParticipants(participants, context.getContentType());
      sub.worked(2);

      buildFile(context, filteredParticipants, sub.newChild(12));

      // stop building if canceled
      if (sub.isCanceled()) {
        break;
      }
    }
    sub.done();
  }
Exemple #9
0
  public IStatus unstageFiles(Collection<ChangedFile> unstageFiles) {
    if (CollectionsUtil.isEmpty(unstageFiles)) {
      // no-op, return OK
      return Status.OK_STATUS;
    }

    StringBuilder input = new StringBuilder();
    for (ChangedFile file : unstageFiles) {
      input.append(file.indexInfo());
    }

    IStatus result =
        repository.executeWithInput(
            input.toString(),
            "update-index",
            "-z",
            "--index-info"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    if (result == null) {
      return new Status(
          IStatus.ERROR,
          GitPlugin.PLUGIN_ID,
          "Failed to unstage files. Process failed to run."); //$NON-NLS-1$
    }
    if (!result.isOK()) {
      IdeLog.logError(
          GitPlugin.getDefault(),
          MessageFormat.format("Failed to stage files: {0}", result.getMessage()),
          IDebugScopes.DEBUG); // $NON-NLS-1$
      return result;
    }

    // Update the staged/unstaged flags in the passed in copy of changed files, and our internal
    // list of changed
    // files.
    ArrayList<ChangedFile> preFiles = new ArrayList<ChangedFile>(unstageFiles.size());
    for (ChangedFile file : unstageFiles) {
      preFiles.add(new ChangedFile(file));

      synchronized (this.changedFilesLock) {
        if (this.changedFiles != null) {
          int index = Collections.binarySearch(this.changedFiles, file);
          if (index >= 0) {

            ChangedFile orig = this.changedFiles.get(index);
            orig.hasUnstagedChanges = true;
            orig.hasStagedChanges = false;
          }
        }
      }

      file.hasUnstagedChanges = true;
      file.hasStagedChanges = false;
    }
    preFiles.trimToSize();

    postIndexChange(preFiles, unstageFiles);
    return result;
  }
 /**
  * getExceptionTypes
  *
  * @return
  */
 public List<String> getExceptionTypes() {
   return CollectionsUtil.map(
       getExceptions(),
       new IMap<ExceptionElement, String>() {
         public String map(ExceptionElement exception) {
           return exception.getType();
         }
       });
 }
 /**
  * getParamterNames
  *
  * @return
  */
 public List<String> getParameterNames() {
   return CollectionsUtil.map(
       getParameters(),
       new IMap<ParameterElement, String>() {
         public String map(ParameterElement parameter) {
           return parameter.getName();
         }
       });
 }
 /**
  * getParameterTypes
  *
  * @return
  */
 public List<String> getParameterTypes() {
   return CollectionsUtil.map(
       getParameters(),
       new IMap<ParameterElement, String>() {
         public String map(ParameterElement parameter) {
           return StringUtil.join(JSTypeConstants.PARAMETER_TYPE_DELIMITER, parameter.getTypes());
         }
       });
 }
 /**
  * getReturnTypeNames
  *
  * @return
  */
 public List<String> getReturnTypeNames() {
   return CollectionsUtil.map(
       getReturnTypes(),
       new IMap<ReturnTypeElement, String>() {
         public String map(ReturnTypeElement type) {
           return type.getType();
         }
       });
 }
Exemple #14
0
  public IStatus stageFiles(Collection<ChangedFile> stageFiles) {
    if (CollectionsUtil.isEmpty(stageFiles)) {
      // no-op
      return Status.OK_STATUS;
    }

    StringBuffer input =
        new StringBuffer(stageFiles.size() * stageFiles.iterator().next().getPath().length());
    for (ChangedFile file : stageFiles) {
      input.append(file.getPath()).append('\n');
    }

    @SuppressWarnings("nls")
    IStatus result =
        repository.executeWithInput(
            input.toString(), "update-index", "--add", "--remove", "--stdin");
    if (result == null) {
      return new Status(
          IStatus.ERROR,
          GitPlugin.PLUGIN_ID,
          "Failed to stage files. Process failed to run."); //$NON-NLS-1$;
    }
    if (!result.isOK()) {
      IdeLog.logError(
          GitPlugin.getDefault(),
          MessageFormat.format("Failed to stage files: {0}", result.getMessage()),
          IDebugScopes.DEBUG); // $NON-NLS-1$
      return result;
    }

    ArrayList<ChangedFile> preFiles = new ArrayList<ChangedFile>(stageFiles.size());
    // Update the staged/unstaged flags in the passed in copy of changed files, and our internal
    // list of changed
    // files.
    for (ChangedFile file : stageFiles) {
      preFiles.add(new ChangedFile(file));
      synchronized (changedFilesLock) {
        if (this.changedFiles != null) {
          int index = Collections.binarySearch(this.changedFiles, file);
          if (index >= 0) {

            ChangedFile orig = this.changedFiles.get(index);
            orig.hasUnstagedChanges = false;
            orig.hasStagedChanges = true;
          }
        }
      }

      file.hasUnstagedChanges = false;
      file.hasStagedChanges = true;
    }
    preFiles.trimToSize();

    postIndexChange(preFiles, stageFiles);
    return result;
  }
 /** Mark the downloaded paths to be deleted on exit. */
 protected void deleteDownloadedPaths() {
   if (!CollectionsUtil.isEmpty(downloadedPaths)) {
     for (IPath f : downloadedPaths) {
       File toDelete = f.toFile();
       if (toDelete.exists()) {
         toDelete.deleteOnExit();
       }
     }
   }
 }
 public boolean isConflicting(ISchedulingRule rule) {
   if (contains(rule)) {
     return true;
   }
   if (rule != this && rule instanceof MetadataRule) {
     List<String> otherFiles = ((MetadataRule) rule).getFiles();
     return CollectionsUtil.intersect(otherFiles, getFiles()).size() > 0;
   }
   return false;
 }
  @Test
  public void testHex() {
    // @formatter:off
    @SuppressWarnings("unchecked")
    List<List<String>> lists =
        CollectionsUtil.newList(
            // { "+", "-", "" },	// TODO: apparently the scanner can't differentiate between 5 + 10
            // and 5 + +10?
            CollectionsUtil.newList("0"),
            CollectionsUtil.newList("x", "X"),
            CollectionsUtil.newList(
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A",
                "B", "C", "D", "E", "F"),
            CollectionsUtil.newList(
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A",
                "B", "C", "D", "E", "F"));
    // @formatter:on

    this.assertListCrossProducts(lists, JSTokenType.NUMBER);
  }
Exemple #18
0
    public IStatus call() throws Exception {
      // index vs working tree (HEAD?)
      List<String> args =
          CollectionsUtil.newList(
              "ls-files",
              "--others", //$NON-NLS-1$ //$NON-NLS-2$
              "--exclude-standard",
              "-z"); //$NON-NLS-1$ //$NON-NLS-2$
      if (!CollectionsUtil.isEmpty(filePaths)) {
        args.add("--"); // $NON-NLS-1$
        args.addAll(filePaths);
      }

      IStatus result =
          repo.execute(GitRepository.ReadWrite.READ, args.toArray(new String[args.size()]));
      if (result != null && result.isOK()) {
        readOtherFiles(result.getMessage());
      }
      return Status.OK_STATUS;
    }
 private void buildStarting(
     List<IBuildParticipant> participants, int kind, IProgressMonitor monitor) {
   if (CollectionsUtil.isEmpty(participants)) {
     return;
   }
   SubMonitor sub = SubMonitor.convert(monitor, participants.size());
   for (IBuildParticipant participant : participants) {
     participant.buildStarting(getProjectHandle(), kind, sub.newChild(1));
   }
   sub.done();
 }
Exemple #20
0
 protected boolean hasUnresolvedMergeConflicts() {
   List<ChangedFile> changedFiles = changedFiles();
   if (CollectionsUtil.isEmpty(changedFiles)) {
     return false;
   }
   for (ChangedFile changedFile : changedFiles) {
     if (changedFile.hasUnmergedChanges() && changedFile.hasUnstagedChanges()) {
       return true;
     }
   }
   return false;
 }
  private void deleteFile(
      BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor) {
    if (CollectionsUtil.isEmpty(participants)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, participants.size());
    for (IBuildParticipant participant : participants) {
      participant.deleteFile(context, sub.newChild(1));
    }
    sub.done();
  }
Exemple #22
0
 public Set<IResource> getChangedResources() {
   Set<IResource> resources = new HashSet<IResource>();
   List<ChangedFile> changedFiles = changedFiles();
   if (!CollectionsUtil.isEmpty(changedFiles)) {
     for (ChangedFile changedFile : changedFiles) {
       IResource resource = getResourceForChangedFile(changedFile);
       if (resource != null) {
         resources.add(resource);
       }
     }
   }
   return resources;
 }
 private void addMarkers(
     Collection<IProblem> items, String markerType, IFile file, IProgressMonitor monitor)
     throws CoreException {
   if (CollectionsUtil.isEmpty(items)) {
     return;
   }
   SubMonitor sub = SubMonitor.convert(monitor, items.size() * 2);
   for (IProblem item : items) {
     IMarker marker = file.createMarker(markerType);
     sub.worked(1);
     marker.setAttributes(item.createMarkerAttributes());
     sub.worked(1);
   }
   sub.done();
 }
  /*
   * (non-Javadoc)
   * @see com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSIdentifierNode)
   */
  @Override
  public void visit(JSIdentifierNode node) {
    String name = node.getText();
    Collection<PropertyElement> properties = null;

    if (this._scope != null && this._scope.hasSymbol(name)) {
      IParseNode parent = node.getParent();

      if (parent != null && parent.getNodeType() == IJSNodeTypes.PARAMETERS) {
        // special handling of parameters to potentially get the type
        // from documentation and to prevent an infinite loop since
        // parameters point to themselves in the symbol table
        this.addParameterTypes(node);
      } else {
        // Check the local scope for type first
        JSSymbolTypeInferrer symbolInferrer =
            new JSSymbolTypeInferrer(this._scope, this._index, this._location);
        PropertyElement property = symbolInferrer.getSymbolPropertyElement(name);
        if (property != null) {
          // We found a match in the local scope
          properties = CollectionsUtil.newList(property);
        } else {
          // No match in the local scope, query the globals in index
          properties = this._queryHelper.getGlobals(this._index, getProject(), getFileName(), name);
        }
      }
    } else {
      // Scope says it doesn't has a symbol with that name, so query the globals in index
      properties = this._queryHelper.getGlobals(this._index, getProject(), getFileName(), name);
    }

    // Hopefully we found at least one match...
    if (properties != null) {
      for (PropertyElement property : properties) {
        if (property instanceof FunctionElement) {
          FunctionElement function = (FunctionElement) property;
          for (String type : function.getSignatureTypes()) {
            this.addType(type);
          }
        } else {
          for (String type : property.getTypeNames()) {
            this.addType(type);
          }
        }
      }
    }
  }
Exemple #25
0
  /**
   * For use in telling if a given resource is a changed file, or is a folder containing changes
   * underneath it.
   *
   * @param resource
   * @return
   */
  protected boolean resourceOrChildHasChanges(IResource resource) {
    List<ChangedFile> changedFiles = changedFiles();
    if (CollectionsUtil.isEmpty(changedFiles)) {
      return false;
    }

    IPath workingDirectory = repository.workingDirectory();
    IPath resourcePath = resource.getLocation();
    for (ChangedFile changedFile : changedFiles) {
      IPath fullPath = workingDirectory.append(changedFile.getPath()).makeAbsolute();
      if (resourcePath.isPrefixOf(fullPath)) {
        return true;
      }
    }

    return false;
  }
Exemple #26
0
  protected ChangedFile getChangedFileForResource(IResource resource) {
    if (resource == null || resource.getLocationURI() == null) {
      return null;
    }

    IPath resourcePath = resource.getLocation();
    List<ChangedFile> changedFiles = changedFiles();
    if (!CollectionsUtil.isEmpty(changedFiles)) {
      for (ChangedFile changedFile : changedFiles) {
        IPath fullPath = workingDirectory().append(changedFile.getPath());
        if (resourcePath.equals(fullPath)) {
          return changedFile;
        }
      }
    }
    return null;
  }
  /**
   * toSource
   *
   * @param printer
   */
  public void toSource(SourcePrinter printer) {
    printer.printIndent();

    // print any annotations
    if (!this.isInstanceProperty()) {
      printer.print("static "); // $NON-NLS-1$
    }
    if (this.isInternal()) {
      printer.print("internal "); // $NON-NLS-1$
    }
    if (this.isConstructor()) {
      printer.print("constructor "); // $NON-NLS-1$
    }
    if (this.isMethod()) {
      printer.print("method "); // $NON-NLS-1$
    }

    // print name
    printer.print(this.getName());

    // print parameter types
    printer
        .print('(')
        .print(StringUtil.join(JSTypeConstants.PARAMETER_DELIMITER, this.getParameterTypes()))
        .print(')');

    // print return types
    List<String> returnTypes = this.getReturnTypeNames();

    printer.print(JSTypeConstants.FUNCTION_SIGNATURE_DELIMITER);

    if (!CollectionsUtil.isEmpty(returnTypes)) {
      printer.print(StringUtil.join(JSTypeConstants.RETURN_TYPE_DELIMITER, returnTypes));
    } else {
      printer.print(JSTypeConstants.UNDEFINED_TYPE);
    }

    // print exceptions
    if (this.hasExceptions()) {
      printer
          .print(" throws ")
          .print(StringUtil.join(", ", this.getExceptionTypes())); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }
  protected void assertElements(String... elements) throws DTDTransformException {
    // gather element names for easy lookup
    List<ElementElement> elementObjects = transformer.getElements();
    assertNotNull("Was unable to determine elements", elementObjects);
    Set<String> names =
        new HashSet<String>(
            CollectionsUtil.map(
                elementObjects,
                new IMap<ElementElement, String>() {
                  public String map(ElementElement item) {
                    return item.getName();
                  }
                }));

    // assert the element name list
    for (String name : elements) {
      assertTrue("Did not find element: " + name, names.contains(name));
    }
  }
Exemple #29
0
  @Test
  public void testPropertyWithConstantValues() {
    String typeName = "MyClass";
    String propertyName = "myProperty";

    // create type
    TypeElement type = new TypeElement();
    type.setName(typeName);

    // create property within type
    PropertyElement property =
        createProperty(
            "name",
            propertyName,
            IHasPredefinedValues.CONSTANTS_PROPERTY,
            CollectionsUtil.newList("Titanium.UI.FILL", "Titanium.UI.ALIGN"));
    type.addProperty(property);

    // write type to index
    this.writeType(type);

    // then retrieve it
    List<TypeElement> retrievedTypes = this.getType(typeName);
    TypeElement retrievedType = retrievedTypes.get(0);

    assertNotNull(retrievedType);
    assertEquals(typeName, retrievedType.getName());

    // make sure we have one property
    List<PropertyElement> properties = retrievedType.getProperties();
    assertNotNull(properties);
    assertEquals(1, properties.size());

    // make sure the name is correct
    PropertyElement retrievedProperty = properties.get(0);
    assertEquals(propertyName, retrievedProperty.getName());
    // Check constants
    List<String> constants = retrievedProperty.getConstants();
    assertEquals(2, constants.size());
    assertTrue(constants.contains("Titanium.UI.FILL"));
    assertTrue(constants.contains("Titanium.UI.ALIGN"));
  }
  /**
   * getContributedFiles
   *
   * @param container
   * @return
   */
  protected Set<IFileStore> getContributedFiles(URI container) {
    // FIXME This shoves all contributed files into the same index as the project!
    // We want the notion of a project referring to build path entries that are maintained in their
    // own indices,
    // which we can share across projects!
    Set<IFileStore> result = new HashSet<IFileStore>();

    IndexManager manager = getIndexManager();
    if (manager != null) {
      for (IIndexFileContributor contributor : manager.getFileContributors()) {
        Set<IFileStore> files = contributor.getFiles(container);

        if (!CollectionsUtil.isEmpty(files)) {
          result.addAll(files);
        }
      }
    }

    return result;
  }