2017-08-26 8 views
4

defrecordConstraintLookupという名前がsre.plan.dsl.constraint名前空間にあります。 私はsre.plan.compiler名前空間に置かれgen-class方法でその生成されたクラスを使用したい:私はAOT nebula-clojureプラグインとのGradleでコンパイルしていますns:gen-classの別の名前空間のクラスを使用できません

(ns sre.plan.compiler 
    (:require 
    [sre.plan.dsl.constraint :as constraint]) 
    (:import (sre.plan.dsl.constraint ConstraintLookup)) 
    (:gen-class 
    :name sre.plan.Compiler 
    :methods [^:static [makeConstraintLookupFromTargetsAndBounds 
         [Iterable Iterable] ConstraintLookup]])) 

。私が取得メソッド宣言にsre.plan.dsl.constraint.Constraint完全修飾を使用した場合も同様に

> Task :sre:compileClojure 
Exception in thread "main" java.lang.ClassNotFoundException: java.lang.ConstraintLookup, compiling:(sre/plan/compiler.clj:1:1) 

:それはNSの宣言に遭遇した場合、コンパイラはエラーを発する

Exception in thread "main" java.lang.ClassNotFoundException: sre.plan.dsl.constraint.ConstraintLookup, compiling:(sre/plan/compiler.clj:1:1) 

ここでの問題は何ですか?迷っています。

UPDATE:

参照nsが次のようになります。

(ns sre.plan.dsl.constraint 
    (:require [clojure.set :refer :all] 
      [clojure.algo.generic.functor :refer :all])) 

(defrecord ConstraintLookup [free bound]) 

UPDATE:

GEN-クラスであなたは関係なく、完全修飾クラス名を使用しないために持っていることを私に思えます。しかし、私はまだ完全に修飾された名前でバージョンが動作しない理由を理解できません。

+1

このエラーを再現するためのサンプルプロジェクトを作成できますか。 –

答えて

1

nsマクロ内の:gen-classディレクティブは、同じ形式の副作用:requireとして生成されたクラスを参照できない可能性があります。 nsマクロによって生成されたコードはrequireのいずれかを呼び出す前にgen-classを呼び出します。したがって、gen-classが呼び出されると、必要な名前空間はまだコンパイルされません。 defrecordのクラスが生成される前にgen-classが呼び出されます。

nsの行動がmacroexpandを使用してin the source codeを見てもREPLですることができます。

(clojure.pprint/pprint (macroexpand '(ns sre.plan.compiler 
    (:require 
    [sre.plan.dsl.constraint :as constraint]) 
    (:import (sre.plan.dsl.constraint ConstraintLookup)) 
    (:gen-class 
    :name sre.plan.Compiler 
    :methods [^:static [makeConstraintLookupFromTargetsAndBounds 
         [Iterable Iterable] ConstraintLookup]])))) 
;; (do 
;; (clojure.core/in-ns 'sre.plan.compiler) 
;; (clojure.core/with-loading-context 
;; (clojure.core/gen-class 
;;  :name 
;;  "sre.plan.compiler" 
;;  :impl-ns 
;;  sre.plan.compiler 
;;  :main 
;;  true 
;;  :name 
;;  sre.plan.Compiler 
;;  :methods 
;;  [[makeConstraintLookupFromTargetsAndBounds 
;;  [Iterable Iterable] 
;;  ConstraintLookup]]) 
;; (clojure.core/refer 'clojure.core) 
;; (clojure.core/require '[sre.plan.dsl.constraint :as constraint]) 
;; (clojure.core/import '(sre.plan.dsl.constraint ConstraintLookup))) 
;; (if 
;; (.equals 'sre.plan.compiler 'clojure.core) 
;; nil 
;; (do 
;;  (clojure.core/dosync 
;;  (clojure.core/commute 
;;  @#'clojure.core/*loaded-libs* 
;;  clojure.core/conj 
;;  'sre.plan.compiler)) 
;;  nil))) 

問題を回避するために、我々はnsgen-classを呼び出すことができます。例:

(ns sre.plan.compiler 
    (:require 
    [sre.plan.dsl.constraint :as constraint]) 
    (:import (sre.plan.dsl.constraint ConstraintLookup))) 

(gen-class 
:impl-ns 
sre.plan.compiler 
:main 
true 
:name 
sre.plan.Compiler 
:methods 
[[makeConstraintLookupFromTargetsAndBounds 
    [Iterable Iterable] 
    sre.plan.dsl.constraint.ConstraintLookup]]) 
関連する問題