当前位置: 首页>>代码示例>>Java>>正文


Java Compiler类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.Compiler的典型用法代码示例。如果您正苦于以下问题:Java Compiler类的具体用法?Java Compiler怎么用?Java Compiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Compiler类属于org.eclipse.jdt.internal.compiler包,在下文中一共展示了Compiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performCompilation

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
public void performCompilation() {
    if(environment == null) {
        environment = this.getLibraryAccess();
    }

    this.startTime = System.currentTimeMillis();
    this.compilerOptions = new CompilerOptions(this.options);
    this.compilerOptions.performMethodsFullRecovery = false;
    this.compilerOptions.performStatementsRecovery = false;
    this.batchCompiler = new Compiler(environment, this.getHandlingPolicy(), this.compilerOptions, this.getBatchRequestor(), this.getProblemFactory(), this.out, this.progress);
    this.batchCompiler.remainingIterations = this.maxRepetition - this.currentRepetition;
    String setting = System.getProperty("jdt.compiler.useSingleThread");
    this.batchCompiler.useSingleThread = setting != null && setting.equals("true");

    this.compilerOptions.verbose = this.verbose;
    this.compilerOptions.produceReferenceInfo = this.produceRefInfo;

    try {
        this.logger.startLoggingSources();
        this.batchCompiler.compile(this.getCompilationUnits());
    } finally {
        this.logger.endLoggingSources();
    }
    this.logger.printStats();
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:27,代码来源:DSpotJDTBatchCompiler.java

示例2: compile

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
public void compile(Collection<Source> sources) {
    Timer timer = metric.startTimer("act:classload:compile:_all");
    int len = sources.size();
    ICompilationUnit[] compilationUnits = new ICompilationUnit[len];
    int i = 0;
    for (Source source: sources) {
        compilationUnits[i++] = source.compilationUnit();
    }
    IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
    IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);

    org.eclipse.jdt.internal.compiler.Compiler jdtCompiler = new Compiler(
            nameEnv, policy, compilerOptions, requestor, problemFactory) {
        @Override
        protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
        }
    };

    jdtCompiler.compile(compilationUnits);
    timer.stop();
}
 
开发者ID:actframework,项目名称:actframework,代码行数:22,代码来源:AppCompiler.java

示例3: incrementalCompilationLoop

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
/**
 * This loop handles the incremental compilation of classes in the compileQueue. Regular apt rounds may occur in this loop, but the apt final round will not.
 * 
 * This loop will be called once after the apt final round is processed to compile all effected types. All prior error/warn/info messages, referenced types, generated outputs and other per-input
 * information tracked by in build context are ignored when a type is recompiled.
 */
