Commit 81a7fd27 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Remove CompilationRounfds.

parent cdd5fc64
/***
* Juliac
* Copyright (C) 2007-2017 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: fractal@ow2.org
*
* Author: Lionel Seinturier
*/
package org.objectweb.fractal.juliac;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.fractal.juliac.conf.JuliacConfig;
/**
* This class manages the compilation rounds generated by Juliac.
* Each compilation round contains a list of input files which need to be
* compiled.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
*/
public class CompilationRounds {
public CompilationRounds( JuliacConfig jconf ) {
this.jconf = jconf;
}
/**
* Return a new compilation round.
*/
public CompilationRound newCompilationRound() {
CompilationRound round = new CompilationRound(jconf);
rounds.add(round);
return round;
}
/**
* Return the compilation rounds.
*
* @since 2.2.4
*/
public List<CompilationRound> getCompilationRounds() {
return rounds;
}
/**
* Return the current compilation round.
*/
public CompilationRound getCurrentCompilationRound() {
int idx = rounds.size();
if( idx == 0 ) {
CompilationRound round = newCompilationRound();
return round;
}
CompilationRound round = rounds.get(idx-1);
return round;
}
/**
* Return <code>true</code> if the specified file has already been generated
* in one of the compilation rounds associated with this instance.
*/
public boolean contains( SourceFile sf ) {
for (CompilationRound round : rounds) {
boolean b = round.contains(sf);
if(b) return true;
}
return false;
}
/**
* Return <code>true</code> if the specified qualified name has already been
* generated in one of the compilation rounds associated with this instance.
*
* @since 2.7
*/
public boolean contains( String qname ) {
for (CompilationRound round : rounds) {
boolean b = round.contains(qname);
if(b) return true;
}
return false;
}
/**
* Return the source type that triggered the generation of the specified
* qualifed name type.
*
* @since 2.7
*/
public Object getSourceType( String qname ) {
for (CompilationRound round : rounds) {
if( round.contains(qname) ) {
Object sourceType = round.getSourceType(qname);
return sourceType;
}
}
return null;
}
// --------------------------------------------------------------------
// Data
// --------------------------------------------------------------------
private List<CompilationRound> rounds = new ArrayList<>();
private JuliacConfig jconf;
}
......@@ -384,8 +384,7 @@ public class Juliac {
URI uri = generateSourceCodeOverride(scg);
JuliacConfig jconf = getJuliacConfig();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = jconf.getCompilationRound();
Object sourceType = scg.getSourceType();
round.addGenerated(
new SourceFileDir(uri,targetClassName,"java"), sourceType );
......@@ -446,11 +445,11 @@ public class Juliac {
public boolean hasBeenGenerated( String name ) {
JuliacConfig jconf = getJuliacConfig();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = jconf.getCompilationRound();
// Check whether the type has been generated by Juliac
SourceFile igf = new SourceFileDir(null,name,"java");
if( rounds.contains(igf) ) {
if( round.contains(igf) ) {
return true;
}
......@@ -505,7 +504,7 @@ public class Juliac {
// ----------------------------------------------------------------------
// Methods for compiling and packaging code
// Methods for compiling code
// ----------------------------------------------------------------------
/**
......@@ -513,15 +512,13 @@ public class Juliac {
* contained in the current compilation round. Move to the next compilation
* round.
*
* @return the current compilation round
* @since 2.0
*/
public CompilationRound build() throws IOException {
public void build() throws IOException {
JuliacConfig jconf = getJuliacConfig();
Logger logger = jconf.getLogger();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = jconf.getCompilationRound();
/*
* Compile input and generated source files.
......@@ -559,14 +556,7 @@ public class Juliac {
total+" file(s) compiled to "+
round.getClassDir().getAbsolutePath();
logger.info(msg);
}
/*
* Move to the next compilation round.
*/
rounds.newCompilationRound();
return round;
}
}
/**
......@@ -574,10 +564,9 @@ public class Juliac {
* contained in the current compilation round. Move to the next compilation
* round. Only errors are reported.
*
* @return the current compilation round
* @since 2.2.4
*/
public CompilationRound buildQuiet() throws IOException {
public void buildQuiet() throws IOException {
/*
* Copy/paste of the #compile() method without log invocations. Getting
......@@ -589,17 +578,11 @@ public class Juliac {
*/
JuliacConfig jconf = getJuliacConfig();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = jconf.getCompilationRound();
// Compile input and generated source files
CompileSupportItf compiler = lookupUnique(CompileSupportItf.class);
round.compile(compiler);
// Move to the next compilation round
rounds.newCompilationRound();
return round;
}
......
......@@ -37,10 +37,8 @@ import java.util.logging.Logger;
import javax.annotation.processing.ProcessingEnvironment;
import org.objectweb.fractal.juliac.CompilationRound;
import org.objectweb.fractal.juliac.CompilationRounds;
import org.objectweb.fractal.juliac.SourceFile;
import org.objectweb.fractal.juliac.commons.io.FileHelper;
import org.objectweb.fractal.juliac.module.SpoonSupportItf;
/**
* This class manages the Juliac configuration parameters.
......@@ -141,7 +139,7 @@ public class JuliacConfig {
Charset.defaultCharset().displayName();
private ClassLoader classLoader;
private CompilationRounds rounds;
private CompilationRound round;
/**
* The default logger.
......@@ -236,9 +234,9 @@ public class JuliacConfig {
* Add the specified location to the list of locations. A location denotes
* either an absolute path or a path relative to {@link #baseDir}, for a
* directory or a jar file. All source files contained in the specified
* location are registered with the {@link CompilationRounds} API for being
* location are registered with the CompilationRound API for being
* compiled when requested (see {@link #build()}) or processed by the
* juliac-spoon module (see {@link SpoonSupportItf}.)
* juliac-spoon module (see SpoonSupportImpl.)
*
* @param src the location to add
* @throws IOException
......@@ -257,8 +255,7 @@ public class JuliacConfig {
/*
* Register the source files with the current compilation round.
*/
CompilationRounds rounds = getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = getCompilationRound();
round.addInput(sfs);
srcs.add(src);
......@@ -382,11 +379,11 @@ public class JuliacConfig {
// Setter/getter methods for loaders and compilation rounds
// ----------------------------------------------------------------------
public CompilationRounds getCompilationRounds() {
if( rounds == null ) {
rounds = new CompilationRounds(this);
public CompilationRound getCompilationRound() {
if( round == null ) {
round = new CompilationRound(this);
}
return rounds;
return round;
}
public ClassLoader getClassLoader() {
......
......@@ -41,7 +41,6 @@ import javax.lang.model.element.TypeElement;
import javax.tools.JavaFileObject;
import org.objectweb.fractal.juliac.CompilationRound;
import org.objectweb.fractal.juliac.CompilationRounds;
import org.objectweb.fractal.juliac.SourceFileDir;
import org.objectweb.fractal.juliac.adlet.api.annotation.Mixin;
import org.objectweb.fractal.juliac.adlet.helper.AnnotatedConstructHelper;
......@@ -153,8 +152,7 @@ public class MixinProcessor extends AbstractJuliacProcessor {
* Add the generated file to the current compilation round.
*/
JuliacConfig jconf = jc.getJuliacConfig();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = jconf.getCompilationRound();
URI uri = sourceFile.toUri();
round.addGenerated(new SourceFileDir(uri,targetClassName,"java"),null);
}
......
......@@ -39,7 +39,7 @@ import javax.lang.model.util.Elements;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.fraclet.annotations.Lifecycle;
import org.objectweb.fractal.fraclet.types.Step;
import org.objectweb.fractal.juliac.CompilationRounds;
import org.objectweb.fractal.juliac.CompilationRound;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.adlet.helper.TypeElementHelper;
import org.objectweb.fractal.juliac.api.JuliacRuntimeException;
......@@ -149,10 +149,10 @@ extends org.objectweb.fractal.juliac.fraclet.InitializerOOCtrlClassGenerator {
* by this method. This is then safe to retrieve the corresponding
* information contained in the source type.
*/
CompilationRounds rounds = jconf.getCompilationRounds();
boolean b = rounds.contains(contentClassName);
CompilationRound round = jconf.getCompilationRound();
boolean b = round.contains(contentClassName);
if(b) {
cl = (TypeElement) rounds.getSourceType(contentClassName);
cl = (TypeElement) round.getSourceType(contentClassName);
}
else {
final String msg =
......
......@@ -35,7 +35,6 @@ import java.util.Map;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.objectweb.fractal.juliac.CompilationRound;
import org.objectweb.fractal.juliac.CompilationRounds;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.SourceFile;
import org.objectweb.fractal.juliac.SourceFileDir;
......@@ -277,8 +276,7 @@ public class SpoonSupportImpl implements SpoonSupportItf {
throw new IOException(msg);
}
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
CompilationRound round = jconf.getCompilationRound();
URI uri = files.get(0).toURI();
round.addGenerated(new SourceFileDir(uri,name,"java"),null);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment