use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newMethodQuickfixes.
protected void newMethodQuickfixes(String newMemberName, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
JvmDeclaredType callersType = getCallersType(call);
LightweightTypeReference receiverType = getReceiverType(call);
LightweightTypeReference returnType = getNewMemberType(call);
if (callersType == null || receiverType == null)
return;
List<LightweightTypeReference> argumentTypes = getResolvedArgumentTypes(call, logicalContainerProvider.getNearestLogicalContainer(call), call.getActualArguments());
newMethodQuickfixes(receiverType, newMemberName, returnType, argumentTypes, call, callersType, issue, issueResolutionAcceptor);
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newConstructorQuickfix.
protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, XConstructorCall call) {
JvmDeclaredType ownerType = call.getConstructor().getDeclaringType();
newConstructorQuickfix(issue, issueResolutionAcceptor, ownerType, call, call.getArguments());
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendOverrideFunction.
public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
methodBuilder.setOverrideFlag(true);
methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
if (_isSynchronized) {
methodBuilder.setSynchronizedFlag(true);
}
boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
newTypeParam.setName(typeParam.getName());
final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
upperBound.setTypeReference(it.toJavaCompliantTypeReference());
EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
_constraints.add(upperBound);
};
overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
typeParameters.add(newTypeParam);
};
IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
methodBuilder.setTypeParameters(typeParameters);
}
boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
boolean _not_1 = (!_isAbstract);
if (_not_1) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("super.");
{
List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
boolean _hasElements = false;
for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
if (!_hasElements) {
_hasElements = true;
_builder.append("<");
} else {
_builder.appendImmediate(", ", "");
}
String _simpleName = typeParam.getSimpleName();
_builder.append(_simpleName);
}
if (_hasElements) {
_builder.append(">");
}
}
String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
_builder.append(_simpleName_1);
_builder.append("(");
final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
return it.getSimpleName();
};
String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
_builder.append(_join);
_builder.append(")");
final String body = _builder.toString();
final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
if (superTypeRef != null) {
superTypeRef.apply(it);
}
it.append(body);
};
methodBuilder.setBodyGenerator(_function_2);
}
boolean _isValid = methodBuilder.isValid();
if (_isValid) {
methodBuilder.build(appendable);
}
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class AbstractKnownTypesScope method findNestedType.
protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
List<String> segments = name.getSegmentCount() == 1 ? Strings.split(name.getFirstSegment(), '$') : name.getSegments();
for (int i = 1; i < segments.size() && result instanceof JvmDeclaredType; i++) {
JvmDeclaredType declaredType = (JvmDeclaredType) result;
String simpleName = segments.get(i);
// TODO handle ambiguous types
for (JvmMember member : declaredType.findAllNestedTypesByName(simpleName)) {
result = (JvmType) member;
break;
}
if (declaredType == result) {
return null;
}
}
return result;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.
the class NestedTypesScope method findNestedTypeInLocalTypeNonResolving.
/**
* We have to be careful to keep the unresolved super type of a local type which may depend on type resolution.
* Therefore these types are treated differently from other types.
*/
protected IEObjectDescription findNestedTypeInLocalTypeNonResolving(JvmDeclaredType localType, QualifiedName name, String firstSegment, int dollarIndex) {
List<JvmMember> members = localType.getMembers();
for (int i = 0; i < members.size(); i++) {
JvmMember member = members.get(i);
if (member instanceof JvmDeclaredType) {
JvmDeclaredType nestedType = (JvmDeclaredType) member;
if (firstSegment.equals(nestedType.getSimpleName())) {
JvmType candidate = findNestedType(nestedType, 0, name);
if (candidate != null) {
return toDescription(name, candidate, dollarIndex, 0);
}
}
}
}
JvmDeclaredType superType = typeScopeProvider.getSuperTypeOfLocalTypeNonResolving(localType);
if (superType == null) {
return null;
}
return doGetSingleElement(superType, name, firstSegment, dollarIndex);
}
Aggregations