Compiler API

Hi,

Can someone please provide some information (and example) of how to use the newly opened Compiler API. In particular, how is the ValidityState supposed to be used? What does it represent?.

Thanks,

Daniel

6 comments
Comment actions Permalink

Okay, let me be a little more specific.

Im writing a new Compiler using the recently opened Compiler Open API. I want this compiler to process and modify my source code prior to compilation, so I am implementing the SourceInstrumentingCompiler interface.

In the getInstrumentationItems method, I am reading through the CompileScope to determine which files I want to instrument. I return a set of InstrumentationItem instances containing references to these virtual files.

In the instrument method, I take these virtual files, copy them to a new location, and change them. When I am finished, I return a set of InstrumentationItem instances that now contain references to these newly created virtual files.

My problem is this. The files that are compiled by the build process are the original files, not the modified source files.

Can someone please tell me if I am using Compiler API correctly?. Is there something I can do to determine where things are going astray?. Is this a bug with the API?.

Thanks.

0
Comment actions Permalink

Hi Daniel,
The only wrong assumption is that compiler will compile the new VirtualFiles.
The SourceInstrumenting compiler is supposed to modify existing files ("instrument' them). The set of InstrumentationItems that is
returned after instrumentation is supposed to be the set of items for which the instrumentation succeeded.

The ValidityState is an object that helps IDEA understand whether the associated VirtualFile should be considered as "changed". The
file is considered changed if saved ValidityState differs from the ValidityState that is returned by the compiler. Usual
implementation of this interface is a timestamp. That way the file is considered changed if its timestamp differs from the one
previously recorded. However, some compilers may want to implement more complex notion of "change" (for example you want IDEA's make
consider the file as "changed" if at least one of its dependent files is modified) and ValidityState abstractions allows this.

--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Hi Eugene,

That all makes sense, but leaves me with the problem of which compiler type is appropriate?

My requirements are that I wish to be able to change the java source prior to it being compiled. These changes 'instrument' the source code, and as such, should not be visible to the user, nor do they need to exist after the source is compiled.

So, effectively, I would like to be able to redirect the compiler to compile the modified source 'instead of' the original source. Is there a way to achieve this?

Some options that I am considering are:
a) implementing my own VirtualFile that is backed by the modified source rather then the original, yet will retain the name of the original file.
b) implementing a translating compiler that modifies AND compiles the source. I would prefer to IDEA handle the compilation of the file.

Thoughts?

-Daniel

0
Comment actions Permalink

Hmmm, scrap option A.

0
Comment actions Permalink

I think wwe'd better add a new compiler cathegory something like a "transformation compiler". Please file an SCR
Meanwhile you may stick with the instrumenting compiler and let the user see changes it made.
--

Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

"Daniel" <no_mail@jetbrains.com> wrote in message news:19854296.1081220923921.JavaMail.itn@is.intellij.net...

Hi Eugene,

>

That all makes sense, but leaves me with the problem of which compiler type is appropriate?

>

My requirements are that I wish to be able to change the java source prior to it being compiled. These changes 'instrument' the

source code, and as such, should not be visible to the user, nor do they need to exist after the source is compiled.
>

So, effectively, I would like to be able to redirect the compiler to compile the modified source 'instead of' the original source.

Is there a way to achieve this?
>

Some options that I am considering are:
a) implementing my own VirtualFile that is backed by the modified source rather then the original, yet will retain the name of the

original file.

b) implementing a translating compiler that modifies AND compiles the source. I would prefer to IDEA handle the compilation of the

file.
>

Thoughts?

>

-Daniel



0
Comment actions Permalink

Thanks Eugene,

Have raised an SCR.

-Daniel

0

Please sign in to leave a comment.