Skip to main content
summaryrefslogtreecommitdiffstats
blob: eb3f9f07cc557121a614daa51659e89e63c915c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************************************
 * Copyright (c) 2017 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Lucas Bullen (Red Hat Inc.) - initial implementation
 *******************************************************************************/
package org.eclipse.ui.internal.genericeditor;

import java.util.List;
import java.util.Objects;

import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilerExtension;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;

public class CompositeReconciler implements IReconciler, IReconcilerExtension {
	private List<IReconciler> fReconcilers;

	public CompositeReconciler(List<IReconciler> reconcilers) {
		fReconcilers = reconcilers;
	}

	@Override
	public String getDocumentPartitioning() {
		boolean defaultFound = false;
		String[] types = (String[]) fReconcilers.stream()
			.filter(IReconcilerExtension.class::isInstance)
			.map(IReconcilerExtension.class::cast)
			.map(IReconcilerExtension::getDocumentPartitioning)
			.filter(Objects::nonNull)
			.toArray();
		for (String type : types) {
			if (type.equals(IDocumentExtension3.DEFAULT_PARTITIONING)) {
				defaultFound = true;
			} else {
				return type;
			}
		}
		return defaultFound ? IDocumentExtension3.DEFAULT_PARTITIONING : null;
	}

	@Override
	public void install(ITextViewer textViewer) {
		for (IReconciler iReconciler : fReconcilers) {
			iReconciler.install(textViewer);
		}
	}

	@Override
	public void uninstall() {
		for (IReconciler iReconciler : fReconcilers) {
			iReconciler.uninstall();
		}
	}

	@Override
	public IReconcilingStrategy getReconcilingStrategy(String contentType) {
		return new CompositeReconcilerStrategy(fReconcilers, contentType);

	}
}

Back to the top