Java Code Examples for org.eclipse.emf.ecore.EObject

The following examples show how to use org.eclipse.emf.ecore.EObject. These examples are extracted from open source projects. 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 Project: xtext-core   Source File: AbstractXtextTests.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception {
	XtextResource resource = doGetResource(in, uri);
	checkNodeModel(resource);
	if (expectedErrors != UNKNOWN_EXPECTATION) {
		if (expectedErrors == EXPECT_ERRORS)
			assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty());
		else
			assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size());
	}
	for(Diagnostic d: resource.getErrors()) {
		if (d instanceof ExceptionDiagnostic)
			fail(d.getMessage());
	}
	if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) {
		SerializerTestHelper tester = get(SerializerTestHelper.class);
		EObject obj = resource.getContents().get(0);
		tester.assertSerializeWithNodeModel(obj);
		tester.assertSerializeWithoutNodeModel(obj);
	}
	return resource;
}
 
Example 2
Source Project: xtext-core   Source File: Bug419429Test.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion)
		throws Exception {
	IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION);
	PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset,
			length);
	String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers
			.getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change));
	assertEquals(expectedReparseRegion, reparseRegion);
	final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
	getPartialParser().setUnloader(new IReferableElementsUnloader() {
		@Override
		public void unloadRoot(EObject root) {
			unloaded.set(Boolean.TRUE);
		}
	});
	IParseResult partiallyReparse = reparse(parseResult, offset, length, change);
	assertTrue("unloaded", unloaded.get());
	String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length);
	assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText());
	
	compareWithFullParse(model, offset, length, change);
}
 
Example 3
@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
    final Expression exp = operation.getLeftOperand();
    if (isVariableType(exp)) {
        return selectFilterForVariableStorage(element, exp);
    } else if (isDocumentType(exp)) {
        final EObject referencedDocument = exp.getReferencedElements().get(0);
        if (referencedDocument instanceof Document) {

            if (((Document) referencedDocument).isMultiple()) {
                return ExpressionConstants.SET_LIST_DOCUMENT_OPERATOR.equals(element);
            } else {
                return ExpressionConstants.SET_DOCUMENT_OPERATOR.equals(element);
            }
        }
    }
    return ExpressionConstants.ASSIGNMENT_OPERATOR.equals(element);
}
 
Example 4
Source Project: n4js   Source File: OrderedEmfFormatter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static void objPath(StringBuffer b, EObject obj) {
	if (obj.eContainer() != null) {
		objPath(b, obj.eContainer());
		b.append(".");
		b.append(obj.eContainingFeature().getName());
		if (obj.eContainingFeature().isMany()) {
			b.append("[");
			b.append(((List<?>) obj.eContainer().eGet(obj.eContainingFeature())).indexOf(obj));
			b.append("]");
		}
		b.append("->");
	}
	b.append(obj.eClass().getName());
	EStructuralFeature nameF = obj.eClass().getEStructuralFeature("name");
	Object name = nameF != null ? obj.eGet(nameF) : null;
	if (name != null) {
		b.append("'");
		b.append(name);
		b.append("'");
	}
}
 
Example 5
Source Project: statecharts   Source File: HelpIntegrationTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private List<String> getFeaturesWithoutDocumentation(String generatorId) {
	Iterable<IEObjectDescription> allElements = getAllElements(generatorId);
	List<String> missingDocumentation = Lists.newArrayList();
	for (IEObjectDescription desc : allElements) {
		if (desc.getEClass() != SGenPackage.Literals.FEATURE_TYPE)
			continue;
		EObject eObjectOrProxy = desc.getEObjectOrProxy();
		String documentation = documentationProvider
				.getDocumentation(eObjectOrProxy);
		if (documentation == null
				|| SGenUserHelpDocumentationProvider.EMPTY_DOCUMENTATION
						.equals(documentation)) {
			missingDocumentation.add(desc.getName().toString());
		}
	}
	return missingDocumentation;
}
 
Example 6
Source Project: kieker   Source File: TraceAdapterFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether this factory is applicable for the type of the object.
 * <!-- begin-user-doc -->
 * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model.
 * <!-- end-user-doc -->
 * @return whether this factory is applicable for the type of the object.
 * @generated
 */
@Override
public boolean isFactoryForType(Object object) {
	if (object == modelPackage) {
		return true;
	}
	if (object instanceof EObject) {
		return ((EObject)object).eClass().getEPackage() == modelPackage;
	}
	return false;
}
 
