KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > elements > IndexedElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.ruby.elements;
20
21 import java.io.IOException JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import javax.swing.text.Document JavaDoc;
25
26 import org.netbeans.api.gsf.ParserFile;
27 import org.netbeans.api.gsf.Modifier;
28 import org.netbeans.modules.ruby.AstUtilities;
29 import org.netbeans.modules.ruby.RubyIndex;
30 import org.netbeans.spi.gsf.DefaultParserFile;
31 import org.openide.filesystems.FileObject;
32
33
34 /**
35  * A program element coming from the persistent index.
36  *
37  * @author Tor Norbye
38  */

39 public abstract class IndexedElement extends RubyElement {
40     protected final String JavaDoc signature;
41     protected String JavaDoc fileUrl;
42     protected final String JavaDoc clz;
43     protected final String JavaDoc fqn;
44     protected final RubyIndex index;
45     protected final String JavaDoc require;
46     protected final Set JavaDoc<Modifier> modifiers;
47     private Document JavaDoc document;
48     private FileObject fileObject;
49
50     protected IndexedElement(String JavaDoc signature, RubyIndex index, String JavaDoc fileUrl, String JavaDoc fqn,
51         String JavaDoc clz, String JavaDoc require, Set JavaDoc<Modifier> modifiers) {
52         this.signature = signature;
53         this.index = index;
54         this.fileUrl = fileUrl;
55         this.fqn = fqn;
56         this.require = require;
57         this.modifiers = modifiers;
58         // XXX Why do methods need to know their clz (since they already have fqn)
59
this.clz = clz;
60     }
61
62     public String JavaDoc getSignature() {
63         return signature;
64     }
65
66     public final String JavaDoc getFileUrl() {
67         return fileUrl;
68     }
69
70     public final String JavaDoc getRequire() {
71         return require;
72     }
73
74     public final String JavaDoc getFqn() {
75         return fqn;
76     }
77
78     @Override JavaDoc
79     public String JavaDoc toString() {
80         return getSignature() + ":" + getFileUrl();
81     }
82
83     public final String JavaDoc getClz() {
84         return clz;
85     }
86
87     public RubyIndex getIndex() {
88         return index;
89     }
90
91     public String JavaDoc getIn() {
92         return getClz();
93     }
94
95     public String JavaDoc getFilenameUrl() {
96         return fileUrl;
97     }
98
99     public Document JavaDoc getDocument() throws IOException JavaDoc {
100         if (document == null) {
101             FileObject fo = getFileObject();
102
103             if (fo == null) {
104                 return null;
105             }
106
107             document = AstUtilities.getBaseDocument(fileObject, true);
108         }
109
110         return document;
111     }
112
113     public ParserFile getFile() {
114         boolean platform = false; // XXX FIND OUT WHAT IT IS!
115

116         return new DefaultParserFile(getFileObject(), null, platform);
117     }
118
119     public FileObject getFileObject() {
120         if ((fileObject == null) && (fileUrl != null)) {
121             fileObject = RubyIndex.getFileObject(fileUrl);
122
123             if (fileObject == null) {
124                 // Don't try again
125
fileUrl = null;
126             }
127         }
128
129         return fileObject;
130     }
131
132     public Set JavaDoc<Modifier> getModifiers() {
133         return modifiers;
134     }
135 }
136
Popular Tags