forked from INRIA/spoon
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
239 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package spoon.reflect; | ||
|
||
import java.util.Collection; | ||
|
||
import spoon.processing.Processor; | ||
import spoon.reflect.declaration.CtPackage; | ||
import spoon.reflect.declaration.CtType; | ||
|
||
/** represents a Java program, modeled by a set of compile-time (Ct) objects | ||
* where each objects is a program element (for instance, a CtClass represents a class). | ||
*/ | ||
public interface CtModel { | ||
|
||
/** returns the root package */ | ||
CtPackage getRootPackage(); | ||
|
||
/** returns all types of the model */ | ||
Collection<CtType<?>> getAllTypes(); | ||
|
||
/** returns all packages of the model */ | ||
Collection<CtPackage> getAllPackages(); | ||
|
||
/** process this model with the given processor */ | ||
void processWith(Processor<?> abstractProcessor); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package spoon.reflect; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import spoon.processing.ProcessingManager; | ||
import spoon.processing.Processor; | ||
import spoon.reflect.declaration.CtElement; | ||
import spoon.reflect.declaration.CtPackage; | ||
import spoon.reflect.declaration.CtType; | ||
import spoon.reflect.declaration.ParentNotInitializedException; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.reflect.visitor.CtVisitor; | ||
import spoon.reflect.visitor.filter.TypeFilter; | ||
import spoon.support.QueueProcessingManager; | ||
import spoon.support.reflect.declaration.CtElementImpl; | ||
import spoon.support.reflect.declaration.CtPackageImpl; | ||
|
||
public class CtModelImpl implements CtModel { | ||
|
||
private static class CtRootPackage extends CtPackageImpl { | ||
{ | ||
this.setSimpleName(CtPackage.TOP_LEVEL_PACKAGE_NAME); | ||
this.setParent(new CtElementImpl() { | ||
@Override | ||
public void accept(CtVisitor visitor) { | ||
|
||
} | ||
|
||
@Override | ||
public CtElement getParent() throws ParentNotInitializedException { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
// @Override | ||
// public | ||
// <T extends CtPackage> T addPackage(CtPackage pack) { | ||
// packs.add(pack); | ||
// return (T)this; | ||
// } | ||
|
||
@Override | ||
public String getSimpleName() { | ||
return super.getSimpleName(); | ||
} | ||
|
||
@Override | ||
public String getQualifiedName() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return packs.size() + " packages"; | ||
} | ||
|
||
} | ||
|
||
private CtPackage rootPackage = new CtRootPackage(); | ||
|
||
public CtModelImpl(Factory f) { | ||
rootPackage.setFactory(f); | ||
} | ||
|
||
@Override | ||
public CtPackage getRootPackage() { | ||
return rootPackage; | ||
} | ||
|
||
|
||
@Override | ||
public Collection<CtType<?>> getAllTypes() { | ||
return Collections.unmodifiableCollection(rootPackage.getElements(new TypeFilter<CtType<?>>(CtType.class))); | ||
} | ||
|
||
|
||
@Override | ||
public Collection<CtPackage> getAllPackages() { | ||
return Collections.unmodifiableCollection(rootPackage.getElements(new TypeFilter<>(CtPackage.class))); | ||
} | ||
|
||
|
||
@Override | ||
public void processWith(Processor<?> abstractProcessor) { | ||
// processing (consume all the processors) | ||
ProcessingManager processing = new QueueProcessingManager(rootPackage.getFactory()); | ||
processing.process(getRootPackage()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.