/** * Returns description for given element, name is assumed to consist of a single segment containing the simple name * of the member. If no subScope contains a member with given name, null is returned. In other error cases (no or * wrong access, mixed types etc.), {@link IEObjectDescriptionWithError}, and in particular * {@link UnionMemberDescriptionWithError}, will be returned. */ @Override protected IEObjectDescription getSingleLocalElementByName(QualifiedName qualifiedName) { String name = qualifiedName.getLastSegment(); TMember member = getOrCreateComposedMember(name); if (member == null) { // no such member, no need for "merging" descriptions, there won't be any return null; } if (isErrorPlaceholder(member)) { return createComposedMemberDescriptionWithErrors(EObjectDescription.create(member.getName(), member)); } IEObjectDescription description = getCheckedDescription(name, member); return description; }
@Override protected IEObjectDescription getCheckedDescription(String name, TMember member) { IEObjectDescription description = EObjectDescription.create(member.getName(), member); QualifiedName qn = QualifiedName.create(name); boolean allDescrWithError = true; for (IScope currSubScope : subScopes) { IEObjectDescription subDescription = currSubScope.getSingleElement(qn); boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError; allDescrWithError &= descrWithError; } if (allDescrWithError) { return createComposedMemberDescriptionWithErrors(description); } return description; }
@Override protected IEObjectDescription getCheckedDescription(String name, TMember member) { IEObjectDescription description = EObjectDescription.create(member.getName(), member); QualifiedName qn = QualifiedName.create(name); for (IScope currSubScope : subScopes) { IEObjectDescription subDescription = currSubScope.getSingleElement(qn); boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError; if (descrWithError) { return createComposedMemberDescriptionWithErrors(description); } } return description; }
public ArrayList<IEObjectDescription> getTypes(final Extension ext) { ArrayList<IEObjectDescription> _xblockexpression = null; { ArrayList<IEObjectDescription> res = new ArrayList<IEObjectDescription>(); EList<DataType> _types = ext.getTypes(); for (final DataType k : _types) { res.add(EObjectDescription.create(QualifiedName.create(k.getName()), k)); } EList<Extension> _import = ext.getImport(); for (final Extension importExtension : _import) { EList<DataType> _types_1 = importExtension.getTypes(); for (final DataType k_1 : _types_1) { res.add(EObjectDescription.create(QualifiedName.create(importExtension.getName(), k_1.getName()), k_1)); } } _xblockexpression = res; } return _xblockexpression; }
public IScope createFeatureCallSerializationScope(EObject context) { if (!(context instanceof XAbstractFeatureCall)) { return IScope.NULLSCOPE; } XAbstractFeatureCall call = (XAbstractFeatureCall) context; JvmIdentifiableElement feature = call.getFeature(); // this and super - logical container aware FeatureScopes if (feature instanceof JvmType) { return getTypeScope(call, (JvmType) feature); } if (feature instanceof JvmConstructor) { return getThisOrSuperScope(call, (JvmConstructor) feature); } if (feature instanceof JvmExecutable) { return getExecutableScope(call, feature); } if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) { return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE); } return IScope.NULLSCOPE; }
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { int segmentIndex = countSegments(call); String packageName = ((JvmDeclaredType) type).getPackageName(); List<String> splitted = Strings.split(packageName, '.'); String segment = splitted.get(segmentIndex); return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE); } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget(); if (target.isPackageFragment()) { String qualifiedName = type.getQualifiedName(); int dot = qualifiedName.lastIndexOf('.'); String simpleName = qualifiedName.substring(dot + 1); return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE); } else { return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } } }
@Override protected List<IEObjectDescription> getLocalElementsByName(QualifiedName name) { XAbstractFeatureCall featureCall = getFeatureCall(); if (featureCall.isExplicitOperationCallOrBuilderSyntax()) return Collections.emptyList(); if (rawEnclosingType instanceof JvmDeclaredType && name.getSegmentCount() == 1) { String singleSegment = name.getFirstSegment(); List<String> lookup = Collections.singletonList(singleSegment); if (singleSegment.indexOf('$') != -1) { lookup = Strings.split(singleSegment, '$'); } JvmType result = findNestedType((JvmDeclaredType)rawEnclosingType, lookup.iterator()); if (result != null) { IEObjectDescription description = EObjectDescription.create(name, result); return Collections.<IEObjectDescription>singletonList(new TypeLiteralDescription(description, enclosingType, isVisible(result))); } } return Collections.emptyList(); }
public IScope createTypeScope(EObject context, EReference reference) { if (context.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmInnerTypeReference casted = (JvmInnerTypeReference) context; JvmParameterizedTypeReference outerType = casted.getOuter(); JvmType outerRawType = outerType.getType(); if (outerRawType instanceof JvmDeclaredType) { Iterable<JvmDeclaredType> nestedTypes = ((JvmDeclaredType) outerRawType).getAllNestedTypes(); List<IEObjectDescription> descriptions = Lists.newArrayList(); for(JvmDeclaredType nestedType: nestedTypes) { descriptions.add(EObjectDescription.create(nestedType.getSimpleName(), nestedType)); } return new SimpleScope(descriptions); } return IScope.NULLSCOPE; } else { final IScope delegateScope = getDelegate().getScope(context, reference); return delegateScope; } }
@Override public IScope getScope(EObject context, EReference reference) { if (reference == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) { XAnnotation annotation = EcoreUtil2.getContainerOfType(context, XAnnotation.class); JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) { return IScope.NULLSCOPE; } Iterable<JvmOperation> operations = ((JvmAnnotationType) annotationType).getDeclaredOperations(); Iterable<IEObjectDescription> descriptions = transform(operations, new Function<JvmOperation, IEObjectDescription>() { @Override public IEObjectDescription apply(JvmOperation from) { return EObjectDescription.create(QualifiedName.create(from.getSimpleName()), from); } }); return MapBasedScope.createScope(IScope.NULLSCOPE, descriptions); } return super.getScope(context, reference); }
protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedNameProvider, boolean isNsURI, EObject eObject, IAcceptor<IEObjectDescription> acceptor) { try { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject); if (qualifiedName != null) { Map<String, String> userData = Maps.newHashMapWithExpectedSize(1); userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData); acceptor.accept(description); return true; } } catch (Exception exc) { LOG.error(exc.getMessage(), exc); } return false; }
@Override public Iterable<IEObjectDescription> getElements(EObject object) { if (object instanceof JvmConstructor) { JvmConstructor constructor = ((JvmConstructor) object); String qualifiedNameWithDots = constructor.getQualifiedName('.'); String qualifiedNameWithDollar = constructor.getQualifiedName(); if (qualifiedNameWithDollar.equals(qualifiedNameWithDots)) { final Set<IEObjectDescription> result = singleton( EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDots), object)); return result; } else { return Arrays.asList( EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDots), object), EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(qualifiedNameWithDollar), object)); } } return emptySet(); }
@Override public Iterable<IEObjectDescription> getElements(final QualifiedName name) { IEObjectDescription typeDescription = typeScope.getSingleElement(name); if (typeDescription == null) return emptySet(); JvmType type = (JvmType) typeDescription.getEObjectOrProxy(); if (type.eIsProxy() || !(type instanceof JvmGenericType)) { return emptySet(); } final JvmGenericType castedType = (JvmGenericType) type; if (castedType.isInterface()) { return emptySet(); } Iterable<JvmConstructor> constructors = new Iterable<JvmConstructor>() { @Override public Iterator<JvmConstructor> iterator() { return castedType.getDeclaredConstructors().iterator(); } }; return transform(constructors, new Function<JvmConstructor,IEObjectDescription>(){ @Override public IEObjectDescription apply(JvmConstructor from) { return EObjectDescription.create(name, from); } }); }
@Override public Iterable<IEObjectDescription> getElements(EObject object) { if (object instanceof JvmIdentifiableElement) { JvmIdentifiableElement identifiable = ((JvmIdentifiableElement) object); String qualifiedNameWithDots = identifiable.getQualifiedName('.'); String qualifiedNameWithDollar = identifiable.getQualifiedName(); if (qualifiedNameWithDollar.equals(qualifiedNameWithDots)) { final Set<IEObjectDescription> result = singleton( EObjectDescription.create(qualifiedNameConverter.toQualifiedName(qualifiedNameWithDots), object)); return filterResult(result); } else { return filterResult(Arrays.asList( EObjectDescription.create(qualifiedNameConverter.toQualifiedName(qualifiedNameWithDots), object), EObjectDescription.create(qualifiedNameConverter.toQualifiedName(qualifiedNameWithDollar), object))); } } return emptySet(); }
@Override public Iterable<IEObjectDescription> getElements(EObject object) { if (object instanceof AbstractRule) { Grammar grammar = GrammarUtil.getGrammar(context); AbstractRule rule = (AbstractRule) object; if (GrammarUtil.getGrammar(rule) == grammar) { return Lists.newArrayList( EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule), EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule)); } List<IEObjectDescription> result = Lists.newArrayList( EObjectDescription.create(SUPER + "." + rule.getName(), rule), EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule), EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule)); AbstractRule contextRule = GrammarUtil.containingRule(context); if (contextRule != null && contextRule.getName().equals(rule.getName())) { result.add(0, EObjectDescription.create(SUPER, rule)); } return result; } return Collections.emptyList(); }
protected IScope createScope(final Grammar grammar, EClass type, IScope current) { if (EcorePackage.Literals.EPACKAGE == type) { return createEPackageScope(grammar); } else if (AbstractMetamodelDeclaration.class.isAssignableFrom(type.getInstanceClass())) { return new SimpleScope(IScope.NULLSCOPE,Iterables.transform(grammar.getMetamodelDeclarations(), new Function<AbstractMetamodelDeclaration,IEObjectDescription>(){ @Override public IEObjectDescription apply(AbstractMetamodelDeclaration from) { String name = from.getAlias() != null ? from.getAlias() : ""; return EObjectDescription.create(QualifiedName.create(name), from); } })); } final List<Grammar> allGrammars = getAllGrammars(grammar); for (int i = allGrammars.size() - 1; i >= 0; i--) { current = doCreateScope(allGrammars.get(i), type, current); } return current; }
@Test public void testHasChanges_DifferentTypes() throws Exception { TestResDesc resourceDesc = new TestResDesc(); resourceDesc.imported.add(FOO); resourceDesc.exported.add(EObjectDescription.create(BAR, EcorePackage.Literals.EANNOTATION, Collections.singletonMap("foo", "bar"))); TestResDesc resourceDesc2 = new TestResDesc(); resourceDesc2.imported.add(FOO); resourceDesc2.exported.add(new EObjectDescription(BAR, EcorePackage.Literals.EANNOTATION__CONTENTS, Collections.singletonMap("foo", "bar")){ @Override public URI getEObjectURI() { return EcoreUtil.getURI(EcorePackage.Literals.EANNOTATION); } } ); assertTrue(new DefaultResourceDescriptionDelta(resourceDesc, resourceDesc2).haveEObjectDescriptionsChanged()); }
@Test public void testHasChanges_DifferentURIs() throws Exception { TestResDesc resourceDesc = new TestResDesc(); resourceDesc.imported.add(FOO); resourceDesc.exported.add(EObjectDescription.create(BAR, EcorePackage.Literals.EANNOTATION, Collections.singletonMap("foo", "bar"))); TestResDesc resourceDesc2 = new TestResDesc(); resourceDesc2.imported.add(FOO); resourceDesc2.exported.add(new EObjectDescription(BAR, EcorePackage.Literals.EANNOTATION, Collections.singletonMap("foo", "bar")){ @Override public URI getEObjectURI() { return super.getEObjectURI().appendFragment("foo"); } } ); assertTrue(new DefaultResourceDescriptionDelta(resourceDesc, resourceDesc2).haveEObjectDescriptionsChanged()); }
@Override protected Iterable<IEObjectDescription> getAllLocalElements() { return new Iterable<IEObjectDescription>() { @Override public Iterator<IEObjectDescription> iterator() { numberOfCalls++; return singleton( (IEObjectDescription) new EObjectDescription(QualifiedName.create(name), EcorePackage.Literals.EATTRIBUTE, null)).iterator(); } @Override public String toString() { try { return Iterables.toString(this); } finally { numberOfCalls--; } } }; }
@Test public void testImports_01() throws Exception { final IEObjectDescription desc1 = EObjectDescription.create(QualifiedName.create("com","foo","bar"), EcorePackage.Literals.EANNOTATION); final IEObjectDescription desc2 = EObjectDescription.create(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE); SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), false); ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, false); ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de","foo"), false, false); TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, false); final Iterable<IEObjectDescription> elements = scope.getAllElements(); Iterator<IEObjectDescription> iterator = elements.iterator(); assertEquals("foo.bar", iterator.next().getName().toString()); assertEquals("foo", iterator.next().getName().toString()); assertSame(desc1,iterator.next()); assertSame(desc2,iterator.next()); assertFalse(iterator.hasNext()); }
@Test public void testRelativeImports_01() throws Exception { final IEObjectDescription desc1 = EObjectDescription.create(QualifiedName.create("com","foo","bar"), EcorePackage.Literals.EANNOTATION); final IEObjectDescription desc2 = EObjectDescription.create(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE); IScope outer = new SimpleScope(newArrayList(desc1,desc2), false); ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, false); ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de"), true, false); outer = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, false); n1 = new ImportNormalizer(QualifiedName.create("foo"), true, false); n2 = new ImportNormalizer(QualifiedName.create("foo"), false, false); TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, false); final Iterable<IEObjectDescription> elements = scope.getAllElements(); Iterator<IEObjectDescription> iterator = elements.iterator(); assertEquals("bar", iterator.next().getName().toString()); assertEquals("foo", iterator.next().getName().toString()); assertEquals("foo.bar", iterator.next().getName().toString()); assertSame(desc1,iterator.next()); assertSame(desc2,iterator.next()); assertFalse(iterator.hasNext()); }
@Override public boolean createEObjectDescriptions(final EObject eObject, final IAcceptor<IEObjectDescription> acceptor) { if (getQualifiedNameProvider() == null || !(eObject instanceof ScopeModel)) { return false; } ScopeModel model = (ScopeModel) eObject; try { QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(model); if (qualifiedName != null) { Hasher hasher = Hashing.murmur3_32().newHasher(HASHER_CAPACITY); hasher.putUnencodedChars(getSourceText(model)); for (ScopeModel include : model.getIncludedScopes()) { hasher.putUnencodedChars(getSourceText(include)); } acceptor.accept(EObjectDescription.create(qualifiedName, model, Collections.singletonMap("fingerprint", hasher.hash().toString()))); } // CHECKSTYLE:CHECK-OFF IllegalCatch } catch (RuntimeException e) { // CHECKSTYLE:CHECK-ON LOG.error(e.getMessage(), e); } return false; }
/** * {@inheritDoc} */ @Override public boolean createEObjectDescriptions(final EObject eObject, final IAcceptor<IEObjectDescription> acceptor) { if (eObject instanceof XBlockExpression || isXbaseLocalVariableName(eObject)) { return false; } boolean indexObject = false; boolean indexDefault = false; String objectFingerprint = null; if (fingerprintComputer != null && eObject.eContainer() instanceof FormatConfiguration && NodeModelUtils.getNode(eObject) != null) { objectFingerprint = fingerprintComputer.computeFingerprint(eObject); } if (objectFingerprint != null && !"".equals(objectFingerprint) && eObject.eContainer() instanceof FormatConfiguration) { acceptor.accept(EObjectDescription.create(objectFingerprint, eObject)); indexObject = true; } indexDefault = createDescriptionsForNonXbaseFormalParameters(eObject, acceptor); return indexDefault || indexObject; }
public FixedCopiedResourceDescription(final IResourceDescription original) { super(); this.uri = original.getURI(); this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedObjects(), new Function<IEObjectDescription, IEObjectDescription>() { @Override @SuppressWarnings("unchecked") public IEObjectDescription apply(final IEObjectDescription from) { if (from.getEObjectOrProxy().eIsProxy()) { return from; } else if (from instanceof IDetachableDescription) { return ((IDetachableDescription<IEObjectDescription>) from).detach(); } InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass()); result.eSetProxyURI(from.getEObjectURI()); ImmutableMap.Builder<String, String> userData = ImmutableMap.builder(); for (final String key : from.getUserDataKeys()) { userData.put(key, from.getUserData(key)); } return EObjectDescription.create(from.getName(), result, userData.build()); } })); }
/** * Returns scoped elements for all given objects by applying all given name functions. The result is first ordered by function * then by object. If a function returns null for a given object no corresponding scoped element will be included in the result. * * @param <T> * type of model objects * @param objects * model objects iterable * @param nameFunctions * list of name functions * @return scoped element iterable */ public static <T extends EObject> Iterable<IEObjectDescription> all(final Iterable<T> objects, final Iterable<INameFunction> nameFunctions) { return Iterables.concat(Iterables.transform(nameFunctions, new Function<INameFunction, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(final INameFunction param) { return Iterables.filter(Iterables.transform(objects, new Function<T, IEObjectDescription>() { @Override public IEObjectDescription apply(final T from) { if (from == null) { return null; } final QualifiedName name = param.apply(from); return (name == null) ? null : EObjectDescription.create(name, from); // NOPMD } }), Predicates.notNull()); } })); }
protected ImmutableList<IEObjectDescription> copyExportedObjects(IResourceDescription original) { return ImmutableList.copyOf(Iterables.filter(Iterables.transform(original.getExportedObjects(), new Function<IEObjectDescription, IEObjectDescription>() { public IEObjectDescription apply(IEObjectDescription from) { if (from == null) return null; EObject proxy = from.getEObjectOrProxy(); if (proxy == null) return null; if (proxy.eIsProxy()) return from; InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass()); result.eSetProxyURI(EcoreUtil.getURI(from.getEObjectOrProxy())); Map<String, String> userData = null; for(String key: from.getUserDataKeys()) { if (userData == null) { userData = Maps.newHashMapWithExpectedSize(2); } userData.put(key, from.getUserData(key)); } return EObjectDescription.create(from.getName(), result, userData); } }), Predicates.notNull())); }
@Override protected List<IEObjectDescription> computeExportedObjects() { Iterator<EObject> contents = resource.getAllContents(); List<IEObjectDescription> result = Lists.newArrayList(); while (contents.hasNext()) { EObject eObject = contents.next(); QualifiedName qualifiedName = qualifiedNameProvider.apply(eObject); if (qualifiedName != null) { Map<String, String> userData = new HashMap<String, String>(); if (eObject instanceof FeatureParameter) { userData.put(FEATURE_CONTAINER, getFqName(eObject)); } result.add(new EObjectDescription(qualifiedName, eObject, userData)); } } return result; }
@Override protected ISelectable getAllDescriptions(final Resource resource) { List<IEObjectDescription> descriptions = null; final Iterator<EObject> iterator = resource.getAllContents(); while (iterator.hasNext()) { final EObject from = iterator.next(); final QualifiedName qualifiedName = getNameProvider().apply(from); if (qualifiedName != null) { if (descriptions == null) descriptions = new ArrayList<>(); descriptions.add(new EObjectDescription(qualifiedName, from, null)); } } return new MultimapBasedSelectable(descriptions); }
static void add(final EClass eClass, final String t, final OperatorProto o) { final GamlDefinition stub = (GamlDefinition) EGaml.getFactory().create(eClass); stub.setName(t); Map<String, String> doc; resources.get(eClass).getContents().add(stub); final IGamlDescription d = GAMA.isInHeadLessMode() ? null : GamlResourceServices.getResourceDocumenter().getGamlDocumentation(o); if (d != null) { doc = new ImmutableMap("doc", d.getDocumentation(), "title", d.getTitle(), "type", "operator"); } else { doc = new ImmutableMap("type", "operator"); } final IEObjectDescription e = EObjectDescription.create(t, stub, doc); descriptions.get(eClass).put(e.getName(), e); allNames.add(e.getName()); }
public static void addVar(final String t, final IGamlDescription o, final String keyword) { final GamlDefinition stub = (GamlDefinition) EGaml.getFactory().create(eVar); // TODO Add the fields definition here stub.setName(t); resources.get(eVar).getContents().add(stub); final IGamlDescription d = GAMA.isInHeadLessMode() ? null : GamlResourceServices.getResourceDocumenter().getGamlDocumentation(o); Map<String, String> doc; if (d != null) { doc = new ImmutableMap("doc", d.getDocumentation(), "title", d.getTitle(), "type", keyword); } else { doc = new ImmutableMap("type", keyword); } final IEObjectDescription e = EObjectDescription.create(t, stub, doc); descriptions.get(eVar).put(e.getName(), e); allNames.add(e.getName()); }
static void addAction(final EClass eClass, final String t, final IGamlDescription o) { final GamlDefinition stub = (GamlDefinition) EGaml.getFactory().create(eClass); // TODO Add the fields definition here stub.setName(t); resources.get(eClass).getContents().add(stub); final IGamlDescription d = GAMA.isInHeadLessMode() ? null : GamlResourceServices.getResourceDocumenter().getGamlDocumentation(o); GamlResourceServices.getResourceDocumenter().setGamlDocumentation(stub, o, false); Map<String, String> doc; if (d != null) { doc = new ImmutableMap("doc", d.getDocumentation(), "title", d.getTitle(), "type", "action"); } else { doc = new ImmutableMap("type", "action"); } final IEObjectDescription e = EObjectDescription.create(t, stub, doc); descriptions.get(eClass).put(e.getName(), e); allNames.add(e.getName()); }
private Collection<IEObjectDescription> getDescriptionFor(EObject obj) { List<IEObjectDescription> descriptions = Lists.newArrayList(); QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(obj); if (qualifiedName == null) { return Collections.emptyList(); } IEObjectDescription description = new EObjectDescription(qualifiedName, obj, null); descriptions.add(description); Optional<QualifiedName> alternativeName = alternativeQualifiedNameProvider .getAlternativeFullyQualifiedName(obj); if (alternativeName.isPresent()) { IEObjectDescription alternativeDescription = new AliasedEObjectDescription(alternativeName.get(), description); descriptions.add(alternativeDescription); } return descriptions; }
@Override public IEObjectDescription getSingleElement(QualifiedName name) { IEObjectDescription result = getOutModel((TransformationDefinition) obj.eContainer(), name.getFirstSegment()); if ( result != null ) return result; // TODO: REVIEW THIS STRATEGY BECAUSE THIS WORKS FOR COMPOSITE, BUT FOR A CHAIN THIS MEANS // THAT TWO TRANSFORMATIONS GENERATE THE SAME MODEL... ChainTransformation t = (ChainTransformation) EcoreUtil.getRootContainer(obj); for(GeneratedModel generated : t.getGeneratedModels()) { if ( generated.getName().equals(name.getFirstSegment()) ) { return EObjectDescription.create(name.getFirstSegment(), generated); } } GeneratedModel g = ChainFactory.eINSTANCE.createGeneratedModel(); g.setName(name.getFirstSegment()); t.getGeneratedModels().add(g); return EObjectDescription.create(g.getName(), g); }
@Override public IEObjectDescription getSingleElement(QualifiedName name) { IEObjectDescription r = getInModel((TransformationDefinition) obj.eContainer(), name.getFirstSegment()); if ( r != null ) return r; // Try to see if there is a link from a generated model passed as parameter ChainTransformation t = (ChainTransformation) EcoreUtil.getRootContainer(obj); for(GeneratedModel generated : t.getGeneratedModels()) { if ( generated.getName().equals(name.getFirstSegment()) ) { return EObjectDescription.create(name.getFirstSegment(), generated); } } return null; }
@Override public IEObjectDescription getSingleElement(QualifiedName name) { // TODO: MOVE THIS TO A POST-PROCESSING STEP IN THE PARSER ChainTransformation t = (ChainTransformation) EcoreUtil.getRootContainer(obj); for(CompositeTransformation composite : t.getComposites()) { if ( composite.getName().equals(name.getFirstSegment()) ) { return EObjectDescription.create(composite.getName(), composite); } } ExternalTransformation found = null; for(ExternalTransformation external : t.getExternals()) { if ( external.getName().equals(name.getFirstSegment()) ) { found = external; break; } } if ( found == null ) { found = ChainFactory.eINSTANCE.createExternalTransformation(); found.setName(name.getFirstSegment()); t.getExternals().add(found); } return EObjectDescription.create(found.getName(), found); }
@Override protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) { TypeDefs typeDefinitions = (TypeDefs) resource.getContents().get(0); for (Type type : typeDefinitions.getTypes()) { if (!(type instanceof VirtualBaseType)) { IEObjectDescription description = EObjectDescription.create(type.getName(), type); elements.put(description.getName(), description); } } }
private void internalCreateEObjectDescriptionForRoot(final TModule module, IAcceptor<IEObjectDescription> acceptor) { // user data: serialized representation final Map<String, String> userData = createUserData(module); QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(module); IEObjectDescription eod = new EObjectDescription(qualifiedName, module, userData); acceptor.accept(eod); }
/** * Create EObjectDescriptions for elements for which N4JSQualifiedNameProvider provides a FQN; elements with a FQN * of <code>null</code> will be ignored. */ private void internalCreateEObjectDescription(Type type, IAcceptor<IEObjectDescription> acceptor) { final String exportedName = type.getExportedName(); final String typeName = exportedName != null ? exportedName : type.getName(); if (typeName != null && typeName.length() != 0) { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type); if (qualifiedName != null) { // e.g. non-exported declared functions will return null for FQN Map<String, String> userData = Collections.singletonMap( ACCESS_MODIFIERY_KEY, String.valueOf(type.getTypeAccessModifier().ordinal())); // Add additional user data for descriptions representing a TClass if (type instanceof TClass) { final TClass tClass = (TClass) type; userData = newHashMap(userData); if (tClass.isExported()) { userData.put(EXPORTED_CLASS_KEY, Boolean.toString(tClass.isExported())); } userData.put(ABSTRACT_KEY, Boolean.toString(tClass.isAbstract())); userData.put(FINAL_KEY, Boolean.toString(tClass.isFinal())); userData.put(POLYFILL_KEY, Boolean.toString(tClass.isPolyfill())); userData.put(STATIC_POLYFILL_KEY, Boolean.toString(tClass.isStaticPolyfill())); userData.put( TEST_CLASS_KEY, Boolean.toString(tClass.getOwnedMembers().stream() .filter(m -> m instanceof TMethod) .anyMatch(m -> AnnotationDefinition.TEST_METHOD.hasAnnotation(m)))); } IEObjectDescription eod = EObjectDescription.create(qualifiedName, type, userData); acceptor.accept(eod); } } }
/** * Create EObjectDescriptions for variables for which N4JSQualifiedNameProvider provides a FQN; variables with a FQN * of <code>null</code> (currently all non-exported variables) will be ignored. */ private void internalCreateEObjectDescription(TVariable type, IAcceptor<IEObjectDescription> acceptor) { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(type); if (qualifiedName != null) { // e.g. non-exported variables will return null for FQN IEObjectDescription eod = EObjectDescription.create(qualifiedName, type); acceptor.accept(eod); } }
@Override public IEObjectDescription getSingleElement(EObject object) { IEObjectDescription result = parent.getSingleElement(object); if (result == null) { if (object instanceof IdentifiableElement) { return EObjectDescription .create(QualifiedName.create(((IdentifiableElement) object).getName()), object); } } return result; }