本文整理汇总了Java中org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java NamespaceDeclaration类的具体用法?Java NamespaceDeclaration怎么用?Java NamespaceDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NamespaceDeclaration类属于org.aikodi.chameleon.core.namespacedeclaration包,在下文中一共展示了NamespaceDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: packagePredicate
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
protected UniversalPredicate<? super Type,Nothing> packagePredicate(AnalysisOptions options) {
List<String> packageNames = packageNames((DependencyOptions) options);
UniversalPredicate<? super Type,Nothing> result;
if(packageNames.isEmpty()) {
result = new True();
} else {
result = new False();
for(final String string: packageNames) {
result = result.or(
new UniversalPredicate<Type,Nothing>(Type.class) {
@Override
public boolean uncheckedEval(Type object) {
return new GlobPredicate(string,'.').eval(object.nearestAncestor(NamespaceDeclaration.class).namespace().fullyQualifiedName());
}
}).makeUniversal(Type.class);
}
}
return result;
}
示例2: toCodeNamespaceDeclaration
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public String toCodeNamespaceDeclaration(NamespaceDeclaration part) {
StringBuffer result = new StringBuffer();
result.append("package "+toCode(part.namespaceReference())+";\n\n");
for(Import imp: part.explicitImports()) {
result.append(toCode(imp));
}
result.append("\n");
Collection<Type> types = part.declarations(Type.class);
new SafePredicate<Type>() {
public boolean eval(Type o) {
return !(o instanceof ArrayType);
}
}.filter(types);
Iterator iter = types.iterator();
while(iter.hasNext()) {
result.append(toCode((Element)iter.next()));
if(iter.hasNext()) {
result.append("\n\n");
}
}
return result.toString();
}
示例3: write
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public void write() throws IOException, ModelException {
Syntax writer = view().language().plugin(Syntax.class);
int i = 1;
for(Type type:typeProvider().elements(view())) {
if(type.nearestAncestor(Type.class) == null) {
String fileName = type.name()+".java";
String packageFQN = type.nearestAncestor(NamespaceDeclaration.class).namespace().fullyQualifiedName();
String relDirName = packageFQN.replace('.', File.separatorChar);
File out = new File(outputDirName()+File.separatorChar + relDirName + File.separatorChar + fileName);
System.out.println(i + " Writing: "+out.getAbsolutePath());
File parent = out.getParentFile();
parent.mkdirs();
out.createNewFile();
FileWriter fw = new FileWriter(out);
fw.write(writer.toCode(type.parent()));
fw.close();
i++;
}
}
}
示例4: visitCompilationUnit
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
@Override
public Element visitCompilationUnit(CompilationUnitContext ctx) {
NamespaceDeclaration ns;
if(ctx.namespace() != null) {
ns = visitNamespace(ctx.namespace());
} else {
ns = factory().createRootNamespaceDeclaration();
}
for(ImportDeclarationContext id: ctx.importDeclaration()) {
ns.addImport(visitImportDeclaration(id));
}
List<KlassContext> klasses = ctx.klass();
for(KlassContext klas : klasses) {
ns.add(visitKlass(klas));
}
_document.add(ns);
return _document;
}
示例5: toCodeCompilationUnit
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public String toCodeCompilationUnit(Document cu) {
StringBuffer result = new StringBuffer();
for(NamespaceDeclaration part: cu.namespaceDeclarations()) {
result.append(toCodeNamespaceDeclaration(part));
}
return result.toString();
}
示例6: writeCode
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public static void writeCode(Arguments arguments) throws IOException {
Java7Syntax writer = new Java7Syntax(2);
List<Type> types = arguments.getTypes();
new SafePredicate<Type>() {
public boolean eval(Type t) {
return t.is(((Java7)t.language()).PUBLIC) == Ternary.TRUE;
}
}.filter(types);
int i = 1;
for(Type type:types) {
String fileName = type.name()+".java";
String packageFQN = type.nearestAncestor(NamespaceDeclaration.class).namespace().fullyQualifiedName();
String relDirName = packageFQN.replace('.', File.separatorChar);
File out = new File(arguments.getOutputDirName()+File.separatorChar + relDirName + File.separatorChar + fileName);
System.out.println(i + " Writing: "+out.getAbsolutePath());
File parent = out.getParentFile();
parent.mkdirs();
out.createNewFile();
FileWriter fw = new FileWriter(out);
fw.write(writer.toCode((Element)type.parent()));
fw.close();
i++;
}
}
示例7: targetDeclarations
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
@Override
public List<Declaration> targetDeclarations(String name) throws LookupException {
try {
load();
} catch (InputException e) {
throw new LookupException("Error opening file",e);
}
// Since we load a class file, there is only 1 top-level declaration: the class or interface defined in the class file.
// Other top-level classes or interface in the same source file must be package accessible and are stored in their own
// class files.
return (List<Declaration>) (List)rawDocument().children(NamespaceDeclaration.class).get(0).children(Type.class);
}
示例8: load
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public Document load(Java7 language) throws FileNotFoundException, IOException, LookupException {
Type t = read(language);
Document doc = new Document();
NamespaceDeclaration decl;
if(packageFQN() != null) {
decl = new JavaNamespaceDeclaration(packageFQN());
} else {
decl = new JavaNamespaceDeclaration(new RootNamespaceReference());
}
doc.add(decl);
decl.add(t);
return doc;
}
示例9: processType
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public void processType(NamespaceDeclaration np, Type type){
if(np == null) {throw new IllegalArgumentException("namespace part given to processType is null.");}
if(type == null) {return;} //throw new IllegalArgumentException("type given to processType is null.");}
np.add(type);
// inherit from java.lang.Object if there is no explicit extends relation
//String fqn = type.getFullyQualifiedName();
//if(fqn != null) {
// if(type.nonMemberInheritanceRelations().isEmpty() && (! fqn.equals("java.lang.Object"))){
// type.addInheritanceRelation(new SubtypeRelation(createTypeReference(expressionFactory().createNamedTarget("java.lang"),"Object")));
// }
//}
}
示例10: read
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
@Override
public Document read(Class clazz, RootNamespace root, Document doc) throws LookupException {
String packageName = clazz.getPackage().getName();
NamespaceDeclaration nsd = new JavaNamespaceDeclaration(packageName);
doc.add(nsd);
Type type = createType(clazz);
nsd.add(type);
return doc;
}
示例11: scope
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public Scope scope(Element element) throws LookupException {
try {
return new NamespaceScope(((Type)element).nearestAncestor(NamespaceDeclaration.class).namespace());
} catch (ClassCastException exc) {
throw new LookupException("The given element is not a type");
}
}
示例12: visitNamespace
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
@Override
public NamespaceDeclaration visitNamespace(NamespaceContext ctx) {
if(ctx != null) {
NamespaceReference namespaceReference = visitNamespaceReference(ctx.namespaceReference());
return factory().createNamespaceDeclaration(namespaceReference);
}
return null;
}
示例13: isNamespacePart
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public boolean isNamespacePart(Element element) {
return element instanceof NamespaceDeclaration;
}
示例14: directoryName
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
public String directoryName(Document compilationUnit) throws LookupException, ModelException {
return mainType(compilationUnit).nearestAncestor(NamespaceDeclaration.class).namespaceReference().toString();
}
示例15: createNamespaceDeclaration
import org.aikodi.chameleon.core.namespacedeclaration.NamespaceDeclaration; //导入依赖的package包/类
@Override
public NamespaceDeclaration createNamespaceDeclaration(CrossReference<Namespace> cref) {
return new JavaNamespaceDeclaration(cref);
}