summaryrefslogtreecommitdiff
path: root/platform/structuralsearch/source/com/intellij/structuralsearch/NamedScriptableDefinition.java
blob: 8c954ab5a0ef7b469fe771f701d3b12ce54a39ac (plain)
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
package com.intellij.structuralsearch;

import com.intellij.openapi.util.JDOMExternalizable;
import org.jdom.Element;
import org.jdom.Attribute;
import org.jetbrains.annotations.NonNls;

/**
 * @author Maxim.Mossienko
 * Date: 11.06.2009
 * Time: 12:55:39
 */
public class NamedScriptableDefinition implements JDOMExternalizable, Cloneable {
  @NonNls private static final String NAME = "name";
  @NonNls private static final String SCRIPT = "script";
  private String name;
  private String scriptCodeConstraint = "";

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getScriptCodeConstraint() {
    return scriptCodeConstraint;
  }

  public void setScriptCodeConstraint(String scriptCodeConstraint) {
    this.scriptCodeConstraint = scriptCodeConstraint;
  }

  public Object clone() {
    try {
      return super.clone();
    } catch(CloneNotSupportedException ex) {
      return null;
    }
  }

  public void readExternal(Element element) {
    Attribute attribute = element.getAttribute(NAME);
    if (attribute != null) {
      name = attribute.getValue();
    }

    String s = element.getAttributeValue(SCRIPT);
    if (s != null) {
      setScriptCodeConstraint(s);
    }
  }

  public void writeExternal(Element element) {
    element.setAttribute(NAME,name);
    if (scriptCodeConstraint.length() > 0) element.setAttribute(SCRIPT,scriptCodeConstraint);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof NamedScriptableDefinition)) return false;

    NamedScriptableDefinition that = (NamedScriptableDefinition)o;

    if (name != null ? !name.equals(that.name) : that.name != null) return false;
    if (scriptCodeConstraint != null ? !scriptCodeConstraint.equals(that.scriptCodeConstraint) : that.scriptCodeConstraint != null) {
      return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int result = name != null ? name.hashCode() : 0;
    result = 31 * result + (scriptCodeConstraint != null ? scriptCodeConstraint.hashCode() : 0);
    return result;
  }
}