use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSDReader method addTestInfoForCodeElement.
/**
* Adds test info to an identified element.
*/
private void addTestInfoForCodeElement(RepoRelativePath rrp, Doclet testMethodDoclet, FullMemberReference ref, TMember testMember, Multimap<String, SpecInfo> typesByName) {
String fullTypeName = ref.fullTypeName();
String regionName = KeyUtils.getSpecKeyWithoutProjectFolder(rrp, fullTypeName);
Collection<SpecInfo> specInfos = typesByName.get(regionName);
boolean testeeMemberFound = false;
for (SpecInfo specInfo : specInfos) {
for (Type testee : specInfo.specElementRef.getTypes()) {
if (testee instanceof ContainerType<?> && ref.memberNameSet()) {
TMember testeeMember = getRefMember((ContainerType<?>) testee, ref);
if (testeeMember != null) {
String testeeName = testeeMember.getName();
SpecTestInfo testSpecInfo = createTestSpecInfo(testeeName, testMethodDoclet, testMember, rrp);
specInfo.addMemberTestInfo(testeeMember, testSpecInfo);
}
testeeMemberFound = true;
}
}
}
if (!testeeMemberFound) {
for (SpecInfo specInfo : specInfos) {
// Type, TFunction of TVariable
String elementName = specInfo.specElementRef.identifiableElement.getName();
SpecTestInfo testSpecInfo = createTestSpecInfo(elementName, testMethodDoclet, testMember, rrp);
specInfo.addTypeTestInfo(testSpecInfo);
}
if (specInfos.isEmpty()) {
issueAcceptor.addWarning("Testee " + fullTypeName + " not found", testMember);
}
}
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method messageImpossibleExtendsImplements.
private void messageImpossibleExtendsImplements(N4ClassifierDefinition n4ClassifierDefinition, Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef) {
for (Entry<ParameterizedTypeRef, MemberList<TMember>> entry : nonAccessibleAbstractMembersBySuperTypeRef.entrySet()) {
final ParameterizedTypeRef superTypeRef = entry.getKey();
final Type type = superTypeRef.getDeclaredType();
final String mode = type instanceof TInterface && !(n4ClassifierDefinition instanceof N4InterfaceDeclaration) ? "implement" : "extend";
final String message = getMessageForCLF_NON_ACCESSIBLE_ABSTRACT_MEMBERS(mode, validatorMessageHelper.description(type), validatorMessageHelper.descriptions(entry.getValue()));
addIssue(message, superTypeRef.eContainer(), superTypeRef.eContainingFeature(), CLF_NON_ACCESSIBLE_ABSTRACT_MEMBERS);
}
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class PolyfillValidatorFragment method holdsPolyfill.
/**
* Checks polyfill constraints on given class declaration using validator to issue errors. Constraints (Polyfill
* Class) 156: Polyfill
*/
public boolean holdsPolyfill(N4JSClassValidator validator, N4ClassDeclaration n4Class) {
boolean isStaticPolyFill = isStaticPolyfill(n4Class);
if (isStaticPolyFill || isPolyfill(n4Class)) {
PolyfillValidationState state = new PolyfillValidationState();
state.host = validator;
state.n4Class = n4Class;
state.name = n4Class.getName();
if (state.name == null || !(n4Class.getDefinedType() instanceof TClass)) {
// consequential error, AST corrupt
return true;
}
state.polyType = (TClass) n4Class.getDefinedType();
if (state.polyType == null || state.name == null) {
// consequential error
return true;
}
if (!holdsExpliciteExtends(state)) {
return false;
}
final Type superType = n4Class.getSuperClassRef().getDeclaredType();
if (!(superType instanceof TClassifier)) {
// consequential error
return true;
}
state.filledType = (TClassifier) superType;
// Different rules for static/non-static polyfills:
if (!isStaticPolyFill) {
if (!(//
holdPolyfillName(state) && //
holdsProvidedByRuntime(state) && //
holdsNoImplementsOrConsumes(state) && //
holdsEqualModifiers(state) && //
holdsEqualTypeVariables(state) && //
holdsSinglePolyfillSource(state))) {
return false;
}
} else {
// static polyfill case, IDE-1735
if (!(//
holdPolyfillName(state) && // && holdsNoImplementsOrConsumes(state) //
holdsFilledClassIsStaticPolyfillAware(//
state) && //
holdsSameJavascriptVariant(state) && //
holdsEqualModifiers(state) && //
holdsEqualTypeVariables(state) && //
holdsSinglePolyfillSource(state))) {
return false;
}
}
}
// ยง 140.1 only polyfills are allowed in StaticPolyfillModule.
if (!isStaticPolyFill && isContainedInStaticPolyfillModule(n4Class)) {
// n4Class is toplevel by default
validator.addIssue(getMessageForPOLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES(), n4Class, N4_TYPE_DECLARATION__NAME, POLY_STATIC_POLYFILL_MODULE_ONLY_FILLING_CLASSES);
return false;
}
return true;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class InferenceContext method containsInterestingLowerBound.
private boolean containsInterestingLowerBound(TypeRef[] typeRefs) {
final Type undefinedType = RuleEnvironmentExtensions.undefinedType(G);
final Type nullType = RuleEnvironmentExtensions.nullType(G);
for (int i = 0; i < typeRefs.length; i++) {
final TypeRef curr = typeRefs[i];
if (curr instanceof ParameterizedTypeRef) {
// for ParameterizedTypeRefs, it depends on the declared type:
final Type currDeclType = curr.getDeclaredType();
if (currDeclType != null && currDeclType != undefinedType && currDeclType != nullType) {
// wow, that bound is interesting!
return true;
}
} else {
// all non-ParameterizedTypeRefs are interesting, except UnknownTypeRef:
if (!(curr instanceof UnknownTypeRef)) {
// wow, that bound looks intriguing!
return true;
}
}
}
// no interesting bounds encountered
return false;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class VisibilityAwareTypeScope method isAccepted.
@Override
protected boolean isAccepted(IEObjectDescription description) {
EObject proxyOrInstance = description.getEObjectOrProxy();
if (proxyOrInstance instanceof Type) {
Type type = (Type) proxyOrInstance;
if (type.eIsProxy() && contextResource != null) {
// we found a proxy. Only valid precondition for a proxy that was returned from a
// UserDataAwareScope is that the resource that contains the real instance is already
// available in the resource set and loaded.
// thus it's save to use resourceSet.getEObject(uri, false) and it has to return a proper instance
//
ResourceSet resourceSet = contextResource.getResourceSet();
// don't load on demand
EObject fromResourceSet = resourceSet.getEObject(description.getEObjectURI(), false);
if (fromResourceSet instanceof Type) {
type = (Type) fromResourceSet;
} else {
// assume the unresolved proxy to be visible to reduce number of follow-up problems.
return true;
}
}
// paranoid double check - object from resource set should never be a proxy
if (!type.eIsProxy()) {
TypeVisibility typeVisibility = checker.isVisible(contextResource, type);
if (typeVisibility.visibility) {
accessModifierSuggestionStore.put(description.getEObjectURI().toString(), typeVisibility.accessModifierSuggestion);
}
return typeVisibility.visibility;
} else {
throw new IllegalStateException("Unexpected proxy:" + type);
}
}
return true;
}
Aggregations