com.thoughtworks.qdox.model.impl.DefaultJavaModuleDescriptor Maven / Gradle / Ivy
package com.thoughtworks.qdox.model.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaModule;
import com.thoughtworks.qdox.model.JavaModuleDescriptor;
import com.thoughtworks.qdox.model.JavaPackage;
public class DefaultJavaModuleDescriptor implements JavaModuleDescriptor
{
private String name;
private boolean open;
private Collection requires = new ArrayList();
private Collection exports = new ArrayList();
private Collection opens = new ArrayList();
private Collection uses = new ArrayList();
private Collection provides = new ArrayList();
public DefaultJavaModuleDescriptor( String name )
{
this.name = name;
}
/** {@inheritDoc} */
public String getName()
{
return name;
}
public void setOpen( boolean open )
{
this.open = open;
}
/** {@inheritDoc} */
public boolean isOpen()
{
return open;
}
public void addExports( DefaultJavaExports exports )
{
this.exports.add( exports );
}
/** {@inheritDoc} */
public Collection getExports()
{
return Collections.unmodifiableCollection( exports );
}
public void addOpens( DefaultJavaOpens opens )
{
this.opens.add( opens );
}
/** {@inheritDoc} */
public Collection getOpens()
{
return Collections.unmodifiableCollection( opens );
}
public void addRequires( DefaultJavaRequires requires )
{
this.requires.add( requires );
}
/** {@inheritDoc} */
public Collection getRequires()
{
return Collections.unmodifiableCollection( requires );
}
public void addProvides( DefaultJavaProvides provides )
{
this.provides.add( provides);
}
/** {@inheritDoc} */
public Collection getProvides()
{
return Collections.unmodifiableCollection( provides );
}
public void addUses( DefaultJavaUses uses)
{
this.uses.add( uses );
}
/** {@inheritDoc} */
public Collection getUses()
{
return Collections.unmodifiableCollection( uses );
}
public static class DefaultJavaExports extends AbstractJavaModel implements JavaModuleDescriptor.JavaExports
{
private JavaPackage source;
private Collection targets;
public DefaultJavaExports( JavaPackage source, Collection targets )
{
this.source = source;
this.targets = targets;
}
/** {@inheritDoc} */
public JavaPackage getSource()
{
return source;
}
/** {@inheritDoc} */
public Collection getTargets()
{
if( targets == null )
{
return Collections.emptyList();
}
else
{
return targets;
}
}
/** {@inheritDoc} */
public String getCodeBlock()
{
return getModelWriter().writeModuleExports( this ).toString();
}
}
public static class DefaultJavaOpens extends AbstractJavaModel implements JavaModuleDescriptor.JavaOpens
{
private JavaPackage source;
private Collection targets;
public DefaultJavaOpens( JavaPackage source, Collection targets )
{
this.source = source;
this.targets = targets;
}
public String source()
{
return source.getName();
}
/** {@inheritDoc} */
public JavaPackage getSource()
{
return source;
}
/** {@inheritDoc} */
public Collection getTargets()
{
if( targets == null )
{
return Collections.emptyList();
}
else
{
return targets;
}
}
public Set targets()
{
if( targets == null )
{
return Collections.emptySet();
}
else
{
Set targetValues = new LinkedHashSet( targets.size() );
for ( JavaModule target : targets )
{
targetValues.add( target.getName() );
}
return Collections.unmodifiableSet( targetValues );
}
}
/** {@inheritDoc} */
public String getCodeBlock()
{
return getModelWriter().writeModuleOpens( this ).toString();
}
}
public static class DefaultJavaProvides extends AbstractJavaModel implements JavaModuleDescriptor.JavaProvides
{
private JavaClass service;
private List providers;
public DefaultJavaProvides( JavaClass service, List providers )
{
super();
this.service = service;
this.providers = providers;
}
/** {@inheritDoc} */
public JavaClass getService()
{
return service;
}
/** {@inheritDoc} */
public List getProviders()
{
return providers;
}
/** {@inheritDoc} */
public String getCodeBlock()
{
return getModelWriter().writeModuleProvides( this ).toString();
}
}
public static class DefaultJavaRequires extends AbstractJavaModel implements JavaModuleDescriptor.JavaRequires
{
private JavaModule module;
private Collection modifiers;
public DefaultJavaRequires( JavaModule module, Collection modifiers )
{
this.module = module;
this.modifiers = modifiers;
}
/** {@inheritDoc} */
public JavaModule getModule()
{
return module;
}
/** {@inheritDoc} */
public boolean isTransitive()
{
return getModifiers().contains( "transitive" );
}
/** {@inheritDoc} */
public boolean isStatic()
{
return getModifiers().contains( "static" );
}
/** {@inheritDoc} */
public Collection getModifiers()
{
if( modifiers == null )
{
return Collections.emptyList();
}
else
{
return modifiers;
}
}
/** {@inheritDoc} */
public String getCodeBlock()
{
return getModelWriter().writeModuleRequires( this ).toString();
}
}
public static class DefaultJavaUses extends AbstractJavaModel implements JavaModuleDescriptor.JavaUses
{
private JavaClass service;
public DefaultJavaUses( JavaClass service )
{
this.service = service;
}
/** {@inheritDoc} */
public JavaClass getService()
{
return service;
}
/** {@inheritDoc} */
public String getCodeBlock()
{
return getModelWriter().writeModuleUses( this ).toString();
}
}
}