Skip to content

Commit

Permalink
[FIXED JENKINS-49976] Get rid of ModelASTValue anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Mar 7, 2018
1 parent a85f7c5 commit ece602d
Showing 1 changed file with 47 additions and 34 deletions.
Expand Up @@ -115,47 +115,60 @@ public String toString() {
}

public static ModelASTValue fromConstant(final Object o, Object sourceLocation) {
return new ModelASTValue(sourceLocation, o) {
@Override
public boolean isLiteral() {
return true;
}
return new ConstantValue(sourceLocation, o);
}

public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
return new GStringValue(sourceLocation, gstring);
}

@Override
public String toGroovy() {
if (getValue() instanceof String) {
String str = (String) getValue();
str = str.replace("\\", "\\\\");
if (str.indexOf('\n') == -1) {
return "'" + (str.replace("'", "\\'")) + "'";
} else {
return "'''" + (str.replace("'", "\\'")) + "'''";
}
} else if (getValue() != null) {
return getValue().toString();
public static final class ConstantValue extends ModelASTValue {
ConstantValue(Object sourceLocation, Object v) {
super(sourceLocation, v);
}

@Override
public boolean isLiteral() {
return true;
}

@Override
public String toGroovy() {
if (getValue() instanceof String) {
String str = (String) getValue();
str = str.replace("\\", "\\\\");
if (str.indexOf('\n') == -1) {
return "'" + (str.replace("'", "\\'")) + "'";
} else {
return null;
return "'''" + (str.replace("'", "\\'")) + "'''";
}
} else if (getValue() != null) {
return getValue().toString();
} else {
return null;
}
};
}
}

public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
return new ModelASTValue(sourceLocation, gstring) {
@Override
public boolean isLiteral() {
return false;
}
public static final class GStringValue extends ModelASTValue {
GStringValue(Object sourceLocation, Object v) {
super(sourceLocation, v);
}

@Override
public String toGroovy() {
String gstring = (String)getValue();
if (gstring.startsWith("${") && gstring.endsWith("}")) {
return gstring.substring(2, gstring.length() - 1);
} else {
return gstring;
}
@Override
public boolean isLiteral() {
return false;
}

@Override
public String toGroovy() {
String gstring = (String)getValue();
if (gstring.startsWith("${") && gstring.endsWith("}")) {
return gstring.substring(2, gstring.length() - 1);
} else {
return gstring;
}
};
}

}
}

0 comments on commit ece602d

Please sign in to comment.