KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Set JavaDoc;
22 import org.netbeans.api.gsf.ElementKind;
23 import org.netbeans.api.gsf.Modifier;
24 import org.netbeans.modules.ruby.RubyIndex;
25 import org.netbeans.modules.ruby.elements.IndexedElement;
26
27
28 /**
29  * A class describing a Ruby class that is rin "textual form" (signature, filename, etc.)
30  * obtained from the code index.
31  *
32  * @author Tor Norbye
33  */

34 public final class IndexedClass extends IndexedElement implements ClassElement {
35     boolean isModule;
36     private String JavaDoc in;
37     private String JavaDoc attributes;
38     private int docLength = -1;
39
40     protected IndexedClass(String JavaDoc signature, RubyIndex index, String JavaDoc fileUrl, String JavaDoc fqn, String JavaDoc clz,
41         String JavaDoc require, boolean isModule, Set JavaDoc<Modifier> modifiers, String JavaDoc attributes) {
42         super(signature, index, fileUrl, fqn, clz, require, modifiers);
43         this.isModule = isModule;
44         this.attributes = attributes;
45     }
46
47     public static IndexedClass create(RubyIndex index, String JavaDoc clz, String JavaDoc fqn, String JavaDoc fileUrl,
48         String JavaDoc require, boolean isModule, Set JavaDoc<Modifier> modifiers, String JavaDoc attributes) {
49         IndexedClass c = new IndexedClass(fqn, index, fileUrl, fqn, clz,
50                 require, isModule, modifiers, attributes);
51
52         return c;
53     }
54
55     public String JavaDoc getIn() {
56         if (in == null) {
57             if (fqn.endsWith("::" + clz)) {
58                 in = fqn.substring(0, fqn.length() - (clz.length() + 2));
59             } else if ((require != null) && (require.length() > 0)) {
60                 // Show the require path instead
61
in = require;
62             }
63         }
64
65         return in;
66     }
67
68     // XXX Is this necessary?
69
public String JavaDoc getSignature() {
70         return fqn;
71     }
72
73     public String JavaDoc getName() {
74         return getClz();
75     }
76
77     public ElementKind getKind() {
78         return isModule ? ElementKind.MODULE : ElementKind.CLASS;
79     }
80
81     public Set JavaDoc<String JavaDoc> getIncludes() {
82         return null;
83     }
84     
85     /** Return the length of the documentation for this class, in characters */
86     public int getDocumentationLength() {
87         if (docLength == -1) {
88             docLength = 0;
89             if (attributes != null) {
90                 int index = attributes.indexOf('(');
91                 if (index != -1) {
92                     docLength = Integer.parseInt(attributes.substring(index+1, attributes.indexOf(')',index+1)));
93                 }
94             }
95         }
96         
97         return docLength;
98     }
99 }
100
Popular Tags