Example 7
Source Project: neoscada   Source File: WorldAdapterFactory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns whether this factory is applicable for the type of the object.
 * <!-- begin-user-doc -->
 * This implementation returns <code>true</code> if the object is either the
 * model's package or is an instance object of the model.
 * <!-- end-user-doc -->
 * @return whether this factory is applicable for the type of the object.
 * @generated
 */
@Override
public boolean isFactoryForType ( Object object )
{
    if ( object == modelPackage )
    {
        return true;
    }
    if ( object instanceof EObject )
    {
        return ( (EObject)object ).eClass ().getEPackage () == modelPackage;
    }
    return false;
}
 
Example 8
/**
 * Returns whether this factory is applicable for the type of the object.
 * <!-- begin-user-doc -->
 * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model.
 * <!-- end-user-doc -->
 * @return whether this factory is applicable for the type of the object.
 * @generated
 */
@Override
public boolean isFactoryForType(Object object)
{
  if (object == modelPackage)
  {
    return true;
  }
  if (object instanceof EObject)
  {
    return ((EObject)object).eClass().getEPackage() == modelPackage;
  }
  return false;
}
 
Example 9
@Override
public String getIssueCode() {
	EObject objectOrProxy = getEObjectOrProxy();
	if (objectOrProxy instanceof TFunction) {
		return IssueCodes.VIS_ILLEGAL_FUN_ACCESS;
	} else if (objectOrProxy instanceof Type) {
		return IssueCodes.VIS_ILLEGAL_TYPE_ACCESS;
	}
	return IssueCodes.VIS_ILLEGAL_VARIABLE_ACCESS;
}
 
Example 10
Source Project: n4js   Source File: EditorOverlay.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
	for (EObject eo : selectedElements) {
		paintConture(e, eo, colorBlue);
	}

	if (hoveredElement != null) {
		paintConture(e, hoveredElement, colorGreen);
	}
}
 
Example 11
Source Project: n4js   Source File: IdentifierRefImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public IdentifiableElement getTargetElement() {
	final IdentifiableElement targetRaw = this.getId();
	if ((targetRaw instanceof ModuleNamespaceVirtualType)) {
		final EObject parent = this.eContainer();
		if ((parent instanceof ParameterizedPropertyAccessExpression)) {
			return ((ParameterizedPropertyAccessExpression)parent).getProperty();
		}
	}
	return targetRaw;
}
 
Example 12
/**
 * Returns whether this factory is applicable for the type of the object.
 * <!-- begin-user-doc -->
 * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model.
 * <!-- end-user-doc -->
 * @return whether this factory is applicable for the type of the object.
 * @generated
 */
@Override
public boolean isFactoryForType(Object object)
{
  if (object == modelPackage)
  {
    return true;
  }
  if (object instanceof EObject)
  {
    return ((EObject)object).eClass().getEPackage() == modelPackage;
  }
  return false;
}
 
Example 13
Source Project: xtext-xtend   Source File: XtendAdapterFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether this factory is applicable for the type of the object.
 * <!-- begin-user-doc -->
 * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model.
 * <!-- end-user-doc -->
 * @return whether this factory is applicable for the type of the object.
 * @generated
 */
@Override
public boolean isFactoryForType(Object object)
{
	if (object == modelPackage)
	{
		return true;
	}
	if (object instanceof EObject)
	{
		return ((EObject)object).eClass().getEPackage() == modelPackage;
	}
	return false;
}
 
Example 14
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<EObject> getItems() {
	if (items == null) {
		items = new EObjectContainmentEList<EObject>(EObject.class, this, SolidityPackage.INLINE_ASSEMBLY_BLOCK__ITEMS);
	}
	return items;
}
 
Example 15
/**
 * 
 */
protected void editFromChannels(EObject element) {
	EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(propertiesEditionComponent.getEditingContext(), propertiesEditionComponent, element, adapterFactory);
	PropertiesEditingProvider provider = (PropertiesEditingProvider)adapterFactory.adapt(element, PropertiesEditingProvider.class);
	if (provider != null) {
		PropertiesEditingPolicy policy = provider.getPolicy(context);
		if (policy != null) {
			policy.execute();
			fromChannels.refresh();
		}
	}
}
 
Example 16
Source Project: xtext-core   Source File: AbstractCleaningLinker.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
@SuppressWarnings("serial")
protected TreeIterator<EObject> getAllLinkableContents(EObject model) {
	return new AbstractTreeIterator<EObject>(model) {
		@Override
		public Iterator<EObject> getChildren(Object object) {
			return ((EObject) object).eContents().iterator();
		}
	};
}
 
