use of org.eclipse.n4js.ts.types.ContainerType in project n4js by eclipse.
the class ProjectCompareHelper method createEntries.
// may be made public later
private ProjectComparisonEntry createEntries(ProjectComparisonEntry parent, int index, EObject api, EObject[] impls, final boolean includePolyfills) {
final ProjectComparisonEntry entry = new ProjectComparisonEntry(parent, index, api, impls);
final EObject[] childrenOfApi = computeChildren(api, false, false, includePolyfills);
final EObject[][] childrenOfImpls = computeChildren(impls, false, true, includePolyfills);
// STEP 1: create entries for children of the API
final Set<EObject> doneImpl = new HashSet<>();
for (EObject childApi : childrenOfApi) {
final EObject[] implsForChildApi = computeMatches(childApi, childrenOfImpls, doneImpl);
// special: for missing members on implementation side, try to find matches among inherited members
if (childApi instanceof TMember) {
for (int idxImpl = 0; idxImpl < impls.length; idxImpl++) {
if (implsForChildApi[idxImpl] == null) {
final EObject currImpl = impls[idxImpl];
if (currImpl instanceof ContainerType<?>) {
implsForChildApi[idxImpl] = computeMatch(childApi, computeChildren(currImpl, true, true, includePolyfills), doneImpl);
}
}
}
}
createEntries(entry, -1, childApi, implsForChildApi, includePolyfills);
}
// STEP 2: create missing entries for children of implementations that are not represented in the API
for (int idxImpl = 0; idxImpl < impls.length; idxImpl++) {
final EObject[] childrenOfCurrImpl = childrenOfImpls[idxImpl];
for (int idxChild = 0; idxChild < childrenOfCurrImpl.length; idxChild++) {
final EObject childImpl = childrenOfCurrImpl[idxChild];
if (!doneImpl.contains(childImpl)) {
// collect matches in other implementations
final EObject[] implsForChildImpl = computeMatches(childImpl, childrenOfImpls, doneImpl);
// look for neighbor EObject in childrenOfCurrImpl
final int idxSib = idxChild - 1;
final EObject siblingImpl = idxSib >= 0 ? childrenOfCurrImpl[idxSib] : null;
// look up neighbor Entry (i.e. entry with elementImpl == siblingImpl)
final ProjectComparisonEntry siblingEntry;
if (siblingImpl != null)
siblingEntry = entry.getChildForElementImpl(siblingImpl);
else
siblingEntry = null;
// add after neighbor OR at beginning if no neighbor found
final int insertIdx = siblingEntry != null ? entry.getChildIndex(siblingEntry) + 1 : 0;
// note: no API
createEntries(entry, insertIdx, null, implsForChildImpl, includePolyfills);
// element here!
}
}
}
return entry;
}
use of org.eclipse.n4js.ts.types.ContainerType in project n4js by eclipse.
the class N4JSASTUtils method getOwnOrSuperCtor.
private static TMember getOwnOrSuperCtor(final ContainerType<?> ownerOfField) {
TClass klass = (TClass) (ownerOfField instanceof TClass ? ownerOfField : null);
while (null != klass) {
final TMember ctor = klass.findOwnedMember(CONSTRUCTOR);
if (null != ctor) {
return ctor;
}
final ParameterizedTypeRef superClassRef = klass.getSuperClassRef();
if (null == superClassRef) {
klass = null;
} else {
final Type declaredType = superClassRef.getDeclaredType();
klass = (TClass) (declaredType instanceof TClass ? declaredType : null);
}
}
return null;
}
use of org.eclipse.n4js.ts.types.ContainerType in project n4js by eclipse.
the class N4JSResourceDescription method getCrossRefTypeAcceptor.
private IAcceptor<EObject> getCrossRefTypeAcceptor(final Set<EObject> crossRefTypesAddHere) {
IAcceptor<EObject> acceptor = new IAcceptor<EObject>() {
@Override
public void accept(EObject to) {
if (to instanceof Type || to instanceof TVariable || to instanceof TEnumLiteral) {
crossRefTypesAddHere.add(to);
}
// Add declared type of a field to cross ref types
if (to instanceof TFunction) {
TypeRef returnTypeRef = ((TFunction) to).getReturnTypeRef();
crossRefTypesAddHere.add(returnTypeRef.getDeclaredType());
}
if (to instanceof TField) {
TypeRef typeRef = ((TField) to).getTypeRef();
crossRefTypesAddHere.add(typeRef.getDeclaredType());
}
// In case of TMember, add the containing type as well
if (to instanceof TMember) {
TMember casted = (TMember) to;
ContainerType<?> declaringType = casted.getContainingType();
crossRefTypesAddHere.add(declaringType);
}
}
};
return acceptor;
}
use of org.eclipse.n4js.ts.types.ContainerType in project n4js by eclipse.
the class StaticWriteAccessFilterScope method isAccepted.
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance instanceof TMember && !proxyOrInstance.eIsProxy()) {
TMember member = (TMember) proxyOrInstance;
// this particular message to hide the better one.
if (member.isStatic() && member.isWriteable() && /* i.e. (member.isField(), not const || member.isSetter()) */
isWriteAccess()) {
ContainerType<?> memberType = member.getContainingType();
memberTypeName = memberType.getName();
// Access only allowed for Direct access, so AST must be IdentifierRef.
final boolean isTargetGivenByIdentifier = getTarget() instanceof IdentifierRef;
if (!isTargetGivenByIdentifier) {
// Not an IdentifierRef --> disallowed for write access.
return false;
}
IdentifierRef idref = (IdentifierRef) getTarget();
// this also covers aliased imports:
if (idref.getId().getName().equals(memberTypeName)) {
// correct name.
return true;
} else {
// wrong name, disallowed
// search for alias, for better error reporting.
Script sc = EcoreUtil2.getContainerOfType(context, Script.class);
Optional<NamedImportSpecifier> namedImport = sc.getScriptElements().stream().filter(se -> se instanceof ImportDeclaration).map(se -> (ImportDeclaration) se).flatMap(idecl -> {
return idecl.getImportSpecifiers().stream().filter(is -> is instanceof NamedImportSpecifier).map(is -> (NamedImportSpecifier) is);
}).filter(s -> s.getImportedElement() == memberType).findFirst();
if (namedImport.isPresent()) {
// if alias is present assign, otherwise null will be passed through
memberTypeAlias = namedImport.get().getAlias();
}
return false;
}
}
}
return true;
}
use of org.eclipse.n4js.ts.types.ContainerType in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method addIssueToMemberOrInterfaceReference.
private void addIssueToMemberOrInterfaceReference(RedefinitionType redefinitionType, TMember overriding, TMember implemented, String message, String issueCode, String... issueData) {
if (redefinitionType == RedefinitionType.overridden && overriding.getContainingType() != getCurrentClassifier()) {
throw new IllegalStateException("must not happen as member is not consumed");
}
TClassifier currentClassifier = getCurrentClassifier();
if (overriding.getContainingType() == currentClassifier) {
addIssue(message, overriding.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, issueCode, issueData);
} else {
MemberCollector memberCollector = containerTypesHelper.fromContext(getCurrentClassifierDefinition());
ContainerType<?> bequestingType = memberCollector.directSuperTypeBequestingMember(currentClassifier, implemented);
Optional<ParameterizedTypeRef> optRef = StreamSupport.stream(getCurrentClassifierDefinition().getImplementedOrExtendedInterfaceRefs().spliterator(), false).filter(ref -> ref.getDeclaredType() == bequestingType).findAny();
ParameterizedTypeRef ref = optRef.get();
EStructuralFeature feature = ref.eContainingFeature();
List<?> list = (List<?>) getCurrentClassifierDefinition().eGet(feature);
int index = list.indexOf(ref);
addIssue(message, getCurrentClassifierDefinition(), feature, index, issueCode, issueData);
}
}
Aggregations