Skip to content

Commit

Permalink
imports only for true source entities
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenson committed Nov 20, 2013
1 parent c3bb7c6 commit a26a160
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
package org.jboss.forge.parser.java;

import org.jboss.forge.parser.Internal;
import org.jboss.forge.parser.java.ReadJavaSource.JavaSource;

/**
* Represents an imported element in a {@link JavaSource}.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface ReadImport extends Internal
public interface Import extends Internal
{
public String getPackage();

Expand All @@ -25,10 +28,7 @@ public interface ReadImport extends Internal

public boolean isWildcard();

public interface Import extends ReadImport
{
public Import setName(final String name);
public Import setName(final String name);

public Import setStatic(final boolean value);
}
public Import setStatic(final boolean value);
}
124 changes: 124 additions & 0 deletions api/src/main/java/org/jboss/forge/parser/java/Importer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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.java.ReadJavaSource.JavaSource;

/**
* Defines the aspect of {@link JavaSource} that handles type imports.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public interface Importer<O extends JavaSource<O>>
{
/**
* Return whether or not this {@link O} has an import for the given {@link Class} type.
*/
boolean hasImport(Class<?> type);

/**
* Return whether or not this {@link O} has an import for the given fully-qualified class name.
*/
boolean hasImport(String type);

/**
* Return whether or not this {@link O} could accept an import for the given {@link Class} type.
*/
boolean requiresImport(Class<?> type);

/**
* Return whether or not this {@link O} could accept an import for the given fully-qualified class name.
*/
boolean requiresImport(String type);

/**
* Return whether or not this {@link O} has an import for the given {@link T} type.
*/
public <T extends ReadJavaSource<T>> boolean hasImport(T type);

/**
* Return whether or not this {@link O} has the given {@link Import} type.
*/
public boolean hasImport(Import imprt);

/**
* Get the {@link Import} for the given fully-qualified class name, if it exists; otherwise, return null;
*/
public Import getImport(String literalValue);

/**
* Get the {@link Import} for the given {@link Class} type, if it exists; otherwise, return null;
*/
public Import getImport(Class<?> type);

/**
* Get the {@link Import} for the given {@link T} type, if it exists; otherwise, return null;
*/
public <T extends ReadJavaSource<?>> Import getImport(T type);

/**
* Get the {@link Import} of the given {@link Import} type, if it exists; otherwise, return null;
*/
public Import getImport(Import imprt);

/**
* Get an immutable list of all {@link Import}s currently imported by this {@link O}
*/
public List<Import> getImports();

/**
* Given a simple or qualified type, resolve that type against the available imports and return the referenced type.
* If the type cannot be resolved, return the given type unchanged.
*/
public String resolveType(String type);

/**
* Add an import by qualified class name. (E.g: "com.example.Imported") unless it is in the provided 'java.lang.*'
* package.
*/
public Import addImport(final String className);

/**
* Add an import for the given {@link Class} type.
*/
public Import addImport(final Class<?> type);

/**
* Add an import for the given {@link Import} type.
*/
public Import addImport(Import imprt);

/**
* Add an import for the given {@link ReadJavaSource} type.
*/
public <T extends ReadJavaSource<?>> Import addImport(T type);

/**
* Remove any {@link Import} for the given fully-qualified class name, if it exists; otherwise, do nothing;
*/
public O removeImport(String name);

/**
* Remove any {@link Import} for the given {@link Class} type, if it exists; otherwise, do nothing;
*/
public O removeImport(Class<?> type);

/**
* Remove any {@link Import} for the given {@link T} type, if it exists; otherwise, do nothing;
*/
public <T extends ReadJavaSource<?>> O removeImport(T type);

/**
* Remove the given {@link Import} from this {@link O} instance, if it exists; otherwise, do nothing;
*/
public O removeImport(Import imprt);

}
151 changes: 0 additions & 151 deletions api/src/main/java/org/jboss/forge/parser/java/ReadImporter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
public interface ReadJavaSource<T extends ReadJavaSource<T>> extends
ReadPackaged<T>,
ReadImporter<T>,
ReadNamed,
ReadVisibilityScoped,
ReadAnnotationTarget<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import org.jboss.forge.parser.ParserException;
import org.jboss.forge.parser.java.ReadAnnotation;
import org.jboss.forge.parser.java.ReadAnnotation.Annotation;
import org.jboss.forge.parser.java.ReadImport;
import org.jboss.forge.parser.java.ReadImport.Import;
import org.jboss.forge.parser.java.Import;
import org.jboss.forge.parser.java.ReadInterfaceCapable.InterfaceCapable;
import org.jboss.forge.parser.java.ReadJavaInterface;
import org.jboss.forge.parser.java.ReadJavaSource;
Expand Down Expand Up @@ -160,7 +159,7 @@ public <T extends ReadJavaSource<?>> Import addImport(final T type)
}

@Override
public Import addImport(final ReadImport imprt)
public Import addImport(final Import imprt)
{
return addImport(imprt.getQualifiedName()).setStatic(imprt.isStatic());
}
Expand Down Expand Up @@ -218,7 +217,7 @@ public <T extends ReadJavaSource<?>> Import getImport(final T type)
}

@Override
public Import getImport(final ReadImport imprt)
public Import getImport(final Import imprt)
{
return getImport(imprt.getQualifiedName());
}
Expand Down Expand Up @@ -249,7 +248,7 @@ public <T extends ReadJavaSource<T>> boolean hasImport(final T type)
}

@Override
public boolean hasImport(final ReadImport imprt)
public boolean hasImport(final Import imprt)
{
return hasImport(imprt.getQualifiedName());
}
Expand Down Expand Up @@ -330,7 +329,7 @@ public String resolveType(final String type)

if (result.equals(original))
{
for (ReadImport imprt : getImports())
for (Import imprt : getImports())
{
if (Types.areEquivalent(result, imprt.getQualifiedName()))
{
Expand All @@ -344,7 +343,7 @@ public String resolveType(final String type)
// If we didn't match any imports directly, we might have a wild-card/on-demand import.
if (Types.isSimpleName(result))
{
for (ReadImport imprt : getImports())
for (Import imprt : getImports())
{
if (imprt.isWildcard())
{
Expand Down Expand Up @@ -396,7 +395,7 @@ private boolean validImport(final String type)
@Override
public O removeImport(final String name)
{
for (ReadImport i : getImports())
for (Import i : getImports())
{
if (i.getQualifiedName().equals(name))
{
Expand All @@ -420,7 +419,7 @@ public <T extends ReadJavaSource<?>> O removeImport(final T type)
}

@Override
public O removeImport(final ReadImport imprt)
public O removeImport(final Import imprt)
{
Object internal = imprt.getInternal();
if (unit.imports().contains(internal))
Expand Down Expand Up @@ -775,7 +774,7 @@ public List<String> getInterfaces()
String name = JDTHelper.getTypeName(type);
if (Types.isSimpleName(name) && this.hasImport(name))
{
ReadImport imprt = this.getImport(name);
Import imprt = this.getImport(name);
String pkg = imprt.getPackage();
if (!Strings.isNullOrEmpty(pkg))
{
Expand Down
Loading

0 comments on commit a26a160

Please sign in to comment.