use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method inferAnonymousClassConstructor.
protected JvmConstructor inferAnonymousClassConstructor(AnonymousClass anonymousClass, JvmGenericType inferredLocalClass, JvmConstructor superConstructor, boolean visible) {
JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
inferredLocalClass.getMembers().add(constructor);
associator.associatePrimary(anonymousClass.getConstructorCall(), constructor);
if (visible) {
constructor.setVisibility(JvmVisibility.DEFAULT);
} else
constructor.setVisibility(JvmVisibility.PRIVATE);
constructor.setSimpleName(inferredLocalClass.getSimpleName());
constructor.setVarArgs(superConstructor.isVarArgs());
final List<JvmFormalParameter> parameters = superConstructor.getParameters();
for (JvmFormalParameter parameter : parameters) {
// trigger name computation
parameter.getName();
constructor.getParameters().add(typesBuilder.cloneWithProxies(parameter));
}
for (JvmTypeReference exception : superConstructor.getExceptions()) constructor.getExceptions().add(typesBuilder.cloneWithProxies(exception));
if (!parameters.isEmpty()) {
typesBuilder.setBody(constructor, new Procedures.Procedure1<ITreeAppendable>() {
@Override
public void apply(ITreeAppendable a) {
a.append("super(");
for (int i = 0; i < parameters.size(); i++) {
if (i != 0) {
a.append(", ");
}
a.append(parameters.get(i).getSimpleName());
}
a.append(");");
}
});
}
return constructor;
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendGenerator method getAddedDeclarations.
protected ArrayList<JvmMember> getAddedDeclarations(final JvmGenericType it, final AnonymousClass anonymousClass) {
final ArrayList<JvmMember> result = CollectionLiterals.<JvmMember>newArrayList();
final JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
int _size = constructor.getParameters().size();
boolean _greaterEqualsThan = (_size >= 1);
if (_greaterEqualsThan) {
result.add(0, constructor);
}
Iterable<JvmField> _declaredFields = it.getDeclaredFields();
Iterables.<JvmMember>addAll(result, _declaredFields);
final Function1<JvmOperation, Boolean> _function = (JvmOperation it_1) -> {
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it_1));
final XtendFunction function = ((XtendFunction) _head);
boolean _isOverride = function.isOverride();
return Boolean.valueOf((!_isOverride));
};
Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(it.getDeclaredOperations(), _function);
Iterables.<JvmMember>addAll(result, _filter);
Iterable<JvmDeclaredType> _filter_1 = Iterables.<JvmDeclaredType>filter(it.getMembers(), JvmDeclaredType.class);
Iterables.<JvmMember>addAll(result, _filter_1);
return result;
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transform.
protected void transform(XtendConstructor source, JvmGenericType container) {
JvmConstructor constructor = typesFactory.createJvmConstructor();
container.getMembers().add(constructor);
associator.associatePrimary(source, constructor);
JvmVisibility visibility = source.getVisibility();
constructor.setSimpleName(container.getSimpleName());
constructor.setVisibility(visibility);
for (XtendParameter parameter : source.getParameters()) {
translateParameter(constructor, parameter);
}
copyAndFixTypeParameters(source.getTypeParameters(), constructor);
for (JvmTypeReference exception : source.getExceptions()) {
constructor.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
}
translateAnnotationsTo(source.getAnnotations(), constructor);
setBody(constructor, source.getExpression());
jvmTypesBuilder.copyDocumentationTo(source, constructor);
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newConstructorQuickfix.
protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, XFeatureCall call) {
JvmDeclaredType ownerType = ((JvmConstructor) call.getFeature()).getDeclaringType();
newConstructorQuickfix(issue, issueResolutionAcceptor, ownerType, call, call.getActualArguments());
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method addQuickfixes.
@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
if (referenceOwner instanceof XAbstractFeatureCall) {
XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner;
String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null;
if (newMemberName != null) {
if (call instanceof XMemberFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
if (logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable)
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XAssignment) {
newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
XAssignment assigment = (XAssignment) call;
if (assigment.getAssignable() == null) {
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
} else if (isThis(assigment)) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
}
}
}
if (call.isOperation()) {
JvmIdentifiableElement feature = call.getFeature();
if (feature.eIsProxy()) {
String operatorMethodName = getOperatorMethodName(call);
if (operatorMethodName != null)
newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor);
}
}
if (call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call);
}
}
if (referenceOwner instanceof XConstructorCall) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner);
}
}
Aggregations