summaryrefslogtreecommitdiff
path: root/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XExpressionImpl.java
blob: b966377a47baa3edf3a7243e5d2384468be363a5 (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
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
/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.xdebugger.impl.breakpoints;

import com.intellij.lang.Language;
import com.intellij.xdebugger.XExpression;
import com.intellij.xdebugger.evaluation.EvaluationMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author egor
*/
public class XExpressionImpl implements XExpression {
  public static final XExpression EMPTY_EXPRESSION = fromText("", EvaluationMode.EXPRESSION);
  public static final XExpression EMPTY_CODE_FRAGMENT = fromText("", EvaluationMode.CODE_FRAGMENT);

  @NotNull private final String myExpression;
  private final Language myLanguage;
  private final String myCustomInfo;
  private final EvaluationMode myMode;

  public XExpressionImpl(@NotNull String expression, Language language, String customInfo) {
    this(expression, language, customInfo, EvaluationMode.EXPRESSION);
  }

  public XExpressionImpl(@NotNull String expression, Language language, String customInfo, EvaluationMode mode) {
    myExpression = expression;
    myLanguage = language;
    myCustomInfo = customInfo;
    myMode = mode;
  }

  @NotNull
  @Override
  public String getExpression() {
    return myExpression;
  }

  @Override
  public Language getLanguage() {
    return myLanguage;
  }

  @Override
  public String getCustomInfo() {
    return myCustomInfo;
  }

  @Override
  public EvaluationMode getMode() {
    return myMode;
  }

  @Nullable
  public static XExpressionImpl fromText(@Nullable String text) {
    return text != null ? new XExpressionImpl(text, null, null, EvaluationMode.EXPRESSION) : null;
  }

  @Nullable
  public static XExpressionImpl fromText(@Nullable String text, EvaluationMode mode) {
    return text != null ? new XExpressionImpl(text, null, null, mode) : null;
  }

  public static XExpressionImpl changeMode(XExpression expression, EvaluationMode mode) {
    return new XExpressionImpl(expression.getExpression(), expression.getLanguage(), expression.getCustomInfo(), mode);
  }

  @Override
  public String toString() {
    return myExpression;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    XExpressionImpl that = (XExpressionImpl)o;

    if (myCustomInfo != null ? !myCustomInfo.equals(that.myCustomInfo) : that.myCustomInfo != null) return false;
    if (!myExpression.equals(that.myExpression)) return false;
    if (myLanguage != null ? !myLanguage.equals(that.myLanguage) : that.myLanguage != null) return false;
    if (myMode != that.myMode) return false;

    return true;
  }

  @Override
  public int hashCode() {
    int result = myExpression.hashCode();
    result = 31 * result + (myLanguage != null ? myLanguage.hashCode() : 0);
    result = 31 * result + (myCustomInfo != null ? myCustomInfo.hashCode() : 0);
    result = 31 * result + (myMode != null ? myMode.hashCode() : 0);
    return result;
  }
}