Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2010 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 
 package org.eclipse.jdt.core.dom;
 
 import java.util.List;
 
String literal nodes.

Since:
2.0
Noinstantiate:
This class is not intended to be instantiated by clients.
 
 public class StringLiteral extends Expression {

The "escapedValue" structural property of this node type (type: java.lang.String).

Since:
3.0
 
 		new SimplePropertyDescriptor(StringLiteral.class"escapedValue"String.class); //$NON-NLS-1$
 
A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.
 
 	private static final List PROPERTY_DESCRIPTORS;
 
 	static {
 		List propertyList = new ArrayList(2);
 		createPropertyList(StringLiteral.classpropertyList);
 	}

Returns a list of structural property descriptors for this node type. Clients must not modify the result.

Parameters:
apiLevel the API level; one of the AST.JLS* constants
Returns:
a list of property descriptors (element type: StructuralPropertyDescriptor)
Since:
3.0
 
 	public static List propertyDescriptors(int apiLevel) {
 	}

The literal string, including quotes and escapes; defaults to the literal for the empty string.
 
 	private String escapedValue = "\"\"";//$NON-NLS-1$
 
Creates a new unparented string literal node owned by the given AST. By default, the string literal denotes the empty string.

N.B. This constructor is package-private.

Parameters:
ast the AST that is to own this node
 
 	StringLiteral(AST ast) {
 		super(ast);
 	}
 
 	/* (omit javadoc for this method)
 	 * Method declared on ASTNode.
 	 */
 	final List internalStructuralPropertiesForType(int apiLevel) {
 		return propertyDescriptors(apiLevel);
 	}
 
 	/* (omit javadoc for this method)
 	 * Method declared on ASTNode.
 	 */
 	final Object internalGetSetObjectProperty(SimplePropertyDescriptor propertyboolean getObject value) {
 		if (property == ) {
 			if (get) {
 				return getEscapedValue();
 			} else {
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetObjectProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final int getNodeType0() {
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	ASTNode clone0(AST target) {
		StringLiteral result = new StringLiteral(target);
		return result;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final boolean subtreeMatch0(ASTMatcher matcherObject other) {
		// dispatch to correct overloaded match method
		return matcher.match(thisother);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	void accept0(ASTVisitor visitor) {
		visitor.visit(this);
		visitor.endVisit(this);
	}

Returns the string value of this literal node to the given string literal token. The token is the sequence of characters that would appear in the source program, including enclosing double quotes and embedded escapes.

Returns:
the string literal token, including enclosing double quotes and embedded escapes
	public String getEscapedValue() {
		return this.;
	}

Sets the string value of this literal node to the given string literal token. The token is the sequence of characters that would appear in the source program, including enclosing double quotes and embedded escapes. For example,
  • "" setLiteral("\"\"")
  • "hello world" setLiteral("\"hello world\"")
  • "boo\nhoo" setLiteral("\"boo\\nhoo\"")

Parameters:
token the string literal token, including enclosing double quotes and embedded escapes
Throws:
java.lang.IllegalArgumentException if the argument is incorrect
	public void setEscapedValue(String token) {
		// update internalSetEscapedValue(String) if this is changed
		if (token == null) {
			throw new IllegalArgumentException("Token cannot be null"); //$NON-NLS-1$
		}
		Scanner scanner = this..;
		char[] source = token.toCharArray();
		scanner.setSource(source);
		scanner.resetTo(0, source.length);
		try {
			int tokenType = scanner.getNextToken();
			switch(tokenType) {
					break;
				default:
					throw new IllegalArgumentException("Invalid string literal : >" + token + "<"); //$NON-NLS-1$//$NON-NLS-2$
			}
catch(InvalidInputException e) {
			throw new IllegalArgumentException("Invalid string literal : >" + token + "<");//$NON-NLS-1$//$NON-NLS-2$
		}
		this. = token;
	}
	/* (omit javadoc for this method)
	 * This method is a copy of setEscapedValue(String) that doesn't do any validation.
	 */
		this. = token;
	}

Returns the value of this literal node.

For example,

 StringLiteral s;
 s.setEscapedValue("\"hello\\nworld\"");
 assert s.getLiteralValue().equals("hello\nworld");
 

Note that this is a convenience method that converts from the stored string literal token returned by getEscapedLiteral.

Returns:
the string value without enclosing double quotes and embedded escapes
Throws:
java.lang.IllegalArgumentException if the literal value cannot be converted
	public String getLiteralValue() {
		int len = s.length();
		if (len < 2 || s.charAt(0) != '\"' || s.charAt(len-1) != '\"' ) {
		}
		Scanner scanner = this..;
		char[] source = s.toCharArray();
		scanner.setSource(source);
		scanner.resetTo(0, source.length);
		try {
			int tokenType = scanner.getNextToken();
			switch(tokenType) {
					return scanner.getCurrentStringLiteral();
				default:
			}
catch(InvalidInputException e) {
		}
	}

Sets the value of this literal node.

For example,

 StringLiteral s;
 s.setLiteralValue("hello\nworld");
 assert s.getEscapedValue().equals("\"hello\\nworld\"");
 assert s.getLiteralValue().equals("hello\nworld");
 

Note that this is a convenience method that converts to the stored string literal token acceptable to setEscapedLiteral.

Parameters:
value the string value without enclosing double quotes and embedded escapes
Throws:
java.lang.IllegalArgumentException if the argument is incorrect
	public void setLiteralValue(String value) {
		if (value == null) {
		}
		int len = value.length();
		StringBuffer b = new StringBuffer(len + 2);
		b.append("\""); // opening delimiter //$NON-NLS-1$
		for (int i = 0; i < leni++) {
			char c = value.charAt(i);
			switch(c) {
				case '\b' :
					b.append("\\b"); //$NON-NLS-1$
					break;
				case '\t' :
					b.append("\\t"); //$NON-NLS-1$
					break;
				case '\n' :
					b.append("\\n"); //$NON-NLS-1$
					break;
				case '\f' :
					b.append("\\f"); //$NON-NLS-1$
					break;
				case '\r' :
					b.append("\\r"); //$NON-NLS-1$
					break;
				case '\"':
					b.append("\\\""); //$NON-NLS-1$
					break;
				case '\\':
					b.append("\\\\"); //$NON-NLS-1$
					break;
				case '\0' :
					b.append("\\0"); //$NON-NLS-1$
					break;
				case '\1' :
					b.append("\\1"); //$NON-NLS-1$
					break;
				case '\2' :
					b.append("\\2"); //$NON-NLS-1$
					break;
				case '\3' :
					b.append("\\3"); //$NON-NLS-1$
					break;
				case '\4' :
					b.append("\\4"); //$NON-NLS-1$
					break;
				case '\5' :
					b.append("\\5"); //$NON-NLS-1$
					break;
				case '\6' :
					b.append("\\6"); //$NON-NLS-1$
					break;
				case '\7' :
					b.append("\\7"); //$NON-NLS-1$
					break;
				default:
					b.append(c);
			}
		}
		b.append("\""); // closing delimiter //$NON-NLS-1$
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		int size =  + 1 * 4 + stringSize(this.);
		return size;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int treeSize() {
		return memSize();
	}
New to GrepCode? Check out our FAQ X