Search in sources :

Example 1 with TMember

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;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) TModule(org.eclipse.n4js.ts.types.TModule)

Example 2 with TMember

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;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) TModule(org.eclipse.n4js.ts.types.TModule)

Example 3 with TMember

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);
        }
    }
}
Also used : ContainerType(org.eclipse.n4js.ts.types.ContainerType) Type(org.eclipse.n4js.ts.types.Type) TMember(org.eclipse.n4js.ts.types.TMember)

Example 4 with TMember

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);
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) TEnum(org.eclipse.n4js.ts.types.TEnum) EObject(org.eclipse.emf.ecore.EObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) TMember(org.eclipse.n4js.ts.types.TMember) Check(org.eclipse.xtext.validation.Check)

Example 5 with TMember

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);
            }
        }
    }
}
Also used : SourceAwareIterator(org.eclipse.n4js.validation.validators.utils.MemberMatrix.SourceAwareIterator) TMember(org.eclipse.n4js.ts.types.TMember) FieldAccessor(org.eclipse.n4js.ts.types.FieldAccessor) TClass(org.eclipse.n4js.ts.types.TClass) N4ClassDefinition(org.eclipse.n4js.n4JS.N4ClassDefinition)

Aggregations

TMember (org.eclipse.n4js.ts.types.TMember)65 EObject (org.eclipse.emf.ecore.EObject)19 TClassifier (org.eclipse.n4js.ts.types.TClassifier)13 Type (org.eclipse.n4js.ts.types.Type)13 ContainerType (org.eclipse.n4js.ts.types.ContainerType)11 ArrayList (java.util.ArrayList)10 TClass (org.eclipse.n4js.ts.types.TClass)10 TField (org.eclipse.n4js.ts.types.TField)10 TMethod (org.eclipse.n4js.ts.types.TMethod)9 TModule (org.eclipse.n4js.ts.types.TModule)9 MemberList (org.eclipse.n4js.ts.types.util.MemberList)9 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)9 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)7 NameStaticPair (org.eclipse.n4js.ts.types.util.NameStaticPair)7 MemberCollector (org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector)7 Optional (java.util.Optional)6 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)6 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)6 Inject (com.google.inject.Inject)5