当前位置: 首页>>代码示例>>Java>>正文


Java ClassInstanceCreation类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.ClassInstanceCreation的典型用法代码示例。如果您正苦于以下问题:Java ClassInstanceCreation类的具体用法?Java ClassInstanceCreation怎么用?Java ClassInstanceCreation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassInstanceCreation类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ClassInstanceCreation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewriteAST

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:57,代码来源:AbstractSerialVersionOperation.java

示例2: getArgumentsProperty

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
  switch (invocation.getNodeType()) {
    case ASTNode.METHOD_INVOCATION:
      return MethodInvocation.ARGUMENTS_PROPERTY;
    case ASTNode.SUPER_METHOD_INVOCATION:
      return SuperMethodInvocation.ARGUMENTS_PROPERTY;

    case ASTNode.CONSTRUCTOR_INVOCATION:
      return ConstructorInvocation.ARGUMENTS_PROPERTY;
    case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
      return SuperConstructorInvocation.ARGUMENTS_PROPERTY;

    case ASTNode.CLASS_INSTANCE_CREATION:
      return ClassInstanceCreation.ARGUMENTS_PROPERTY;
    case ASTNode.ENUM_CONSTANT_DECLARATION:
      return EnumConstantDeclaration.ARGUMENTS_PROPERTY;

    default:
      throw new IllegalArgumentException(invocation.toString());
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:Invocations.java

示例3: createCollectionInitStmt

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void createCollectionInitStmt(final CaptureLog log, final int logRecNo) 
{
	final int      oid          = log.objectIds.get(logRecNo);
	final Object[] params       = log.params.get(logRecNo);
	String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
	final Class<?> collType     = getClassForName(collTypeName);

	final String varName;
	
	// -- determine if an alternative collection must be used for code generation
	final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
	if(isPrivate || ! hasDefaultConstructor(collType))
	{
		if(Set.class.isAssignableFrom(collType))
		{
			collTypeName = HashSet.class.getName();
		}
		else if (List.class.isAssignableFrom(collType))
		{
			collTypeName = ArrayList.class.getName();
		}
		else if(Queue.class.isAssignableFrom(collType))
		{
			collTypeName = ArrayDeque.class.getName();
		}
		else
		{
			throw new RuntimeException("Collection " + collType + " is not supported");
		}
	}

	// -- create code for instantiating collection
	varName = this.createNewVarName(oid, collTypeName);
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	final SimpleName varNameExpr = ast.newSimpleName(varName); 
	vd.setName(varNameExpr);	
	
	final ClassInstanceCreation ci = ast.newClassInstanceCreation();
	    ci.setType(this.createAstType(collTypeName, ast));
	    vd.setInitializer(ci);
	
	final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
	stmt.setType(this.createAstType(collTypeName, ast));
	
	methodBlock.statements().add(stmt);	

	// --- create code for filling the collection
	Integer paramOID;
	MethodInvocation mi;
	for(int i = 0; i < params.length; i++)
	{
		mi = ast.newMethodInvocation();
		mi.setName(ast.newSimpleName("add"));
		
		paramOID = (Integer) params[i];
		if(paramOID == null)
		{
			mi.arguments().add(ast.newNullLiteral());
		}
		else
		{
			mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(paramOID)));
		}
		
		methodBlock.statements().add(mi);	
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:71,代码来源:JUnitCodeGenerator.java

示例4: createMapInitStmt

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
@Override
public void createMapInitStmt(final CaptureLog log, final int logRecNo) {
	final int      oid          = log.objectIds.get(logRecNo);
	final Object[] params       = log.params.get(logRecNo);
	String         collTypeName = log.oidClassNames.get(log.oidRecMapping.get(oid));
	final Class<?> collType     = getClassForName(collTypeName);


	final String varName;
	
	// -- determine if an alternative collection must be used for code generation
	final boolean isPrivate = java.lang.reflect.Modifier.isPrivate(collType.getModifiers());
	if(isPrivate || ! hasDefaultConstructor(collType))
	{
		collTypeName = HashMap.class.getName();
	}

	// -- create code for instantiating collection
	varName = this.createNewVarName(oid, collTypeName);
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	final SimpleName varNameExpr = ast.newSimpleName(varName); 
	vd.setName(varNameExpr);	
	
	final ClassInstanceCreation ci = ast.newClassInstanceCreation();
	    ci.setType(this.createAstType(collTypeName, ast));
	    vd.setInitializer(ci);
	
	final VariableDeclarationStatement stmt = ast.newVariableDeclarationStatement(vd);
	stmt.setType(this.createAstType(collTypeName, ast));
	
	methodBlock.statements().add(stmt);	

	// --- create code for filling the collection
	Integer valueOID;
	Integer keyOID;
	
	MethodInvocation mi;
	for(int i = 0; i + 1< params.length; i+=2)
	{
		mi = ast.newMethodInvocation();
		mi.setName(ast.newSimpleName("put"));
		
		keyOID = (Integer) params[i];
	    mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(keyOID)));
		
		valueOID = (Integer) params[i + 1];
		if(valueOID == null)
		{
			mi.arguments().add(ast.newNullLiteral());
		}
		else
		{
			mi.arguments().add(ast.newSimpleName(this.oidToVarMapping.get(valueOID)));
		}
		
		methodBlock.statements().add(mi);	
	}
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:60,代码来源:JUnitCodeGenerator.java

