public static StringLiteral newStringLiteral(final AST ast, final String value) { final StringLiteral result = ast.newStringLiteral(); result.setLiteralValue(value); return result; }
private void flushBuffer() { if (buffer.length() > 0) { StringLiteral bufferedStringLiteral= fAst.newStringLiteral(); bufferedStringLiteral.setLiteralValue(buffer.toString()); buffer.setLength(0); expression= createSumExpression(expression, bufferedStringLiteral); } }
/** * Builds a new {@link StringLiteral} instance. * * @param s the string literal value * @return a new string literal */ public StringLiteral string(String s) { final StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(s); return sl; }
/** * Create a string literal. * * @param value literal value * @return literal */ public StringLiteral stringLiteral(String value) { StringLiteral literal = m_ast.newStringLiteral(); literal.setLiteralValue(value); return literal; }
private void flushBuffer() { if (buffer.length() > 0) { StringLiteral bufferedStringLiteral= fAst.newStringLiteral(); bufferedStringLiteral.setLiteralValue(buffer.toString()); buffer.setLength(0); expression= createSumExpression(expression, bufferedStringLiteral); } }
@Override protected StringLiteral convertObject(String string, AST ast) { StringLiteral stringLiteral = ast.newStringLiteral(); stringLiteral.setLiteralValue(string); return stringLiteral; }
protected void flushBuffer() { if (fBuffer.length() > 0) { if (temporaryBlock == null) temporaryBlock= toStringMethod.getBody(); StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(fBuffer.toString()); appendExpression(literal); fBuffer.setLength(0); } }
protected void flushBuffer() { if (fBuffer.length() > 0) { if (temporaryBlock == null) temporaryBlock= toStringMethod.getBody(); StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(fBuffer.toString()); appendExpression(literal); fBuffer.setLength(0); } }
/** * Add a string literal operand to expression. * * @param value string literal operand */ public void addStringLiteralOperand(String value) { StringLiteral strlit = m_ast.newStringLiteral(); strlit.setLiteralValue(value); addOperand(strlit); }
/** * Set initializer as a string literal. * * @param value initializer */ public void setStringInitializer(String value) { VariableDeclarationFragment frag = (VariableDeclarationFragment)m_field.fragments().get(0); StringLiteral literal = m_ast.newStringLiteral(); literal.setLiteralValue(value); frag.setInitializer(literal); }
protected void flushBuffer(Block target) { if (fBuffer.length() > 0) { StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(fBuffer.toString()); if (target == null) target= toStringMethod.getBody(); target.statements().add(fAst.newExpressionStatement(createMethodInvocation(fBuilderVariableName, APPEND_METHOD_NAME, literal))); fBuffer.setLength(0); } }
protected void flushBuffer(Block target) { if (fBuffer.length() > 0) { StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(fBuffer.toString()); if (target == null) target= toStringMethod.getBody(); target.statements().add(fAst.newExpressionStatement(createMethodInvocation(fBuilderVariableName, APPEND_METHOD_NAME, literal))); fBuffer.setLength(0); } }
private void correctMI(MethodInvocation mi) { StringLiteral sl = mi.getAST().newStringLiteral(); sl.setLiteralValue("Error occurred: "); mi.arguments().add(0, sl); }
/** * Escapes a string value to a literal that can be used in Java source. * * @param stringValue the string value * @return the escaped string * @see StringLiteral#getEscapedValue() */ public static String getEscapedStringLiteral(String stringValue) { StringLiteral stringLiteral= AST.newAST(IASTSharedValues.SHARED_AST_LEVEL).newStringLiteral(); stringLiteral.setLiteralValue(stringValue); return stringLiteral.getEscapedValue(); }
/** * Escapes a string value to a literal that can be used in Java source. * * @param stringValue the string value * @return the escaped string * @see StringLiteral#getEscapedValue() */ public static String getEscapedStringLiteral(String stringValue) { StringLiteral stringLiteral= AST.newAST(ASTProvider.SHARED_AST_LEVEL).newStringLiteral(); stringLiteral.setLiteralValue(stringValue); return stringLiteral.getEscapedValue(); }
private static MemberValuePair newKeyValueString(final AST ast, final String key, final String value) { final MemberValuePair pair = ast.newMemberValuePair(); pair.setName(ast.newSimpleName(key)); final StringLiteral topicLiteral = ast.newStringLiteral(); topicLiteral.setLiteralValue(value); pair.setValue(topicLiteral); return pair; }
public SingleMemberAnnotation createCatchMark(String catchMark) { SingleMemberAnnotation supp = ast.newSingleMemberAnnotation(); supp.setTypeName(ast.newSimpleName("SuppressWarnings")); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(catchMark); supp.setValue(sl); return supp; }
/** * Build a string concatenation expression starting from from a string literal. * * @param text literal text * @return string concatenation expression */ public InfixExpressionBuilder buildStringConcatenation(String text) { InfixExpression expr = getAST().newInfixExpression(); StringLiteral strlit = getAST().newStringLiteral(); strlit.setLiteralValue(text); expr.setOperator(Operator.PLUS); return new InfixExpressionBuilder(this, expr, strlit); }
/** * Build new instance creator of a simple type using a constructor that takes a single string value. * * @param type simple type name * @param value string value to be passed to constructor * @return instance creation */ public NewInstanceBuilder newInstanceFromString(String type, String value) { ClassInstanceCreation create = getAST().newClassInstanceCreation(); create.setType(createType(type)); StringLiteral literal = getAST().newStringLiteral(); literal.setLiteralValue(value); create.arguments().add(literal); return new NewInstanceBuilder(this, create); }
@SuppressWarnings("unchecked") public static String addXmlRootAnnotation(final String source, final String name) { final CompilationUnit unit = JavaSourceUtils.getCompilationUnit(source); final AST ast = unit.getAST(); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final NormalAnnotation xmlRootAnnotation = ast.newNormalAnnotation(); xmlRootAnnotation.setTypeName(ast.newName(XmlRootElement.class.getSimpleName())); // name final MemberValuePair generatedMemberValue = ast.newMemberValuePair(); generatedMemberValue.setName(ast.newSimpleName("name")); final StringLiteral internalNameLiteral = ast.newStringLiteral(); internalNameLiteral.setLiteralValue(name); generatedMemberValue.setValue(internalNameLiteral); xmlRootAnnotation.values().add(generatedMemberValue); JavaSourceUtils.addAnnotation(classType, xmlRootAnnotation); JavaSourceUtils.addImport(unit, XmlRootElement.class.getName()); return JavaSourceUtils.rewrite(unit, ast); }