Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2b2702e97777899ad2bacfaed993902f39711b1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
 * Copyright (c) 2015 Takari, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *      Anton Tanasenko. - initial API and implementation
 *******************************************************************************/

package org.eclipse.m2e.editor.xml.mojo;

import java.util.Collections;
import java.util.List;


/**
 * @since 1.6
 */
public class MojoParameter {

  private String name;

  private String type;

  private boolean required;

  private String description;

  private String expression;

  private String defaultValue;

  private List<MojoParameter> nested;

  private boolean multiple;

  private boolean map;

  public MojoParameter(String name, String type, List<MojoParameter> parameters) {
    this.name = name;
    this.type = type;
    nested = parameters;
  }

  public MojoParameter(String name, String type, MojoParameter parameter) {
    this(name, type, Collections.singletonList(parameter));
  }

  public MojoParameter(String name, String type) {
    this(name, type, Collections.<MojoParameter> emptyList());
  }

  public MojoParameter multiple() {
    this.multiple = true;
    return this;
  }

  public MojoParameter map() {
    this.map = true;
    return this;
  }

  public boolean isMultiple() {
    return multiple;
  }

  public boolean isMap() {
    return this.map;
  }

  public List<MojoParameter> getNestedParameters() {
    return nested == null ? Collections.<MojoParameter> emptyList() : Collections.unmodifiableList(nested);
  }

  public String getName() {
    return this.name;
  }

  public String getType() {
    return this.type;
  }

  public boolean isRequired() {
    return this.required;
  }

  public void setRequired(boolean required) {
    this.required = required;
  }

  public String getDescription() {
    return this.description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public String getExpression() {
    return this.expression;
  }

  public void setExpression(String expression) {
    this.expression = expression;
  }

  public String getDefaultValue() {
    return this.defaultValue;
  }

  public void setDefaultValue(String defaultValue) {
    this.defaultValue = defaultValue;
  }

  public String toString() {
    return name + "{" + type + "}"; //$NON-NLS-1$ //$NON-NLS-2$
  }

  public MojoParameter getNestedParameter(String name) {

    List<MojoParameter> params = getNestedParameters();
    if(params.size() == 1) {
      MojoParameter param = params.get(0);
      if(param.isMultiple()) {
        return param;
      }
    }

    for(MojoParameter p : params) {
      if(p.getName().equals(name)) {
        return p;
      }
    }
    return null;
  }

  public MojoParameter getContainer(String[] path) {

    if(path == null || path.length == 0) {
      return this;
    }

    MojoParameter param = this;
    int i = 0;
    while(param != null && i < path.length) {
      param = param.getNestedParameter(path[i]);
      i++ ;
    }

    if(param == null) {
      return null;
    }

    return param;
  }
}

Back to the top