use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ParameterizedTypeRefStructural_IMImpl method getTypeRefAsString.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getTypeRefAsString() {
TypingStrategy _typingStrategy = this.getTypingStrategy();
Type _declaredType = this.getDeclaredType();
String _rawTypeAsString = null;
if (_declaredType != null) {
_rawTypeAsString = _declaredType.getRawTypeAsString();
}
String _plus = (_typingStrategy + _rawTypeAsString);
String _xifexpression = null;
boolean _isEmpty = this.getTypeArgs().isEmpty();
if (_isEmpty) {
_xifexpression = "";
} else {
final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {
public String apply(final TypeArgument it) {
return it.getTypeRefAsString();
}
};
String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
String _plus_1 = ("<" + _join);
_xifexpression = (_plus_1 + ">");
}
String _plus_2 = (_plus + _xifexpression);
String _xifexpression_1 = null;
boolean _isEmpty_1 = this.getStructuralMembers().isEmpty();
if (_isEmpty_1) {
_xifexpression_1 = "";
} else {
final Function1<TStructMember, String> _function_1 = new Function1<TStructMember, String>() {
public String apply(final TStructMember it) {
return it.getMemberAsString();
}
};
String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TStructMember, String>map(this.getStructuralMembers(), _function_1), "; ");
String _plus_3 = (" with { " + _join_1);
String _plus_4 = (_plus_3 + " }");
String _xifexpression_2 = null;
boolean _isEmpty_2 = this.getPostponedSubstitutions().isEmpty();
if (_isEmpty_2) {
_xifexpression_2 = "";
} else {
final Function1<TypeVariableMapping, String> _function_2 = new Function1<TypeVariableMapping, String>() {
public String apply(final TypeVariableMapping it) {
String _typeAsString = it.getTypeVar().getTypeAsString();
String _plus = (_typeAsString + "->");
String _typeRefAsString = it.getTypeArg().getTypeRefAsString();
return (_plus + _typeRefAsString);
}
};
String _join_2 = IterableExtensions.join(XcoreEListExtensions.<TypeVariableMapping, String>map(this.getPostponedSubstitutions(), _function_2), ", ");
String _plus_5 = (" [[" + _join_2);
_xifexpression_2 = (_plus_5 + "]]");
}
_xifexpression_1 = (_plus_4 + _xifexpression_2);
}
return (_plus_2 + _xifexpression_1);
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiMethods.
/**
* @param type
* type to search for APIs.
* @param context
* context holding the comparison-adapter
* @return List of {@link VirtualApiTMethod}
*/
public List<TMethod> computeMissingApiMethods(TClass type, EObject context) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(context.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(EcoreUtil2.getContainerOfType(type, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(type);
if (typeCompare != null) {
return typeCompare.allChildren().filter(pce -> pce.getElementAPI() instanceof TMethod).filter(pce -> pce.getElementImpl()[0] == null).map(pce -> {
TMethod apiMethod = (TMethod) pce.getElementAPI();
TMethod copy = TypeUtils.copyPartial(apiMethod, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT);
TMethod ret = new VirtualApiTMethod(apiMethod.getName(), copy);
return ret;
}).collect(Collectors.toList());
}
}
return emptyList();
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiMethods.
/**
* Looking for at.ProvidesDefaultImplementation on Methods. Normal method declarations are not taken into account,
* since they would not be executed on the interface level.
*
* Beware: also the inheritance in the original API will be taken into account since compiled client code will link
* against that.
*
* @param type
* type to search for apis.
* @return List of {@link VirtualApiTMethod}
*/
public List<TMethod> computeMissingApiMethods(TInterface type, EObject context) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(context.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(type, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(type);
if (typeCompare == null) {
// are we in a completely missing API implementation (super-interfaces not implemented ?)
typeCompare = compareEntry.getChildForElementAPI(type);
}
if (typeCompare == null) {
if (logger.isDebugEnabled()) {
logger.debug(" want to throw new IllegalstateException() --> comparison for implementation not found type=" + type.getTypeAsString() + " in Implementation " + compareEntry.getElementImpl()[0]);
}
return emptyList();
}
LinkedHashMultimap<TMethod, TInterface> lhmmMehodInterface = LinkedHashMultimap.<TMethod, TInterface>create();
Predicate<ProjectComparisonEntry> filter = (pce -> pce.getElementAPI() instanceof TMethod);
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(pce -> PROVIDES_DEFAULT_IMPLEMENTATION.hasAnnotation((TMethod) pce.getElementAPI()));
Function<TInterface, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
TMethod method = ((TMethod) pce.getElementAPI());
lhmmMehodInterface.put(method, pivot);
};
if (!checkInterfaceImplementsInterface(type, typeCompare.getElementAPI())) {
return emptyList();
}
// Call the supertype iterations scaffolding:
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TInterface) typeCompare.getElementAPI(), TInterface.class);
// out in the caller when processing our results...
return lhmmMehodInterface.keySet().stream().map(m -> new VirtualApiTMethod(m.getName(), TypeUtils.copyPartial(m, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT))).collect(Collectors.toList());
}
return emptyList();
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ScriptApiTracker method computeMethodDiff.
/**
* Find last missing methods, which the implType would have if it would follow the inheritance as defined in the API
*
* @param implType
* Type of implementation project, calculated from AST
* @param collector
* member collector for the project.
* @param ownedAndMixedInConcreteMember
* already computed for implType
* @param missingApiMethods2
* already computed for implType
* @return list of virtual Methods
*/
public List<VirtualApiTMethod> computeMethodDiff(TClass implType, MemberCollector collector, List<TMember> ownedAndMixedInConcreteMember, MemberList<TMethod> missingApiMethods2) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(implType.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(EcoreUtil2.getContainerOfType(implType, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(implType);
if (typeCompare != null && typeCompare.getElementAPI() != null) {
TClass apiType = (TClass) typeCompare.getElementAPI();
MemberList<TMember> implMembers = collector.allMembers(implType, false, true);
MemberList<TMember> apiMembers = collector.allMembers(apiType, false, true);
final HashSet<String> methodNamesAlreadyDefined = new HashSet<>();
Stream.concat(implMembers.stream(), Stream.concat(ownedAndMixedInConcreteMember.stream(), missingApiMethods2.stream())).forEach(m -> {
if (m instanceof TMethod) {
methodNamesAlreadyDefined.add(m.getName());
}
});
return apiMembers.stream().filter(t -> t instanceof TMethod).filter(m -> !methodNamesAlreadyDefined.contains(((TMethod) m).getName())).map(m2 -> {
TMethod m = (TMethod) m2;
VirtualApiTMethod vMethod = new VirtualApiTMethod(m.getName(), TypeUtils.copyPartial(m, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT));
return vMethod;
}).collect(Collectors.toList());
}
}
return emptyList();
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ParameterizedTypeRefImpl method setDeclaredType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDeclaredType(Type newDeclaredType) {
Type oldDeclaredType = declaredType;
declaredType = newDeclaredType;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypeRefsPackage.PARAMETERIZED_TYPE_REF__DECLARED_TYPE, oldDeclaredType, declaredType));
}
Aggregations