use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
*/
@Override
public ITypeConstraint[] create(ClassInstanceCreation instanceCreation) {
List<Expression> arguments = instanceCreation.arguments();
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
IMethodBinding methodBinding = instanceCreation.resolveConstructorBinding();
result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
if (instanceCreation.getAnonymousClassDeclaration() == null) {
ConstraintVariable constructorVar = fConstraintVariableFactory.makeExpressionOrTypeVariable(instanceCreation, getContext());
ConstraintVariable typeVar = fConstraintVariableFactory.makeRawBindingVariable(instanceCreation.resolveTypeBinding());
result.addAll(Arrays.asList(fTypeConstraintFactory.createDefinesConstraint(constructorVar, typeVar)));
}
return result.toArray(new ITypeConstraint[result.size()]);
}
use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
*/
@Override
public ITypeConstraint[] create(SuperConstructorInvocation invocation) {
List<Expression> arguments = invocation.arguments();
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>(arguments.size());
IMethodBinding methodBinding = invocation.resolveConstructorBinding();
result.addAll(Arrays.asList(getArgumentConstraints(arguments, methodBinding)));
return result.toArray(new ITypeConstraint[result.size()]);
}
use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.CastExpression)
*/
@Override
public ITypeConstraint[] create(CastExpression castExpression) {
Expression expression = castExpression.getExpression();
Type type = castExpression.getType();
ITypeConstraint[] definesConstraint = fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext()), fConstraintVariableFactory.makeTypeVariable(castExpression.getType()));
if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) {
ConstraintVariable expressionVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
ConstraintVariable castExpressionVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext());
ITypeConstraint[] c2 = createOrOrSubtypeConstraint(expressionVariable, castExpressionVariable);
if (definesConstraint.length == 0) {
return c2;
} else {
ITypeConstraint c1 = definesConstraint[0];
Collection<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>();
constraints.add(c1);
constraints.addAll(Arrays.asList(c2));
return constraints.toArray(new ITypeConstraint[constraints.size()]);
}
} else
return definesConstraint;
}
use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.
the class RemoveDeclarationCorrectionProposal method removeVariableReferences.
/**
* Remove the field or variable declaration including the initializer.
* @param rewrite the ast rewrite
* @param reference the reference
*/
private void removeVariableReferences(ASTRewrite rewrite, SimpleName reference) {
ASTNode parent = reference.getParent();
while (parent instanceof QualifiedName) {
parent = parent.getParent();
}
if (parent instanceof FieldAccess) {
parent = parent.getParent();
}
int nameParentType = parent.getNodeType();
if (nameParentType == ASTNode.ASSIGNMENT) {
Assignment assignment = (Assignment) parent;
Expression rightHand = assignment.getRightHandSide();
ASTNode assignParent = assignment.getParent();
if (assignParent.getNodeType() == ASTNode.EXPRESSION_STATEMENT && rightHand.getNodeType() != ASTNode.ASSIGNMENT) {
removeVariableWithInitializer(rewrite, rightHand, assignParent);
} else {
rewrite.replace(assignment, rewrite.createCopyTarget(rightHand), null);
}
} else if (nameParentType == ASTNode.SINGLE_VARIABLE_DECLARATION) {
rewrite.remove(parent, null);
} else if (nameParentType == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
VariableDeclarationFragment frag = (VariableDeclarationFragment) parent;
ASTNode varDecl = frag.getParent();
List<VariableDeclarationFragment> fragments;
if (varDecl instanceof VariableDeclarationExpression) {
fragments = ((VariableDeclarationExpression) varDecl).fragments();
} else if (varDecl instanceof FieldDeclaration) {
fragments = ((FieldDeclaration) varDecl).fragments();
} else {
fragments = ((VariableDeclarationStatement) varDecl).fragments();
}
if (fragments.size() == 1) {
rewrite.remove(varDecl, null);
} else {
// don't try to preserve
rewrite.remove(frag, null);
}
}
}
use of org.eclipse.jdt.core.dom.Expression in project che by eclipse.
the class InlineTempRefactoring method getInitializerSource.
private Expression getInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
Expression copy = getModifiedInitializerSource(rewrite, reference);
if (NecessaryParenthesesChecker.needsParentheses(copy, reference.getParent(), reference.getLocationInParent())) {
ParenthesizedExpression parentExpr = rewrite.getAST().newParenthesizedExpression();
parentExpr.setExpression(copy);
return parentExpr;
}
return copy;
}
Aggregations