use of org.eclipse.n4js.compare.ProjectComparisonEntry 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.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.
TModule superModule = pivot.getContainingModule();
if (superModule != null) {
ProjectComparisonEntry useCompareEntry = projectComparisonAdapter.getEntryFor(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 // end if null-check for module...
{
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.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();
}
use of org.eclipse.n4js.compare.ProjectComparisonEntry in project n4js by eclipse.
the class ApiCompareView method makeActions.
private void makeActions() {
actionUpdate = new Action() {
@Override
public void run() {
updateComparison();
}
};
actionUpdate.setText("Update");
actionUpdate.setToolTipText("Recompute comparison for all API project and their implementation projects in the workspace.");
// action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
// getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
actionOpenInEditor = new Action() {
@Override
public void run() {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof ProjectComparisonEntry)
showInEditor((ProjectComparisonEntry) obj, true, true);
}
};
actionOpenInEditor.setText("Open in Editor");
actionOpenInEditor.setToolTipText("Open the currently selected API element and its implementations in N4JS editors.");
}
use of org.eclipse.n4js.compare.ProjectComparisonEntry in project n4js by eclipse.
the class ProjectCompareTreeHelper method readDocumentation.
/**
* Read documentation from the special <code>@api</code> tag in the JSdoc of all types and members in the given
* comparison. Documentation from the API source code will always be included; documentation from the implementation
* source code will only be included for the given implementation indices. Strings will be stored in the given map
* on a per-entry basis.
*/
public Map<ProjectComparisonEntry, String> readDocumentation(ProjectComparison comparison, int[] implIndices) {
final Map<ProjectComparisonEntry, String> result = new HashMap<>();
final ResourceSet resourceSetForDocRetrieval = n4jsCore.createResourceSet(Optional.absent());
comparison.getAllEntries().forEach(currE -> {
final String doc = readDocumentation(resourceSetForDocRetrieval, currE, implIndices);
if (doc != null) {
result.put(currE, doc);
}
});
return result;
}
Aggregations