use of org.eclipse.n4js.tooling.compare.ProjectComparisonEntry in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiFields.
/**
* Computes the list of virtual fields.
*
* @return List of {@link VirtualApiTField}
*/
public List<TField> computeMissingApiFields(N4InterfaceDeclaration declaration) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonEntry compareEntry = optAdapt.get().getEntryFor(EcoreUtil2.getContainerOfType(declaration.getDefinedType(), TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration.getDefinedTypeAsInterface());
if (typeCompare != null) {
return typeCompare.allChildren().filter(pce -> pce.getElementAPI() instanceof TField).filter(pce -> pce.getElementImpl()[0] == null).map(pce -> {
TField apiMethod = (TField) pce.getElementAPI();
// do not touch AST on copy!:
TField copy = TypeUtils.copyPartial(apiMethod, TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT);
TField ret = new VirtualApiTField(apiMethod.getName(), copy);
return ret;
}).collect(Collectors.toList());
}
}
return emptyList();
}
use of org.eclipse.n4js.tooling.compare.ProjectComparisonEntry in project n4js by eclipse.
the class ScriptApiTracker method interfaceApiSupertypeWalker.
/**
* This methods takes an API-Element and pulls the projectComparisons along the suptertype chain.
*
* Does nothing if apiElement is null.
*
* @param filter
* applied to each encountered projectComparison
* @param actionProvider
* function to apply on filtered ProjectComparinsonEntries.
* @param apiElement
* concrete API element to start from.
*/
public <T extends TClassifier> void interfaceApiSupertypeWalker(Predicate<? super ProjectComparisonEntry> filter, Function<T, Consumer<? super ProjectComparisonEntry>> actionProvider, ProjectComparisonAdapter projectComparisonAdapter, /* ProjectComparisonEntry compareEntry, */
T apiElement, Class<T> castGuard) {
if (apiElement == null) {
// from projects
return;
}
LinkedHashSet<T> toBeProcessedSuperInterfaces = new LinkedHashSet<>();
LinkedHashSet<T> processedSuperInterfaces = new LinkedHashSet<>();
// Yes it is correct ~Not correct~, since we need VirtualMethods for the direct missing parts:: //
toBeProcessedSuperInterfaces.add(apiElement);
while (!toBeProcessedSuperInterfaces.isEmpty()) {
Iterator<T> iter = toBeProcessedSuperInterfaces.iterator();
T pivot = iter.next();
iter.remove();
// do not process built-in types
if (TypeUtils.isBuiltIn(pivot)) {
continue;
}
// collect to be processed:
includeAdditionsSuperInterfaces2(toBeProcessedSuperInterfaces, processedSuperInterfaces, pivot, castGuard);
// go over methods.
// Is the superInterface from the same Project ? If not it cannot be an API problem of this
// implementation.
AbstractModule superModule = pivot.getContainingModule();
if (superModule instanceof TModule) {
// not required for TDeclaredModule
ProjectComparisonEntry useCompareEntry = projectComparisonAdapter.getEntryFor((TModule) superModule);
if (useCompareEntry == null) {
if (logger.isDebugEnabled()) {
logger.debug("No comparison found for pivot = " + pivot.getName());
}
} else {
// Is there an API entry at all ? --> If not it was just a normal implementation of some library ?
ProjectComparisonEntry superInterfaceCompareEntry = useCompareEntry.getChildForElementAPI(pivot);
if (superInterfaceCompareEntry != null) {
// Is there a difference between this API and the implementations ?
if (superInterfaceCompareEntry.hasChildren()) {
// get the ones which are missing implementations; others are real errors and will not be
// touched!
superInterfaceCompareEntry.allChildren().filter(filter).forEach(actionProvider.apply(pivot));
}
}
// end if superInterfaceCompareEntry != null
}
} else if (superModule == null) {
if (logger.isDebugEnabled()) {
logger.debug("-#- could not get module for super-classifier: " + pivot.getName() + " of type " + pivot.getTypeAsString() + " providedByRuntime=" + pivot.isProvidedByRuntime());
}
}
}
}
use of org.eclipse.n4js.tooling.compare.ProjectComparisonEntry in project n4js by eclipse.
the class ScriptApiTracker method computeMissingApiFields.
/**
* Computes the list of virtual AccessorTuples for missing static fields on Interfaces
*
* @return List of {@link VirtualApiTField}
*/
private List<AccessorTuple> computeMissingApiFields(TInterface declaration) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(declaration, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
if (typeCompare != null) {
ArrayList<AccessorTuple> collectedMissingFields = new ArrayList<>();
Predicate<ProjectComparisonEntry> filter = (pce -> pce.getElementAPI() instanceof TField);
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(pce -> PROVIDES_INITIALZER.hasAnnotation((TField) pce.getElementAPI()));
Function<TInterface, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
TField apiField = ((TField) pce.getElementAPI());
VirtualApiMissingFieldAccessorTuple ret = createVirtFieldAccessorTuple(apiField);
collectedMissingFields.add(ret);
};
if (!checkInterfaceImplementsInterface(declaration, typeCompare.getElementAPI())) {
return emptyList();
}
// Call the supertype iterations scaffolding:
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TInterface) typeCompare.getElementAPI(), TInterface.class);
return collectedMissingFields;
}
}
return emptyList();
}
Aggregations