use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class KeyUtils method nameFromElement.
private static String nameFromElement(RepoRelativePathHolder rrph, IdentifiableElement element) {
if (element instanceof TMember) {
TMember tMember = (TMember) element;
String name = nameFromElement(rrph, tMember.getContainingType());
return name + "#" + element.getName();
}
TModule module = element.getContainingModule();
if (module == null) {
String name = "##global##." + element.getName();
return name;
} else {
String name = module.getModuleSpecifier() + "." + element.getName();
return name;
}
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class KeyUtils method getSpecKeyPrefix.
/**
* @return a complete spec key comprised of the whole {@link RepoRelativePath}
*/
public static String getSpecKeyPrefix(RepoRelativePathHolder rrph, IdentifiableElement element) {
if (element instanceof TMember) {
ContainerType<?> containingType = ((TMember) element).getContainingType();
return getSpecKeyPrefix(rrph, containingType);
}
TModule module = element.getContainingModule();
if (module == null) {
return "GLOBAL.";
} else {
RepoRelativePath rrp = rrph.get(element);
String key = rrp.getFullPath();
return key;
}
}
use of org.eclipse.n4js.ts.types.TMember 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.TMember in project n4js by eclipse.
the class N4JSEnumValidator method checkUsageOfStringBasedEnum.
/**
* See N4JS Specification, Req. IDE-41, Nr. 6.
*/
@Check
public void checkUsageOfStringBasedEnum(IdentifierRef identRef) {
final IdentifiableElement id = identRef.getId();
if (id == null || id.eIsProxy()) {
return;
}
if (!(id instanceof TEnum)) {
return;
}
final TEnum tEnum = (TEnum) id;
if (!AnnotationDefinition.STRING_BASED.hasAnnotation(tEnum)) {
return;
}
// we now have an IdentifierRef pointing to a string-based enum ...
final EObject parent = N4JSASTUtils.skipParenExpressionUpward(identRef.eContainer());
final ParameterizedPropertyAccessExpression parentPAE = parent instanceof ParameterizedPropertyAccessExpression ? (ParameterizedPropertyAccessExpression) parent : null;
final IdentifiableElement prop = parentPAE != null ? parentPAE.getProperty() : null;
if (prop != null) {
if (prop.eIsProxy()) {
// unnecessary duplicate error
return;
}
if (tEnum.getLiterals().contains(prop)) {
// reference to one of tEnum's literals -> valid usage!
return;
}
final RuleEnvironment G = RuleEnvironmentExtensions.newRuleEnvironment(identRef);
final TMember getterLiterals = RuleEnvironmentExtensions.n4StringBasedEnumType(G).findOwnedMember("literals", false, true);
if (prop == getterLiterals) {
// reference to static getter 'literals' in N4StringBasedEnum -> valid usage!
return;
}
}
// invalid usage!
addIssue(getMessageForENM_INVALID_USE_OF_STRINGBASED_ENUM(), identRef, ENM_INVALID_USE_OF_STRINGBASED_ENUM);
}
use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkUnpairedAccessorFilling.
private void checkUnpairedAccessorFilling(MemberMatrix mm, N4ClassifierDefinition definition) {
if (definition.getDefinedType().isStaticPolyfill() && mm.hasMixedAccessorPair()) {
FieldAccessor ownedAccessor = (FieldAccessor) Iterables.getFirst(mm.owned(), null);
if (null == ownedAccessor) {
// Should not happen, a mixed accessor pair implies at least one owned member
return;
}
if (!(definition instanceof N4ClassDefinition)) {
// Non-class static polyfills aren't allowed. Validated somewhere else.
return;
}
TClass filledClass = MemberRedefinitionUtils.getFilledClass((N4ClassDefinition) definition);
if (null == filledClass) {
// Invalid static polyfill class. Validated somewhere else.
return;
}
// Iterate over all inherited members
SourceAwareIterator memberIterator = mm.actuallyInheritedAndMixedMembers();
while (memberIterator.hasNext()) {
TMember next = memberIterator.next();
ContainerType<?> containingType = next.getContainingType();
// Issue an error if the member isn't owned by the filled class
if (containingType != filledClass) {
messageMissingOwnedAccessor(ownedAccessor);
}
}
}
}
Aggregations