Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#remove()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#remove() . 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: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Fix(REDUNDANT_ATTRIBUTE)
public void fixRedundantAttribute(final Issue issue,
		IssueResolutionAcceptor acceptor) {
	if (issue.getData() == null || issue.getData().length == 0) {
		return;
	}

	String attributeName = issue.getData()[0];

	String label = "Remove '" + attributeName + "' attribute."; //$NON-NLS-1$ //$NON-NLS-2$
	String description = "Remove the redundant '" + attributeName //$NON-NLS-1$
			+ "' attribute."; //$NON-NLS-1$
	ISemanticModification semanticModification = (EObject element,
			IModificationContext context) -> EcoreUtil.remove(element);

	acceptor.accept(issue, label, description, DELETE_IMAGE,
			semanticModification);
}
 
Example 2
Source File: WorkflowFacadeTest.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void initializingMissing() throws IOException {
	Resource coffeeResource = loadResource("SuperBrewer3000.coffee");
	Resource notationResource = loadResource("SuperBrewer3000.coffeenotation");
	WorkflowFacade facade = new WorkflowFacade(coffeeResource, notationResource);

	Machine machine = (Machine) coffeeResource.getContents().get(0);
	Workflow workflow = machine.getWorkflows().get(0);
	Node preHeat = workflow.getNodes().get(0);

	Optional<DiagramElement> diagramElement = facade.findDiagramElement(preHeat);
	assertTrue(diagramElement.isPresent());
	assertTrue(diagramElement.get() instanceof Shape);

	EcoreUtil.remove(diagramElement.get());
	assertTrue(facade.findDiagramElement(preHeat).isEmpty());

	facade.initializeMissing(facade.findDiagram(workflow).get());

	assertTrue(facade.findDiagramElement(preHeat).isPresent());
}
 
Example 3
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  this.checkMutable();
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final Function1<JvmConstructor, Boolean> _function = (JvmConstructor it) -> {
    return Boolean.valueOf(this.getCompilationUnit().getTypeExtensions().isSingleSyntheticDefaultConstructor(it));
  };
  final JvmConstructor constructor = IterableExtensions.<JvmConstructor>findFirst(Iterables.<JvmConstructor>filter(this.getDelegate().getMembers(), JvmConstructor.class), _function);
  if ((constructor != null)) {
    EcoreUtil.remove(constructor);
  }
  final JvmConstructor newConstructor = TypesFactory.eINSTANCE.createJvmConstructor();
  newConstructor.setVisibility(JvmVisibility.PUBLIC);
  newConstructor.setSimpleName(this.getSimpleName());
  this.getDelegate().getMembers().add(newConstructor);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newConstructor);
  final MutableConstructorDeclaration mutableConstructorDeclaration = ((MutableConstructorDeclaration) _memberDeclaration);
  initializer.apply(mutableConstructorDeclaration);
  return mutableConstructorDeclaration;
}
 
Example 4
Source File: JvmElementImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public void remove() {
  this.checkMutable();
  Resource _eResource = this.getDelegate().eResource();
  boolean _tripleNotEquals = (_eResource != null);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("This element has already been removed: ");
  T _delegate = this.getDelegate();
  _builder.append(_delegate);
  Preconditions.checkState(_tripleNotEquals, _builder);
  this.getCompilationUnit().getJvmModelAssociator().removeAllAssociation(this.getDelegate());
  EcoreUtil.remove(this.getDelegate());
  Resource _eResource_1 = this.getDelegate().eResource();
  boolean _tripleEquals = (_eResource_1 == null);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Couldn\'t remove: ");
  T _delegate_1 = this.getDelegate();
  _builder_1.append(_delegate_1);
  Preconditions.checkState(_tripleEquals, _builder_1);
}
 
Example 5
Source File: MutableJvmTypeParameterDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void remove() {
  this.checkMutable();
  Resource _eResource = this.getDelegate().eResource();
  boolean _tripleNotEquals = (_eResource != null);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("This element has already been removed: ");
  JvmTypeParameter _delegate = this.getDelegate();
  _builder.append(_delegate);
  Preconditions.checkState(_tripleNotEquals, _builder);
  this.getCompilationUnit().getJvmModelAssociator().removeAllAssociation(this.getDelegate());
  EcoreUtil.remove(this.getDelegate());
  Resource _eResource_1 = this.getDelegate().eResource();
  boolean _tripleEquals = (_eResource_1 == null);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("Couldn\'t remove: ");
  JvmTypeParameter _delegate_1 = this.getDelegate();
  _builder_1.append(_delegate_1);
  Preconditions.checkState(_tripleEquals, _builder_1);
}
 
