List of usage examples for org.eclipse.jdt.core.dom Expression toString
@Override public final String toString()
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(IfStatement node) { Statement thenStmt = node.getThenStatement(); Statement elseStmt = node.getElseStatement(); Expression condExpr = node.getExpression(); String thenStr = thenStmt.toString().replace('\n', ' '); String elseStr = ""; if (elseStmt != null) { elseStr = elseStmt.toString().replace('\n', ' '); }//from w w w .ja v a 2 s. com if (this.mtbStack.isEmpty()) { return true; } IMethodBinding mtb = (IMethodBinding) this.mtbStack.peek(); String methodStr = getQualifiedName(mtb); String condStr = condExpr.toString(); condStr = edit_str(condStr); thenStr = edit_str(thenStr); elseStr = edit_str(elseStr); try { this.facts.add(Fact.makeConditionalFact(condStr, thenStr, elseStr, methodStr)); } catch (Exception e) { System.err.println("Cannot resolve conditional \"" + condExpr.toString() + "\""); System.out.println("ifStmt: " + thenStr); System.out.println("elseStmt: " + elseStr); System.err.println(e.getMessage()); } return true; }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(CastExpression node) { if (this.mtbStack.isEmpty()) { return true; }//from w w w. j a v a2s. co m Expression expression = node.getExpression(); ITypeBinding type = node.getType().resolveBinding(); IMethodBinding mtb = (IMethodBinding) this.mtbStack.peek(); String exprStr = expression.toString(); String typeStr = getQualifiedName(type); String methodStr = getQualifiedName(mtb); exprStr = edit_str(exprStr); this.facts.add(Fact.makeCastFact(exprStr, typeStr, methodStr)); return true; }
From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaAbstractAstNodeModelAdapter.java
License:Open Source License
protected String getStringFromExpression(Expression expression) { if (expression == null) { return null; }/*from ww w . j a va 2 s . c o m*/ return expression.toString(); }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaField.java
License:Open Source License
@Override protected Object getFeatureValueFromAST(EStructuralFeature feature, FieldDeclaration astElement) { if (astElement == null) throw new IllegalArgumentException("astElement is null"); String typeName = JavaSyncUtils.getReturnTypeAsString(astElement); ReversePackage_JavaTypes reversePackage_JavaTypes = parentReverse.parentReverse.parentReverse; switch (feature.getFeatureID()) { case UMLPackage.TYPED_ELEMENT__TYPE: return SyncUtils.getTypeOrCreateInUnknownTypes(typeName, new JavaTypeCreation(JavaTypeCreation.CLASS_OR_INTERFACE), reversePackage_JavaTypes, currentElement);/*from w ww . j a v a 2s .com*/ case UMLPackage.PROPERTY__DEFAULT_VALUE: Expression initializer = ((VariableDeclarationFragment) astElement.fragments().get(0)).getInitializer(); LiteralString defaultVal = null; if (initializer != null) { defaultVal = CodeSyncFactory.eINSTANCE.createSyncLiteralString(); defaultVal.setValue(initializer.toString()); } return defaultVal; default: return super.getFeatureValueFromAST(feature, astElement); } }
From source file:com.dnw.depmap.ast.MethodInvocationVisitor.java
License:Open Source License
/** * Makes the string representation of all arguments passed by this method invocation. * /*from w w w .j av a 2 s. c om*/ * @author manbaum * @since Oct 10, 2014 * @param list a list of <code>Expression</code>. * @return a string list contains all arguments passed by this method invocation. */ private List<Object> args(List<?> list) { int n = list.size(); List<Object> r = new ArrayList<Object>(n); for (int i = 0; i < n; i++) { Expression e = (Expression) list.get(i); r.add(e.toString()); } return r; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
/** * Prints a multi-dimensional array that is defined using array sizes, * rather than an initializer. For example, "new int[2][3][4]". *//* w ww . ja v a 2 s . c o m*/ private void printMultiDimArray(ITypeBinding elementType, List<Expression> dimensions) { if (dimensions.size() == 1) { printSingleDimArray(elementType, dimensions.get(0), false); } else { buffer.append("[IOSObjectArray arrayWithObjects:(id[]){ "); Expression dimension = dimensions.get(0); int dim; // An array dimension may either be a number literal, constant, or expression. if (dimension instanceof NumberLiteral) { dim = Integer.parseInt(dimension.toString()); } else { IVariableBinding var = Types.getVariableBinding(dimension); if (var != null) { Number constant = (Number) var.getConstantValue(); dim = constant != null ? constant.intValue() : 1; } else { dim = 1; } } List<Expression> subDimensions = dimensions.subList(1, dimensions.size()); for (int i = 0; i < dim; i++) { printMultiDimArray(elementType, subDimensions); if (i + 1 < dim) { buffer.append(','); } buffer.append(' '); } buffer.append("} count:"); dimension.accept(this); buffer.append(" type:[IOSClass classWithClass:["); buffer.append( subDimensions.size() > 1 ? "IOSObjectArray" : Types.resolveArrayType(elementType).toString()); buffer.append(" class]]]"); } }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
/** * Converts a string concatenation expression into a NSString format string and a * list of arguments for it, containing all the non-literal expressions. If the * expression is all literals, then a string concatenation is printed. If not, * then a NSString stringWithFormat: message is output. *//*from w w w .j a v a 2 s .co m*/ @SuppressWarnings("fallthrough") private void printStringConcatenation(Expression leftOperand, Expression rightOperand, List<Expression> extendedOperands, boolean needRetainRhs) { // Copy all operands into a single list. List<Expression> operands = Lists.newArrayList(leftOperand, rightOperand); operands.addAll(extendedOperands); String format = "@\""; List<Expression> args = Lists.newArrayList(); for (Expression operand : operands) { if (operand instanceof BooleanLiteral || operand instanceof CharacterLiteral || operand instanceof NullLiteral) { format += operand.toString(); } else if (operand instanceof StringLiteral) { StringLiteral literal = (StringLiteral) operand; if (isValidCppString(literal)) { String s = (((StringLiteral) operand).getEscapedValue()); s = s.substring(1, s.length() - 1); // remove surrounding double-quotes s = UnicodeUtils.escapeUnicodeSequences(s); format += s.replace("%", "%%"); // escape % character } else { // Convert to NSString invocation when printing args. format += "%@"; args.add(operand); } } else if (operand instanceof NumberLiteral) { format += ((NumberLiteral) operand).getToken(); } else { args.add(operand); // Append format specifier. ITypeBinding operandType = Types.getTypeBinding(operand); if (operandType.isPrimitive()) { String type = operandType.getBinaryName(); assert type.length() == 1; switch (type.charAt(0)) { case 'B': // byte case 'I': // int case 'S': // short format += "%d"; break; case 'J': // long format += "%qi"; break; case 'D': // double case 'F': // float format += "%f"; break; case 'C': // char format += "%c"; break; case 'Z': // boolean format += "%@"; break; default: throw new AssertionError("unknown primitive type: " + type); } } else { format += "%@"; } } } format += '"'; if (args.isEmpty()) { buffer.append(format.replace("%%", "%")); // unescape % character return; } if (needRetainRhs) { buffer.append("[[NSString alloc] initWithFormat:"); } else { buffer.append("[NSString stringWithFormat:"); } buffer.append(format); buffer.append(", "); for (Iterator<Expression> iter = args.iterator(); iter.hasNext();) { Expression arg = iter.next(); if (Types.getTypeBinding(arg).isEqualTo(arg.getAST().resolveWellKnownType("boolean"))) { buffer.append("[JavaLangBoolean toStringWithBOOL:"); arg.accept(this); buffer.append(']'); } else if (arg instanceof StringLiteral) { // Strings with all valid C99 characters were previously converted, // so this literal needs to be defined with a char array. buffer.append(buildStringFromChars(((StringLiteral) arg).getLiteralValue())); } else { arg.accept(this); } if (iter.hasNext()) { buffer.append(", "); } } buffer.append(']'); }
From source file:com.google.gdt.eclipse.designer.gxt.model.widgets.UntypedEventsRootProcessor.java
License:Open Source License
/** * @return the {@link MethodInvocation} of <code>addListener()</code> for given event. May be * <code>null</code>. *///from www. j a v a2 s . c om private MethodInvocation getInvocation(ComponentInfo component, EventDescription description) { List<MethodInvocation> invocations = component.getMethodInvocations(ADD_LISTENER_SIGNATURE); for (MethodInvocation invocation : invocations) { Expression nameExpression = DomGenerics.arguments(invocation).get(0); if (nameExpression.toString().endsWith(description.getName())) { return invocation; } } return null; }
From source file:com.google.gdt.eclipse.designer.model.widgets.menu.MenuItemInfo.java
License:Open Source License
private static boolean isNullCommandExpression(Expression commandExpression) { return commandExpression.toString().endsWith("null"); }
From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java
License:Open Source License
private CAstNode visit(ArrayInitializer n, WalkContext context) { ITypeBinding type = n.resolveTypeBinding(); assert type != null : "Could not determine type of ArrayInitializer"; TypeReference newTypeRef = fIdentityMapper.getTypeRef(type); CAstNode[] eltNodes = new CAstNode[n.expressions().size() + 1]; int idx = 0;/*from w w w.j a v a2 s .c o m*/ eltNodes[idx++] = makeNode(context, fFactory, n, CAstNode.NEW, fFactory.makeConstant(newTypeRef), fFactory.makeConstant(n.expressions().size())); for (Iterator iter = n.expressions().iterator(); iter.hasNext(); idx++) { Expression element = (Expression) iter.next(); eltNodes[idx] = visitNode(element, context); if (eltNodes[idx] == null) assert eltNodes[idx] != null : element.toString(); } return makeNode(context, fFactory, n, CAstNode.ARRAY_LITERAL, eltNodes); }