Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ ENV RUNTIME_NATIVE_VERSION $RUNTIME_NATIVE_VERSION

RUN apk add --no-cache openjdk8-jre="$RUNTIME_NATIVE_VERSION"

ADD build /opt/driver/bin
CMD /opt/driver/bin/driver
ADD build /opt/driver
ENTRYPOINT ["/opt/driver/bin/driver"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test-native-internal:
build-native-internal:
cd native; \
$(MVN_CMD) package
cp native/target/$(JAR) $(BUILD_PATH); \
cp native/src/main/sh/native.sh $(BUILD_PATH)/native; \
chmod +x $(BUILD_PATH)/native
cp native/target/$(JAR) $(BUILD_PATH)/bin; \
cp native/src/main/sh/native.sh $(BUILD_PATH)/bin/native; \
chmod +x $(BUILD_PATH)/bin/native

21 changes: 10 additions & 11 deletions driver/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package main

import (
"gopkg.in/bblfsh/sdk.v1/protocol/driver"

"github.com/bblfsh/java-driver/driver/normalizer"
)

var version string
var build string
"gopkg.in/bblfsh/sdk.v1/sdk/driver"
)

func main() {
d := driver.Driver{
Version: version,
Build: build,
ParserBuilder: normalizer.ParserBuilder,
Annotate: normalizer.AnnotationRules,
d, err := driver.NewDriver(normalizer.ToNode, normalizer.Transformers)
if err != nil {
panic(err)
}

s := driver.NewServer(d)
if err := s.Start(); err != nil {
panic(err)
}
d.Exec()
}
12 changes: 12 additions & 0 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ import (

"gopkg.in/bblfsh/sdk.v1/uast"
. "gopkg.in/bblfsh/sdk.v1/uast/ann"
"gopkg.in/bblfsh/sdk.v1/uast/transformer"
"gopkg.in/bblfsh/sdk.v1/uast/transformer/annotatter"
)

// Transformers is the of list `transformer.Transfomer` to apply to a UAST, to
// learn more about the Transformers and the available ones take a look to:
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/transformers
var Transformers = []transformer.Tranformer{
annotatter.NewAnnotatter(AnnotationRules),
}

// AnnotationRules describes how a UAST should be annotated with `uast.Role`.
//
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast/ann
var AnnotationRules = On(jdt.CompilationUnit).Roles(uast.File).Descendants(
// Names
On(jdt.QualifiedName).Roles(uast.Expression, uast.Identifier, uast.Qualified),
Expand Down
8 changes: 4 additions & 4 deletions driver/normalizer/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"path/filepath"
"testing"

"gopkg.in/bblfsh/sdk.v1/uast"
"github.com/stretchr/testify/require"
"gopkg.in/bblfsh/sdk.v1/uast"
)

var (
Expand All @@ -22,7 +22,7 @@ func TestAnnotate(t *testing.T) {
f, err := getFixture("java_example_1.json")
require.NoError(err)

n, err := ToNoder.ToNode(f)
n, err := ToNode.ToNode(f)
require.NoError(err)
require.NotNil(n)

Expand Down Expand Up @@ -51,7 +51,7 @@ func TestAnnotatePrettyAnnotationsOnly(t *testing.T) {
f, err := getFixture("java_example_1.json")
require.NoError(err)

n, err := ToNoder.ToNode(f)
n, err := ToNode.ToNode(f)
require.NoError(err)
require.NotNil(n)

Expand All @@ -70,7 +70,7 @@ func TestNodeTokens(t *testing.T) {
f, err := getFixture("java_example_1.json")
require.NoError(err)

n, err := ToNoder.ToNode(f)
n, err := ToNode.ToNode(f)
require.NoError(err)
require.NotNil(n)

Expand Down
55 changes: 0 additions & 55 deletions driver/normalizer/parser.go

This file was deleted.

34 changes: 34 additions & 0 deletions driver/normalizer/tonode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package normalizer

import (
"gopkg.in/bblfsh/sdk.v1/uast"
)

// ToNode is an instance of `uast.ObjectToNode`, defining how to transform an
// into a UAST (`uast.Node`).
//
// https://godoc.org/gopkg.in/bblfsh/sdk.v1/uast#ObjectToNode
var ToNode = &uast.ObjectToNode{
InternalTypeKey: "internalClass",
LineKey: "startLine",
ColumnKey: "startColumn",
OffsetKey: "startPosition",
EndLineKey: "endLine",
EndColumnKey: "endColumn",
EndOffsetKey: "endPosition",

//TODO: Should this be part of the UAST rules?
TokenKeys: map[string]bool{
"identifier": true, // SimpleName
"escapedValue": true, // StringLiteral
"keyword": true, // Modifier
"primitiveTypeCode": true, // ?
},
SyntheticTokens: map[string]string{
"PackageDeclaration": "package",
"IfStatement": "if",
"NullLiteral": "null",
},
//TODO: add names of children (e.g. elseStatement) as
// children node properties.
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package normalizer

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestNativeToNoder(t *testing.T) {
func TestNativeToNode(t *testing.T) {
require := require.New(t)

f, err := getFixture("java_example_1.json")
require.NoError(err)

n, err := ToNoder.ToNode(f)
n, err := ToNode.ToNode(f)
require.NoError(err)
require.NotNil(n)
fmt.Println("NODE", n)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.