-
Notifications
You must be signed in to change notification settings - Fork 316
/
ParseResult.java
70 lines (60 loc) · 2.1 KB
/
ParseResult.java
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
68
69
70
/*******************************************************************************
* Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*******************************************************************************/
package org.eclipse.xtext.parser;
import java.util.Collections;
import java.util.Iterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.impl.AbstractNode;
import org.eclipse.xtext.nodemodel.impl.CompositeNode;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
/**
* The result of a parsing operation.
*
* @author Jan Köhnlein
*/
public class ParseResult extends AbstractParseResult {
private ICompositeNode rootNode;
public ParseResult(/* @Nullable */ EObject rootAstElement, /* @NonNull */ ICompositeNode rootNode, boolean hasErrors) {
super(rootAstElement, hasErrors);
this.rootNode = Preconditions.checkNotNull(rootNode);
}
/* @NonNull */
@Override
public Iterable<INode> getSyntaxErrors() {
if (rootNode == null || !hasSyntaxErrors())
return Collections.emptyList();
return new Iterable<INode>() {
@Override
@SuppressWarnings("unchecked")
public Iterator<INode> iterator() {
Iterator<? extends INode> result = Iterators.filter(((CompositeNode) rootNode).basicIterator(),
new Predicate<AbstractNode>() {
@Override
public boolean apply(AbstractNode input) {
return input.getSyntaxErrorMessage() != null;
}
});
return (Iterator<INode>) result;
}
};
}
/* @NonNull */
@Override
public ICompositeNode getRootNode() {
return rootNode;
}
public void setRootNode(/* @NonNull */ ICompositeNode rootNode) {
this.rootNode = Preconditions.checkNotNull(rootNode);
}
}