private void incrementalCompilationLoop(Classpath namingEnvironment, Compiler compiler, AnnotationProcessorManager aptmanager) throws IOException {
  while (!compileQueue.isEmpty() || !staleOutputs.isEmpty()) {
    processedQueue.clear();
    processedQueue.addAll(compileQueue.keySet());

    // All prior error/warn/info messages, referenced types, generated outputs and other per-input information tracked by in build context are wiped away within.
    processSources();

    // invoke the compiler
    ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
    compileQueue.clear();
    compiler.compile(compilationUnits);
    namingEnvironment.reset();

    if (aptmanager != null) {
      aptmanager.incrementalIterationReset();
    }

    deleteStaleOutputs(); // delete stale outputs and enqueue affected sources

    enqueueAffectedSources();
  }
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:30,代码来源:CompilerJdt.java

示例4: compile

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
public int compile(Classpath namingEnvironment, Compiler compiler) throws IOException {
  processSources();

  if (aptstate != null) {
    staleOutputs.addAll(aptstate.writtenOutputs);
    aptstate = null;
  }

  if (!compileQueue.isEmpty()) {
    ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
    compiler.compile(compilationUnits);
  }

  persistAnnotationProcessingState(compiler, null);

  deleteStaleOutputs();

  return compileQueue.size();
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:21,代码来源:CompilerJdt.java

示例5: compile

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
public CompilationResult compile(final Collection<String> sourceNames) {
	final Map<String, byte[]> compiled = new HashMap<String, byte[]>();
	final List<CompilationProblem> problems = new ArrayList<CompilationProblem>();

	final List<ICompilationUnit> compilationUnits = collectCompilationUnits(sourceNames, problems);

	// Exit if problems
	if (! problems.isEmpty()) {
		return new CompilationResult(problems);
	}

	// Setup compiler environment
	final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
	final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
	final INameEnvironment nameEnvironment = new NameEnvironment();
	final ICompilerRequestor compilerRequestor = new CompilerRequestor(problems, compiled);

	// Compile
	final Compiler compiler = new Compiler(nameEnvironment, policy, new CompilerOptions(STANDARD_OPTIONS),
			compilerRequestor, problemFactory);
	compiler.compile(compilationUnits.toArray(new ICompilationUnit[0]));

	return new CompilationResult(problems, compiled);
}
 
开发者ID:MattiasBuelens,项目名称:junit,代码行数:26,代码来源:EclipseCompiler.java

示例6: compileUnits

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
protected String compileUnits(final JRCompilationUnit[] units, String classpath, File tempDirFile)
{
	final INameEnvironment env = getNameEnvironment(units);

	final IErrorHandlingPolicy policy = 
		DefaultErrorHandlingPolicies.proceedWithAllProblems();

	final Map<String,String> settings = getJdtSettings();

	final IProblemFactory problemFactory = 
		new DefaultProblemFactory(Locale.getDefault());

	final CompilerRequestor requestor = getCompilerRequestor(units);

	final Compiler compiler = new Compiler(env, policy, settings, requestor, problemFactory);

	do
	{
		CompilationUnit[] compilationUnits = requestor.processCompilationUnits();

		compiler.compile(compilationUnits);
	}
	while (requestor.hasMissingMethods());
	
	requestor.processProblems();

	return requestor.getFormattedProblems();
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:30,代码来源:JRJdtCompiler.java

示例7: BindingKeyResolver

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
private BindingKeyResolver(BindingKeyParser parser, Compiler compiler, LookupEnvironment environment, CompilationUnitDeclaration outerMostParsedUnit, HashtableOfObject parsedUnits) {
	super(parser);
	this.compiler = compiler;
	this.environment = environment;
	this.outerMostParsedUnit = outerMostParsedUnit;
	this.resolvedUnits = parsedUnits;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:BindingKeyResolver.java

示例8: initializeAnnotationProcessorManager

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
protected void initializeAnnotationProcessorManager(Compiler newCompiler) {
	AbstractAnnotationProcessorManager annotationManager = JavaModelManager.getJavaModelManager().createAnnotationProcessorManager();
	if (annotationManager != null) {
		annotationManager.configureFromPlatform(newCompiler, this, this.javaBuilder.javaProject);
		annotationManager.setErr(new PrintWriter(System.err));
		annotationManager.setOut(new PrintWriter(System.out));
	}
	newCompiler.annotationProcessorManager = annotationManager;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:AbstractImageBuilder.java

示例9: getCompiler

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
/**
 * Creates and returns a compiler for this evaluator.
 */
Compiler getCompiler(ICompilerRequestor compilerRequestor) {
	CompilerOptions compilerOptions = new CompilerOptions(this.options);
	compilerOptions.performMethodsFullRecovery = true;
	compilerOptions.performStatementsRecovery = true;
	return new Compiler(
		this.environment,
		DefaultErrorHandlingPolicies.exitAfterAllProblems(),
		compilerOptions,
		compilerRequestor,
		this.problemFactory);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:Evaluator.java

示例10: persistAnnotationProcessingState

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
private void persistAnnotationProcessingState(Compiler compiler, AnnotationProcessingState carryOverState) {
  if (compiler.annotationProcessorManager == null) {
    return; // not processing annotations
  }
  final AnnotationProcessingState aptstate;
  if (carryOverState != null) {
    // incremental build did not need to process annotations, carry over the state and outputs to the next build
    aptstate = carryOverState;
    aptstate.writtenOutputs.forEach(context::markUptodateOutput);
  } else {
    AnnotationProcessorManager aptmanager = (AnnotationProcessorManager) compiler.annotationProcessorManager;
    aptstate = new AnnotationProcessingState(aptmanager.getProcessedSources(), aptmanager.getReferencedTypes(), aptmanager.getWittenOutputs());
  }
  context.setAttribute(ATTR_APTSTATE, aptstate);
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:16,代码来源:CompilerJdt.java

示例11: testBinaryOriginatingElements

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Test
public void testBinaryOriginatingElements() throws Exception {
  // the point of this test is to assert Filer#createSourceFile does not puke when originatingElements are not sources

  // originating source elements are used to cleanup generated outputs when corresponding sources change
  // originating binary elements are not currently fully supported and are not tracked during incremental build

  Classpath namingEnvironment = createClasspath();
  IErrorHandlingPolicy errorHandlingPolicy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
  IProblemFactory problemFactory = ProblemFactory.getProblemFactory(Locale.getDefault());
  CompilerOptions compilerOptions = new CompilerOptions();
  ICompilerRequestor requestor = null;
  Compiler compiler = new Compiler(namingEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory);

  EclipseFileManager fileManager = new EclipseFileManager(null, Charsets.UTF_8);
  File outputDir = temp.newFolder();
  fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outputDir));

  CompilerBuildContext context = null;
  Map<String, String> processorOptions = null;
  CompilerJdt incrementalCompiler = null;
  ProcessingEnvImpl env = new ProcessingEnvImpl(context, fileManager, processorOptions, compiler, incrementalCompiler);

  TypeElement typeElement = env.getElementUtils().getTypeElement("java.lang.Object");

  FilerImpl filer = new FilerImpl(null /* context */, fileManager, null /* compiler */, null /* env */);
  filer.createSourceFile("test.Source", typeElement);
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:29,代码来源:FilerImplTest.java

示例12: generateJavaClass

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
protected void generateJavaClass(JavaSource source) throws IOException {
    INameEnvironment env = new NameEnvironment(source);
    IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems();
    CompilerOptions options = getCompilerOptions();
    CompilerRequestor requestor = new CompilerRequestor();
    IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());

    Compiler compiler = new Compiler(env, policy, options, requestor, problemFactory);
    compiler.compile(new ICompilationUnit[] { new CompilationUnit(source) });

    if (requestor.hasErrors()) {
        String sourceCode = source.getSourceCode();
        String[] sourceCodeLines = sourceCode.split("(\r\n|\r|\n)", -1);
        StringBuilder sb = new StringBuilder();
        sb.append("Compilation failed.");
        sb.append('\n');
        for (IProblem p : requestor.getErrors()) {
            sb.append(p.getMessage()).append('\n');
            int start = p.getSourceStart();
            int column = start; // default
            for (int i = start; i >= 0; i--) {
                char c = sourceCode.charAt(i);
                if (c == '\n' || c == '\r') {
                    column = start - i;
                    break;
                }
            }
            sb.append(StringUtils.getPrettyError(sourceCodeLines, p.getSourceLineNumber(), column, p.getSourceStart(), p.getSourceEnd(), 3));
        }
        sb.append(requestor.getErrors().length);
        sb.append(" error(s)\n");
        throw new CompileErrorException(sb.toString());
    }

    requestor.save(source.getOutputdir());
}
 
开发者ID:subchen,项目名称:jetbrick-template-1x,代码行数:38,代码来源:JdtCompiler.java

示例13: compileUnits

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
/**
 *
 */
protected String compileUnits(final JRCompilationUnit[] units, String classpath, File tempDirFile) {
	final INameEnvironment env = getNameEnvironment(units);

	final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());

	final CompilerRequestor requestor = getCompilerRequestor(units);

	final Compiler compiler = new Compiler(env, policy, getJdtSettings(), requestor, problemFactory);

	do {
		CompilationUnit[] compilationUnits = requestor.processCompilationUnits();

		compiler.compile(compilationUnits);
	} while (requestor.hasMissingMethods());

	requestor.processProblems();

	return requestor.getFormattedProblems();
}
 
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:23,代码来源:JRJdtCompiler.java

示例14: configureFromPlatform

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
@Override
public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) {
	// Implemented by IdeAnnotationProcessorManager.
	throw new UnsupportedOperationException();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:BaseAnnotationProcessorManager.java

示例15: getCompiler

import org.eclipse.jdt.internal.compiler.Compiler; //导入依赖的package包/类
public Compiler getCompiler() {
	return _compiler;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:BaseProcessingEnvImpl.java


注:本文中的org.eclipse.jdt.internal.compiler.Compiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。