Skip to content

Commit

Permalink
Created parser-java addon
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Dec 18, 2012
1 parent 96d4858 commit ea3fc20
Show file tree
Hide file tree
Showing 117 changed files with 11,851 additions and 0 deletions.
12 changes: 12 additions & 0 deletions parser-java/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge</groupId>
<artifactId>parser-java-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>parser-java-api</artifactId>
<name>Forge - Java Parser Addon API</name>
</project>
24 changes: 24 additions & 0 deletions parser-java/api/src/main/java/org/jboss/forge/parser/Internal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.parser;

/**
* Represents an object that stores implementation-specific data. This data must be accessible to other objects sharing
* the implementation, but should not be referenced by end-users.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface Internal
{
/**
* Returns the implementation-specific Object representing <code>this</code>. <b>Do not call this method</b> unless
* you are willing to risk breaking backwards compatibility if future versions do not use the same internal object
* implementations.
*/
Object getInternal();
}
122 changes: 122 additions & 0 deletions parser-java/api/src/main/java/org/jboss/forge/parser/JavaParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.parser;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import org.jboss.forge.parser.java.JavaClass;
import org.jboss.forge.parser.java.JavaSource;
import org.jboss.forge.parser.spi.JavaParserProvider;

/**
* Responsible for parsing data into new {@link JavaClass} instances.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public final class JavaParser
{
public static ServiceLoader<JavaParserProvider> loader = ServiceLoader.load(JavaParserProvider.class);
private static List<JavaParserProvider> parsers;

private static JavaParserProvider getParser()
{
if (parsers == null)
{
parsers = new ArrayList<JavaParserProvider>();
for (JavaParserProvider p : loader)
{
parsers.add(p);
}
}
if (parsers.size() == 0)
{
throw new IllegalStateException("No instances of [" + JavaParserProvider.class.getName()
+ "] were found on the classpath.");
}
return parsers.get(0);
}

/**
* Open the given {@link File}, parsing its contents into a new {@link JavaClass} instance.
*/
public static JavaSource<?> parse(final File file) throws FileNotFoundException
{
return getParser().parse(file);
}

/**
* Read the given {@link InputStream} and parse the data into a new {@link JavaClass} instance.
*/
public static JavaSource<?> parse(final InputStream data)
{
return getParser().parse(data);
}

/**
* Parse the given character array into a new {@link JavaClass} instance.
*/
public static JavaSource<?> parse(final char[] data)
{
return getParser().parse(data);
}

/**
* Parse the given String data into a new {@link JavaClass} instance.
*/
public static JavaSource<?> parse(final String data)
{
return getParser().parse(data);
}

/**
* Create a new empty {@link JavaClass} instance.
*/
public static <T extends JavaSource<?>> T create(final Class<T> type)
{
return getParser().create(type);
}

/**
* Read the given {@link File} and parse its data into a new {@link JavaSource} instance of the given type.
*
* @throws FileNotFoundException
*/
public static <T extends JavaSource<?>> T parse(final Class<T> type, final File file) throws FileNotFoundException
{
return getParser().parse(type, file);
}

/**
* Read the given {@link InputStream} and parse its data into a new {@link JavaSource} instance of the given type.
*/
public static <T extends JavaSource<?>> T parse(final Class<T> type, final InputStream data)
{
return getParser().parse(type, data);
}

/**
* Read the given character array and parse its data into a new {@link JavaSource} instance of the given type.
*/
public static <T extends JavaSource<?>> T parse(final Class<T> type, final char[] data)
{
return getParser().parse(type, data);
}

/**
* Read the given string and parse its data into a new {@link JavaSource} instance of the given type.
*/
public static <T extends JavaSource<?>> T parse(final Class<T> type, final String data)
{
return getParser().parse(type, data);
}
}
23 changes: 23 additions & 0 deletions parser-java/api/src/main/java/org/jboss/forge/parser/Origin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.parser;


/**
* Represents an object that has a root ancestor that should be made accessible
* to its clients.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface Origin<T>
{
/**
* @return the instance of the root ancestor.
*/
T getOrigin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.parser;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class ParserException extends RuntimeException
{
private static final long serialVersionUID = 642493448571856848L;

public ParserException()
{
}

public ParserException(final String message)
{
super(message);
}

public ParserException(final Throwable e)
{
super(e);
}

public ParserException(final String message, final Throwable e)
{
super(message, e);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.parser.java;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface Abstractable<T>
{
public abstract boolean isAbstract();

public abstract T setAbstract(boolean abstrct);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.parser.java;

import java.util.List;

import org.jboss.forge.parser.Internal;
import org.jboss.forge.parser.Origin;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface Annotation<O extends JavaSource<O>> extends Internal, Origin<O>
{
boolean isSingleValue();

boolean isMarker();

boolean isNormal();

String getName();

String getQualifiedName();

<T extends Enum<T>> T getEnumValue(Class<T> type);

<T extends Enum<T>> T getEnumValue(Class<T> type, String name);

String getLiteralValue();

String getLiteralValue(String name);

List<ValuePair> getValues();

String getStringValue();

String getStringValue(String name);

Annotation<O> removeValue(String name);

Annotation<O> removeAllValues();

Annotation<O> setName(String className);

Annotation<O> setEnumValue(String name, Enum<?> value);

Annotation<O> setEnumValue(Enum<?>... value);

Annotation<O> setLiteralValue(String value);

Annotation<O> setLiteralValue(String name, String value);

Annotation<O> setStringValue(String value);

Annotation<O> setStringValue(String name, String value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.parser.java;

import java.util.List;

import org.jboss.forge.parser.Internal;
import org.jboss.forge.parser.Origin;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface AnnotationTarget<O extends JavaSource<O>, T> extends Internal, Origin<O>
{
/**
* Add a new annotation instance to this {@link T}. (Note that an import statement must be added manually if
* required.)
*/
public abstract Annotation<O> addAnnotation();

/**
* Add a new annotation instance to this {@link T}, using the given {@link Class} as the annotation type. Attempt to
* add an import statement to this object's {@link O} if required.
*/
public abstract Annotation<O> addAnnotation(Class<? extends java.lang.annotation.Annotation> type);

/**
* Add a new annotation instance to this {@link T}, using the given {@link String} className as the annotation type.
* Attempt to add an import statement to this object's {@link O} if required. (Note that the given className must be
* fully-qualified in order to properly import required classes)
*/
public abstract Annotation<O> addAnnotation(final String className);

public abstract List<Annotation<O>> getAnnotations();

public boolean hasAnnotation(final Class<? extends java.lang.annotation.Annotation> type);

public boolean hasAnnotation(final String type);

public Annotation<O> getAnnotation(final Class<? extends java.lang.annotation.Annotation> type);

public Annotation<O> getAnnotation(final String type);

public abstract T removeAnnotation(Annotation<O> annotation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.parser.java;

import org.jboss.forge.parser.Internal;
import org.jboss.forge.parser.Origin;

public interface EnumConstant<O extends JavaSource<O>> extends Internal, Origin<O>
{
/**
* Get this enum constant name.
*/
String getName();

/**
* Set this enum constant name.
*/
EnumConstant<O> setName(String name);
}
Loading

0 comments on commit ea3fc20

Please sign in to comment.