use of org.eclipse.wb.internal.core.utils.ast.AstEditor in project windowbuilder by eclipse.
the class DisplayExpressionPropertyEditor method getText.
// //////////////////////////////////////////////////////////////////////////
//
// Presentation
//
// //////////////////////////////////////////////////////////////////////////
@Override
protected String getText(Property property) throws Exception {
GenericProperty genericProperty = (GenericProperty) property;
Expression expression = genericProperty.getExpression();
if (expression != null) {
AstEditor editor = genericProperty.getJavaInfo().getEditor();
return editor.getSource(expression);
}
return null;
}
use of org.eclipse.wb.internal.core.utils.ast.AstEditor in project windowbuilder by eclipse.
the class MethodInvocationArgumentAccessor method setExpression.
@Override
public boolean setExpression(final JavaInfo javaInfo, final String source) throws Exception {
final List<String> defaultArguments = getMethodDescription(javaInfo).getDefaultArguments();
// modify expression
final MethodInvocation invocation = getMethodInvocation(javaInfo);
if (invocation != null) {
final AstEditor editor = javaInfo.getEditor();
final Expression oldArgumentExpression = getArgumentExpression(invocation);
final String argumentSource = source != null ? source : defaultArguments.get(m_index);
if (!isSameSource(editor, oldArgumentExpression, argumentSource)) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
editor.replaceExpression(oldArgumentExpression, argumentSource);
if (isDefaultArguments(javaInfo, invocation)) {
editor.removeEnclosingStatement(invocation);
}
}
});
}
} else if (source != null) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
String argumentsSource = getNewInvocationArguments();
javaInfo.addMethodInvocation(m_methodSignature, argumentsSource);
}
private String getNewInvocationArguments() {
List<String> arguments = Lists.newArrayList(defaultArguments);
arguments.set(m_index, source);
return StringUtils.join(arguments.iterator(), ", ");
}
});
}
// success
return true;
}
use of org.eclipse.wb.internal.core.utils.ast.AstEditor in project windowbuilder by eclipse.
the class MethodInvocationArgumentAccessor method isDefaultArguments.
private boolean isDefaultArguments(JavaInfo javaInfo, MethodInvocation invocation) {
AstEditor editor = javaInfo.getEditor();
boolean allDefault = true;
List<ParameterDescription> parameters = getMethodDescription(javaInfo).getParameters();
List<Expression> arguments = DomGenerics.arguments(invocation);
for (ParameterDescription parameter : parameters) {
int index = parameter.getIndex();
Expression argument = arguments.get(index);
allDefault &= isDefaultArgument(editor, argument, parameter);
}
return allDefault;
}
use of org.eclipse.wb.internal.core.utils.ast.AstEditor in project windowbuilder by eclipse.
the class FieldAccessor method splitAssignmentsSequence.
private static Assignment splitAssignmentsSequence(JavaInfo javaInfo, Assignment targetAssignment, AssignmentsSequence sequence) throws Exception {
Assignment newTargetAssignment = null;
{
AstEditor editor = javaInfo.getEditor();
String assignedSource = editor.getSource(sequence.getAssignedExpression());
Statement targetStatement = AstNodeUtils.getEnclosingStatement(targetAssignment);
for (Assignment assignment : sequence.getAssignments()) {
String source = editor.getSource(assignment.getLeftHandSide()) + " = " + assignedSource;
// add new assignment
StatementTarget target = new StatementTarget(targetStatement, false);
Assignment newAssignment = (Assignment) javaInfo.addExpressionStatement(target, source);
if (assignment == targetAssignment) {
newTargetAssignment = newAssignment;
}
// prepare new statement target
targetStatement = AstNodeUtils.getEnclosingStatement(newAssignment);
}
// remove old statement
editor.removeEnclosingStatement(targetAssignment);
}
// use new target assignment
Assert.isNotNull(newTargetAssignment);
return newTargetAssignment;
}
use of org.eclipse.wb.internal.core.utils.ast.AstEditor in project windowbuilder by eclipse.
the class InvocationChildAssociationAccessor method setExpression.
@Override
public boolean setExpression(JavaInfo javaInfo, String source) throws Exception {
// if given source is "null", use default source (but it also can be "null")
final String newSource;
if (source != null) {
newSource = source;
} else {
newSource = m_defaultSource;
}
// if we have source to replace current, do this
if (newSource != null) {
final AstEditor editor = javaInfo.getEditor();
final Expression oldExpression = getExpression(javaInfo);
if (!editor.getSource(oldExpression).equals(source)) {
ExecutionUtils.run(javaInfo, new RunnableEx() {
@Override
public void run() throws Exception {
editor.replaceExpression(oldExpression, newSource);
}
});
return true;
}
}
// no changes
return false;
}
Aggregations