Java Code Examples for org.eclipse.jdt.core.dom.ClassInstanceCreation#getExpression()

The following examples show how to use org.eclipse.jdt.core.dom.ClassInstanceCreation#getExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectCreation.java    From RefactoringMiner with MIT License 6 votes vote down vote up
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();
	}
}
 
Example 2
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
	}
}
 
Example 6
Source File: SourceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
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;
}
 
Example 8
Source File: ClassInstanceCreationWriter.java    From juniversal with MIT License 5 votes vote down vote up
@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(")");
}
 
Example 9
Source File: ClassInstanceCreationWriter.java    From juniversal with MIT License 5 votes vote down vote up
@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(")");
}
 
Example 10
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@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;
}