Search in sources :

Example 36 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class MethodDeclarationImpl method getDefinedTypeElement.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public TMember getDefinedTypeElement() {
    TMember _xifexpression = null;
    Type _definedType = this.getDefinedType();
    boolean _tripleEquals = (_definedType == null);
    if (_tripleEquals) {
        _xifexpression = null;
    } else {
        TMember _xifexpression_1 = null;
        Type _definedType_1 = this.getDefinedType();
        if ((_definedType_1 instanceof TMember)) {
            Type _definedType_2 = this.getDefinedType();
            _xifexpression_1 = ((TMember) _definedType_2);
        } else {
            throw new IllegalArgumentException("");
        }
        _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TMember(org.eclipse.n4js.ts.types.TMember)

Example 37 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class AccessModifierXpectMethod method calculateActual.

private String calculateActual(EObject context) {
    String actual = null;
    if (context instanceof TMember) {
        TMember tMember = (TMember) context;
        actual = tMember.getMemberAccessModifier().getName();
    } else {
        FunctionDeclaration functionDeclaration = EcoreUtil2.getContainerOfType(context, FunctionDeclaration.class);
        if (functionDeclaration != null) {
            actual = functionDeclaration.getDefinedType().getTypeAccessModifier().getName();
        } else {
            VariableStatement variableStatement = EcoreUtil2.getContainerOfType(context, VariableStatement.class);
            if (variableStatement != null) {
                context = variableStatement.getVarDecl().get(0);
                if (context instanceof ExportedVariableDeclaration) {
                    actual = ((ExportedVariableDeclaration) context).getDefinedVariable().getTypeAccessModifier().getName();
                } else if (context instanceof VariableDeclaration) {
                    actual = "private";
                }
            } else if (context instanceof ExportDeclaration) {
                context = ((ExportDeclaration) context).getExportedElement();
                actual = calculateActual(context);
            } else if (context instanceof ParameterizedPropertyAccessExpression) {
                ParameterizedPropertyAccessExpression ppae = (ParameterizedPropertyAccessExpression) context;
                IdentifiableElement ie = ppae.getProperty();
                actual = calculateActual(ie);
            } else if (context instanceof ParameterizedCallExpression) {
                ParameterizedCallExpression pce = (ParameterizedCallExpression) context;
                Expression targetExpr = pce.getTarget();
                actual = calculateActual(targetExpr);
            } else {
                N4MemberDeclaration member = EcoreUtil2.getContainerOfType(context, N4MemberDeclaration.class);
                N4TypeDeclaration type = EcoreUtil2.getContainerOfType(context, N4TypeDeclaration.class);
                if (type == null && member == null) {
                    actual = "no element with access modifier found";
                } else if (type != null && (member == null || EcoreUtil.isAncestor(member, type))) {
                    actual = type.getDefinedType().getTypeAccessModifier().getName();
                } else {
                    actual = member.getDefinedTypeElement().getMemberAccessModifier().getName();
                }
            }
        }
    }
    return actual;
}
Also used : ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) FunctionDeclaration(org.eclipse.n4js.n4JS.FunctionDeclaration) VariableStatement(org.eclipse.n4js.n4JS.VariableStatement) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) N4TypeDeclaration(org.eclipse.n4js.n4JS.N4TypeDeclaration) TMember(org.eclipse.n4js.ts.types.TMember)

Example 38 with TMember

use of org.eclipse.n4js.ts.types.TMember 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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TMember(org.eclipse.n4js.ts.types.TMember) HashSet(java.util.HashSet)

Example 39 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class ConcreteSyntaxAwareReferenceFinder method referenceHasBeenFound.

private boolean referenceHasBeenFound(Predicate<URI> targetURIs, URI refURI, EObject instanceOrProxy) {
    boolean result = false;
    // If the EObject is a composed member, we compare the target URIs with the URIs of the constituent members.
    if (instanceOrProxy instanceof TMember && ((TMember) instanceOrProxy).isComposed()) {
        TMember member = (TMember) instanceOrProxy;
        if (member.isComposed()) {
            for (TMember constituentMember : member.getConstituentMembers()) {
                URI constituentReffURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(constituentMember);
                result = result || targetURIs.apply(constituentReffURI);
            }
        }
    } else {
        // Standard case
        result = targetURIs.apply(refURI);
    }
    return result;
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) URI(org.eclipse.emf.common.util.URI)

Example 40 with TMember

use of org.eclipse.n4js.ts.types.TMember in project n4js by eclipse.

the class InferredElementsTargetURICollector method doAdd.

@Override
protected void doAdd(EObject primaryTarget, TargetURIs targetURIsAddHere) {
    Resource resource = primaryTarget.eResource();
    // If the target is not contained in a resource, we cannot do anything but return.
    if (resource == null)
        return;
    EcoreUtil.resolveAll(primaryTarget.eResource());
    // Special handling for composed members and TStructMember
    if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
        // In case of composed member, add the constituent members instead.
        List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
        for (TMember constituentMember : constituentMembers) {
            super.doAdd(constituentMember, targetURIsAddHere);
        }
    } else {
        if (primaryTarget instanceof TStructMember) {
            TStructMember crossRefStructMember = ((TStructMember) primaryTarget).getDefinedMember();
            if (crossRefStructMember != null)
                // If this TStructMember is an AST, also add the defined member located in the TModule
                super.doAdd(((TStructMember) primaryTarget).getDefinedMember(), targetURIsAddHere);
        }
        super.doAdd(primaryTarget, targetURIsAddHere);
    }
    inferredElements.collectInferredElements(primaryTarget, (object) -> {
        if (object != null) {
            super.doAdd(object, targetURIsAddHere);
        }
    }, staticPolyfillHelper);
}
Also used : TStructMember(org.eclipse.n4js.ts.types.TStructMember) Resource(org.eclipse.emf.ecore.resource.Resource) TMember(org.eclipse.n4js.ts.types.TMember)

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