Commit 3becab22 authored by Philippe Merle's avatar Philippe Merle
Browse files

* Improved the code quality according to checking rules of Sonar.

* Cosmetic updates.
parent 6cdda1d0
......@@ -54,17 +54,18 @@ public class FrascatiBindingJnaProcessor
// Internal methods.
// --------------------------------------------------------------------------
/*
/**
* @see org.ow2.frascati.assembly.factory.processor.AbstractProcessor#toStringBuffer(EObjectType, StringBuffer)
*/
@Override
protected final void toStringBuffer(JnaBinding jnaBinding, StringBuffer sb) {
protected final void toStringBuffer(JnaBinding jnaBinding, StringBuffer sb)
{
sb.append("binding.jna");
append(sb, "library", jnaBinding.getLibrary());
super.toStringBuffer(jnaBinding, sb);
}
/*
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#check(ElementType, ProcessingContext)
*/
@Override
......@@ -80,7 +81,7 @@ public class FrascatiBindingJnaProcessor
checkBinding(jnaBinding, processingContext);
}
/*
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#generate(ElementType, ProcessingContext)
*/
@Override
......@@ -90,7 +91,7 @@ public class FrascatiBindingJnaProcessor
logFine(jnaBinding, "nothing to generate");
}
/*
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#instantiate(ElementType, ProcessingContext)
*/
@Override
......@@ -114,7 +115,7 @@ public class FrascatiBindingJnaProcessor
logFine(jnaBinding, "importing done");
}
/*
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#complete(ElementType, ProcessingContext)
*/
@Override
......@@ -128,10 +129,11 @@ public class FrascatiBindingJnaProcessor
// Public methods.
// --------------------------------------------------------------------------
/*
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#getProcessorID()
*/
public final String getProcessorID() {
public final String getProcessorID()
{
return getID(NativePackage.Literals.JNA_BINDING);
}
}
......@@ -20,7 +20,7 @@
*
* Author: Romain Rouvoy
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
package org.ow2.frascati.native_;
......@@ -32,6 +32,7 @@ import java.io.IOException;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.assembly.factory.api.ProcessorException;
import org.ow2.frascati.assembly.factory.processor.AbstractInterfaceProcessor;
......@@ -43,41 +44,45 @@ import org.ow2.frascati.component.factory.api.MembraneGeneration;
* @author <a href="mailto:romain.rouvoy@lifl.fr">Romain Rouvoy</a>
* @version 1.3
*/
public class FraSCAtiInterfaceNativeProcessor extends
AbstractInterfaceProcessor<NativeInterface> {
public class FraSCAtiInterfaceNativeProcessor
extends AbstractInterfaceProcessor<NativeInterface>
{
// ---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
@Reference(name = "native-compiler")
// ---------------------------------------------------------------------------
@Reference(name = "native-compiler")
private NativeCompiler compiler;
/** Reference to Juliac configuration. */
@Reference(name = "membrane-generation")
protected MembraneGeneration membraneGen;
private MembraneGeneration membraneGen;
@Property(name = "target-directory")
protected String targetDir = "native";
private String targetDir = "native";
// ---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/* (non-Javadoc)
/**
* @see org.ow2.frascati.assembly.factory.processor.AbstractInterfaceProcessor#toStringBuffer(org.eclipse.stp.sca.Interface, java.lang.StringBuffer)
*/
@Override
protected void toStringBuffer(NativeInterface nativeItf, StringBuffer sb) {
protected final void toStringBuffer(NativeInterface nativeItf, StringBuffer sb)
{
sb.append("native:interface.native");
append(sb, "descriptor", nativeItf.getDescriptor());
super.toStringBuffer(nativeItf, sb);
}
/* (non-Javadoc)
/**
* @see org.ow2.frascati.assembly.factory.processor.AbstractProcessor#doCheck(org.eclipse.emf.ecore.EObject, org.ow2.frascati.assembly.factory.api.ProcessingContext)
*/
@Override
protected void doCheck(NativeInterface nativeItf,
ProcessingContext processingContext) throws ProcessorException {
protected final void doCheck(NativeInterface nativeItf,
ProcessingContext processingContext) throws ProcessorException
{
// Check the attribute 'descriptor'
String desc = nativeItf.getDescriptor();
if (desc == null || desc.equals("")) {
......@@ -88,37 +93,40 @@ public class FraSCAtiInterfaceNativeProcessor extends
}
File file = new File(desc);
if (!file.exists())
if (!file.exists()) {
log.severe("The descriptor '" + desc
+ "' does not exist on the system.");
else if (!file.canRead())
} else if (!file.canRead()) {
log.severe("The descriptor '" + desc + "' is not readable.");
}
String javaInterface = this.compiler.packageName(file) + "."
+ this.compiler.interfaceName(file);
Class<?> clazz = null;
try {
clazz = processingContext.loadClass(javaInterface);
storeJavaInterface(nativeItf, processingContext, javaInterface, clazz);
} catch (ClassNotFoundException cnfe) {
// If the Java interface is not found then this requires to compile Native to Java.
}
storeJavaInterface(nativeItf, processingContext, javaInterface, clazz);
}
/* (non-Javadoc)
/**
* @see org.ow2.frascati.assembly.factory.processor.AbstractProcessor#doGenerate(org.eclipse.emf.ecore.EObject, org.ow2.frascati.assembly.factory.api.ProcessingContext)
*/
@Override
protected void doGenerate(NativeInterface nativeItf,
ProcessingContext processingContext) throws ProcessorException {
protected final void doGenerate(NativeInterface nativeItf,
ProcessingContext processingContext) throws ProcessorException
{
// If no Java interface computed during doCheck() then compile
if (getClass(nativeItf, processingContext) != null)
if (getClass(nativeItf, processingContext) != null) {
return;
}
final String filename = nativeItf.getDescriptor();
if (this.log.isLoggable(INFO))
if (this.log.isLoggable(INFO)) {
this.log.info("Compiling the descriptor '" + filename + "'...");
}
File output = new File(this.membraneGen.getOutputDirectory() + "/"
+ targetDir);
......@@ -135,12 +143,13 @@ public class FraSCAtiInterfaceNativeProcessor extends
// ---------------------------------------------------------------------------
// Public methods.
// --------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/* (non-Javadoc)
/**
* @see org.ow2.frascati.assembly.factory.api.Processor#getProcessorID()
*/
public String getProcessorID() {
public final String getProcessorID()
{
return getID(NativePackage.Literals.NATIVE_INTERFACE);
}
}
......@@ -20,7 +20,7 @@
*
* Author: Romain Rouvoy
*
* Contributor(s):
* Contributor(s): Philippe Merle
*
*/
package org.ow2.frascati.native_;
......@@ -35,6 +35,7 @@ import java.util.logging.Logger;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.util.AbstractLoggeable;
import com.ochafik.lang.jnaerator.JNAerator;
......@@ -50,14 +51,17 @@ import com.ochafik.lang.jnaerator.JNAeratorConfig;
* @version 1.3
*/
@Scope("COMPOSITE")
public class JNAeratorCompiler extends AbstractLoggeable implements
NativeCompiler {
public class JNAeratorCompiler
extends AbstractLoggeable
implements NativeCompiler
{
private final JNAeratorConfig cfg = new JNAeratorConfig();
private final Feedback feedback = new FraSCAtiCompilerFeedback(log);
private final JNAerator generator = new JNAerator(this.cfg);
@Init
public void init() {
public final void init()
{
this.cfg.compile = false;
this.cfg.skipLibraryInstanceDeclarations = true;
this.cfg.followIncludes = true;
......@@ -65,79 +69,95 @@ public class JNAeratorCompiler extends AbstractLoggeable implements
this.cfg.autoConf = true;
}
/* (non-Javadoc)
/**
* @see org.ow2.frascati.native_.NativeCompiler#interfaceName(java.io.File)
*/
public String interfaceName(File file) {
public final String interfaceName(File file)
{
String itf = packageName(file);
return itf.substring(0, 1).toUpperCase()+itf.substring(1)+"Library";
}
/* (non-Javadoc)
/**
* @see org.ow2.frascati.native_.NativeCompiler#packageName(java.io.File)
*/
public String packageName(File file) {
public final String packageName(File file)
{
return file.getName().substring(0, file.getName().indexOf('.'));
}
/* (non-Javadoc)
/**
* @see org.ow2.frascati.native_.NativeCompiler#compile(java.io.File, java.io.File)
*/
public void compile(File file, File output) throws IOException {
public final void compile(File file, File output) throws IOException
{
this.cfg.outputDir = output;
if (!this.cfg.outputDir.exists())
if (!this.cfg.outputDir.exists()) {
this.cfg.outputDir.mkdirs();
}
this.cfg.addSourceFile(file, packageName(file), true);
this.generator.jnaerate(this.feedback);
}
private static final class FraSCAtiCompilerFeedback implements Feedback {
private static final class FraSCAtiCompilerFeedback implements Feedback
{
private final Logger logger;
public FraSCAtiCompilerFeedback(Logger log) {
public FraSCAtiCompilerFeedback(Logger log)
{
this.logger = log;
}
/* (non-Javadoc)
/**
* @see com.ochafik.lang.jnaerator.JNAerator.Feedback#setFinished(java.io.File)
*/
public void setFinished(File file) {
if (this.logger.isLoggable(INFO))
public final void setFinished(File file)
{
if (this.logger.isLoggable(INFO)) {
this.logger.info("File '" + file.getName()
+ "' has been successfully generated.");
}
}
/* (non-Javadoc)
/**
* @see com.ochafik.lang.jnaerator.JNAerator.Feedback#setFinished(java.lang.Throwable)
*/
public void setFinished(Throwable error) {
if (this.logger.isLoggable(SEVERE))
public final void setFinished(Throwable error)
{
if (this.logger.isLoggable(SEVERE)) {
this.logger.log(SEVERE, "File failed to generate.", error);
}
}
/* (non-Javadoc)
/**
* @see com.ochafik.lang.jnaerator.JNAerator.Feedback#setStatus(java.lang.String)
*/
public void setStatus(String status) {
if (this.logger.isLoggable(FINE))
public void setStatus(String status)
{
if (this.logger.isLoggable(FINE)) {
this.logger.fine("Status is '" + status + "'");
}
}
/* (non-Javadoc)
/**
* @see com.ochafik.lang.jnaerator.JNAerator.Feedback#sourcesParsed(com.ochafik.lang.jnaerator.SourceFiles)
*/
public void sourcesParsed(SourceFiles sources) {
if (this.logger.isLoggable(FINE))
public void sourcesParsed(SourceFiles sources)
{
if (this.logger.isLoggable(FINE)) {
this.logger.fine("Parsed sources are: "
+ sources.getNameSpace());
}
}
/* (non-Javadoc)
/**
* @see com.ochafik.lang.jnaerator.JNAerator.Feedback#wrappersGenerated(com.ochafik.lang.jnaerator.Result)
*/
public void wrappersGenerated(Result result) {
if (this.logger.isLoggable(FINE))
public void wrappersGenerated(Result result)
{
if (this.logger.isLoggable(FINE)) {
this.logger.fine("Generated wrappers are: " + result);
}
}
}
}
......@@ -34,7 +34,8 @@ import java.io.IOException;
* @author <a href="mailto:romain.rouvoy@lifl.fr">Romain Rouvoy</a>
* @version 1.3
*/
public interface NativeCompiler {
public interface NativeCompiler
{
/**
* Provides the name of the generated interface.
*
......@@ -60,4 +61,4 @@ public interface NativeCompiler {
* compile
*/
void compile(File library, File output) throws IOException;
}
\ No newline at end of file
}
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