001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.ruby;
042:
043: import org.jruby.ast.Node;
044: import org.jruby.ast.RootNode;
045: import org.jruby.parser.RubyParserResult;
046: import org.netbeans.modules.gsf.api.CompilationInfo;
047: import org.netbeans.modules.gsf.api.OffsetRange;
048: import org.netbeans.modules.gsf.api.ParserFile;
049: import org.netbeans.modules.gsf.api.ParserResult;
050: import org.netbeans.modules.gsf.api.annotations.NonNull;
051:
052: /**
053: *
054: * @author Tor Norbye
055: */
056: public class RubyParseResult extends ParserResult {
057: private AstTreeNode ast;
058: private Node root;
059: private RootNode realRoot;
060: private String source;
061: private OffsetRange sanitizedRange = OffsetRange.NONE;
062: private String sanitizedContents;
063: private StructureAnalyzer.AnalysisResult analysisResult;
064: private RubyParser.Sanitize sanitized;
065: private RubyParserResult jrubyResult;
066: private boolean commentsAdded;
067:
068: public RubyParseResult(RubyParser parser, ParserFile file,
069: AstTreeNode ast, Node root, RootNode realRoot,
070: RubyParserResult jrubyResult) {
071: super (parser, file, RubyMimeResolver.RUBY_MIME_TYPE);
072: this .ast = ast;
073: this .root = root;
074: this .realRoot = realRoot;
075: this .jrubyResult = jrubyResult;
076: }
077:
078: public ParserResult.AstTreeNode getAst() {
079: return ast;
080: }
081:
082: public void setAst(AstTreeNode ast) {
083: this .ast = ast;
084: }
085:
086: /** The root node of the AST produced by the parser.
087: * Later, rip out the getAst part etc.
088: */
089: public Node getRootNode() {
090: return root;
091: }
092:
093: public Node getRealRoot() {
094: return realRoot;
095: }
096:
097: public String getSource() {
098: return source;
099: }
100:
101: public void setSource(String source) {
102: this .source = source;
103: }
104:
105: /**
106: * Return whether the source code for the parse result was "cleaned"
107: * or "sanitized" (modified to reduce chance of parser errors) or not.
108: * This method returns OffsetRange.NONE if the source was not sanitized,
109: * otherwise returns the actual sanitized range.
110: */
111: public OffsetRange getSanitizedRange() {
112: return sanitizedRange;
113: }
114:
115: public String getSanitizedContents() {
116: return sanitizedContents;
117: }
118:
119: /**
120: * Set the range of source that was sanitized, if any.
121: */
122: void setSanitized(RubyParser.Sanitize sanitized,
123: OffsetRange sanitizedRange, String sanitizedContents) {
124: this .sanitized = sanitized;
125: this .sanitizedRange = sanitizedRange;
126: this .sanitizedContents = sanitizedContents;
127: }
128:
129: public RubyParser.Sanitize getSanitized() {
130: return sanitized;
131: }
132:
133: public RubyParserResult getJRubyResult() {
134: return jrubyResult;
135: }
136:
137: public void setStructure(@NonNull
138: StructureAnalyzer.AnalysisResult result) {
139: this .analysisResult = result;
140: }
141:
142: @NonNull
143: public StructureAnalyzer.AnalysisResult getStructure() {
144: if (analysisResult == null) {
145: analysisResult = new StructureAnalyzer().analyze(this ,
146: getInfo());
147: }
148: return analysisResult;
149: }
150:
151: public boolean isCommentsAdded() {
152: return commentsAdded;
153: }
154:
155: public void setCommentsAdded(boolean commentsAdded) {
156: this.commentsAdded = commentsAdded;
157: }
158: }
|