示例5: asClosure

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
                                      Expression expression, String methodName) {
    if (expression instanceof ClassInstanceCreation) {
        ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
        if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
            AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
            if (classDeclaration.bodyDeclarations().size() == 1 &&
                    classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
                    ((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
                            .getName().getIdentifier().equals(methodName)) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
                List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
                GroovyClosure closure = groovyClosureBuilder.aClosure()
                        .withBodyStatements(statements)
                        .withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
                        .withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
                        .build();
                return Optional.of(closure);
            }
        }
    }
    return empty();
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:24,代码来源:ClosureHelper.java

示例6: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public boolean visit(ClassInstanceCreation node) {
	IMethodBinding mmtb = node.resolveConstructorBinding();

	if (mtbStack.isEmpty()) // not part of a method
		return true;

	// make field access fact
	try {
		facts.add(Fact.makeCallsFact(getQualifiedName(mtbStack.peek()),
				getQualifiedName(mmtb)));
	} catch (Exception e) {
		System.err.println("Cannot resolve class instance creation \""
				+ node.getType().toString() + "\"");
	}
	return true;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:17,代码来源:ASTVisitorAtomicChange.java

示例7: createReturnBlock

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public Block createReturnBlock(AST ast, TypeDeclaration builderType, String withName, String parameterName) {
    Block builderMethodBlock = ast.newBlock();
    ReturnStatement returnStatement = ast.newReturnStatement();
    ClassInstanceCreation newClassInstanceCreation = ast.newClassInstanceCreation();
    newClassInstanceCreation.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));

    MethodInvocation withMethodInvocation = ast.newMethodInvocation();
    withMethodInvocation.setExpression(newClassInstanceCreation);
    withMethodInvocation.setName(ast.newSimpleName(withName));
    withMethodInvocation.arguments().add(ast.newSimpleName(parameterName));

    returnStatement.setExpression(withMethodInvocation);
    builderMethodBlock.statements().add(returnStatement);
    return builderMethodBlock;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:16,代码来源:NewBuilderAndWithMethodCallCreationFragment.java

示例8: needsExplicitBoxing

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
/**
 * Returns whether an expression at the given location needs explicit boxing.
 *
 * @param expression the expression
 * @return <code>true</code> iff an expression at the given location needs explicit boxing
 * @since 3.6
 */
private static boolean needsExplicitBoxing(Expression expression) {
	StructuralPropertyDescriptor locationInParent= expression.getLocationInParent();
	if (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return needsExplicitBoxing((ParenthesizedExpression) expression.getParent());
	}

	if (locationInParent == ClassInstanceCreation.EXPRESSION_PROPERTY
			|| locationInParent == FieldAccess.EXPRESSION_PROPERTY
			|| locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
		return true;
	}

	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ASTNodes.java

示例9: getDeclarationNode

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name
 *            the name of the node
 *
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
	ASTNode parent = name.getParent();
	if (!(parent instanceof AbstractTypeDeclaration)) {

		parent = parent.getParent();
		if (parent instanceof ParameterizedType || parent instanceof Type) {
			parent = parent.getParent();
		}
		if (parent instanceof ClassInstanceCreation) {

			final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
			parent = creation.getAnonymousClassDeclaration();
		}
	}
	return parent;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:PotentialProgrammingProblemsFix.java

示例10: transfer

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
@Override
public OOGContext transfer(SourceVariableDeclaration instr, OOGContext value) {
	// Get the source variable that is being declared
	SourceVariable declaredVariable = instr.getDeclaredVariable();
	// Get the set of qualifiers of the variable that is being declared
	Set<OType> declVarSet = this.tm.getAnalysisResult(declaredVariable);
	
	// Check if the declared variable is the left-hand side of a new expression, call T-New for its ser
	// And remove the qualfiers that contain 'n.PD'
	VariableDeclaration node = instr.getNode();
	ASTNode parent = node.getParent();
	if(parent instanceof VariableDeclarationStatement){
		if(node.getInitializer()!=null && node.getInitializer() instanceof ClassInstanceCreation){
			TypeConstraints.tNewNoOthersPublicDomain(declVarSet);
		}
	}
	
	return value;
}
 
开发者ID:aroog,项目名称:code,代码行数:20,代码来源:PushIntoOwnedTransferFunctions.java

示例11: ExpressionVisitor

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public ExpressionVisitor(ASTNode enclosingDeclartion, BaseTraceability trace) {
	AstNode expression = trace.getExpression();
	if(expression instanceof ast.ClassInstanceCreation){
		expressionType = ExpressionType.CLASS_INSTANCE_CREATION;
		expressionToFind =((ast.ClassInstanceCreation) expression).complexExpression;
	}else if(expression instanceof ast.FieldWrite){
		expressionType = ExpressionType.FIELD_WRITE;
		expressionToFind = ((ast.FieldWrite) expression).complexExpression;
	}else if(expression instanceof ast.FieldAccess){
		expressionType = ExpressionType.FIELD_ACCESS;
		expressionToFind = ((ast.FieldAccess) expression).complexExpression;
	}else if(expression instanceof ast.MethodInvocation){
		expressionToFind =((ast.MethodInvocation) expression).complexExpression;
		expressionType = ExpressionType.METHOD_INVOCATION;
	}
	enclosingDeclaration = enclosingDeclartion;
	enclosingDeclaration.accept(this);
}
 
开发者ID:aroog,项目名称:code,代码行数:19,代码来源:ExpressionVisitor.java

示例12: getIJavaElement

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public static IJavaElement getIJavaElement(ASTNode node){
	IJavaElement javaElement = null;
	// Find IJavaElement corresponding to the ASTNode
	if (node instanceof MethodDeclaration) {
		javaElement = ((MethodDeclaration) node).resolveBinding()
				.getJavaElement();
	} else if (node instanceof VariableDeclaration) {
		javaElement = ((VariableDeclaration) node).resolveBinding()
				.getJavaElement();
	}else if(node instanceof TypeDeclaration){
		javaElement = ((TypeDeclaration)node).resolveBinding()
				.getJavaElement();
	}else if(node instanceof ClassInstanceCreation){
		javaElement = ((ClassInstanceCreation)node).resolveConstructorBinding().getJavaElement();
	}
	
	return javaElement;
}
 
开发者ID:aroog,项目名称:code,代码行数:19,代码来源:TraceUtility.java

示例13: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public boolean visit(ClassInstanceCreation node)
{
  IMethodBinding mmtb = node.resolveConstructorBinding();
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  try
  {
    this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding)this.mtbStack.peek()), 
      getQualifiedName(mmtb)));
  }
  catch (Exception e)
  {
    System.err.println("Cannot resolve class instance creation \"" + 
      node.getType().toString() + "\"");
  }
  return true;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:19,代码来源:ASTVisitorAtomicChange.java

示例14: visit

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
public boolean visit(ClassInstanceCreation node)
{
  IMethodBinding mmtb = node.resolveConstructorBinding();
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  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;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:19,代码来源:ASTVisitorAtomicChange.java

示例15: getDeclarationNode

import org.eclipse.jdt.core.dom.ClassInstanceCreation; //导入依赖的package包/类
/**
 * Returns the declaration node for the originally selected node.
 *
 * @param name the name of the node
 * @return the declaration node
 */
private static ASTNode getDeclarationNode(SimpleName name) {
  ASTNode parent = name.getParent();
  if (!(parent instanceof AbstractTypeDeclaration)) {

    parent = parent.getParent();
    if (parent instanceof ParameterizedType || parent instanceof Type)
      parent = parent.getParent();
    if (parent instanceof ClassInstanceCreation) {

      final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
      parent = creation.getAnonymousClassDeclaration();
    }
  }
  return parent;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:PotentialProgrammingProblemsFix.java


注:本文中的org.eclipse.jdt.core.dom.ClassInstanceCreation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。