Example 6
Source File: TermDeleter.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public static void delete(List<Term> termsToDelete) {
	Map<Document, List<Term>> termsInDocuments = new HashMap<>(); 
	for (Term term : termsToDelete) {
		Map<Document, Term> termInDocuments = SearchUtils.findDocumentsWithTerm(term);
		termInDocuments.forEach((k, v) -> {
				if (termsInDocuments.containsKey(k)) termsInDocuments.get(k).add(v);
				else termsInDocuments.put(k, new LinkedList<Term>(Arrays.asList(v)));
		});
		Optional<Model> model = SearchUtils.getContainingModel(term);
		EcoreUtil.remove(term);			
		if (model.isPresent()) {
			TaxonomyUtils.saveTaxonomy(model.get());
		}
	}
	Set<Resource> resourcesToUpdate = new TreeSet<>(
			(Resource r1, Resource r2) -> r1 == r2 ? 0 : 1);
	for (Map.Entry<Document, List<Term>> entry : termsInDocuments.entrySet()) {	
		entry.getValue().forEach(t -> EcoreUtil.remove(t));
		resourcesToUpdate.add(entry.getKey().eResource());
	}
	resourcesToUpdate.forEach(r -> BibtexFileWriter.updateBibtexFile(r));
}
 
Example 7
Source File: ChangeSerializerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDeleteChild() {
  final InMemoryURIHandler fs = new InMemoryURIHandler();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("#1 root { child1 { foo1; } }");
  Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
  this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
  final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
  final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
  final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
  final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
    EcoreUtil.remove(model.getChildren().get(0).getChildren().get(0));
  };
  serializer.<Resource>addModification(model.eResource(), _function);
  Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
  _builder_1.newLine();
  _builder_1.append("#1 root { child1 { <19:5|> } }");
  _builder_1.newLine();
  _builder_1.append("--------------------------------------------------------------------------------");
  _builder_1.newLine();
  _builder_1.append("19 5 \"foo1;\" -> \"\"");
  _builder_1.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
 
Example 8
Source File: RemoveBoundaryWithItsFlows.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void cleanExceptionFlow() {
    final EList<Connection> exceptionFlowsToDelete = boundaryToRemove.getOutgoing();
    for (final Connection exceptionFlowToDelete : exceptionFlowsToDelete) {
        EcoreUtil.remove(exceptionFlowToDelete);
        final TargetElement target = exceptionFlowToDelete.getTarget();
        if (target != null) {
            target.getIncoming().remove(exceptionFlowToDelete);
        }
    }
    exceptionFlowsToDelete.clear();
}
 
Example 9
Source File: MBrickdImpl.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Removes devices which are no longer available. If the device has
 * sub devices these are removed before removing the device. This gives the
 * model adapter a chance to handle sub device removal as well.
 *
 * @generated NOT
 */
private void removeDevice(String uid) {
    MDevice<?> device = (MDevice<?>) getDevice(uid);
    if (device instanceof MSubDeviceHolder<?>) {
        logger.debug("{} removing all subdevices", LoggerConstants.TFINIT);
        @SuppressWarnings("unchecked")
        MSubDeviceHolder<MSubDevice<?>> mSubDeviceHolder = (MSubDeviceHolder<MSubDevice<?>>) device;
        mSubDeviceHolder.getMsubdevices().clear();
    }
    if (device != null) {
        EcoreUtil.remove(device);
    }
    // getMdevices().remove(device);
    logger.debug("{} removeDevice called for uid: {}", LoggerConstants.TFINIT, uid);
}
 
Example 10
Source File: TermMerger.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Merges all terms and returns the updated model
 * @param taxonomy
 * @param termsToMerge
 * @param targetTerm
 * @return The updated model
 */
private static Model doMerge(Model taxonomy, Collection<Term> termsToMerge, Term targetTerm) {
	Term targetTermInTaxonomy = SearchUtils.findTermInTaxonomy(taxonomy, targetTerm);
	for (Term term : termsToMerge) {			
		if (!TermUtils.equals(term, targetTerm)) {
			Term termInTaxonomy = SearchUtils.findTermInTaxonomy(taxonomy, term);				
			// remove container
			EcoreUtil.remove(termInTaxonomy);
			// append child's to target
			targetTermInTaxonomy.getSubclasses().addAll(termInTaxonomy.getSubclasses());
		}
	}
	return taxonomy;		
}
 
Example 11
Source File: RefactoringHelper.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void removeReactionsOfEventType(EList<Reaction> reactions, Class<? extends EventSpec> eventType) {
	for (Reaction reaction : reactions) {
		List<EventSpec> triggers = new ArrayList<EventSpec>(
				((ReactionTrigger) reaction.getTrigger()).getTriggers());
		if (containsOnlyEventsOfType(triggers, eventType)) {
			EcoreUtil.remove(reaction);
		} else if (containsAtLeastOneEventOfType(triggers, eventType)) {
			deleteAllEventsOfType(triggers, eventType);
		}
	}
}
 
