List of usage examples for org.eclipse.jdt.core.dom ClassInstanceCreation getType
public Type getType()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(ClassInstanceCreation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.fBuffer.append(".");//$NON-NLS-1$ }//from w w w. j a v a 2s . com this.fBuffer.append("new ");//$NON-NLS-1$ 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$ } node.getType().accept(this); } this.fBuffer.append("(");//$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$ if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(ClassInstanceCreation node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.NEW); boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName(node.getType()))); tb.setKind(boa.types.Ast.TypeKind.CLASS); b.setNewType(tb.build());/*from w w w . j av a 2 s . c o m*/ for (Object t : node.typeArguments()) { boa.types.Ast.Type.Builder gtb = boa.types.Ast.Type.newBuilder(); gtb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t))); gtb.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(gtb.build()); } if (node.getExpression() != null) { node.getExpression().accept(this); b.addExpressions(expressions.pop()); } for (Object a : node.arguments()) { ((org.eclipse.jdt.core.dom.Expression) a).accept(this); b.addExpressions(expressions.pop()); } if (node.getAnonymousClassDeclaration() != null) { declarations.push(new ArrayList<boa.types.Ast.Declaration>()); node.getAnonymousClassDeclaration().accept(this); for (boa.types.Ast.Declaration d : declarations.pop()) b.setAnonDeclaration(d); } expressions.push(b.build()); return false; }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
public static String getNameFromAnon(AnonymousClassDeclaration anon) { String name = PPATypeRegistry.UNKNOWN_CLASS_FQN; ASTNode parent = anon.getParent();//from www . j ava 2 s . co m if (parent instanceof ClassInstanceCreation) { ClassInstanceCreation cic = (ClassInstanceCreation) parent; Type type = cic.getType(); if (type instanceof SimpleType) { name = ((SimpleType) type).getName().getFullyQualifiedName(); } else if (type instanceof QualifiedType) { name = ((QualifiedType) type).getName().getFullyQualifiedName(); } } // Parent could also be enum constant declaration, although this is a // lot less interesting // for PPA than anon. return name; }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(ClassInstanceCreation node) { IMethodBinding mmtb = node.resolveConstructorBinding(); if (this.mtbStack.isEmpty()) { return true; }/* ww w . j av a2 s . co m*/ try { this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding) this.mtbStack.peek()), getQualifiedName(mmtb))); } catch (Exception localException) { System.err.println("Cannot resolve class instance creation \"" + node.getType().toString() + "\""); } return true; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(ClassInstanceCreation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.buffer.append(".");//$NON-NLS-1$ }/*from w w w . jav a 2 s. c o m*/ this.buffer.append("new ");//$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$ } node.getType().accept(this); } this.buffer.append("(");//$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(")");//$NON-NLS-1$ if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java
License:Open Source License
@Override public boolean visit(ClassInstanceCreation node) { List<Type> typeArguments = node.typeArguments(); handleTypeArguments(typeArguments);//from w w w . j a v a2 s. c om handleInvocation(node, node.getType(), node.getAnonymousClassDeclaration()); if (!typeArguments.isEmpty()) { handleTokenBefore(typeArguments.get(0), TokenNamenew, false, true); // fix for: new<Integer>A<String>() } handleCommas(node.arguments(), this.options.insert_space_before_comma_in_allocation_expression, this.options.insert_space_after_comma_in_allocation_expression); return true; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { IMethodBinding binding = node.resolveConstructorBinding(); String signature = JavaUtils.getJdtSignature(binding); TypeName typeNameNode = (TypeName) translate(node.getType()); final List<Expression> arguments = translateArguments(binding, node.arguments()); final ClassDeclaration innerClass; {// www .ja va 2s . c om AnonymousClassDeclaration anoDeclaration = node.getAnonymousClassDeclaration(); if (anoDeclaration != null) { ITypeBinding superclass = anoDeclaration.resolveBinding().getSuperclass(); signature = superclass.getKey() + StringUtils.substringAfter(signature, ";"); String name = typeNameNode.getName().getName().replace('.', '_'); name = name + "_" + context.generateTechnicalAnonymousClassIndex(); innerClass = declareInnerClass(binding, anoDeclaration, name, ArrayUtils.EMPTY_STRING_ARRAY); typeNameNode = typeName(name); // prepare enclosing type final ITypeBinding enclosingTypeBinding = getEnclosingTypeBinding(node); final SimpleIdentifier enclosingTypeRef; final AtomicBoolean addEnclosingTypeRef = new AtomicBoolean(); { if (enclosingTypeBinding != null) { enclosingTypeRef = identifier(enclosingTypeBinding.getName() + "_this"); // add enclosing class references innerClass.accept(new RecursiveASTVisitor<Void>() { @Override public Void visitMethodInvocation(MethodInvocation node) { if (node.getTarget() == null) { IMethodBinding methodBinding = (IMethodBinding) context.getNodeBinding(node); if (methodBinding != null && methodBinding.getDeclaringClass() == enclosingTypeBinding) { addEnclosingTypeRef.set(true); node.setTarget(enclosingTypeRef); } } return super.visitMethodInvocation(node); } @Override public Void visitSimpleIdentifier(SimpleIdentifier node) { if (!(node.getParent() instanceof PropertyAccess) && !(node.getParent() instanceof PrefixedIdentifier)) { Object binding = context.getNodeBinding(node); if (binding instanceof IVariableBinding) { IVariableBinding variableBinding = (IVariableBinding) binding; if (variableBinding.isField() && variableBinding.getDeclaringClass() == enclosingTypeBinding) { addEnclosingTypeRef.set(true); replaceNode(node.getParent(), node, propertyAccess(enclosingTypeRef, node)); } } } return super.visitSimpleIdentifier(node); } }); } else { enclosingTypeRef = null; } } // declare referenced final variables XXX final String finalName = name; anoDeclaration.accept(new ASTVisitor() { final Set<org.eclipse.jdt.core.dom.IVariableBinding> addedParameters = Sets.newHashSet(); final List<FormalParameter> constructorParameters = Lists.newArrayList(); int index; @Override public void endVisit(AnonymousClassDeclaration node) { if (!constructorParameters.isEmpty()) { // add parameters to the existing "inner" constructor XXX for (ClassMember classMember : innerClass.getMembers()) { if (classMember instanceof ConstructorDeclaration) { ConstructorDeclaration innerConstructor = (ConstructorDeclaration) classMember; innerConstructor.getParameters().getParameters().addAll(constructorParameters); return; } } // create new "inner" constructor innerClass.getMembers().add(index, constructorDeclaration(identifier(finalName), null, formalParameterList(constructorParameters), null)); } super.endVisit(node); } @Override public void endVisit(SimpleName node) { IBinding nameBinding = node.resolveBinding(); if (nameBinding instanceof org.eclipse.jdt.core.dom.IVariableBinding) { org.eclipse.jdt.core.dom.IVariableBinding variableBinding = (org.eclipse.jdt.core.dom.IVariableBinding) nameBinding; org.eclipse.jdt.core.dom.MethodDeclaration enclosingMethod = getEnclosingMethod(node); if (!variableBinding.isField() && enclosingMethod != null && variableBinding.getDeclaringMethod() != enclosingMethod.resolveBinding() && addedParameters.add(variableBinding)) { TypeName parameterTypeName = translateTypeName(variableBinding.getType()); String parameterName = variableBinding.getName(); SimpleIdentifier parameterNameNode = identifier(parameterName); innerClass.getMembers().add(index++, fieldDeclaration(parameterTypeName, variableDeclaration(parameterNameNode))); constructorParameters.add(fieldFormalParameter(null, null, parameterNameNode)); arguments.add(parameterNameNode); context.putReference(parameterNameNode, variableBinding, null); } } super.endVisit(node); } @Override public boolean visit(AnonymousClassDeclaration node) { if (addEnclosingTypeRef.get()) { TypeName parameterTypeName = translateTypeName(enclosingTypeBinding); innerClass.getMembers().add(index++, fieldDeclaration(false, Keyword.FINAL, parameterTypeName, variableDeclaration(enclosingTypeRef))); constructorParameters.add(fieldFormalParameter(null, null, enclosingTypeRef)); arguments.add(thisExpression()); } return super.visit(node); } }); } else { innerClass = null; } } InstanceCreationExpression creation = instanceCreationExpression(Keyword.NEW, typeNameNode, null, arguments); context.putNodeBinding(creation, binding); context.putAnonymousDeclaration(creation, innerClass); context.getConstructorDescription(binding).instanceCreations.add(creation); return done(creation); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// ww w . ja va2 s . c o m public boolean visit(ClassInstanceCreation node) { boolean addAutorelease = useReferenceCounting && !isNewAssignment(node); buffer.append(addAutorelease ? "[[[" : "[["); ITypeBinding type = Types.getTypeBinding(node.getType()); ITypeBinding outerType = type.getDeclaringClass(); buffer.append(NameTable.getFullName(type)); buffer.append(" alloc] init"); IMethodBinding method = Types.getMethodBinding(node); List<Expression> arguments = node.arguments(); if (node.getExpression() != null && type.isMember() && arguments.size() > 0 && !Types.getTypeBinding(arguments.get(0)).isEqualTo(outerType)) { // This is calling an untranslated "Outer.new Inner()" method, // so update its binding and arguments as if it had been translated. GeneratedMethodBinding newBinding = new GeneratedMethodBinding(method); newBinding.addParameter(0, outerType); method = newBinding; arguments = Lists.newArrayList(node.arguments()); arguments.add(0, node.getExpression()); } printArguments(method, arguments); buffer.append(']'); if (addAutorelease) { buffer.append(" autorelease]"); } return false; }
From source file:com.google.devtools.j2cpp.types.ImplementationImportCollector.java
License:Open Source License
@Override public boolean visit(ClassInstanceCreation node) { addReference(node.getType()); IMethodBinding binding = Types.getMethodBinding(node); if (binding != null) { ITypeBinding[] parameterTypes = binding.getParameterTypes(); for (int i = 0; i < node.arguments().size(); i++) { ITypeBinding parameterType;// w ww . j a v a2s . c o m if (i < parameterTypes.length) { parameterType = parameterTypes[i]; } else { parameterType = parameterTypes[parameterTypes.length - 1]; } ITypeBinding actualType = Types.getTypeBinding(node.arguments().get(i)); if (!parameterType.equals(actualType) && actualType.isAssignmentCompatible(parameterType)) { addReference(actualType); } } } return super.visit(node); }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(ClassInstanceCreation node) { if (node.getExpression() != null) { node.getExpression().accept(this); sb.print('.'); }// w ww.j a v a 2s . co m sb.print("new "); printTypeParameters(node.getMethodBinding().getTypeParameters()); node.getType().accept(this); sb.print("("); for (Iterator<Expression> it = node.getArguments().iterator(); it.hasNext();) { Expression e = it.next(); e.accept(this); if (it.hasNext()) { sb.print(','); } } sb.print(')'); if (node.getAnonymousClassDeclaration() != null) { node.getAnonymousClassDeclaration().accept(this); } return false; }