下面列出了怎么用org.eclipse.emf.ecore.EObject的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
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);
}
@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);
}
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("'");
}
}
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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
@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;
}
@Override
public void paintControl(PaintEvent e) {
for (EObject eo : selectedElements) {
paintConture(e, eo, colorBlue);
}
if (hoveredElement != null) {
paintConture(e, hoveredElement, colorGreen);
}
}
/**
* <!-- 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* <!-- 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;
}
/**
*
*/
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();
}
}
}
/**
* @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();
}
};
}
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;
}
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);
}
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);
}
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;
}
/**
* 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();
}
@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);
}
@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);
}
}
}
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;
}
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;
}
@Override
protected ITextRegion getTotalTextRegion(EObject element, INode node) {
if (element.eContainer() instanceof RichString) {
return getRichStringPartTextRegion(element);
}
return super.getTotalTextRegion(element, node);
}
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;
}
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;
}
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);
}
}
}
/**
* <!-- 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;
}