tor@1
|
1 |
/*
|
phrebejk@559
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
tor@1
|
3 |
*
|
jglick@4117
|
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
|
jglick@4117
|
5 |
*
|
jglick@4117
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jglick@4117
|
7 |
* Other names may be trademarks of their respective owners.
|
tor@1
|
8 |
*
|
phrebejk@559
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
phrebejk@559
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
phrebejk@559
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
phrebejk@559
|
12 |
* "License"). You may not use this file except in compliance with the
|
phrebejk@559
|
13 |
* License. You can obtain a copy of the License at
|
phrebejk@559
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
phrebejk@559
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
phrebejk@559
|
16 |
* specific language governing permissions and limitations under the
|
phrebejk@559
|
17 |
* License. When distributing the software, include this License Header
|
phrebejk@559
|
18 |
* Notice in each file and include the License file at
|
jglick@4117
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
phrebejk@559
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jglick@4117
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
phrebejk@559
|
22 |
* accompanied this code. If applicable, add the following below the
|
phrebejk@559
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
phrebejk@559
|
24 |
* your own identifying information:
|
tor@1
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
tor@1
|
26 |
*
|
phrebejk@559
|
27 |
* Contributor(s):
|
phrebejk@559
|
28 |
*
|
tor@1
|
29 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
mkrauskopf@2738
|
30 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
|
tor@1
|
31 |
* Microsystems, Inc. All Rights Reserved.
|
phrebejk@559
|
32 |
*
|
phrebejk@559
|
33 |
* If you wish your version of this file to be governed by only the CDDL
|
phrebejk@559
|
34 |
* or only the GPL Version 2, indicate your decision by adding
|
phrebejk@559
|
35 |
* "[Contributor] elects to include this software in this distribution
|
phrebejk@559
|
36 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
phrebejk@559
|
37 |
* single choice of license, a recipient has the option to distribute
|
phrebejk@559
|
38 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
phrebejk@559
|
39 |
* to extend the choice of license to its licensees as provided above.
|
phrebejk@559
|
40 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
phrebejk@559
|
41 |
* Version 2 license, then the option applies only if the new code is
|
phrebejk@559
|
42 |
* made subject to such option by the copyright holder.
|
tor@1
|
43 |
*/
|
tor@1
|
44 |
package org.netbeans.modules.ruby;
|
tor@1
|
45 |
|
mkrauskopf@3030
|
46 |
import java.util.ArrayList;
|
mkrauskopf@3030
|
47 |
import java.util.List;
|
emononen@3259
|
48 |
import org.jrubyparser.ast.Node;
|
emononen@3259
|
49 |
import org.jrubyparser.parser.ParserResult;
|
mkrauskopf@2904
|
50 |
import org.netbeans.api.annotations.common.NonNull;
|
mkrauskopf@3030
|
51 |
import org.netbeans.modules.csl.api.Error;
|
mkrauskopf@3030
|
52 |
import org.netbeans.modules.csl.api.OffsetRange;
|
mkrauskopf@3030
|
53 |
import org.netbeans.modules.parsing.api.Snapshot;
|
tor@1
|
54 |
|
tor@1
|
55 |
/**
|
tor@1
|
56 |
* @author Tor Norbye
|
tor@1
|
57 |
*/
|
emononen@3259
|
58 |
public class RubyParseResult extends org.netbeans.modules.csl.spi.ParserResult {
|
mkrauskopf@2738
|
59 |
|
mkrauskopf@3030
|
60 |
private final Node rootNode;
|
mkrauskopf@3030
|
61 |
|
tor@1
|
62 |
private String source;
|
tor@1
|
63 |
private OffsetRange sanitizedRange = OffsetRange.NONE;
|
tor@581
|
64 |
private String sanitizedContents;
|
tor@1719
|
65 |
private RubyStructureAnalyzer.AnalysisResult analysisResult;
|
tor@371
|
66 |
private RubyParser.Sanitize sanitized;
|
emononen@3259
|
67 |
private ParserResult jrubyResult;
|
tor@1
|
68 |
private boolean commentsAdded;
|
mkrauskopf@3030
|
69 |
private List<Error> errors;
|
tor@1
|
70 |
|
enebo@4554
|
71 |
public RubyParseResult(Snapshot snapshot, Node rootNode) {
|
mkrauskopf@3030
|
72 |
super(snapshot);
|
mkrauskopf@3030
|
73 |
this.rootNode = rootNode;
|
mkrauskopf@3030
|
74 |
this.errors = new ArrayList<Error>();
|
tor@1
|
75 |
}
|
tor@1
|
76 |
|
mkrauskopf@3030
|
77 |
@Override
|
mkrauskopf@3030
|
78 |
protected void invalidate() {
|
mkrauskopf@3030
|
79 |
// XXX: what exactly should we do here?
|
tor@1
|
80 |
}
|
tor@1
|
81 |
|
mkrauskopf@3030
|
82 |
@Override
|
mkrauskopf@3030
|
83 |
public List<? extends Error> getDiagnostics() {
|
mkrauskopf@3030
|
84 |
return errors;
|
tor@1
|
85 |
}
|
tor@1
|
86 |
|
mkrauskopf@3030
|
87 |
public void setErrors(List<? extends Error> errors) {
|
mkrauskopf@3030
|
88 |
this.errors = new ArrayList<Error>(errors);
|
mkrauskopf@3030
|
89 |
}
|
mkrauskopf@3030
|
90 |
|
tor@1
|
91 |
/** The root node of the AST produced by the parser.
|
tor@1
|
92 |
* Later, rip out the getAst part etc.
|
tor@1
|
93 |
*/
|
tor@1
|
94 |
public Node getRootNode() {
|
mkrauskopf@3030
|
95 |
return rootNode;
|
tor@1
|
96 |
}
|
tor@1
|
97 |
|
tor@1
|
98 |
public String getSource() {
|
tor@1
|
99 |
return source;
|
tor@1
|
100 |
}
|
tor@1
|
101 |
|
tor@1
|
102 |
public void setSource(String source) {
|
tor@1
|
103 |
this.source = source;
|
tor@1
|
104 |
}
|
tor@1
|
105 |
|
tor@1
|
106 |
/**
|
tor@1
|
107 |
* Return whether the source code for the parse result was "cleaned"
|
tor@1
|
108 |
* or "sanitized" (modified to reduce chance of parser errors) or not.
|
tor@1
|
109 |
* This method returns OffsetRange.NONE if the source was not sanitized,
|
tor@1
|
110 |
* otherwise returns the actual sanitized range.
|
tor@1
|
111 |
*/
|
tor@1
|
112 |
public OffsetRange getSanitizedRange() {
|
tor@1
|
113 |
return sanitizedRange;
|
tor@1
|
114 |
}
|
tor@581
|
115 |
|
tor@581
|
116 |
public String getSanitizedContents() {
|
tor@581
|
117 |
return sanitizedContents;
|
tor@581
|
118 |
}
|
tor@1
|
119 |
|
tor@1
|
120 |
/**
|
tor@1
|
121 |
* Set the range of source that was sanitized, if any.
|
tor@1
|
122 |
*/
|
tor@581
|
123 |
void setSanitized(RubyParser.Sanitize sanitized, OffsetRange sanitizedRange, String sanitizedContents) {
|
tor@371
|
124 |
this.sanitized = sanitized;
|
tor@1
|
125 |
this.sanitizedRange = sanitizedRange;
|
tor@581
|
126 |
this.sanitizedContents = sanitizedContents;
|
tor@1
|
127 |
}
|
tor@1
|
128 |
|
tor@371
|
129 |
public RubyParser.Sanitize getSanitized() {
|
tor@371
|
130 |
return sanitized;
|
tor@371
|
131 |
}
|
tor@371
|
132 |
|
emononen@3259
|
133 |
public ParserResult getJRubyResult() {
|
tor@1
|
134 |
return jrubyResult;
|
tor@1
|
135 |
}
|
tor@1
|
136 |
|
tor@1719
|
137 |
public void setStructure(@NonNull RubyStructureAnalyzer.AnalysisResult result) {
|
tor@236
|
138 |
this.analysisResult = result;
|
tor@1
|
139 |
}
|
tor@1
|
140 |
|
tor@236
|
141 |
@NonNull
|
tor@1719
|
142 |
public RubyStructureAnalyzer.AnalysisResult getStructure() {
|
tor@236
|
143 |
if (analysisResult == null) {
|
mkrauskopf@3030
|
144 |
analysisResult = new RubyStructureAnalyzer().analyze(this);
|
tor@236
|
145 |
}
|
tor@236
|
146 |
return analysisResult;
|
tor@1
|
147 |
}
|
tor@1
|
148 |
|
tor@1
|
149 |
public boolean isCommentsAdded() {
|
tor@1
|
150 |
return commentsAdded;
|
tor@1
|
151 |
}
|
tor@1
|
152 |
|
tor@1
|
153 |
public void setCommentsAdded(boolean commentsAdded) {
|
tor@1
|
154 |
this.commentsAdded = commentsAdded;
|
tor@1
|
155 |
}
|
mkrauskopf@3030
|
156 |
|
tor@1
|
157 |
}
|