Skip to content
Permalink
Browse files
Generification
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/jci/trunk@1515205 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ebourg committed Aug 18, 2013
1 parent 4893326 commit 86b14671bcabec569688c682e1cddcde06c83baf
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 164 deletions.
@@ -61,7 +61,7 @@ public EclipseJavaCompiler() {
this(new EclipseJavaCompilerSettings());
}

public EclipseJavaCompiler( final Map pSettings ) {
public EclipseJavaCompiler( final Map<String, String> pSettings ) {
defaultSettings = new EclipseJavaCompilerSettings(pSettings);
}

@@ -139,7 +139,7 @@ public org.apache.commons.jci.compilers.CompilationResult compile(

final Map settingsMap = new EclipseJavaCompilerSettings(pSettings).toNativeSettings();

final Collection problems = new ArrayList();
final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>();

final ICompilationUnit[] compilationUnits = new ICompilationUnit[pSourceFiles.length];
for (int i = 0; i < compilationUnits.length; i++) {
@@ -345,9 +345,7 @@ public void cleanup() {
final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
public void acceptResult( final CompilationResult pResult ) {
if (pResult.hasProblems()) {
final IProblem[] iproblems = pResult.getProblems();
for (int i = 0; i < iproblems.length; i++) {
final IProblem iproblem = iproblems[i];
for (IProblem iproblem : pResult.getProblems()) {
final CompilationProblem problem = new EclipseCompilationProblem(iproblem);
if (problemHandler != null) {
problemHandler.handle(problem);
@@ -357,8 +355,7 @@ public void acceptResult( final CompilationResult pResult ) {
}
if (!pResult.hasErrors()) {
final ClassFile[] clazzFiles = pResult.getClassFiles();
for (int i = 0; i < clazzFiles.length; i++) {
final ClassFile clazzFile = clazzFiles[i];
for (ClassFile clazzFile : clazzFiles) {
final char[][] compoundName = clazzFile.getCompoundName();
final StringBuilder clazzName = new StringBuilder();
for (int j = 0; j < compoundName.length; j++) {
@@ -29,7 +29,7 @@
*/
public final class EclipseJavaCompilerSettings extends JavaCompilerSettings {

final private Map defaultEclipseSettings = new HashMap();
final private Map<String, String> defaultEclipseSettings = new HashMap<String, String>();

public EclipseJavaCompilerSettings() {
defaultEclipseSettings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
@@ -46,11 +46,11 @@ public EclipseJavaCompilerSettings( final JavaCompilerSettings pSettings ) {
}
}

public EclipseJavaCompilerSettings( final Map pMap ) {
public EclipseJavaCompilerSettings( final Map<String, String> pMap ) {
defaultEclipseSettings.putAll(pMap);
}

private static Map nativeVersions = new HashMap() {
private static Map<String, String> nativeVersions = new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("1.1", CompilerOptions.VERSION_1_1);
@@ -63,7 +63,7 @@ public EclipseJavaCompilerSettings( final Map pMap ) {
}};

private String toNativeVersion( final String pVersion ) {
final String nativeVersion = (String) nativeVersions.get(pVersion);
final String nativeVersion = nativeVersions.get(pVersion);

if (nativeVersion == null) {
throw new RuntimeException("unknown version " + pVersion);
@@ -72,8 +72,8 @@ private String toNativeVersion( final String pVersion ) {
return nativeVersion;
}

Map toNativeSettings() {
final Map map = new HashMap(defaultEclipseSettings);
Map<String, String> toNativeSettings() {
final Map<String, String> map = new HashMap<String, String>(defaultEclipseSettings);

map.put(CompilerOptions.OPTION_SuppressWarnings, isWarnings()?CompilerOptions.GENERATE:CompilerOptions.DO_NOT_GENERATE);
map.put(CompilerOptions.OPTION_ReportDeprecation, isDeprecations()?CompilerOptions.GENERATE:CompilerOptions.DO_NOT_GENERATE);
@@ -21,7 +21,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.jci.problems.CompilationProblem;
@@ -80,24 +79,22 @@ public CompilationResult compile(
unit.addSource(source[i]);
}

final Collection problems = new ArrayList();
final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>();

try {
log.debug("compiling");
unit.compile(Phases.CLASS_GENERATION);

final List classes = unit.getClasses();
for (final Iterator it = classes.iterator(); it.hasNext();) {
final GroovyClass clazz = (GroovyClass) it.next();
final List<GroovyClass> classes = (List<GroovyClass>) unit.getClasses();
for (GroovyClass clazz : classes) {
final byte[] bytes = clazz.getBytes();
pStore.write(ConversionUtils.convertClassToResourcePath(clazz.getName()), bytes);
}
} catch (final MultipleCompilationErrorsException e) {
final ErrorCollector col = e.getErrorCollector();
final Collection warnings = col.getWarnings();
final Collection<WarningMessage> warnings = (Collection<WarningMessage>) col.getWarnings();
if (warnings != null) {
for (final Iterator it = warnings.iterator(); it.hasNext();) {
final WarningMessage warning = (WarningMessage) it.next();
for (WarningMessage warning : warnings) {
final CompilationProblem problem = new GroovyCompilationProblem(warning);
if (problemHandler != null) {
problemHandler.handle(problem);
@@ -106,10 +103,9 @@ public CompilationResult compile(
}
}

final Collection errors = col.getErrors();
final Collection<Message> errors = (Collection<Message>) col.getErrors();
if (errors != null) {
for (final Iterator it = errors.iterator(); it.hasNext();) {
final Message message = (Message) it.next();
for (Message message : errors) {
final CompilationProblem problem = new GroovyCompilationProblem(message);
if (problemHandler != null) {
problemHandler.handle(problem);
@@ -104,7 +104,7 @@ public void close() throws IOException {

public CompilationResult compile( final String[] pSourceNames, final ResourceReader pResourceReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings ) {

final Collection problems = new ArrayList();
final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>();

final StringPattern[] pattern = StringPattern.PATTERNS_NONE;

@@ -24,6 +24,7 @@
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.readers.ResourceReader;
@@ -67,7 +68,7 @@ private final class RhinoCompilingClassLoader extends ClassLoader {
private final ResourceReader reader;
private final ResourceStore store;

private final Collection problems = new ArrayList();
private final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>();

private final class ProblemCollector implements ErrorReporter {

@@ -109,7 +110,7 @@ public RhinoCompilingClassLoader( final ResourceReader pReader, final ResourceSt
Context.exit();
}

public Collection getProblems() {
public Collection<CompilationProblem> getProblems() {
return problems;
}

@@ -143,7 +144,7 @@ private Class compileClass( final Context pContext, final String pClassName) thr
superclass = Class.forName((String) baseClassName);
}

final ArrayList interfaceClasses = new ArrayList();
final List<Class> interfaceClasses = new ArrayList<Class>();

final Object interfaceNames = ScriptableObject.getProperty(target, "__implements__");

@@ -265,7 +266,7 @@ public CompilationResult compile( final String[] pResourcePaths, final ResourceR
}
}

final Collection problems = cl.getProblems();
final Collection<CompilationProblem> problems = cl.getProblems();
final CompilationProblem[] result = new CompilationProblem[problems.size()];
problems.toArray(result);
return new CompilationResult(result);
@@ -41,7 +41,7 @@ public void testSimpleCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();

final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
final private Map<String, byte[]> sources = new HashMap<String, byte[]>() {
private static final long serialVersionUID = 1L;
{
put("jci/Simple.js", (
@@ -51,7 +51,7 @@ public void testSimpleCompile() throws Exception {
}};

public byte[] getBytes( final String pResourceName ) {
return (byte[]) sources.get(pResourceName);
return sources.get(pResourceName);
}

public boolean isAvailable( final String pResourceName ) {
@@ -84,7 +84,7 @@ public void testUppercasePackageNameCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();

final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
final private Map<String, byte[]> sources = new HashMap<String, byte[]>() {
private static final long serialVersionUID = 1L;
{
put("Jci/Simple.js", (
@@ -94,7 +94,7 @@ public void testUppercasePackageNameCompile() throws Exception {
}};

public byte[] getBytes( final String pResourceName ) {
return (byte[]) sources.get(pResourceName);
return sources.get(pResourceName);
}

public boolean isAvailable( final String pResourceName ) {
@@ -35,11 +35,10 @@ public final class CompilationResult {
private final CompilationProblem[] warnings;

public CompilationResult( final CompilationProblem[] pProblems ) {
final Collection errorsColl = new ArrayList();
final Collection warningsColl = new ArrayList();
final Collection<CompilationProblem> errorsColl = new ArrayList<CompilationProblem>();
final Collection<CompilationProblem> warningsColl = new ArrayList<CompilationProblem>();

for (int i = 0; i < pProblems.length; i++) {
final CompilationProblem problem = pProblems[i];
for (CompilationProblem problem : pProblems) {
if (problem.isError()) {
errorsColl.add(problem);
} else {
@@ -37,7 +37,7 @@ public final class JavaCompilerFactory {
*/
private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();

private final Map classCache = new HashMap();
private final Map<String, Class> classCache = new HashMap<String, Class>();

/**
* @deprecated will be remove after the next release, please create an instance yourself
@@ -20,7 +20,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.jci.compilers.CompilationResult;
import org.apache.commons.jci.compilers.JavaCompiler;
@@ -99,20 +98,18 @@ public void onStart( final FilesystemAlterationObserver pObserver ) {
}

public String[] getResourcesToCompile( final FilesystemAlterationObserver pObserver ) {
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection<File> created = getCreatedFiles();
final Collection<File> changed = getChangedFiles();

final Collection resourceNames = new ArrayList();
final Collection<String> resourceNames = new ArrayList<String>();

for (final Iterator it = created.iterator(); it.hasNext();) {
final File createdFile = (File) it.next();
for (File createdFile : created) {
if (createdFile.getName().endsWith(getSourceFileExtension())) {
resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
}
}

for (final Iterator it = changed.iterator(); it.hasNext();) {
final File changedFile = (File) it.next();
for (File changedFile : changed) {
if (changedFile.getName().endsWith(getSourceFileExtension())) {
resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
}
@@ -126,16 +123,14 @@ public String[] getResourcesToCompile( final FilesystemAlterationObserver pObser
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
boolean reload = false;

final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
final Collection<File> created = getCreatedFiles();
final Collection<File> changed = getChangedFiles();
final Collection<File> deleted = getDeletedFiles();

log.debug("created:" + created.size() + " changed:" + changed.size() + " deleted:" + deleted.size() + " resources");

if (deleted.size() > 0) {
for (Iterator it = deleted.iterator(); it.hasNext();) {
final File deletedFile = (File) it.next();

for (File deletedFile : deleted) {
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), deletedFile));

if (resourceName.endsWith(getSourceFileExtension())) {
@@ -21,7 +21,6 @@
import java.io.FileInputStream;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.io.IOUtils;
@@ -44,7 +43,7 @@ public class ReloadingListener extends AbstractFilesystemAlterationListener {

private final Log log = LogFactory.getLog(ReloadingListener.class);

private final Set notificationListeners = new HashSet();
private final Set<ReloadNotificationListener> notificationListeners = new HashSet<ReloadNotificationListener>();
private final ResourceStore store;

public ReloadingListener() {
@@ -71,24 +70,22 @@ public void addReloadNotificationListener( final ReloadNotificationListener pNot
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
boolean reload = false;

final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
final Collection<File> created = getCreatedFiles();
final Collection<File> changed = getChangedFiles();
final Collection<File> deleted = getDeletedFiles();

log.debug("created:" + created.size() + " changed:" + changed.size() + " deleted:" + deleted.size() + " resources");

if (deleted.size() > 0) {
for (Iterator it = deleted.iterator(); it.hasNext();) {
final File file = (File) it.next();
for (File file : deleted) {
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.remove(resourceName);
}
reload = true;
}

if (created.size() > 0) {
for (Iterator it = created.iterator(); it.hasNext();) {
final File file = (File) it.next();
for (File file : created) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
@@ -104,8 +101,7 @@ public boolean isReloadRequired( final FilesystemAlterationObserver pObserver )
}

if (changed.size() > 0) {
for (Iterator it = changed.iterator(); it.hasNext();) {
final File file = (File) it.next();
for (File file : changed) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
@@ -145,10 +141,7 @@ public void onStop( final FilesystemAlterationObserver pObserver ) {
}

void notifyReloadNotificationListeners() {

for (Iterator it = notificationListeners.iterator(); it.hasNext();) {
final ReloadNotificationListener listener = (ReloadNotificationListener) it.next();

for (ReloadNotificationListener listener : notificationListeners) {
log.debug("notifying listener " + listener);

listener.handleNotification();
@@ -52,15 +52,15 @@ public byte[] getBytes( final String pResourceName ) {
* @deprecated
*/
public String[] list() {
final List files = new ArrayList();
final List<String> files = new ArrayList<String>();
list(root, files);
return (String[]) files.toArray(new String[files.size()]);
}

/**
* @deprecated
*/
private void list( final File pFile, final List pFiles ) {
private void list( final File pFile, final List<String> pFiles ) {
if (pFile.isDirectory()) {
final File[] directoryFiles = pFile.listFiles();
for (int i = 0; i < directoryFiles.length; i++) {

0 comments on commit 86b1467

Please sign in to comment.