org.eclipse.jdt.core.dom.ClassInstanceCreation#getExpression ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.ClassInstanceCreation#getExpression ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RefactoringMiner   文件: ObjectCreation.java
public ObjectCreation(CompilationUnit cu, String filePath, ClassInstanceCreation creation) {
	this.locationInfo = new LocationInfo(cu, filePath, creation, CodeElementType.CLASS_INSTANCE_CREATION);
	this.type = UMLType.extractTypeObject(cu, filePath, creation.getType(), 0);
	this.typeArguments = creation.arguments().size();
	this.arguments = new ArrayList<String>();
	List<Expression> args = creation.arguments();
	for(Expression argument : args) {
		this.arguments.add(argument.toString());
	}
	if(creation.getExpression() != null) {
		this.expression = creation.getExpression().toString();
	}
	if(creation.getAnonymousClassDeclaration() != null) {
		this.anonymousClassDeclaration = creation.getAnonymousClassDeclaration().toString();
	}
}
 
@Override
public boolean visit(final ClassInstanceCreation node) {
	Assert.isNotNull(node);
	if (fCreateInstanceField) {
		final AST ast= node.getAST();
		final Type type= node.getType();
		final ITypeBinding binding= type.resolveBinding();
		if (binding != null && binding.getDeclaringClass() != null && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null) {
			if (!Modifier.isStatic(binding.getModifiers())) {
				Expression expression= null;
				if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
					final FieldAccess access= ast.newFieldAccess();
					access.setExpression(ast.newThisExpression());
					access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
					expression= access;
				} else
					expression= ast.newSimpleName(fEnclosingInstanceFieldName);
				if (node.getExpression() != null)
					fSourceRewrite.getImportRemover().registerRemovedNode(node.getExpression());
				fSourceRewrite.getASTRewrite().set(node, ClassInstanceCreation.EXPRESSION_PROPERTY, expression, fGroup);
			} else
				addTypeQualification(type, fSourceRewrite, fGroup);
		}
	}
	return true;
}
 
@Override
public void endVisit(ClassInstanceCreation node) {
	Expression receiver= node.getExpression();
	Type createdType= node.getType();

	ConstraintVariable2 typeCv;
	if (node.getAnonymousClassDeclaration() == null) {
		typeCv= getConstraintVariable(createdType);
	} else {
		typeCv= fTCModel.makeImmutableTypeVariable(createdType.resolveBinding(), null);
		setConstraintVariable(createdType, typeCv);
	}
	setConstraintVariable(node, typeCv);

	IMethodBinding methodBinding= node.resolveConstructorBinding();
	Map<String, IndependentTypeVariable2> methodTypeVariables= createMethodTypeArguments(methodBinding);
	List<Expression> arguments= node.arguments();
	doVisitMethodInvocationArguments(methodBinding, arguments, receiver, methodTypeVariables, createdType);
}
 
源代码4 项目: SimFix   文件: CodeBlock.java
private ClassInstanceCreate visit(ClassInstanceCreation node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	ClassInstanceCreate classInstanceCreate = new ClassInstanceCreate(startLine, endLine, node);
	
	if(node.getExpression() != null){
		Expr expression = (Expr) process(node.getExpression());
		expression.setParent(classInstanceCreate);
		classInstanceCreate.setExpression(expression);
	}
	
	if(node.getAnonymousClassDeclaration() != null){
		AnonymousClassDecl anonymousClassDecl = (AnonymousClassDecl) process(node.getAnonymousClassDeclaration());
		anonymousClassDecl.setParent(classInstanceCreate);
		classInstanceCreate.setAnonymousClassDecl(anonymousClassDecl);
	}

	List<Expr> arguments = new ArrayList<>();
	for(Object object : node.arguments()){
		Expr arg = (Expr) process((ASTNode) object);
		arg.setParent(classInstanceCreate);
		arguments.add(arg);
	}
	classInstanceCreate.setArguments(arguments);
	
	classInstanceCreate.setClassType(node.getType());
	classInstanceCreate.setType(node.getType());
	
	return classInstanceCreate;
}
 
private void updateConstructorReference(final ClassInstanceCreation creation, final CompilationUnitRewrite targetRewrite, final ICompilationUnit unit, TextEditGroup group) throws JavaModelException {
	Assert.isNotNull(creation);
	Assert.isNotNull(targetRewrite);
	Assert.isNotNull(unit);
	final ASTRewrite rewrite= targetRewrite.getASTRewrite();
	if (fCreateInstanceField)
		insertExpressionAsParameter(creation, rewrite, unit, group);
	final Expression expression= creation.getExpression();
	if (expression != null) {
		rewrite.remove(expression, null);
		targetRewrite.getImportRemover().registerRemovedNode(expression);
	}
}
 
@Override
public boolean visit(ClassInstanceCreation node) {
	if (fTypeCounter == 0) {
		Expression receiver= node.getExpression();
		if (receiver == null) {
			if (node.resolveTypeBinding().isLocal())
				fImplicitReceivers.add(node);
		}
	}
	return true;
}
 
