Java Code Examples for org.eclipse.xtext.util.Strings#convertToJavaString()

The following examples show how to use org.eclipse.xtext.util.Strings#convertToJavaString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneratedClassAnnotation.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String toString() {
	StringBuilder stringBuilder = new StringBuilder("@Generated(");
	if (includeDate || !Strings.isEmpty(comment)) {
		stringBuilder.append("value = ");
	}
	stringBuilder.append('\"').append(getGeneratorName()).append('\"');
	if (includeDate) {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
		String date = dateFormat.format(new Date());
		stringBuilder.append(", date = \"").append(date).append('\"');
	}
	if (!Strings.isEmpty(comment)) {
		String convertedComment = Strings.convertToJavaString(comment);
		stringBuilder.append(", comments = \"").append(convertedComment).append('\"');
	}
	return stringBuilder.append(')').toString();
}
 
Example 2
Source File: XtendCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void writeExpression(XExpression expression, CharSequence indentation, boolean immediate) {
	boolean referenced = !isPrimitiveVoid(expression);
	internalToJavaStatement(expression, appendable, referenced);
	if (referenced) {
		ITreeAppendable tracingAppendable = appendable.trace(expression, true);
		tracingAppendable.newLine();
		tracingAppendable.append(variableName);
		if (immediate)
			tracingAppendable.append(".appendImmediate(");
		else
			tracingAppendable.append(".append(");
		internalToJavaExpression(expression, tracingAppendable);

		String javaIndentation = Strings.convertToJavaString(indentation.toString(), false);
		if (immediate || !javaIndentation.isEmpty()) {
			tracingAppendable.append(", \"");
			tracingAppendable.append(javaIndentation);
			tracingAppendable.append("\"");
		}
		tracingAppendable.append(");");
	}
}
 
Example 3
Source File: MutableJvmFieldDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setConstantValueAsChar(final char value) {
  this.internalGenericSetConstantValue(Character.valueOf(value));
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("\'");
      String _convertToJavaString = Strings.convertToJavaString(Character.toString(value));
      _builder.append(_convertToJavaString);
      _builder.append("\'");
    }
  };
  this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
 
Example 4
Source File: MutableJvmFieldDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setConstantValueAsString(final String value) {
  this.internalGenericSetConstantValue(value);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("\"");
      String _convertToJavaString = Strings.convertToJavaString(value);
      _builder.append(_convertToJavaString);
      _builder.append("\"");
    }
  };
  this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client);
}
 
Example 5
Source File: NewLineNode.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toString() {
	String result = getClass().getSimpleName() + " \"" + Strings.convertToJavaString(lineDelimiter) + "\"";
	if (ifNotEmpty) {
		result = result + " if not empty";
	}
	return result;
}
 
Example 6
Source File: TerminalRuleTestLanguageConverters.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@ValueConverter(rule = "STRING")
public IValueConverter<String> STRING() {
	return new AbstractNullSafeConverter<String>() {
		@Override
		protected String internalToValue(String string, INode node) {
			return Strings.convertFromJavaString(string.substring(1, string.length() - 1), false);
		}

		@Override
		protected String internalToString(String value) {
			return '"' + Strings.convertToJavaString(value, false) + '"';
		}
	};
}
 
Example 7
Source File: SingleQuotedStringConverter.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String toEscapedString(String value) {
	return '\'' + Strings.convertToJavaString(value, false) + '\'';
}
 
Example 8
Source File: TextNode.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getSimpleName() + " \"" + Strings.convertToJavaString(text.toString()) + "\"";
}
 
Example 9
Source File: STRINGValueConverter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String toEscapedString(String value) {
	return '"' + Strings.convertToJavaString(value, false) + '"';
}
 
Example 10
Source File: UIDtoStringConverter.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String toEscapedString(String value) {
    return '"' + Strings.convertToJavaString(value, false) + '"';
}
 
Example 11
Source File: ValueTypeToStringConverter.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String toEscapedString(String value) {
    return '"' + Strings.convertToJavaString(value, false) + '"';
}
 
Example 12
Source File: GenerateTestsMojo.java    From sarl with Apache License 2.0 4 votes vote down vote up
private static String str(Object obj) {
	if (obj == null) {
		return ""; //$NON-NLS-1$
	}
	return Strings.convertToJavaString(obj.toString());
}
 
Example 13
Source File: UIDtoStringConverter.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
protected String toEscapedString(String value) {
    return '"' + Strings.convertToJavaString(value, false) + '"';
}
 
Example 14
Source File: ValueTypeToStringConverter.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
protected String toEscapedString(String value) {
    return '"' + Strings.convertToJavaString(value, false) + '"';
}
 
Example 15
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Convert a given input string to a Java string. Non-ascii characters will
 * be replaced by a unicode escape sequence by default.
 */
protected String doConvertToJavaString(final String input) {
  return Strings.convertToJavaString(input, true);
}
 
Example 16
Source File: XtendGenerator.java    From xtext-xtend with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Convert a given input string to a Java string.
 * 
 * Unicode escaping is handled by the {@link UnicodeAwarePostProcessor}.
 */
@Override
public String doConvertToJavaString(final String input) {
  return Strings.convertToJavaString(input, false);
}