Bug 107798 - Supported Compiler API
Summary: Supported Compiler API
Status: RESOLVED DUPLICATE of bug 81471
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-23 17:35 EDT by Gili Mendel CLA
Modified: 2006-02-16 07:55 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gili Mendel CLA 2005-08-23 17:35:44 EDT
VE may use the JDT compiler to compile (EMF) JavaJet templates on the fly.  The
compiled templates are than used by VE to generate code.   The .class, and .java
files are not in any workspace project, and these artifacts are placed in the VE
plugin's metadata.

All the JDT compiler API today are internal.
Comment 1 Olivier Thomann CLA 2005-08-23 20:20:13 EDT
I think this will be done when the jsr199 will be publicly available.
Comment 2 Jerome Lanneluc CLA 2005-09-20 06:54:13 EDT

*** This bug has been marked as a duplicate of 81471 ***
Comment 3 Philipe Mulet CLA 2005-11-09 07:15:18 EST
Gili,

How much do you exactly need there ? The JSR-199 will likely require JRE 1.6
classlibs, and is not going to be a happy scenario for you I guess.

Are you trying to perform validation on the fly ? If so, is that much different
from JSP validation done by WTP in essence ? If not, then I believe you should
use a similar approach, which is entirely based on our public API; e.g. you can
compile a file in memory using workingCopy and reconcile operation.
Comment 4 Gili Mendel CLA 2005-11-09 07:51:45 EST
It has been a while since I have been in this area of the code; it might be that
there is a better way to do this in 3.1.  In essence here is the problem I am
solving:


I have a .javajet file.... it is similar (content/semantic) to a .jsp file. 
This file will be (EMF JavaJet) translated to a .java file.  The .java file will
be then compiled to a .class and loaded.  The loaded class is a CodeGen template
that VE uses to generate code.  Upfront, these .javajets are compiled.  Bug,
when the .javajet is modified (user customization), VE will reTranslate/Compile
and load the new CodeGen template on the fly.

The .javajet/.java/.class are not in any IProject; they are all stored in the
VE's .metadata area.  The following is the snippet of code that I using today;
it is internal, and I would like to stop using it this way.   Is there any other
way to solve this problem, or is there any support that you can provide so that
I can use formal API.


		EmitterCompilationUnit[] cu = new EmitterCompilationUnit[] { new
EmitterCompilationUnit()};
		INameEnvironment env = new FileSystem(classPath, new String[0], fEncodeing);
		tick(pm);
		IErrorHandlingPolicy errorPolicy =
DefaultErrorHandlingPolicies.exitOnFirstError();
		IProblemFactory problemFactory =
org.eclipse.jdt.internal.core.builder.ProblemFactory.getProblemFactory(java.util.Locale.getDefault());
		EmiterCompilerRequestor requestor = new EmiterCompilerRequestor();
		org.eclipse.jdt.internal.compiler.Compiler cmp = new
org.eclipse.jdt.internal.compiler.Compiler(env, errorPolicy,
JavaCore.getOptions(), requestor, problemFactory);
		tick(pm);

		cmp.compile(cu);
		if (requestor.getErrCount() > 0)
			throw new TemplatesException("SyntaxError: " +
requestor.getProblems()[0].getMessage()); //$NON-NLS-1$
		tick(pm);
		env.cleanup();


Comment 5 Philipe Mulet CLA 2005-11-10 07:55:47 EST
Couldn't you contribute a builder for producing the .java file simply ? Then the
Java builder will consume it and produce the .class files.
Comment 6 Philipe Mulet CLA 2005-11-10 07:57:43 EST
Alternatively, could you wait until we implement JSR199 which will require a 1.6
JRE ? (i.e. likely to be addressed LATER).
Comment 7 Gili Mendel CLA 2005-11-10 09:16:41 EST
... creating a meta .java file and push it onto a user's a project, drive a
build, and snatch the .class, and clean up is kind of heavy (not to mention the
hack factor ;-).


VE is not going to be using JRE1.6 for a while.

Comment 8 Philipe Mulet CLA 2005-11-10 09:46:21 EST
Ok, but can you remain on the internal API until we come up with jsr199
implementation ? I am reluctant to add an API which is soon going to be
obsoleted by jsr199. If we end up with 2 APIs to maintain it is overkill.
Comment 9 Philipe Mulet CLA 2005-11-18 13:04:17 EST
Gili - do you agree to wait until we provide a compiler API based on JSR199 ? In
the meantime, you can stay on internal side, it is not changing much anyway at
this level.
Comment 10 Gili Mendel CLA 2005-11-21 10:52:32 EST
Sure thing, assume that the internals will not change much and be there until we get to JSR199. 
Comment 11 Philipe Mulet CLA 2005-11-21 11:03:57 EST
Ok, then it is really a dup of bug 81471.
Comment 12 Philipe Mulet CLA 2006-02-16 07:55:57 EST
FYI, here is a note I just posted on jdt-dev-core mailing list, pls respond there.
============================
If you are NOT using compiler internal API IProblemFactory, then you may ignore this note.

The current definition of IProblemFactory says that #createProblem(...) is answering 
org.eclipse.jdt.core.compiler.IProblem.
We would like to change this into org.eclipse.jdt.core.compiler.CategorizedProblem

CategorizedProblem is an extension of IProblem introduced in 3.2, which offers possibility
to categorize problems better and have participant issue their own problems in a non
colliding fashion (i.e. no longer need to worry about colliding problem IDs).

Since IProblemFactory is not public API, this is not a breaking change; but they are a few
users of our batch compiler technology out there, and we would like them to speak up if
they want to veto this change. 

If we do not perform the change, then we internally need to swallow arbitrary IProblem
and CategorizedProblem, which is causing unnecessary pain.

NOTE: if you are simply using: org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory
then no change is required, since it will get leveraged for free.

This is what IProblemFactory would look like after the change:

package org.eclipse.jdt.internal.compiler;
import java.util.Locale;
import org.eclipse.jdt.core.compiler.*;
public interface IProblemFactory {
	CategorizedProblem createProblem(
		char[] originatingFileName,
		int problemId,
		String[] problemArguments,
		String[] messageArguments, // shorter versions of the problemArguments
		int severity,
		int startPosition,
		int endPosition,
		int lineNumber);
	Locale getLocale();
	String getLocalizedMessage(int problemId, String[] messageArguments);