Example 17
protected EObject setName(URI targetElementURI, String newName, ResourceSet resourceSet) {
	EObject targetElement = resourceSet.getEObject(targetElementURI, false);
	if (targetElement == null) {
		throw new RefactoringException("Target element not loaded.");
	}
	targetElement.eSet(nameAttribute, newName);
	return targetElement;
}
 
Example 18
private void writeDoubleValue(double value, EObject object, EStructuralFeature feature) throws SerializerException, IOException {
	if (model.isUseDoubleStrings()) {
		Object stringValue = object.eGet(object.eClass().getEStructuralFeature(feature.getName() + "AsString"));
		if (stringValue != null) {
			print((String)stringValue);
			return;
		}
	}
	IfcParserWriterUtils.writePrimitive(value, outputStream);
}
 
Example 19
private void assertContains(Iterable<IEObjectDescription> exportedObjects, EObject ...expectedContents) {
	Collection<IEObjectDescription> collection = Lists.newArrayList(exportedObjects);
	for (EObject obj : expectedContents) {
		boolean found = false;
		for (IEObjectDescription ieObjectDescription : collection) {
			found = found || ieObjectDescription.getEObjectOrProxy()==obj;
		}
		assertTrue(obj+" wasn't contained",found);
	}
	assertEquals(collection.size(),expectedContents.length);
}
 
Example 20
Source Project: n4js   Source File: ControlFlowGraphFactory.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static FinallyBlock getEnteringFinallyBlock(Node catchNode) {
	if (catchNode.name.equals(NodeNames.FINALLY)) {
		ControlFlowElement cfe = catchNode.getDelegatedControlFlowElement();
		EObject cfeContainer = cfe.eContainer();
		return (FinallyBlock) cfeContainer;
	}
	return null;
}
 
Example 21
/**
 * Constraint:
 *     value=STRING
 */
protected void sequence_Expression_String(EObject context, Expression_String semanticObject) {
	if(errorAcceptor != null) {
		if(transientValues.isValueTransient(semanticObject, ConditionModelPackage.Literals.EXPRESSION_STRING__VALUE) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, ConditionModelPackage.Literals.EXPRESSION_STRING__VALUE));
	}
	INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
	SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
	feeder.accept(grammarAccess.getExpression_StringAccess().getValueSTRINGTerminalRuleCall_1_0(), semanticObject.getValue());
	feeder.finish();
}
 
Example 22
Source Project: xtext-xtend   Source File: XtendProposalProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeXbaseConstructorCall_Constructor(EObject model, Assignment assignment,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	completeJavaTypes(
			context,
			TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE,
			true,
			getQualifiedNameValueConverter(),
			createVisibilityFilter(context),
			acceptor);
}
 
Example 23
@Override
public void selectionChanged(final SelectionChangedEvent event) {
    final ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        return;
    }
    final EObject element = unwrap(selection);
    final IEditorReference activeEditorReference = activeEditorReference(activePage);
    final IWorkbenchPart editorPart = activeEditorReference.getPart(false);
    if (editorPart instanceof DiagramEditor) {
        final DiagramEditor diagramEditor = (DiagramEditor) editorPart;
        try {
            final IGraphicalEditPart editPart = editPartResolver.findEditPart(diagramEditor.getDiagramEditPart(), element);
            final ITabbedPropertySelectionProvider defaultProvider = findDefaultProvider(editorPart, editPart);
            updateDiagramSelection(diagramEditor, editPart);
            final ITabbedPropertySelectionProvider selectionProvider = registry.findSelectionProvider(element, activeEditorReference, defaultProvider);
            IViewPart part = null;
            try {
                part = activePage.showView(selectionProvider.viewId());
            } catch (final PartInitException e1) {
                return;
            }
            if (part != null) {
                updateSelectedTabInPage(element, selectionProvider, part);
            }
        } catch (final EditPartNotFoundException e) {
            BonitaStudioLog.debug("No edit part found for semantic element: " + element, Activator.PLUGIN_ID);
        }
    }
}
 
