Java Code Examples for com.github.javaparser.ast.ImportDeclaration#getNameAsString()
The following examples show how to use
com.github.javaparser.ast.ImportDeclaration#getNameAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassHelper.java From apigcc with MIT License | 5 votes |
/** * 寻找import行,组装完整的类名称 * @param name * @param compilationUnit * @return */ private static String getNameFromImport(String name, CompilationUnit compilationUnit){ int dotPos = name.indexOf('.'); String prefix = null; if (dotPos > -1) { prefix = name.substring(0, dotPos); } for (ImportDeclaration importDecl : compilationUnit.getImports()) { if (!importDecl.isAsterisk()) { String qName = importDecl.getNameAsString(); boolean defaultPackage = !importDecl.getName().getQualifier().isPresent(); boolean found = !defaultPackage && importDecl.getName().getIdentifier().equals(name); if (!found) { if (prefix != null) { found = qName.endsWith("." + prefix); if (found) { qName = qName + name.substring(dotPos); } } } if (found) { return qName; } } } return name; }
Example 2
Source File: JavaParsingAtomicLinkedQueueGenerator.java From JCTools with Apache License 2.0 | 5 votes |
void organiseImports(CompilationUnit cu) { List<ImportDeclaration> importDecls = new ArrayList<>(); for (ImportDeclaration importDeclaration : cu.getImports()) { String name = importDeclaration.getNameAsString(); if (name.startsWith("org.jctools.util.Unsafe")) { continue; } if (name.startsWith("org.jctools.queues.LinkedArrayQueueUtil")) { continue; } importDecls.add(importDeclaration); } cu.getImports().clear(); for (ImportDeclaration importDecl : importDecls) { cu.addImport(importDecl); } cu.addImport(importDeclaration("java.util.concurrent.atomic.AtomicReferenceFieldUpdater")); cu.addImport(importDeclaration("java.util.concurrent.atomic.AtomicLongFieldUpdater")); cu.addImport(importDeclaration("java.util.concurrent.atomic.AtomicReferenceArray")); cu.addImport(importDeclaration("org.jctools.queues.MessagePassingQueue")); cu.addImport(importDeclaration("org.jctools.queues.MessagePassingQueue.Supplier")); cu.addImport(importDeclaration("org.jctools.queues.MessagePassingQueueUtil")); cu.addImport(importDeclaration("org.jctools.queues.QueueProgressIndicators")); cu.addImport(importDeclaration("org.jctools.queues.IndexedQueueSizeUtil")); cu.addImport(staticImportDeclaration("org.jctools.queues.atomic.AtomicQueueUtil.*")); }