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.
adds support for incremental model (INRIA#584)
- Loading branch information
Showing
17 changed files
with
415 additions
and
100 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,48 @@ | ||
/** | ||
* Copyright (C) 2006-2015 INRIA and contributors | ||
* Spoon - http://spoon.gforge.inria.fr/ | ||
* | ||
* This software is governed by the CeCILL-C License under French law and | ||
* abiding by the rules of distribution of free software. You can use, modify | ||
* and/or redistribute the software under the terms of the CeCILL-C license as | ||
* circulated by CEA, CNRS and INRIA at http://www.cecill.info. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. | ||
* | ||
* The fact that you are presently reading this means that you have had | ||
* knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
package spoon.reflect; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import spoon.processing.Processor; | ||
import spoon.reflect.declaration.CtElement; | ||
import spoon.reflect.declaration.CtPackage; | ||
import spoon.reflect.declaration.CtType; | ||
import spoon.reflect.visitor.Filter; | ||
|
||
/** 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 top-level 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<?> processor); | ||
|
||
/** Returns all the model elements matching the filter. */ | ||
<E extends CtElement> List<E> getElements(Filter<E> filter); | ||
|
||
} |
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,111 @@ | ||
/** | ||
* Copyright (C) 2006-2015 INRIA and contributors | ||
* Spoon - http://spoon.gforge.inria.fr/ | ||
* | ||
* This software is governed by the CeCILL-C License under French law and | ||
* abiding by the rules of distribution of free software. You can use, modify | ||
* and/or redistribute the software under the terms of the CeCILL-C license as | ||
* circulated by CEA, CNRS and INRIA at http://www.cecill.info. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. | ||
* | ||
* The fact that you are presently reading this means that you have had | ||
* knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
package spoon.reflect; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
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; | ||
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 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() { | ||
List<CtType<?>> types = new ArrayList<CtType<?>>(); | ||
for (CtPackage pack : getAllPackages()) { | ||
types.addAll(pack.getTypes()); | ||
} | ||
return types; | ||
} | ||
|
||
|
||
@Override | ||
public Collection<CtPackage> getAllPackages() { | ||
return Collections.unmodifiableCollection(rootPackage.getElements(new TypeFilter<CtPackage>(CtPackage.class))); | ||
} | ||
|
||
|
||
@Override | ||
public void processWith(Processor<?> processor) { | ||
new QueueProcessingManager(rootPackage.getFactory()).process(getRootPackage()); | ||
} | ||
|
||
@Override | ||
public <E extends CtElement> List<E> getElements(Filter<E> filter) { | ||
return getRootPackage().getElements(filter); | ||
} | ||
|
||
} |
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
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.