List of usage examples for org.eclipse.jdt.core.dom CharacterLiteral charValue
public char charValue()
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.CharacterLiteral node) { int intValue = node.charValue(); return done(integerHex(intValue)); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(CharacterLiteral node) { int c = node.charValue(); if (c >= 0x20 && c <= 0x7E) { // if ASCII buffer.append(UnicodeUtils.escapeUnicodeSequences(node.getEscapedValue())); } else {/*from ww w .j a va 2 s. com*/ buffer.append(String.format("0x%04x", c)); } return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(CharacterLiteral node) { sb.print(UnicodeUtils.escapeCharLiteral(node.charValue())); return false; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java
License:Open Source License
public static Object getValue(ASTNode node) { switch (node.getNodeType()) { // case ASTNode.ANONYMOUS_CLASS_DECLARATION: // return "Anonymous class declaration"; // case ASTNode.ARRAY_ACCESS: // return "Array access"; // case ASTNode.ARRAY_CREATION: // return "Array creation"; // case ASTNode.ARRAY_INITIALIZER: // return "Array initializer"; // case ASTNode.ARRAY_TYPE: // ArrayType arrayType = (ArrayType)node; // return "Array type: " + arrayType.getElementType().toString(); // case ASTNode.ASSERT_STATEMENT: // return "Assert statement"; // case ASTNode.ASSIGNMENT: // return "Assignment"; // case ASTNode.BLOCK: // return "Block"; case ASTNode.BOOLEAN_LITERAL: BooleanLiteral booleanLiteral = (BooleanLiteral) node; return booleanLiteral.booleanValue(); // case ASTNode.BREAK_STATEMENT: // return "Break statement"; // case ASTNode.CAST_EXPRESSION: // return "Cast expression"; // case ASTNode.CATCH_CLAUSE: // return "Catch clause"; case ASTNode.CHARACTER_LITERAL: CharacterLiteral characterLiteral = (CharacterLiteral) node; return characterLiteral.charValue(); // case ASTNode.CLASS_INSTANCE_CREATION: // return "Class instance creation"; // case ASTNode.COMPILATION_UNIT: // return "Compilation unit"; // case ASTNode.CONDITIONAL_EXPRESSION: // return "Conditional Expression"; // case ASTNode.CONSTRUCTOR_INVOCATION: // return "constructor invocation"; // case ASTNode.CONTINUE_STATEMENT: // return "continue statement"; // case ASTNode.DO_STATEMENT: // return "Do statement"; // case ASTNode.EMPTY_STATEMENT: // return "Empty statement"; // case ASTNode.EXPRESSION_STATEMENT: // return "Expression statement"; // case ASTNode.FIELD_ACCESS: // return "field access"; // case ASTNode.FIELD_DECLARATION: // return "Field declaration"; // case ASTNode.FOR_STATEMENT: // return "For statement"; // case ASTNode.IF_STATEMENT: // return "If statement"; // case ASTNode.IMPORT_DECLARATION: // return "Import declaration"; // case ASTNode.INFIX_EXPRESSION: // return "Infix expression"; // case ASTNode.INITIALIZER: // return "Initializer"; // case ASTNode.INSTANCEOF_EXPRESSION: // return "Instanceof expression"; // case ASTNode.JAVADOC: // return "Javadoc"; // case ASTNode.LABELED_STATEMENT: // return "Labeled statement"; // case ASTNode.METHOD_DECLARATION: // return "Method declaration"; // case ASTNode.METHOD_INVOCATION: // return "Method invocation"; // case ASTNode.NULL_LITERAL: // return "Null literal"; case ASTNode.NUMBER_LITERAL: NumberLiteral numberLiteral = (NumberLiteral) node; String token = numberLiteral.getToken(); try {/* w w w . j a v a2 s .c o m*/ return Integer.parseInt(token); } catch (Exception ex) { } try { return Long.parseLong(token); } catch (Exception ex) { } try { return Double.parseDouble(token); } catch (Exception ex) { } try { return Float.parseFloat(token); } catch (Exception ex) { } return Double.NaN; // case ASTNode.PACKAGE_DECLARATION: // return "Package declaration"; // case ASTNode.PARENTHESIZED_EXPRESSION: // return "Parenthesized expression"; // case ASTNode.POSTFIX_EXPRESSION: // return "Postfix expression"; // case ASTNode.PREFIX_EXPRESSION: // return "Prefix expression"; // case ASTNode.PRIMITIVE_TYPE: // PrimitiveType primitiveType = (PrimitiveType) node; // return "Primitive type: " + primitiveType.getPrimitiveTypeCode().toString(); case ASTNode.QUALIFIED_NAME: QualifiedName qualifiedName = (QualifiedName) node; return new AstUtils.QualifiedNameValue(qualifiedName.getQualifier().getFullyQualifiedName(), qualifiedName.getName().getIdentifier()); // case ASTNode.RETURN_STATEMENT: // return "Return statement"; // case ASTNode.SIMPLE_NAME: // SimpleName simpleName = (SimpleName) node; // return "Simple name: " + simpleName.getIdentifier(); // case ASTNode.SIMPLE_TYPE: // SimpleType simpleType = (SimpleType) node; // return "Simple type (" + simpleType.getName().toString() + ")"; // case ASTNode.SINGLE_VARIABLE_DECLARATION: // return "Single variable declaration"; case ASTNode.STRING_LITERAL: StringLiteral stringLiteral = (StringLiteral) node; return stringLiteral.getLiteralValue(); // case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: // return "Super constructor invocation"; // case ASTNode.SUPER_FIELD_ACCESS: // return "Super field access"; // case ASTNode.SUPER_METHOD_INVOCATION: // return "Super method invocation"; // case ASTNode.SWITCH_CASE: // return "Switch case"; // case ASTNode.SWITCH_STATEMENT: // return "Switch statement"; // case ASTNode.SYNCHRONIZED_STATEMENT: // return "Synchronized statement"; // case ASTNode.THIS_EXPRESSION: // return "This expression"; // case ASTNode.THROW_STATEMENT: // return "Throw statement"; // case ASTNode.TRY_STATEMENT: // return "Try statement"; // case ASTNode.TYPE_DECLARATION: // return "Type declaration"; // case ASTNode.TYPE_DECLARATION_STATEMENT: // return "Type declaration statement"; case ASTNode.TYPE_LITERAL: TypeLiteral typeLiteral = (TypeLiteral) node; return new AstUtils.TypeLiteralValue(typeLiteral.toString()); // case ASTNode.VARIABLE_DECLARATION_EXPRESSION: // return "Varialbe declaration expression"; // case ASTNode.VARIABLE_DECLARATION_FRAGMENT: // return "Variable declaration fragment"; // case ASTNode.VARIABLE_DECLARATION_STATEMENT: // return "Variable declaration statement"; // case ASTNode.WHILE_STATEMENT: // return "While statement"; } return null; }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
private CAstNode visit(CharacterLiteral n, WalkContext context) { return fFactory.makeConstant(n.charValue()); }
From source file:edu.cmu.cs.crystal.tac.eclipse.EclipseTACInstructionFactory.java
License:Open Source License
public TACInstruction create(CharacterLiteral node, IEclipseVariableQuery eclipseVariableQuery) { return new LoadLiteralInstructionImpl(node, node.charValue(), eclipseVariableQuery); }
From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java
License:Open Source License
public boolean visit(Assignment node) { Expression left = node.getLeftHandSide(); Expression right = node.getRightHandSide(); IVariableBinding varBinding = null;/* w w w . j ava 2 s . c om*/ if (left instanceof Name) { Name leftName = (Name) left; IBinding nameBinding = leftName.resolveBinding(); if (nameBinding instanceof IVariableBinding) { varBinding = (IVariableBinding) nameBinding; } } else if (left instanceof FieldAccess) { FieldAccess leftAccess = (FieldAccess) left; varBinding = leftAccess.resolveFieldBinding(); } String op = node.getOperator().toString(); ITypeBinding declaring = null; String qName = null; if (varBinding != null && (varBinding.getModifiers() & Modifier.STATIC) != 0 && (declaring = varBinding.getDeclaringClass()) != null && !(qName = declaring.getQualifiedName()).startsWith("org.eclipse.swt.internal.xhtml.") && !qName.startsWith("net.sf.j2s.html.")) { boolean directStaticAccess = left instanceof SimpleName || (left instanceof QualifiedName && ((QualifiedName) left).getQualifier() instanceof SimpleName) || (left instanceof FieldAccess && ((FieldAccess) left).getExpression() instanceof ThisExpression); ASTNode parent = node.getParent(); boolean needParenthesis = (supportsObjectStaticFields || !directStaticAccess) && !(parent instanceof Statement); if (needParenthesis) { buffer.append("("); } if (left instanceof QualifiedName) { QualifiedName leftName = (QualifiedName) left; if (!(leftName.getQualifier() instanceof SimpleName)) { leftName.getQualifier().accept(this); buffer.append(", "); } } else if (left instanceof FieldAccess) { FieldAccess leftAccess = (FieldAccess) left; if (!(leftAccess.getExpression() instanceof ThisExpression)) { leftAccess.getExpression().accept(this); buffer.append(", "); } } if (supportsObjectStaticFields) { buffer.append(assureQualifiedName( shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName()))); buffer.append(".prototype."); if (left instanceof QualifiedName) { QualifiedName leftName = (QualifiedName) left; leftName.getName().accept(this); } else if (left instanceof FieldAccess) { FieldAccess leftAccess = (FieldAccess) left; leftAccess.getName().accept(this); } else { Name leftName = (Name) left; leftName.accept(this); } buffer.append(" = "); } buffer.append( assureQualifiedName(shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName()))); buffer.append('.'); if (left instanceof QualifiedName) { QualifiedName leftName = (QualifiedName) left; leftName.getName().accept(this); } else if (left instanceof FieldAccess) { FieldAccess leftAccess = (FieldAccess) left; leftAccess.getName().accept(this); } else { Name leftName = (Name) left; leftName.accept(this); } buffer.append(' '); boolean isMixedOp = op.trim().length() > 1; ITypeBinding leftTypeBinding = left.resolveTypeBinding(); if (leftTypeBinding != null && "char".equals(leftTypeBinding.getName())) { ITypeBinding rightTypeBinding = right.resolveTypeBinding(); if (!isMixedOp) { // = buffer.append(op); buffer.append(' '); if (rightTypeBinding != null && "char".equals(rightTypeBinding.getName())) { boxingNode(right); } else { buffer.append("String.fromCharCode ("); boxingNode(right); buffer.append(')'); } } else { buffer.append("= String.fromCharCode ("); buffer.append(assureQualifiedName( shortenQualifiedName(varBinding.getDeclaringClass().getQualifiedName()))); buffer.append('.'); if (left instanceof QualifiedName) { QualifiedName leftName = (QualifiedName) left; leftName.getName().accept(this); } else if (left instanceof FieldAccess) { FieldAccess leftAccess = (FieldAccess) left; leftAccess.getName().accept(this); } else { Name leftName = (Name) left; leftName.accept(this); } buffer.append(".charCodeAt (0) "); buffer.append(op.charAt(0)); buffer.append(' '); if (rightTypeBinding != null && "char".equals(rightTypeBinding.getName())) { Object constValue = right.resolveConstantExpressionValue(); if (constValue != null && constValue instanceof Character) { buffer.append(((Character) constValue).charValue() + 0); } else { boxingNode(right); buffer.append(".charCodeAt (0)"); } } else { boxingNode(right); } buffer.append(")"); } } else { buffer.append(op); buffer.append(' '); boxingNode(right); } if (needParenthesis) { buffer.append(")"); } return false; } ITypeBinding typeBinding = left.resolveTypeBinding(); if (typeBinding != null && typeBinding.isPrimitive()) { if ("boolean".equals(typeBinding.getName())) { if (op.startsWith("^") || op.startsWith("|") || op.startsWith("&") /*|| op.startsWith("!")*/) { left.accept(this); buffer.append(" = new Boolean ("); left.accept(this); buffer.append(' '); buffer.append(op.charAt(0)); if (right instanceof InfixExpression) { buffer.append(" ("); right.accept(this); buffer.append("))"); } else { buffer.append(' '); right.accept(this); buffer.append(')'); } buffer.append(".valueOf ()"); return false; } } else if (typeBinding != null && "char".equals(typeBinding.getName())) { boolean isMixedOp = op.trim().length() > 1; if (!isMixedOp) { if (right instanceof Name || right instanceof CharacterLiteral || right instanceof ArrayAccess || right instanceof FieldAccess || right instanceof MethodInvocation || right instanceof ParenthesizedExpression || right instanceof SuperFieldAccess || right instanceof SuperMethodInvocation || right instanceof ThisExpression || right instanceof CastExpression) { left.accept(this); buffer.append(" = "); right.accept(this); return false; } } ITypeBinding rightTypeBinding = right.resolveTypeBinding(); /* * FIXME: Bug here!: * v[count++] += 'a'; * v[count++] = String.fromCharCode ((v[count++]).charCodeAt (0) + 97); */ left.accept(this); if (rightTypeBinding != null && "char".equals(rightTypeBinding.getName()) && !isMixedOp) { buffer.append(' '); buffer.append(op); buffer.append(' '); right.accept(this); } else { buffer.append(" = String.fromCharCode ("); if (isMixedOp) { if (left instanceof SimpleName || left instanceof QualifiedName) { left.accept(this); } else { buffer.append("("); left.accept(this); buffer.append(")"); } buffer.append(".charCodeAt (0) "); buffer.append(op.charAt(0)); } buffer.append(' '); if (right instanceof InfixExpression) { String constValue = checkConstantValue(right); if (constValue != null) { buffer.append(constValue); } else { buffer.append("("); right.accept(this); buffer.append(")"); } if ("char".equals(rightTypeBinding.getName())) { buffer.append(".charCodeAt (0)"); } } else { if ("char".equals(rightTypeBinding.getName())) { Object constValue = right.resolveConstantExpressionValue(); if (constValue != null && constValue instanceof Character) { buffer.append(((Character) constValue).charValue() + 0); } else { boolean needParenthesis = !(right instanceof ParenthesizedExpression || right instanceof PrefixExpression || right instanceof PostfixExpression); if (needParenthesis) { buffer.append("("); } right.accept(this); if (needParenthesis) { buffer.append(")"); } buffer.append(".charCodeAt (0)"); } } else { right.accept(this); } } buffer.append(')'); } return false; } } left.accept(this); buffer.append(' '); buffer.append(op); buffer.append(' '); ITypeBinding binding = right.resolveTypeBinding(); if (binding != null && "char".equals(binding.getName())) { String typeBindingName = (typeBinding != null) ? typeBinding.getName() : null; if (right instanceof CharacterLiteral) { CharacterLiteral cl = (CharacterLiteral) right; if ("char".equals(typeBindingName) || typeBindingName.indexOf("String") != -1) { String constValue = checkConstantValue(right); buffer.append(constValue); } else { buffer.append(0 + cl.charValue()); } } else { if (typeBindingName != null && ("char".equals(typeBindingName) || typeBindingName.indexOf("String") != -1)) { right.accept(this); } else { int idx1 = buffer.length(); buffer.append('('); right.accept(this); buffer.append(")"); boolean appendingCode = true; int length = buffer.length(); if (right instanceof MethodInvocation) { MethodInvocation m = (MethodInvocation) right; if ("charAt".equals(m.getName().toString())) { int idx2 = buffer.indexOf(".charAt ", idx1); if (idx2 != -1) { StringBuffer newMethodBuffer = new StringBuffer(); newMethodBuffer.append(buffer.substring(idx1 + 1, idx2)); newMethodBuffer.append(".charCodeAt "); newMethodBuffer.append(buffer.substring(idx2 + 8, length - 1)); buffer.delete(idx1, length); buffer.append(newMethodBuffer.toString()); appendingCode = false; } } } if (appendingCode) { buffer.append(".charCodeAt (0)"); } } } } else { boxingNode(right); } return false; }
From source file:net.sf.j2s.core.astvisitors.ASTKeywordVisitor.java
License:Open Source License
public boolean visit(VariableDeclarationFragment node) { SimpleName name = node.getName();//from w ww . java 2 s. co m IBinding binding = name.resolveBinding(); if (binding != null) { String identifier = name.getIdentifier(); ASTFinalVariable f = null; if (methodDeclareStack.size() == 0) { f = new ASTFinalVariable(blockLevel, identifier, null); } else { String methodSig = (String) methodDeclareStack.peek(); f = new ASTFinalVariable(blockLevel, identifier, methodSig); } List finalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).finalVars; List normalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).normalVars; f.toVariableName = getIndexedVarName(identifier, normalVars.size()); normalVars.add(f); if ((binding.getModifiers() & Modifier.FINAL) != 0) { finalVars.add(f); } } name.accept(this); Expression initializer = node.getInitializer(); if (initializer != null) { buffer.append(" = "); ITypeBinding typeBinding = initializer.resolveTypeBinding(); if (typeBinding != null && "char".equals(typeBinding.getName())) { ITypeBinding nameTypeBinding = name.resolveTypeBinding(); String nameType = nameTypeBinding.getName(); if (initializer instanceof CharacterLiteral) { CharacterLiteral cl = (CharacterLiteral) initializer; if ("char".equals(nameType)) { String constValue = checkConstantValue(initializer); buffer.append(constValue); } else { buffer.append(0 + cl.charValue()); } return false; } else { if (nameType != null && !"char".equals(nameType) && nameType.indexOf("String") == -1) { int idx1 = buffer.length(); buffer.append("("); initializer.accept(this); buffer.append(")"); boolean appendingCode = true; int length = buffer.length(); if (initializer instanceof MethodInvocation) { MethodInvocation m = (MethodInvocation) initializer; if ("charAt".equals(m.getName().toString())) { int idx2 = buffer.indexOf(".charAt ", idx1); if (idx2 != -1) { StringBuffer newMethodBuffer = new StringBuffer(); newMethodBuffer.append(buffer.substring(idx1 + 1, idx2)); newMethodBuffer.append(".charCodeAt "); newMethodBuffer.append(buffer.substring(idx2 + 8, length - 1)); buffer.delete(idx1, length); buffer.append(newMethodBuffer.toString()); appendingCode = false; } } } if (appendingCode) { buffer.append(".charCodeAt (0)"); } return false; } } } ITypeBinding nameTypeBinding = name.resolveTypeBinding(); if (nameTypeBinding != null) { String nameType = nameTypeBinding.getName(); if ("char".equals(nameType)) { if (typeBinding != null && !"char".equals(typeBinding.getName())) { buffer.append("String.fromCharCode ("); initializer.accept(this); buffer.append(")"); return false; } } } boxingNode(initializer); } return false; }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
private void visitArgumentItem(ASTNode element, String clazzName, String methodName, String parameterTypeName, int position) { /*//from w ww . j a v a 2 s .com Object[] ignores = new Object[] { "java.lang.String", "indexOf", new int[] { 0 }, "java.lang.String", "lastIndexOf", new int[] { 0 }, "java.lang.StringBuffer", "append", new int[] { 0 }, "java.lang.StringBuilder", "append", new int[] { 0 } }; */ String typeStr = null; if (element instanceof CastExpression) { CastExpression castExp = (CastExpression) element; Expression exp = castExp.getExpression(); if (exp instanceof NullLiteral) { ITypeBinding nullTypeBinding = castExp.resolveTypeBinding(); if (nullTypeBinding != null) { if (nullTypeBinding.isArray()) { typeStr = "Array"; } else if (nullTypeBinding.isPrimitive()) { Code code = PrimitiveType.toCode(nullTypeBinding.getName()); if (code == PrimitiveType.BOOLEAN) { typeStr = "Boolean"; } else { typeStr = "Number"; } } else if (!nullTypeBinding.isTypeVariable()) { typeStr = assureQualifiedName(shortenQualifiedName(nullTypeBinding.getQualifiedName())); } } } } if (typeStr != null) { buffer.append("Clazz.castNullAs (\""); buffer.append(typeStr.replaceFirst("^\\$wt.", "org.eclipse.swt.")); buffer.append("\")"); } else { Expression exp = (Expression) element; ITypeBinding typeBinding = exp.resolveTypeBinding(); String typeName = null; if (typeBinding != null) { typeName = typeBinding.getName(); } int idx1 = buffer.length(); if ("char".equals(typeName) && !"char".equals(parameterTypeName)) { boolean ignored = false; /* for (int j = 0; j < ignores.length / 3; j++) { int[] indexes = (int[]) ignores[i + i + i + 2]; boolean existed = false; for (int k = 0; k < indexes.length; k++) { if (indexes[k] == i) { existed = true; break; } } if (existed) { if (ignores[0].equals(Bindings.removeBrackets(clazzName)) && ignores[1].equals(methodName)) { ignored = true; break; } } } */ // Keep String#indexOf(int) and String#lastIndexOf(int)'s first char argument ignored = (position == 0 && (/*"append".equals(methodName) || */"indexOf".equals(methodName) || "lastIndexOf".equals(methodName)) && ("java.lang.String".equals(Bindings.removeBrackets(clazzName)))); if (!ignored && exp instanceof CharacterLiteral) { CharacterLiteral cl = (CharacterLiteral) exp; buffer.append(0 + cl.charValue()); ignored = true; } else { boxingNode(element); } if (!ignored) { boolean appendingCode = true; int length = buffer.length(); if (exp instanceof MethodInvocation) { MethodInvocation m = (MethodInvocation) exp; if ("charAt".equals(m.getName().toString())) { int idx2 = buffer.indexOf(".charAt ", idx1); if (idx2 != -1) { StringBuffer newMethodBuffer = new StringBuffer(); newMethodBuffer.append(buffer.substring(idx1, idx2)); newMethodBuffer.append(".charCodeAt "); newMethodBuffer.append(buffer.substring(idx2 + 8, length)); buffer.delete(idx1, length); buffer.append(newMethodBuffer.toString()); appendingCode = false; } } } if (appendingCode) { buffer.append(".charCodeAt (0)"); } } } else { boxingNode(element); } } }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
private void charVisit(ASTNode node, boolean beCare) { if (!beCare || !(node instanceof Expression)) { boxingNode(node);/*w w w. j a va2 s .c om*/ return; } Expression exp = (Expression) node; ITypeBinding binding = exp.resolveTypeBinding(); if (binding.isPrimitive() && "char".equals(binding.getName())) { if (node instanceof CharacterLiteral) { CharacterLiteral cl = (CharacterLiteral) node; buffer.append(0 + cl.charValue()); } else if (node instanceof SimpleName || node instanceof QualifiedName) { boxingNode(node); buffer.append(".charCodeAt (0)"); } else { int idx1 = buffer.length(); if (node instanceof PrefixExpression || node instanceof PostfixExpression || node instanceof ParenthesizedExpression) { boxingNode(node); } else { buffer.append("("); boxingNode(node); buffer.append(")"); } boolean appendingCode = true; int length = buffer.length(); if (exp instanceof MethodInvocation) { MethodInvocation m = (MethodInvocation) exp; if ("charAt".equals(m.getName().toString())) { int idx2 = buffer.indexOf(".charAt ", idx1); if (idx2 != -1) { StringBuffer newMethodBuffer = new StringBuffer(); newMethodBuffer.append(buffer.substring(idx1 + 1, idx2)); newMethodBuffer.append(".charCodeAt "); newMethodBuffer.append(buffer.substring(idx2 + 8, length - 1)); buffer.delete(idx1, length); buffer.append(newMethodBuffer.toString()); appendingCode = false; } } } if (appendingCode) { buffer.append(".charCodeAt (0)"); } } } else { boxingNode(node); } }