diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java
index 549db936218..b38a062f0a1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java
@@ -1,19 +1,20 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 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 - Initial API and implementation
+ * Doug Schaefer (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* This expression represents a literal in the program.
*
- * @author Doug Schaefer
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTLiteralExpression extends IASTExpression {
@@ -28,39 +29,70 @@ public interface IASTLiteralExpression extends IASTExpression {
public static final int lk_float_constant = 1;
/**
- * A char literal e.g. 'abc'
+ * A char literal e.g. 'a'
*/
public static final int lk_char_constant = 2;
/**
- * A string literal e.g. "abcdefg"
+ * A string literal e.g. "a literal"
*/
public static final int lk_string_literal = 3;
/**
* A constant defined for subclasses to extend from.
+ * @deprecated all possible values must be defined in {@link IASTLiteralExpression}.
*/
+ @Deprecated
public static final int lk_last = lk_string_literal;
+ /**
+ * lk_this
represents the 'this' keyword for c++ only.
+ * @since 5.1
+ */
+ public static final int lk_this = 4;
+
+ /**
+ * lk_true
represents the 'true' keyword.
+ * @since 5.1
+ */
+ public static final int lk_true = 5;
+
+ /**
+ * lk_false
represents the 'false' keyword.
+ * @since 5.1
+ */
+ public static final int lk_false = 6;
+
/**
* Get the literal expression kind.
- *
- * @return int
*/
public int getKind();
+ /**
+ * Returns the value of the literal as char-array.
+ * @since 5.1
+ */
+ public char[] getValue();
+
+ /**
+ * Returns the value of the literal as string.
+ * @since 5.1
+ */
+ public String toString();
+
/**
* Set the literal expression kind.
- *
- * @param value
- * int
*/
public void setKind(int value);
/**
- * Set the value of the literal expression.
- *
- * @param value
+ * Provide the value for the expression.
+ * @since 5.1
+ */
+ public void setValue(char[] value);
+
+ /**
+ * @deprecated, use {@link #setValue(char[])}, instead.
*/
public void setValue(String value);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java
index 48670ba032b..ec366f6c9c1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLiteralExpression.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 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 - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
@@ -15,24 +15,24 @@ import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
/**
* C++ adds additional literal types to primary expression.
*
- * @author jcamelon
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTLiteralExpression extends IASTLiteralExpression {
/**
* lk_this
represents the 'this' keyword.
*/
- public static final int lk_this = IASTLiteralExpression.lk_last + 1;
+ public static final int lk_this = IASTLiteralExpression.lk_this;
/**
* lk_true
represents the 'true' keyword.
*/
- public static final int lk_true = IASTLiteralExpression.lk_last + 2;
+ public static final int lk_true = IASTLiteralExpression.lk_true;
/**
* lk_false
represents the 'false' keyword.
*/
- public static final int lk_false = IASTLiteralExpression.lk_last + 3;
+ public static final int lk_false = IASTLiteralExpression.lk_false;
/**
* lk_last
is maintained for future subinterfaces.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
index e1592fcc53a..b4e44c4c3fb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
@@ -24,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IVariable;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
@@ -229,19 +228,19 @@ public class Value implements IValue {
if (e instanceof IASTLiteralExpression) {
IASTLiteralExpression litEx= (IASTLiteralExpression) e;
switch (litEx.getKind()) {
- case ICPPASTLiteralExpression.lk_false:
+ case IASTLiteralExpression.lk_false:
return "0";
- case ICPPASTLiteralExpression.lk_true:
+ case IASTLiteralExpression.lk_true:
return "1";
case IASTLiteralExpression.lk_integer_constant:
try {
- return ExpressionEvaluator.getNumber(e.toString().toCharArray());
+ return ExpressionEvaluator.getNumber(litEx.getValue());
} catch (EvalException e1) {
throw UNKNOWN_EX;
}
case IASTLiteralExpression.lk_char_constant:
try {
- final char[] image= e.toString().toCharArray();
+ final char[] image= litEx.getValue();
if (image.length > 1)
if (image[0] == 'L')
return ExpressionEvaluator.getChar(image, 2);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java
index 434f5f90bbf..1f939ede309 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLiteralExpression.java
@@ -6,30 +6,30 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * John Camelon (IBM Rational Software) - Initial API and implementation
+ * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
- * @author jcamelon
+ * Represents a literal
*/
public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpression {
private int kind;
- private String value = ""; //$NON-NLS-1$
+ private char[] value = CharArrayUtils.EMPTY;
-
-
public CASTLiteralExpression() {
}
- public CASTLiteralExpression(int kind, String value) {
+ public CASTLiteralExpression(int kind, char[] value) {
this.kind = kind;
this.value = value;
}
@@ -42,13 +42,17 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
kind = value;
}
- public void setValue(String value) {
- this.value = value;
+ public char[] getValue() {
+ return value;
+ }
+
+ public void setValue(char[] value) {
+ this.value= value;
}
@Override
public String toString() {
- return value;
+ return new String(value);
}
@Override
@@ -74,4 +78,19 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
return CVisitor.getExpressionType(this);
}
+ /**
+ * @deprecated, use {@link #setValue(char[])}, instead.
+ */
+ @Deprecated
+ public void setValue(String value) {
+ this.value = value.toCharArray();
+ }
+
+ /**
+ * @deprecated use {@link #CASTLiteralExpression(int, char[])}, instead.
+ */
+ @Deprecated
+ public CASTLiteralExpression(int kind, String value) {
+ this(kind, value.toCharArray());
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java
index 0b47a08d6b4..a62469eb03c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLiteralExpression.java
@@ -6,30 +6,30 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
-
/**
- * @author jcamelon
+ * Represents a c++ literal.
*/
public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralExpression {
private int kind;
- private String value = ""; //$NON-NLS-1$
+ private char[] value = CharArrayUtils.EMPTY;
-
public CPPASTLiteralExpression() {
}
- public CPPASTLiteralExpression(int kind, String value) {
+ public CPPASTLiteralExpression(int kind, char[] value) {
this.kind = kind;
this.value = value;
}
@@ -39,16 +39,20 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
}
public void setKind(int value) {
- this.kind = value;
+ kind = value;
}
- public void setValue(String value) {
- this.value = value;
+ public char[] getValue() {
+ return value;
+ }
+
+ public void setValue(char[] value) {
+ this.value= value;
}
@Override
public String toString() {
- return value;
+ return new String(value);
}
@Override
@@ -74,4 +78,20 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
return CPPVisitor.getExpressionType(this);
}
+ /**
+ * @deprecated, use {@link #setValue(char[])}, instead.
+ */
+ @Deprecated
+ public void setValue(String value) {
+ this.value = value.toCharArray();
+ }
+
+
+ /**
+ * @deprecated use {@link #CPPASTLiteralExpression(int, char[])}, instead.
+ */
+ @Deprecated
+ public CPPASTLiteralExpression(int kind, String value) {
+ this(kind, value.toCharArray());
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java
index 1dfb8b9ecf7..399f3271fe3 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
@@ -43,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
@@ -328,12 +327,12 @@ public class ExtractConstantRefactoring extends CRefactoring {
case IASTLiteralExpression.lk_string_literal:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t);
break;
- case ICPPASTLiteralExpression.lk_false:
+ case IASTLiteralExpression.lk_false:
//Like lk_true a boolean type
- case ICPPASTLiteralExpression.lk_true:
+ case IASTLiteralExpression.lk_true:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_bool);
break;
- case ICPPASTLiteralExpression.lk_this:
+ case IASTLiteralExpression.lk_this:
break;
}
@@ -348,7 +347,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
init.setExpression(unary);
} else {
- CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.toString());
+ CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.getValue());
init.setExpression(expression);
}
decl.setInitializer(init);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java
index 36f96b2f1d1..225bbab8f0a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@@ -29,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
@@ -61,13 +60,14 @@ import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation;
*
*/
public class ExtractExpression extends ExtractedFunctionConstructionHelper {
+ final static char[] ZERO= {'0'};
@Override
public void constructMethodBody(IASTCompoundStatement compound,
List list, ASTRewrite rewrite, TextEditGroup group) {
CPPASTReturnStatement statement = new CPPASTReturnStatement();
- IASTExpression nullReturnExp = new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "0"); //$NON-NLS-1$
+ IASTExpression nullReturnExp = new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, ZERO);
statement.setReturnValue(nullReturnExp);
ASTRewrite nestedRewrite = rewrite.insertBefore(compound, null, statement, group);
@@ -112,9 +112,9 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_int);
case IASTLiteralExpression.lk_string_literal:
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_wchar_t);
- case ICPPASTLiteralExpression.lk_false:
+ case IASTLiteralExpression.lk_false:
//Like lk_true a boolean type
- case ICPPASTLiteralExpression.lk_true:
+ case IASTLiteralExpression.lk_true:
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_bool);
default:
return null;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java
index 685bbb3440b..441ba73d6fd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/FunctionFactory.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
@@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
@@ -89,7 +90,7 @@ public class FunctionFactory {
CPPASTBinaryExpression binExpr = new CPPASTBinaryExpression();
CPPASTFieldReference fieldRef = new CPPASTFieldReference();
CPPASTLiteralExpression litExpr = new CPPASTLiteralExpression();
- litExpr.setValue("this"); //$NON-NLS-1$
+ litExpr.setValue(Keywords.cTHIS);
fieldRef.setFieldOwner(litExpr);
fieldRef.setFieldName(fieldDeclaration.getDeclarators()[0].getName());
fieldRef.setIsPointerDereference(true);