use of org.eclipse.jdt.internal.compiler.ast.SingleNameReference in project lombok by rzwitserloot.
the class EclipseJavaUtilMapSingularizer method generateSingularMethod.
private void generateSingularMethod(boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
md.modifiers = ClassFileConstants.AccPublic;
List<Statement> statements = new ArrayList<Statement>();
statements.add(createConstructBuilderVarIfNeeded(data, builderType, true));
String sN = new String(data.getSingularName());
String pN = new String(data.getPluralName());
char[] keyParamName = (sN + "Key").toCharArray();
char[] valueParamName = (sN + "Value").toCharArray();
char[] keyFieldName = (pN + "$key").toCharArray();
char[] valueFieldName = (pN + "$value").toCharArray();
/* this.pluralname$key.add(singularnameKey); */
{
FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L);
thisDotKeyField.receiver = new ThisReference(0, 0);
MessageSend thisDotKeyFieldDotAdd = new MessageSend();
thisDotKeyFieldDotAdd.arguments = new Expression[] { new SingleNameReference(keyParamName, 0L) };
thisDotKeyFieldDotAdd.receiver = thisDotKeyField;
thisDotKeyFieldDotAdd.selector = "add".toCharArray();
statements.add(thisDotKeyFieldDotAdd);
}
/* this.pluralname$value.add(singularnameValue); */
{
FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L);
thisDotValueField.receiver = new ThisReference(0, 0);
MessageSend thisDotValueFieldDotAdd = new MessageSend();
thisDotValueFieldDotAdd.arguments = new Expression[] { new SingleNameReference(valueParamName, 0L) };
thisDotValueFieldDotAdd.receiver = thisDotValueField;
thisDotValueFieldDotAdd.selector = "add".toCharArray();
statements.add(thisDotValueFieldDotAdd);
}
if (returnStatement != null)
statements.add(returnStatement);
md.statements = statements.toArray(new Statement[statements.size()]);
TypeReference keyParamType = cloneParamType(0, data.getTypeArgs(), builderType);
Argument keyParam = new Argument(keyParamName, 0, keyParamType, 0);
TypeReference valueParamType = cloneParamType(1, data.getTypeArgs(), builderType);
Argument valueParam = new Argument(valueParamName, 0, valueParamType, 0);
md.arguments = new Argument[] { keyParam, valueParam };
md.returnType = returnType;
md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("put", new String(data.getSingularName())).toCharArray();
md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
data.setGeneratedByRecursive(md);
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.SingleNameReference in project spoon by INRIA.
the class ReferenceBuilder method getExecutableReference.
<T> CtExecutableReference<T> getExecutableReference(MessageSend messageSend) {
if (messageSend.binding != null) {
return getExecutableReference(messageSend.binding);
}
CtExecutableReference<T> ref = jdtTreeBuilder.getFactory().Core().createExecutableReference();
ref.setSimpleName(CharOperation.charToString(messageSend.selector));
ref.setType(this.<T>getTypeReference(messageSend.expectedType()));
if (messageSend.receiver.resolvedType == null) {
// It is crisis dude! static context, we don't have much more information.
if (messageSend.receiver instanceof SingleNameReference) {
ref.setDeclaringType(jdtTreeBuilder.getHelper().createTypeAccessNoClasspath((SingleNameReference) messageSend.receiver).getAccessedType());
} else if (messageSend.receiver instanceof QualifiedNameReference) {
ref.setDeclaringType(jdtTreeBuilder.getHelper().createTypeAccessNoClasspath((QualifiedNameReference) messageSend.receiver).getAccessedType());
}
} else {
ref.setDeclaringType(getTypeReference(messageSend.receiver.resolvedType));
}
if (messageSend.arguments != null) {
final List<CtTypeReference<?>> parameters = new ArrayList<>();
for (Expression expression : messageSend.arguments) {
parameters.add(getTypeReference(expression.resolvedType));
}
ref.setParameters(parameters);
}
return ref;
}
Aggregations