源代码7 项目: JDeodorant   文件: StyledStringVisitor.java
public boolean visit(ClassInstanceCreation expr) {
	/*
	 * 
	 * [ Expression . ] new [ < Type { , Type } > ] Type ( [ Expression { ,
	 * Expression } ] ) [ AnonymousClassDeclaration ]
	 */
	activateDiffStyle(expr);
	if (expr.getExpression() != null) {
		handleExpression(expr.getExpression());
		appendPeriod();
	}
	styledString.append("new", determineDiffStyle(expr, new StyledStringStyler(keywordStyle)));
	appendSpace();
	handleTypeArguments(expr.typeArguments());
	handleType(expr.getType());
	handleParameters(expr.arguments());
	if(expr.getAnonymousClassDeclaration() != null) {
		appendSpace();
		appendOpenCurlyBracket();
		for(int i=0; i<3; i++) {
			appendPeriod();
		}
		appendClosedCurlyBracket();
	}
	deactivateDiffStyle(expr);
	return false;
}
 
源代码8 项目: juniversal   文件: ClassInstanceCreationWriter.java
@Override
public void write(ASTNode node) {
	ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) node;

	//TODO: Handle type arguments
	//TODO: Handle different reference operator used for stack objects

	// TODO: Support inner class creation via object.new
	if (classInstanceCreation.getExpression() != null)
		throw sourceNotSupported("Inner classes not yet supported");

	matchAndWrite("new");
	copySpaceAndComments();

       swiftASTWriters.writeNode(classInstanceCreation.getType());
	copySpaceAndComments();

	matchAndWrite("(");
	copySpaceAndComments();

	List<?> arguments = classInstanceCreation.arguments();

	boolean first = true;
	for (Object object : arguments) {
		Expression argument = (Expression) object;

		if (! first) {
			matchAndWrite(",");
			copySpaceAndComments();
		}

           swiftASTWriters.writeNode(argument);
		copySpaceAndComments();

		first = false;
	}

	matchAndWrite(")");
}
 
源代码9 项目: juniversal   文件: ClassInstanceCreationWriter.java
@Override
public void write(ClassInstanceCreation classInstanceCreation) {
	//TODO: Handle type arguments
	//TODO: Handle different reference operator used for stack objects

	// TODO: Support inner class creation via object.new
	if (classInstanceCreation.getExpression() != null)
		throw sourceNotSupported("Inner classes not yet supported");

	matchAndWrite("new");
	copySpaceAndComments();

       writeNode(classInstanceCreation.getType());
	copySpaceAndComments();

	matchAndWrite("(");
	copySpaceAndComments();

	List<?> arguments = classInstanceCreation.arguments();

	boolean first = true;
	for (Object object : arguments) {
		Expression argument = (Expression) object;

		if (! first) {
			matchAndWrite(",");
			copySpaceAndComments();
		}

           writeNode(argument);
		copySpaceAndComments();

		first = false;
	}

	matchAndWrite(")");
}
 
源代码10 项目: xtext-xtend   文件: JavaASTFlattener.java
@Override
public boolean visit(final ClassInstanceCreation node) {
  Expression _expression = node.getExpression();
  boolean _tripleNotEquals = (_expression != null);
  if (_tripleNotEquals) {
    node.getExpression().accept(this);
    this.appendToBuffer(".");
  }
  boolean _isLambdaCase = this._aSTFlattenerUtils.isLambdaCase(node);
  if (_isLambdaCase) {
    if (this.fallBackStrategy) {
      this.appendToBuffer("(");
    }
    this.appendToBuffer("[");
    Object _get = node.getAnonymousClassDeclaration().bodyDeclarations().get(0);
    final MethodDeclaration method = ((MethodDeclaration) _get);
    boolean _isEmpty = method.parameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      this.visitAllSeparatedByComma(method.parameters());
      this.appendToBuffer("|");
    } else {
      if (this.fallBackStrategy) {
        this.appendToBuffer("|");
      }
    }
    this.visitAll(method.getBody().statements());
    this.appendToBuffer("]");
    if (this.fallBackStrategy) {
      this.appendToBuffer(" as ");
      boolean _isEmpty_1 = node.typeArguments().isEmpty();
      boolean _not_1 = (!_isEmpty_1);
      if (_not_1) {
        this.appendTypeParameters(node.typeArguments());
      }
      node.getType().accept(this);
      this.appendToBuffer(")");
    }
  } else {
    this.appendToBuffer("new ");
    boolean _isEmpty_2 = node.typeArguments().isEmpty();
    boolean _not_2 = (!_isEmpty_2);
    if (_not_2) {
      this.appendTypeParameters(node.typeArguments());
    }
    node.getType().accept(this);
    this.appendToBuffer("(");
    for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext();) {
      {
        Expression e = it.next();
        e.accept(this);
        boolean _hasNext = it.hasNext();
        if (_hasNext) {
          this.appendToBuffer(",");
        }
      }
    }
    this.appendToBuffer(")");
    AnonymousClassDeclaration _anonymousClassDeclaration = node.getAnonymousClassDeclaration();
    boolean _tripleNotEquals_1 = (_anonymousClassDeclaration != null);
    if (_tripleNotEquals_1) {
      node.getAnonymousClassDeclaration().accept(this);
    }
  }
  return false;
}