Ejemplo n.º 1
0
  /** {@inheritDoc} */
  public Object execute(CommandLine commandLine) throws Exception {
    String name = commandLine.getValue(Options.PROJECT_OPTION);
    IProject project = ProjectUtils.getProject(name);
    String[] aliases = StringUtils.split(commandLine.getValue(Options.NATURE_OPTION), ',');

    IProjectDescription desc = project.getDescription();
    String[] natureIds = desc.getNatureIds();
    ArrayList<String> modified = new ArrayList<String>();
    ArrayList<String> newNatures = new ArrayList<String>();
    CollectionUtils.addAll(modified, natureIds);
    for (String alias : aliases) {
      String natureId = ProjectNatureFactory.getNatureForAlias(alias);
      if (natureId != null && !modified.contains(natureId)) {
        modified.add(natureId);
        newNatures.add(natureId);
      }
    }

    desc.setNatureIds((String[]) modified.toArray(new String[modified.size()]));
    project.setDescription(desc, new NullProgressMonitor());

    for (String nature : newNatures) {
      ProjectManager manager = ProjectManagement.getProjectManager(nature);
      if (manager != null) {
        manager.create(project, commandLine);
      }
    }

    return Services.getMessage("project.nature.added");
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  public Object execute(CommandLine commandLine) throws Exception {
    String name = commandLine.getValue(Options.PROJECT_OPTION);
    IProject project = ProjectUtils.getProject(name, true);
    String setting = commandLine.getValue(Options.SETTING_OPTION);

    Preferences preferences = getPreferences();

    if (commandLine.hasOption(Options.VALUE_OPTION)) {
      String value = commandLine.getValue(Options.VALUE_OPTION);
      preferences.setValue(project, setting, value);
      return null;
    }

    return preferences.getValue(project, setting);
  }
Ejemplo n.º 3
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclim.command.Command#execute(CommandLine)
   */
  public String execute(CommandLine commandLine) throws Exception {
    Object family = getFamily(commandLine.getValue(Options.FAMILY_OPTION));
    IJobManager manager = Job.getJobManager();
    Job[] jobs = manager.find(family);

    StringBuffer buffer = new StringBuffer();
    int maxlength = 0;
    for (Job job : jobs) {
      int length = job.toString().length();
      if (length > maxlength) {
        maxlength = length;
      }
    }

    for (Job job : jobs) {
      if (buffer.length() > 0) {
        buffer.append('\n');
      }
      buffer
          .append(StringUtils.rightPad(job.toString(), maxlength))
          .append(" - ")
          .append(getStatus(job));
    }
    return buffer.toString();
  }
Ejemplo n.º 4
0
  /** {@inheritDoc} */
  public Object execute(CommandLine commandLine) throws Exception {
    String name = commandLine.getValue(Options.PROJECT_OPTION);

    IProject project = ProjectUtils.getProject(name, true);
    ProjectManagement.refresh(project, commandLine);

    return Services.getMessage("project.refreshed", name);
  }
Ejemplo n.º 5
0
  /** {@inheritDoc} */
  public Object execute(CommandLine commandLine) throws Exception {
    String project = commandLine.getValue(Options.PROJECT_OPTION);
    String file = commandLine.getValue(Options.FILE_OPTION);
    String propertiesOption = commandLine.getValue(Options.PROPERTIES_OPTION);
    String[] properties = {};
    if (propertiesOption != null) {
      properties = StringUtils.split(propertiesOption, ',');
    }
    int offset = getOffset(commandLine);

    // validate supplied fields.
    ICompilationUnit src = JavaUtils.getCompilationUnit(project, file);
    IType type = TypeUtils.getType(src, offset);
    for (int ii = 0; ii < properties.length; ii++) {
      if (!type.getField(properties[ii]).exists()) {
        throw new RuntimeException(
            Services.getMessage("field.not.found", properties[ii], type.getElementName()));
      }
    }

    // check if constructor already exists.
    IMethod method = null;
    if (properties.length == 0) {
      method = type.getMethod(type.getElementName(), null);
    } else {
      String[] fieldSigs = new String[properties.length];
      for (int ii = 0; ii < properties.length; ii++) {
        fieldSigs[ii] = type.getField(properties[ii]).getTypeSignature();
      }
      method = type.getMethod(type.getElementName(), fieldSigs);
    }
    if (method.exists()) {
      throw new RuntimeException(
          Services.getMessage(
              "constructor.already.exists",
              type.getElementName() + " (" + buildParams(type, properties) + ")"));
    }

    // find the sibling to insert before.
    IJavaElement sibling = null;
    IMethod[] methods = type.getMethods();
    for (int ii = 0; ii < methods.length; ii++) {
      if (methods[ii].isConstructor()) {
        sibling = ii < methods.length - 1 ? methods[ii + 1] : null;
      }
    }
    // insert before any other methods or inner classes if any.
    if (sibling == null) {
      if (methods.length > 0) {
        sibling = methods[0];
      } else {
        IType[] types = type.getTypes();
        sibling = types != null && types.length > 0 ? types[0] : null;
      }
    }

    HashMap<String, Object> values = new HashMap<String, Object>();
    values.put("type", type.getElementName());
    boolean hasProperties = properties != null && properties.length > 0;
    values.put("fields", hasProperties ? properties : null);
    values.put("params", hasProperties ? buildParams(type, properties) : StringUtils.EMPTY);

    PluginResources resources = (PluginResources) Services.getPluginResources(PluginResources.NAME);
    String constructor = TemplateUtils.evaluate(resources, TEMPLATE, values);
    Position position =
        TypeUtils.getPosition(type, type.createMethod(constructor, sibling, false, null));
    JavaUtils.format(
        src, CodeFormatter.K_COMPILATION_UNIT, position.getOffset(), position.getLength());

    return null;
  }