org.eclipse.xtext.util.SimpleAttributeResolver Java Examples
The following examples show how to use
org.eclipse.xtext.util.SimpleAttributeResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N4JSRenameStrategy.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Override this method to handle the case in which PropertyNameOwner has a LiteralOrComputedPropertyName child node * that contains 'literalName' to be renamed */ @Override protected ITextRegion getOriginalNameRegion(final EObject targetElement, EAttribute nameAttribute) { if (targetElement instanceof SyntaxRelatedTElement) { EObject nameElement = ((SyntaxRelatedTElement) targetElement).getAstElement(); // PropertyNameOwner has a LiteralOrComputedPropertyName child node that contains 'literalName' to be // renamed if (nameElement instanceof PropertyNameOwner) { nameElement = ((PropertyNameOwner) nameElement).getDeclaredName(); EAttribute nAttribute = SimpleAttributeResolver.newResolver(String.class, "literalName") .getAttribute(nameElement); return this.getOriginalNameRegion(nameElement, nAttribute); } } return super.getOriginalNameRegion(targetElement, nameAttribute); }
Example #2
Source File: XtextGrammarRefactoringIntegrationTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testRefactorXtextGrammarWithGeneratedClassifier() throws Exception { ResourceSet rs = resourceSetProvider.get(); Resource ecoreResource = createEcoreModel(rs, ecoreURI, initialModelRoot); final EClass greetingClass = getGreetingClass(ecoreResource); final EReference greetingRef = getReferenceoGreeting(ecoreResource, greetingClass); String greetingClassFragment = EcoreUtil.getURI(greetingClass).fragment(); String greetingRefFragment = EcoreUtil.getURI(greetingRef).fragment(); ecoreResource.unload(); waitForBuild(); final XtextEditor editor = openEditor(grammarFile); doRefactoring(editor); waitForBuild(); checkConsistenceOfGrammar(editor); ecoreResource.load(null); assertEquals(REFACTOREDCLASSIFIERNAME, SimpleAttributeResolver.NAME_RESOLVER.apply(ecoreResource .getEObject(greetingClassFragment.replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME)))); EReference greetingReference = (EReference) ecoreResource.getEObject(greetingRefFragment); EClassifier eType = greetingReference.getEType(); assertFalse(eType.eIsProxy()); assertEquals(REFACTOREDCLASSIFIERNAME, eType.getName()); }
Example #3
Source File: N4TSQualifiedNameProvider.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public QualifiedName getFullyQualifiedName(EObject obj) { String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); if (name == null || name.isEmpty()) return null; return converter.toQualifiedName(name); }
Example #4
Source File: ProcQualifiedNameProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public QualifiedName getFullyQualifiedName(final EObject obj) { final String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); if (name == null || name.isEmpty()) { return null; } return converter.toQualifiedName(name); }
Example #5
Source File: SGraphNameProvider.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public QualifiedName qualifiedName(Scope ele) { QualifiedName name = null; String nameString = SimpleAttributeResolver.NAME_RESOLVER.apply(ele); if (!Strings.isEmpty(nameString)) { name = nameConverter.toQualifiedName(nameString); } QualifiedName namespace = getNamespace(ele); if (namespace != null && name != null) { name = namespace.append(name); } return name; }
Example #6
Source File: SimpleNameLabelProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Calculates the simple-name based on the type of the passed {@code element}. If the {@code element} is an instance * of {@code EObject}, the value of the {@code name} attribute is returned. If the {@code element} is an instance of * {@code IEObjectDescription}, the value of the {@link QualifiedName#getLastSegment()} is returned. A {@code null} * value is returned otherwise. */ @Override public String getNameLabel(Object element) { if (element instanceof EObject) { return SimpleAttributeResolver.NAME_RESOLVER.apply(((EObject) element)); } else if (element instanceof IEObjectDescription) { return ((IEObjectDescription) element).getName().getLastSegment(); } return null; }
Example #7
Source File: DefaultReferenceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IResourceDescription createResourceDescription(Resource testResource) { DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy(); strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() { @Override public QualifiedName getFullyQualifiedName(EObject obj) { String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); return (name != null) ? QualifiedName.create(name) : null; } }); strategy.setLazyURIEncoder(new LazyURIEncoder()); IResourceDescription resourceDescription = new DefaultResourceDescription(testResource, strategy); return resourceDescription; }
Example #8
Source File: DefaultResourceDescription2Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected IResourceDescription createResourceDescription(Resource testResource) { DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy(); strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() { @Override public QualifiedName getFullyQualifiedName(EObject obj) { String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); return (name != null) ? QualifiedName.create(name) : null; } }); IResourceDescription resourceDescription = new DefaultResourceDescription(testResource, strategy); return resourceDescription; }
Example #9
Source File: SimpleNameProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public QualifiedName getFullyQualifiedName(EObject obj) { String name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); if(name == null || name.length() == 0) return null; return qualifiedNameConverter.toQualifiedName(name); }
Example #10
Source File: DotQualifiedNameProvider.java From gef with Eclipse Public License 2.0 | 5 votes |
public QualifiedName getFullyQualifiedName(EObject obj) { // customize the name calculation for NodeId String name = null; if (obj instanceof NodeId) { NodeId node = (NodeId) obj; name = node.getName().toValue(); } else { name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj); } if (name == null || name.length() == 0) return null; return qualifiedNameConverter.toQualifiedName(name); }
Example #11
Source File: ReferenceQueryExecutor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String getElementName(EObject primaryTarget) { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(primaryTarget); if (qualifiedName != null) { return qualifiedNameConverter.toString(qualifiedName); } String simpleName = SimpleAttributeResolver.NAME_RESOLVER.getValue(primaryTarget); return (simpleName != null) ? simpleName : primaryTarget.eResource().getURIFragment(primaryTarget); }
Example #12
Source File: TargetURIKey.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Add information about the given object to this cache. * * @param object * the object to handle */ public void add(EObject object) { this.applicableTypes.add(object.eClass()); this.valueStrings.add(SimpleAttributeResolver.NAME_RESOLVER.apply(object)); // Handle composed members if (object instanceof TMember && ((TMember) object).isComposed()) { List<TMember> constituentMembers = ((TMember) object).getConstituentMembers(); for (TMember constituentMember : constituentMembers) { addFQNs(constituentMember); } } else { addFQNs(object); } }
Example #13
Source File: Scopes.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * creates a scope using {@link SimpleAttributeResolver#NAME_RESOLVER} to compute the names */ public static IScope scopeFor(Iterable<? extends EObject> elements, IScope outer) { return scopeFor(elements, QualifiedName.wrapper(SimpleAttributeResolver.NAME_RESOLVER), outer); }
Example #14
Source File: ImportUriResolver.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public SimpleAttributeResolver<EObject, String> getResolver() { if (resolver == null) { resolver = SimpleAttributeResolver.newResolver(String.class, attributeName); } return resolver; }
Example #15
Source File: StatusWrapper.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected String _toString(EObject element) { return element.eClass().getName() + " '" + notNull(SimpleAttributeResolver.NAME_RESOLVER.apply(element)) + "' in " + _toString(element.eResource().getURI()); }
Example #16
Source File: AbstractRenameStrategy.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected EAttribute getNameAttribute(EObject targetElement) { return SimpleAttributeResolver.NAME_RESOLVER.getAttribute(targetElement); }
Example #17
Source File: SimpleAttributeResolverTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Before public void setUp() throws Exception { factory = EcoreFactory.eINSTANCE; nameResolver = SimpleAttributeResolver.newResolver(String.class, "name"); superClassResolver = SimpleAttributeResolver.newResolver(EList.class, "eSuperTypes"); }
Example #18
Source File: SGraphNameProvider.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@Override protected Function<EObject, String> getResolver() { return SimpleAttributeResolver.NAME_RESOLVER; }
Example #19
Source File: XtextGrammarRefactoringIntegrationTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Test public void testRefactorXtextGrammarWithGeneratedClassifierAndModelWithRefToClassifier() throws Exception { ResourceSet rs = resourceSetProvider.get(); EcoreFactory eInstance = EcoreFactory.eINSTANCE; Resource ecoreModelResource = createEcoreModel(rs, ecoreURI, initialModelRoot); EClass greetingClass = getGreetingClass(ecoreModelResource); EReference greetingRefLocal = getReferenceoGreeting(ecoreModelResource, greetingClass); String greetingClassFragment = EcoreUtil.getURI(greetingClass).fragment(); String greetingRefFragment = EcoreUtil.getURI(greetingRefLocal).fragment(); EPackage refPackage = eInstance.createEPackage(); refPackage.setName("myDsl2"); refPackage.setNsPrefix("myDsl2"); refPackage.setNsURI("http://testrefactoring2"); EClass modelRefClass = eInstance.createEClass(); refPackage.getEClassifiers().add(modelRefClass); modelRefClass.setName("ModelRef"); EReference reference = eInstance.createEReference(); reference.setName("ref"); reference.setLowerBound(0); reference.setUpperBound(-1); reference.setEType(greetingClass); modelRefClass.getEStructuralFeatures().add(reference); Resource refToGreetingResource = createEcoreModel(rs, URI.createPlatformResourceURI(TEST_PROJECT + "/src/org/xtext/example/mydsl/" + "MyDsl2.ecore", true), refPackage); refToGreetingResource.unload(); ecoreModelResource.unload(); waitForBuild(); waitForDisplay(); XtextEditor editor = openEditor(grammarFile); doRefactoring(editor); waitForBuild(); checkConsistenceOfGrammar(editor); ecoreModelResource.load(null); String renamedGreetingClassFragment = greetingClassFragment.replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME); EObject renamedGreetingClass = ecoreModelResource.getEObject(renamedGreetingClassFragment); assertNotNull(renamedGreetingClass); assertEquals(REFACTOREDCLASSIFIERNAME, SimpleAttributeResolver.NAME_RESOLVER.apply(renamedGreetingClass)); EReference greetingReference = (EReference) ecoreModelResource.getEObject(greetingRefFragment); EClassifier eType = greetingReference.getEType(); assertFalse(eType.eIsProxy()); assertEquals(REFACTOREDCLASSIFIERNAME, eType.getName()); refToGreetingResource.load(null); EReference externalReferenceToGreeting = getReferenceoGreeting(refToGreetingResource, eType); assertFalse(externalReferenceToGreeting.getEType().eIsProxy()); assertEquals(REFACTOREDCLASSIFIERNAME, externalReferenceToGreeting.getEType().getName()); }
Example #20
Source File: Scopes.java From xtext-core with Eclipse Public License 2.0 | 2 votes |
/** * transforms an {@link Iterable} of {@link EObject}s into an {@link Iterable} of {@link IEObjectDescription}s computing * the {@link EAttribute} 'name' to compute the {@link IEObjectDescription}'s name. If not existent the object is * filtered out. */ public static Iterable<IEObjectDescription> scopedElementsFor(Iterable<? extends EObject> elements) { return scopedElementsFor(elements, QualifiedName.wrapper(SimpleAttributeResolver.NAME_RESOLVER)); }