Example 12
Source File: RefactoringHelper.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteAllEventsOfType(List<EventSpec> events, Class<? extends EventSpec> eventType) {
	for (EventSpec event : events) {
		if (eventType.isAssignableFrom(event.getClass())) {
			EcoreUtil.remove(event);
		}
	}
}
 
Example 13
Source File: ChangeSerializerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDeleteTwoChildren() {
  final InMemoryURIHandler fs = new InMemoryURIHandler();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("#1 root { child1; child2; }");
  Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
  this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
  final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
  final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
  final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
  final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
    EcoreUtil.remove(model.getChildren().get(1));
    EcoreUtil.remove(model.getChildren().get(0));
  };
  serializer.<Resource>addModification(model.eResource(), _function);
  Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
  _builder_1.newLine();
  _builder_1.append("#1 root { <10:7|> <18:7|> }");
  _builder_1.newLine();
  _builder_1.append("--------------------------------------------------------------------------------");
  _builder_1.newLine();
  _builder_1.append("10 7 \"child1;\" -> \"\"");
  _builder_1.newLine();
  _builder_1.append("18 7 \"child2;\" -> \"\"");
  _builder_1.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
 
Example 14
Source File: PartialSerializerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOptionalChildRemoveListAllOne() {
  final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
    EcoreUtil.remove(it.getChildren().get(0));
  };
  ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x1", _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("0 0   H");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("B OptionalChildList    Model");
  _builder.newLine();
  _builder.append("0 3    S \"#13\"                Model:\'#13\'");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("E OptionalChildList    Model");
  _builder.newLine();
  _builder.append("3 1 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 1 ------------");
  _builder.newLine();
  _builder.append("3 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("4 2  S \"x1\"                 MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("6 0  H");
  _builder.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
 
Example 15
Source File: PartialSerializerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testOptionalChildRemoveListMiddleTwo() {
  final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
    EcoreUtil.remove(it.getChildren().get(2));
    EcoreUtil.remove(it.getChildren().get(1));
  };
  ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b c d", _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("0 0   H");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("B OptionalChildList    Model");
  _builder.newLine();
  _builder.append("0 3    S \"#13\"                Model:\'#13\'");
  _builder.newLine();
  _builder.append("3 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("B MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("4 1     S \"a\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("E MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("5   2  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("\" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("3    \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("B MandatoryValue\'d\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
  _builder.newLine();
  _builder.append("8 1     S \"d\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("E MandatoryValue\'d\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("E OptionalChildList    Model");
  _builder.newLine();
  _builder.append("9 0   H");
  _builder.newLine();
  _builder.append("------------ diff 1 ------------");
  _builder.newLine();
  _builder.append("5 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("6 1  S \"b\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("7 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 2 ------------");
  _builder.newLine();
  _builder.append("7 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("8 1 S \"c\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("9 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
 
Example 16
Source File: PartialSerializerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testOptionalChildRemoveListLastTwo() {
  final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
    EcoreUtil.remove(it.getChildren().get(2));
    EcoreUtil.remove(it.getChildren().get(1));
  };
  ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b c", _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("0 0   H");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("B OptionalChildList    Model");
  _builder.newLine();
  _builder.append("0 3    S \"#13\"                Model:\'#13\'");
  _builder.newLine();
  _builder.append("3 1    H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("B MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("4 1     S \"a\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("E MandatoryValue\'a\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("E OptionalChildList    Model");
  _builder.newLine();
  _builder.append("5   2 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("2   \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 1 ------------");
  _builder.newLine();
  _builder.append("5 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("6 1  S \"b\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("7 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 2 ------------");
  _builder.newLine();
  _builder.append("7 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("8 1  S \"c\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("9 0  H");
  _builder.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
 
Example 17
Source File: PartialSerializerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testOptionalChildRemoveListFirstTwo() {
  final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
    EcoreUtil.remove(it.getChildren().get(1));
    EcoreUtil.remove(it.getChildren().get(0));
  };
  ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b c", _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("0 0   H");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("B OptionalChildList    Model");
  _builder.newLine();
  _builder.append("0 3    S \"#13\"                Model:\'#13\'");
  _builder.newLine();
  _builder.append("3   2  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("\" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("3    \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("B MandatoryValue\'c\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("6 1     S \"c\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("       ");
  _builder.append("E MandatoryValue\'c\'    OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("E OptionalChildList    Model");
  _builder.newLine();
  _builder.append("7 0   H");
  _builder.newLine();
  _builder.append("------------ diff 1 ------------");
  _builder.newLine();
  _builder.append("3 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("4 1 S \"a\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("5 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 2 ------------");
  _builder.newLine();
  _builder.append("5 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("6 1 S \"b\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("7 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
 
Example 18
Source File: PartialSerializerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testOptionalChildRemoveListAllTwo() {
  final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> {
    EcoreUtil.remove(it.getChildren().get(1));
    EcoreUtil.remove(it.getChildren().get(0));
  };
  ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b", _function);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("0 0   H");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("B OptionalChildList    Model");
  _builder.newLine();
  _builder.append("0 3    S \"#13\"                Model:\'#13\'");
  _builder.newLine();
  _builder.append("      ");
  _builder.append("E OptionalChildList    Model");
  _builder.newLine();
  _builder.append("3   2 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("2   \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 1 ------------");
  _builder.newLine();
  _builder.append("3 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("4 1 S \"a\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("5 1 H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("------------ diff 2 ------------");
  _builder.newLine();
  _builder.append("5 1  H \" \"                  Whitespace:TerminalRule\'WS\'");
  _builder.newLine();
  _builder.append("6 1  S \"b\"                  MandatoryValue:name=ID");
  _builder.newLine();
  _builder.append("7 0  H");
  _builder.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder);
}
 
Example 19
Source File: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static TreeIterator<EObject> eAll(final EObject obj) {
	return new TreeIterator<EObject>() {
		private TreeIterator<EObject> it = null;
		private int index = 0;

		@Override
		public void prune() {
			switch (index) {
				case 0:
					return;
				case 1:
					it = null;
					break;
				default:
					if (it != null)
						it.prune();
			}
		}

		@Override
		public boolean hasNext() {
			if (index == 0)
				return true;
			if (it != null)
				return it.hasNext();
			return false;
		}

		@Override
		public EObject next() {
			if (index++ == 0) {
				it = obj.eAllContents();
				return obj;
			}
			if (it != null)
				return it.next();
			return null;
		}

		@Override
		public void remove() {
			if (index == 0)
				EcoreUtil.remove(obj);
			if (it != null)
				it.remove();
		}
	};
}
 
Example 20
Source File: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private void provideQuickfixesForDeprecatedStyleItem(Issue issue,
		IssueResolutionAcceptor acceptor) {
	String[] issueData = issue.getData();
	String styleItemName = issueData[1];

	final String penwidthValue = issueData.length > 2 ? issueData[2] : ""; //$NON-NLS-1$

	final String styleItem = styleItemName + (penwidthValue == "" ? "" //$NON-NLS-1$ //$NON-NLS-2$
			: "(" + penwidthValue + ")"); //$NON-NLS-1$ //$NON-NLS-2$

	String label = "Replace '" + styleItem + "' with 'penwidth=" //$NON-NLS-1$ //$NON-NLS-2$
			+ penwidthValue + "'."; //$NON-NLS-1$
	String description = "Use the 'penwidth' attribute instead of the deprecated '" //$NON-NLS-1$
			+ styleItemName + "' style."; //$NON-NLS-1$

	ISemanticModification semanticModification = new ChangingDotAttributeValueSemanticModification() {
		private String newValue;

		public void apply(EObject element, IModificationContext context)
				throws Exception {
			super.apply(element, context);
			EObject container = element.eContainer();

			// if the valid style attribute value is empty, remove the
			// entire style attribute
			if (newValue.isEmpty()) {
				EcoreUtil.remove(element);
			}

			// add a new pendwidth attribute
			Attribute penwidthAttribute = DotFactory.eINSTANCE
					.createAttribute();
			penwidthAttribute
					.setName(ID.fromValue(DotAttributes.PENWIDTH__CNE));
			penwidthAttribute.setValue(
					ID.fromValue(penwidthValue, ID.Type.QUOTED_STRING));
			if (container instanceof AttrList) {
				AttrList attrList = (AttrList) container;
				attrList.getAttributes().add(penwidthAttribute);
			} else if (container instanceof Subgraph) {
				Subgraph subgraph = (Subgraph) container;
				subgraph.getStmts().add(penwidthAttribute);
			}
		}

		@Override
		public String getNewValue(String currentValue) {
			newValue = currentValue.replace(styleItem, "").trim(). //$NON-NLS-1$
			// trim the unnecessary ',' if any is left over
			replaceAll("^,", "") //$NON-NLS-1$ //$NON-NLS-2$
					.replaceAll(",$", "").replace(", ,", ",").trim(); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-1$
			return newValue;
		}
	};

	acceptor.accept(issue, label, description, null, semanticModification);
}