Permalink
Browse files

java: Fill in content.Type structure for #2

  • Loading branch information...
quarnster committed Mar 18, 2013
1 parent 1bfbccc commit 29af60e3419627e07af78ae2157db06d28d1e53e
View
@@ -46,8 +46,8 @@ type (
This_class u2
Super_class u2
Interfaces []u2
- Fields []member_info
- Methods []member_info
+ RawFields []member_info
+ RawMethods []member_info
Attributes []attribute_info
}
@@ -124,11 +124,11 @@ func (c *Class) String() (ret string) {
ret += fmt.Sprintf("\t%s\n", String(c.Constant_pool, i))
}
ret += fmt.Sprintln("Fields")
- for _, f := range c.Fields {
+ for _, f := range c.RawFields {
ret += fmt.Sprintf("\t%s\n", f.String(c.Constant_pool))
}
ret += fmt.Sprintln("Methods")
- for _, m := range c.Methods {
+ for _, m := range c.RawMethods {
ret += fmt.Sprintf("\t%s\n", m.String(c.Constant_pool))
}
return ret
View
@@ -2,6 +2,7 @@ package java
import (
"bytes"
+ "fmt"
"github.com/quarnster/completion/util"
"io/ioutil"
"os"
@@ -69,18 +70,25 @@ func TestSpecificClasses(t *testing.T) {
continue
}
+ ret := c.String()
+ if ct, err := c.ToContentType(); err != nil {
+ t.Error(err)
+ } else {
+ ret += fmt.Sprintf("%s\n", ct)
+ }
+
if len(v) <= 1 {
// Just if we want to add new tests, this will spit out the newly added
// test data
fn := testdata_path + strings.Replace(string(k.Filename()), "/", "_", -1)
t.Logf("Creating new test data: %s", fn)
- if err := ioutil.WriteFile(fn, []byte(c.String()), 0666); err != nil {
+ if err := ioutil.WriteFile(fn, []byte(ret), 0666); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
continue
}
- if d := util.Diff(c.String(), v); len(d) != 0 {
+ if d := util.Diff(v, ret); len(d) != 0 {
t.Error(d)
}
}
View
@@ -0,0 +1,98 @@
+package java
+
+import (
+ "github.com/quarnster/completion/content"
+ "github.com/quarnster/completion/java/descriptors"
+ "strings"
+)
+
+func (af AccessFlags) ToContentFlags() (ret content.Flags) {
+ if af&ACC_PUBLIC != 0 {
+ ret |= content.FLAG_ACC_PUBLIC
+ }
+ if af&ACC_PRIVATE != 0 {
+ ret |= content.FLAG_ACC_PRIVATE
+ }
+ if af&ACC_PROTECTED != 0 {
+ ret |= content.FLAG_ACC_PROTECTED
+ }
+ if af&ACC_STATIC != 0 {
+ ret |= content.FLAG_STATIC
+ }
+ if af&ACC_FINAL != 0 {
+ ret |= content.FLAG_FINAL
+ }
+ return
+}
+
+func (c *Class) ToContentFQN(index u2) (ret content.FullyQualifiedName) {
+ ret.Absolute = strings.Replace(String(c.Constant_pool, index), "/", ".", -1)
+ ret.Relative = ret.Absolute
+ if i := strings.LastIndex(ret.Absolute, "."); i > 0 {
+ ret.Relative = ret.Relative[i+1:]
+ }
+ return
+}
+
+func (c *Class) Fields() (fields []content.Field, err error) {
+ for _, inf := range c.RawFields {
+ var p descriptors.DESCRIPTORS
+ p.Parse(String(c.Constant_pool, inf.Descriptor_index))
+ outf := descriptors.ToContentField(p.RootNode().Children[0])
+ outf.Flags = inf.Access_flags.ToContentFlags()
+ outf.Name.Relative = String(c.Constant_pool, inf.Name_index)
+ fields = append(fields, outf)
+ }
+ return
+}
+
+func (c *Class) Methods() (methods []content.Method, err error) {
+ for _, inf := range c.RawMethods {
+ var p descriptors.DESCRIPTORS
+ p.Parse(String(c.Constant_pool, inf.Descriptor_index))
+ outf := descriptors.ToContentMethod(p.RootNode().Children[0])
+ outf.Flags = inf.Access_flags.ToContentFlags()
+ outf.Name.Relative = String(c.Constant_pool, inf.Name_index)
+ methods = append(methods, outf)
+ }
+ return
+}
+
+func (c *Class) Implements() (ret []content.Type, err error) {
+ for _, i := range c.Interfaces {
+ ret = append(ret, content.Type{Name: c.ToContentFQN(i)})
+ }
+ return
+}
+
+func (c *Class) Extends() (ret []content.Type, err error) {
+ ret = append(ret, content.Type{Name: c.ToContentFQN(c.Super_class)})
+ return
+}
+
+func (c *Class) ToContentType() (ret content.Type, err error) {
+ ret.Name = c.ToContentFQN(c.This_class)
+ ret.Flags = c.Access_flags.ToContentFlags()
+ if f, err := c.Fields(); err != nil {
+ return ret, err
+ } else {
+ ret.Fields = f
+ }
+ if m, err := c.Methods(); err != nil {
+ return ret, err
+ } else {
+ ret.Methods = m
+ }
+ if i, err := c.Implements(); err != nil {
+ return ret, err
+ } else {
+ ret.Implements = i
+ }
+ if e, err := c.Extends(); err != nil {
+ return ret, err
+ } else {
+ ret.Extends = e
+ }
+
+ return
+}
@@ -1,6 +1,7 @@
package descriptors
import (
+ "github.com/quarnster/completion/content"
"github.com/quarnster/parser"
"strings"
)
@@ -17,6 +18,42 @@ var lut = map[string]string{
"Z": "boolean",
"V": "void"}
+func ToContentType(node *parser.Node) (ret content.Type) {
+ if node.Name == "ArrayType" {
+ ret.Flags |= content.FLAG_TYPE_ARRAY
+ ret.Specialization = append(ret.Specialization, ToContentType(node.Children[0]))
+ return
+ }
+ switch node.Name {
+ case "BaseType":
+ fallthrough
+ case "VoidDescriptor":
+ ret.Name.Relative = lut[node.Data()]
+ ret.Name.Absolute = ret.Name.Relative
+ case "Classname":
+ ret.Name.Absolute = strings.Replace(node.Data(), "/", ".", -1)
+ ret.Name.Relative = "TODO"
+ default:
+ return ToContentType(node.Children[0])
+ }
+
+ return
+}
+
+func ToContentField(node *parser.Node) (ret content.Field) {
+ ret.Type = ToContentType(node.Children[0])
+ return
+}
+
+func ToContentMethod(node *parser.Node) (ret content.Method) {
+ ri := len(node.Children) - 1
+ ret.Returns = append(ret.Returns, content.Variable{Type: ToContentType(node.Children[ri])})
+ for i := range node.Children[:ri] {
+ ret.Parameters = append(ret.Parameters, content.Variable{Type: ToContentType(node.Children[i])})
+ }
+ return
+}
+
func convert(node *parser.Node) string {
ret := ""
switch node.Name {
@@ -32,3 +32,34 @@ Methods
private readObject (Ljava/io/ObjectInputStream;)V
public getAccessibleContext ()Ljavax/accessibility/AccessibleContext;
static <clinit> ()V
+public java.awt.Button
+ extends java.awt.Component
+ implements javax.accessibility.Accessible
+ java.lang.String label
+ java.lang.String actionCommand
+ java.awt.event.ActionListener actionListener
+ private static final java.lang.String base
+ private static int nameCounter
+ private static final long serialVersionUID
+ private int buttonSerializedDataVersion
+ private static void initIDs()
+ public void <init>()
+ public void <init>(java.lang.String )
+ java.lang.String constructComponentName()
+ public void addNotify()
+ public java.lang.String getLabel()
+ public void setLabel(java.lang.String )
+ public void setActionCommand(java.lang.String )
+ public java.lang.String getActionCommand()
+ public void addActionListener(java.awt.event.ActionListener )
+ public void removeActionListener(java.awt.event.ActionListener )
+ public java.awt.event.ActionListener[] getActionListeners()
+ public java.util.EventListener[] getListeners(java.lang.Class )
+ boolean eventEnabled(java.awt.AWTEvent )
+ protected void processEvent(java.awt.AWTEvent )
+ protected void processActionEvent(java.awt.event.ActionEvent )
+ protected java.lang.String paramString()
+ private void writeObject(java.io.ObjectOutputStream )
+ private void readObject(java.io.ObjectInputStream )
+ public javax.accessibility.AccessibleContext getAccessibleContext()
+ static void <clinit>()
@@ -104,3 +104,104 @@ Methods
hash32 ()I
public volatile synthetic compareTo (Ljava/lang/Object;)I
static <clinit> ()V
+public final java.lang.String
+ extends java.lang.Object
+ implements java.io.Serializable, java.lang.Comparable, java.lang.CharSequence
+ private final char[] value
+ private int hash
+ private static final long serialVersionUID
+ private static final java.io.ObjectStreamField[] serialPersistentFields
+ public static final java.util.Comparator CASE_INSENSITIVE_ORDER
+ private static final int HASHING_SEED
+ private int hash32
+ public void <init>()
+ public void <init>(java.lang.String )
+ public void <init>(char[] )
+ public void <init>(char[] , int , int )
+ public void <init>(int[] , int , int )
+ public void <init>(byte[] , int , int , int )
+ public void <init>(byte[] , int )
+ private static void checkBounds(byte[] , int , int )
+ public void <init>(byte[] , int , int , java.lang.String )
+ public void <init>(byte[] , int , int , java.nio.charset.Charset )
+ public void <init>(byte[] , java.lang.String )
+ public void <init>(byte[] , java.nio.charset.Charset )
+ public void <init>(byte[] , int , int )
+ public void <init>(byte[] )
+ public void <init>(java.lang.StringBuffer )
+ public void <init>(java.lang.StringBuilder )
+ void <init>(char[] , boolean )
+ void <init>(int , int , char[] )
+ public int length()
+ public boolean isEmpty()
+ public char charAt(int )
+ public int codePointAt(int )
+ public int codePointBefore(int )
+ public int codePointCount(int , int )
+ public int offsetByCodePoints(int , int )
+ void getChars(char[] , int )
+ public void getChars(int , int , char[] , int )
+ public void getBytes(int , int , byte[] , int )
+ public byte[] getBytes(java.lang.String )
+ public byte[] getBytes(java.nio.charset.Charset )
+ public byte[] getBytes()
+ public boolean equals(java.lang.Object )
+ public boolean contentEquals(java.lang.StringBuffer )
+ public boolean contentEquals(java.lang.CharSequence )
+ public boolean equalsIgnoreCase(java.lang.String )
+ public int compareTo(java.lang.String )
+ public int compareToIgnoreCase(java.lang.String )
+ public boolean regionMatches(int , java.lang.String , int , int )
+ public boolean regionMatches(boolean , int , java.lang.String , int , int )
+ public boolean startsWith(java.lang.String , int )
+ public boolean startsWith(java.lang.String )
+ public boolean endsWith(java.lang.String )
+ public int hashCode()
+ public int indexOf(int )
+ public int indexOf(int , int )
+ private int indexOfSupplementary(int , int )
+ public int lastIndexOf(int )
+ public int lastIndexOf(int , int )
+ private int lastIndexOfSupplementary(int , int )
+ public int indexOf(java.lang.String )
+ public int indexOf(java.lang.String , int )
+ static int indexOf(char[] , int , int , char[] , int , int , int )
+ public int lastIndexOf(java.lang.String )
+ public int lastIndexOf(java.lang.String , int )
+ static int lastIndexOf(char[] , int , int , char[] , int , int , int )
+ public java.lang.String substring(int )
+ public java.lang.String substring(int , int )
+ public java.lang.CharSequence subSequence(int , int )
+ public java.lang.String concat(java.lang.String )
+ public java.lang.String replace(char , char )
+ public boolean matches(java.lang.String )
+ public boolean contains(java.lang.CharSequence )
+ public java.lang.String replaceFirst(java.lang.String , java.lang.String )
+ public java.lang.String replaceAll(java.lang.String , java.lang.String )
+ public java.lang.String replace(java.lang.CharSequence , java.lang.CharSequence )
+ public java.lang.String[] split(java.lang.String , int )
+ public java.lang.String[] split(java.lang.String )
+ public java.lang.String toLowerCase(java.util.Locale )
+ public java.lang.String toLowerCase()
+ public java.lang.String toUpperCase(java.util.Locale )
+ public java.lang.String toUpperCase()
+ public java.lang.String trim()
+ public java.lang.String toString()
+ public char[] toCharArray()
+ public static java.lang.String format(java.lang.String , java.lang.Object[] )
+ public static java.lang.String format(java.util.Locale , java.lang.String , java.lang.Object[] )
+ public static java.lang.String valueOf(java.lang.Object )
+ public static java.lang.String valueOf(char[] )
+ public static java.lang.String valueOf(char[] , int , int )
+ public static java.lang.String copyValueOf(char[] , int , int )
+ public static java.lang.String copyValueOf(char[] )
+ public static java.lang.String valueOf(boolean )
+ public static java.lang.String valueOf(char )
+ public static java.lang.String valueOf(int )
+ public static java.lang.String valueOf(long )
+ public static java.lang.String valueOf(float )
+ public static java.lang.String valueOf(double )
+ public java.lang.String intern()
+ int hash32()
+ public int compareTo(java.lang.Object )
+ static void <clinit>()
Oops, something went wrong.

0 comments on commit 29af60e

Please sign in to comment.