List of usage examples for org.eclipse.jdt.core.dom SuperConstructorInvocation arguments
ASTNode.NodeList arguments
To view the source code for org.eclipse.jdt.core.dom SuperConstructorInvocation arguments.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(SuperConstructorInvocation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.fBuffer.append(".");//$NON-NLS-1$ }// w w w .ja v a2s. co m if (node.getAST().apiLevel() >= JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<");//$NON-NLS-1$ for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext();) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(">");//$NON-NLS-1$ } } this.fBuffer.append("super(");//$NON-NLS-1$ for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext();) { Expression e = it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(");");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(SuperConstructorInvocation node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.EXPRESSION); boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); // eb.setPosition(pos.build());//FIXME eb.setKind(boa.types.Ast.Expression.ExpressionKind.METHODCALL); eb.setMethod("super"); if (node.getExpression() != null) { node.getExpression().accept(this); eb.addExpressions(expressions.pop()); }/*from ww w .j a va 2s . c om*/ for (Object a : node.arguments()) { ((org.eclipse.jdt.core.dom.Expression) a).accept(this); eb.addMethodArgs(expressions.pop()); } for (Object t : node.typeArguments()) { boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t))); tb.setKind(boa.types.Ast.TypeKind.GENERIC); eb.addGenericParameters(tb.build()); } b.setExpression(eb.build()); list.add(b.build()); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(SuperConstructorInvocation node) { printIndent();/* ww w . ja v a 2 s. com*/ if (node.getExpression() != null) { node.getExpression().accept(this); this.buffer.append(".");//$NON-NLS-1$ } if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeArguments().isEmpty()) { this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeArguments().iterator(); it.hasNext();) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(">");//$NON-NLS-1$ } } this.buffer.append("super(");//$NON-NLS-1$ for (Iterator it = node.arguments().iterator(); it.hasNext();) { Expression e = (Expression) it.next(); e.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(");\n");//$NON-NLS-1$ return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(SuperConstructorInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_explicit_constructor_call); return true;/*w w w . java 2s . c o m*/ }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(SuperConstructorInvocation node) { handleTypeArguments(node.typeArguments()); handleInvocation(node, node);/*from w w w .jav a 2s. c o m*/ handleCommas(node.arguments(), this.options.insert_space_before_comma_in_explicit_constructor_call_arguments, this.options.insert_space_after_comma_in_explicit_constructor_call_arguments); return true; }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w . j a va2 s . co m public boolean visit(SuperConstructorInvocation node) { buffer.append("[super init"); printArguments(Types.getMethodBinding(node), node.arguments()); buffer.append(']'); return false; }
From source file:com.google.devtools.j2cpp.translate.AnonymousClassConverter.java
License:Open Source License
private void addArguments(List<Expression> invocationArguments, AST ast, ITypeBinding clazz, MethodDeclaration constructor, GeneratedMethodBinding binding) { // Create a parameter list, based on the invocation arguments. @SuppressWarnings("unchecked") // safe by definition List<SingleVariableDeclaration> parameters = constructor.parameters(); int parameterOffset = binding.getParameterTypes().length; for (int i = 0; i < invocationArguments.size(); i++) { Expression arg = invocationArguments.get(i); ITypeBinding argType = Types.getTypeBinding(arg); SimpleName paramName = ast.newSimpleName("arg$" + i); GeneratedVariableBinding paramBinding = new GeneratedVariableBinding(paramName.getIdentifier(), 0, argType, false, true, clazz, null); Types.addBinding(paramName, paramBinding); SingleVariableDeclaration param = ast.newSingleVariableDeclaration(); param.setName(paramName);//from ww w . j a v a2s .co m param.setType(Types.makeType(argType)); Types.addBinding(param, paramBinding); parameters.add(param); binding.addParameter(i + parameterOffset, argType); } // Add super constructor call, forwarding the invocation arguments. SuperConstructorInvocation superInvocation = ast.newSuperConstructorInvocation(); @SuppressWarnings("unchecked") List<Expression> superArgs = superInvocation.arguments(); // safe by definition for (SingleVariableDeclaration param : parameters) { superArgs.add(NodeCopier.copySubtree(ast, param.getName())); } Types.addBinding(superInvocation, findSuperConstructorBinding(clazz.getSuperclass(), invocationArguments)); @SuppressWarnings("unchecked") List<Statement> statements = constructor.getBody().statements(); // safe by definition statements.add(superInvocation); }
From source file:com.google.devtools.j2cpp.translate.Autoboxer.java
License:Open Source License
@Override public void endVisit(SuperConstructorInvocation node) { @SuppressWarnings("unchecked") List<Expression> args = node.arguments(); // safe by definition convertArguments(Types.getMethodBinding(node), args); }
From source file:com.google.devtools.j2cpp.translate.ClassConverter.java
License:Open Source License
protected void addInnerParameters(MethodDeclaration constructor, GeneratedMethodBinding binding, List<IVariableBinding> innerFields, AST ast, boolean methodVars) { // Add parameters and initializers for each field. @SuppressWarnings("unchecked") // safe by definition List<SingleVariableDeclaration> parameters = constructor.parameters(); List<SingleVariableDeclaration> newParams = createConstructorArguments(innerFields, Types.getMethodBinding(constructor), ast, "outer$"); Block body = constructor.getBody();/*from w w w . ja v a 2 s . co m*/ @SuppressWarnings("unchecked") // safe by definition List<Statement> statements = body.statements(); Statement first = statements.size() > 0 ? statements.get(0) : null; int offset = first != null && (first instanceof SuperConstructorInvocation || first instanceof ConstructorInvocation) ? 1 : 0; boolean firstIsThisCall = first != null && first instanceof ConstructorInvocation; // If superclass constructor takes an outer$ parameter, create or edit // an invocation for it first if (!innerFields.isEmpty() && !methodVars) { if (firstIsThisCall) { ConstructorInvocation thisCall = (ConstructorInvocation) first; IMethodBinding cons = Types.getMethodBinding(thisCall); GeneratedMethodBinding newCons = new GeneratedMethodBinding(cons.getMethodDeclaration()); // Create a new this invocation to the updated constructor. @SuppressWarnings("unchecked") List<Expression> args = ((ConstructorInvocation) first).arguments(); int index = 0; for (SingleVariableDeclaration param : newParams) { IVariableBinding paramBinding = Types.getVariableBinding(param); newCons.addParameter(index, Types.getTypeBinding(param)); args.add(index++, makeFieldRef(paramBinding, ast)); } Types.addBinding(thisCall, newCons); } else { ITypeBinding superType = binding.getDeclaringClass().getSuperclass().getTypeDeclaration(); if ((superType.getDeclaringClass() != null || superType.getDeclaringMethod() != null) && (superType.getModifiers() & Modifier.STATIC) == 0) { // There may be more than one outer var supplied, find the right one. IVariableBinding outerVar = null; for (SingleVariableDeclaration param : newParams) { IVariableBinding paramBinding = Types.getVariableBinding(param); if (paramBinding.getType().isAssignmentCompatible(superType.getDeclaringClass())) { outerVar = paramBinding; } } assert outerVar != null; IMethodBinding cons = null; if (offset > 0) { cons = Types.getMethodBinding(statements.get(0)); } else { for (IMethodBinding method : superType.getDeclaredMethods()) { // The super class's constructor may or may not have been already // modified. if (method.isConstructor()) { if (method.getParameterTypes().length == 0) { cons = method; break; } else if (method.getParameterTypes().length == 1 && outerVar.getType().isAssignmentCompatible(method.getParameterTypes()[0]) && method instanceof GeneratedMethodBinding) { cons = method; break; } } } } assert cons != null; if (!updatedConstructors.contains(cons)) { GeneratedMethodBinding newSuperCons = new GeneratedMethodBinding( cons.getMethodDeclaration()); newSuperCons.addParameter(0, superType.getDeclaringClass()); cons = newSuperCons; } SimpleName outerRef = makeFieldRef(outerVar, ast); SuperConstructorInvocation superInvocation = offset == 0 ? ast.newSuperConstructorInvocation() : (SuperConstructorInvocation) statements.get(0); @SuppressWarnings("unchecked") List<Expression> args = superInvocation.arguments(); // safe by definition args.add(0, outerRef); if (offset == 0) { statements.add(0, superInvocation); offset = 1; } Types.addBinding(superInvocation, cons); } } } for (int i = 0; i < newParams.size(); i++) { SingleVariableDeclaration parameter = newParams.get(i); // Only add an assignment statement for fields. if (innerFields.get(i).isField()) { statements.add(i + offset, createAssignment(innerFields.get(i), Types.getVariableBinding(parameter), ast)); } // Add methodVars at the end of the method invocation. if (methodVars) { parameters.add(parameter); binding.addParameter(Types.getVariableBinding(parameter)); } else { parameters.add(i, parameter); binding.addParameter(i, Types.getVariableBinding(parameter)); } } Symbols.scanAST(constructor); updatedConstructors.add(binding); assert constructor.parameters().size() == binding.getParameterTypes().length; }
From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java
License:Open Source License
/** * Adds a nullary constructor that invokes a superclass constructor with * default arguments.//from w ww. j a v a2s. c om */ @SuppressWarnings("unchecked") private void generateConstructor(TypeDeclaration node) { ITypeBinding clazz = node.resolveBinding(); IMethodBinding superConstructor = getVisible(getConstructors(clazz.getSuperclass())).next(); // Add an explicit constructor that calls super with suitable default arguments. AST ast = node.getAST(); MethodDeclaration constructor = ast.newMethodDeclaration(); constructor.setConstructor(true); constructor.setName(ast.newSimpleName(node.getName().getIdentifier())); constructor.modifiers().add(ast.newModifier(ModifierKeyword.PROTECTED_KEYWORD)); node.bodyDeclarations().add(constructor); Block block = ast.newBlock(); constructor.setBody(block); SuperConstructorInvocation invocation = ast.newSuperConstructorInvocation(); block.statements().add(invocation); addAssertionError(block); for (ITypeBinding type : superConstructor.getParameterTypes()) { Expression value = getDefaultValue(ast, type); CastExpression cast = ast.newCastExpression(); cast.setExpression(value); cast.setType(createType(ast, clazz, type)); invocation.arguments().add(cast); } }