Example 24
public final EObject entryRuleScenario7() throws RecognitionException {
    EObject current = null;

    EObject iv_ruleScenario7 = null;


    try {
        // InternalTwoParametersTestLanguage.g:677:50: (iv_ruleScenario7= ruleScenario7 EOF )
        // InternalTwoParametersTestLanguage.g:678:2: iv_ruleScenario7= ruleScenario7 EOF
        {
        if ( state.backtracking==0 ) {
           newCompositeNode(grammarAccess.getScenario7Rule()); 
        }
        pushFollow(FollowSets000.FOLLOW_1);
        iv_ruleScenario7=ruleScenario7();

        state._fsp--;
        if (state.failed) return current;
        if ( state.backtracking==0 ) {
           current =iv_ruleScenario7; 
        }
        match(input,EOF,FollowSets000.FOLLOW_2); if (state.failed) return current;

        }

    }

        catch (RecognitionException re) {
            recover(input,re);
            appendSkippedTokens();
        }
    finally {
    }
    return current;
}
 
Example 25
public final EObject entryRuleExpression() throws RecognitionException {
    EObject current = null;

    EObject iv_ruleExpression = null;


    try {
        // InternalSimpleExpressions.g:138:2: (iv_ruleExpression= ruleExpression EOF )
        // InternalSimpleExpressions.g:139:2: iv_ruleExpression= ruleExpression EOF
        {
         newCompositeNode(grammarAccess.getExpressionRule()); 
        pushFollow(FOLLOW_1);
        iv_ruleExpression=ruleExpression();

        state._fsp--;

         current =iv_ruleExpression; 
        match(input,EOF,FOLLOW_2); 

        }

    }
     
        catch (RecognitionException re) { 
            recover(input,re); 
            appendSkippedTokens();
        } 
    finally {
    }
    return current;
}
 
Example 26
Source Project: xtext-xtend   Source File: XtendExpressionUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ITextRegion getTotalTextRegion(EObject element, INode node) {
	if (element.eContainer() instanceof RichString) {
		return getRichStringPartTextRegion(element);
	}
	return super.getTotalTextRegion(element, node);
}
 
Example 27
Source Project: dsl-devkit   Source File: InternalValidParser.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public final EObject entryRuleRangeRule() throws RecognitionException {
    EObject current = null;

    EObject iv_ruleRangeRule = null;


    try {
        // InternalValid.g:867:2: (iv_ruleRangeRule= ruleRangeRule EOF )
        // InternalValid.g:868:2: iv_ruleRangeRule= ruleRangeRule EOF
        {
         newCompositeNode(grammarAccess.getRangeRuleRule()); 
        pushFollow(FOLLOW_1);
        iv_ruleRangeRule=ruleRangeRule();

        state._fsp--;

         current =iv_ruleRangeRule; 
        match(input,EOF,FOLLOW_2); 

        }

    }
     
        catch (RecognitionException re) { 
            recover(input,re); 
            appendSkippedTokens();
        } 
    finally {
    }
    return current;
}
 
Example 28
private boolean isInvalidQueryExpression(final Operation operation) {
    if (leftOperandHasReferencedElement(operation)) {
        final EObject data = operation.getLeftOperand().getReferencedElements().get(0);
        return !(data instanceof BusinessObjectData)
                && Objects.equals(operation.getRightOperand().getType(), ExpressionConstants.QUERY_TYPE)
                && !isPrimitive(operation.getRightOperand().getReturnType());
    }
    return false;
}
 
Example 29
protected void diagnose(EObject object, String... expectedUnresolvedProxies) {
	Resource resource = object.eResource();
	for (EObject content : resource.getContents()) {
		Diagnostic diagnostic = diagnostician.validate(content);
		if (diagnostic.getSeverity() != Diagnostic.OK) {
			URI[] expectedUnresolvedProxyURIs = new URI[expectedUnresolvedProxies.length];
			for (int i = 0; i < expectedUnresolvedProxies.length; i++) {
				expectedUnresolvedProxyURIs[i] = URI.createURI(expectedUnresolvedProxies[i]);
			}
			diagnose(diagnostic, expectedUnresolvedProxyURIs);
		}

	}
}
 
Example 30
Source Project: n4js   Source File: TFormalParameterImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EObject getAstElement() {
	if (astElement != null && astElement.eIsProxy()) {
		InternalEObject oldAstElement = (InternalEObject)astElement;
		astElement = eResolveProxy(oldAstElement);
		if (astElement != oldAstElement) {
			if (eNotificationRequired())
				eNotify(new ENotificationImpl(this, Notification.RESOLVE, TypesPackage.TFORMAL_PARAMETER__AST_ELEMENT, oldAstElement, astElement));
		}
	}
	return astElement;
}