com.thoughtworks.qdox.model.JavaSource Java Examples
The following examples show how to use
com.thoughtworks.qdox.model.JavaSource.
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: Util.java From uima-uimafit with Apache License 2.0 | 6 votes |
public static String getComponentDocumentation(JavaSource aAst, String aComponentTypeName) { // if (aComponentType.getName().contains("$")) { // // rec 2013-01-27: see comment on bindings resolving in ComponentDescriptionExtractor // getLog().warn( // "Inner classes not supported. Component description for [" + aComponentType.getName() // + "] cannot be extracted. "); // return null; // } for (JavaClass clazz : aAst.getClasses()) { if (clazz.asType().getFullyQualifiedName().equals(aComponentTypeName)) { return postProcessJavaDoc(clazz.getComment()); } } return null; }
Example #2
Source File: TestClass.java From code with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws FileNotFoundException { String fileFullPath = "D:\\code\\GitRepository\\Code\\java-basic\\jdk5\\src\\main\\java\\cn\\lastwhisper\\jdk5\\feature\\reflect\\TestClass.java"; JavaDocBuilder builder = new JavaDocBuilder(); builder.addSource(new FileReader(fileFullPath)); JavaSource src = builder.getSources()[0]; String[] imports = src.getImports(); for (String imp : imports) { System.out.println(imp); } }
Example #3
Source File: FlowContext.java From nomulus with Apache License 2.0 | 5 votes |
/** * Returns the set of exceptions imported in this test file. First extracts the set of * all names imported by the test file, and then uses these to filter a global list of possible * exceptions, so that the additional exception information available via the global list objects * (which are ErrorCases wrapping exception names) can be preserved. */ private Set<ErrorCase> getImportExceptionsFromFile(String filename) throws IOException { JavaDocBuilder builder = new JavaDocBuilder(); JavaSource src = builder.addSource(new File(filename)); final Set<String> importedNames = Sets.newHashSet(src.getImports()); return possibleExceptions .stream() .filter(errorCase -> importedNames.contains(errorCase.getClassName())) .collect(toImmutableSet()); }
Example #4
Source File: EnhanceMojo.java From uima-uimafit with Apache License 2.0 | 5 votes |
private JavaSource parseSource(String aSourceFile) throws MojoExecutionException { try { return Util.parseSource(aSourceFile, encoding); } catch (IOException e) { throw new MojoExecutionException("Unable to parse source file [" + aSourceFile + "]: " + ExceptionUtils.getRootCauseMessage(e), e); } }
Example #5
Source File: ComponentDescriptionExtractorTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { // Create the Java parser and parse the source code into an abstract syntax tree JavaSource source = Util.parseSource("src/test/resources/TestComponent.java", "UTF-8"); String javadoc = Util.getComponentDocumentation(source, "some.test.mypackage.TestComponent"); assertEquals("A test component used to test JavadocTextExtractor.", javadoc); }
Example #6
Source File: EnhanceMojo.java From uima-uimafit with Apache License 2.0 | 4 votes |
/** * Enhance descriptions in configuration parameters. */ private void enhanceConfigurationParameter(JavaSource aAST, Class<?> aClazz, CtClass aCtClazz, Multimap<String, String> aReportData) throws MojoExecutionException { // Get the parameter name constants Map<String, String> parameterNameFields = getParameterConstants(aClazz, parameterNameConstantPrefixes); Map<String, String> resourceNameFields = getParameterConstants(aClazz, externalResourceNameConstantPrefixes); // Fetch configuration parameters from the @ConfigurationParameter annotations in the // compiled class. We only need the fields in the class itself. Superclasses should be // enhanced by themselves. for (Field field : aClazz.getDeclaredFields()) { final String pname; final String type; final String pdesc; // Is this a configuration parameter? if (ConfigurationParameterFactory.isConfigurationParameterField(field)) { type = "parameter"; // Extract configuration parameter information from the uimaFIT annotation pname = ConfigurationParameterFactory.createPrimitiveParameter(field).getName(); // Extract JavaDoc for this resource from the source file pdesc = Util.getParameterDocumentation(aAST, field.getName(), parameterNameFields.get(pname)); } // Is this an external resource? else if (ExternalResourceFactory.isExternalResourceField(field)) { type = "external resource"; // Extract resource key from the uimaFIT annotation pname = ExternalResourceFactory.createResourceDependency(field).getKey(); // Extract JavaDoc for this resource from the source file pdesc = Util.getParameterDocumentation(aAST, field.getName(), resourceNameFields.get(pname)); } else { continue; } if (pdesc == null) { String msg = "No description found for " + type + " [" + pname + "]"; getLog().debug(msg); aReportData.put(aClazz.getName(), msg); continue; } // Update the "description" field of the annotation try { CtField ctField = aCtClazz.getField(field.getName()); AnnotationsAttribute annoAttr = (AnnotationsAttribute) ctField.getFieldInfo().getAttribute( AnnotationsAttribute.visibleTag); // Locate and update annotation if (annoAttr != null) { Annotation[] annotations = annoAttr.getAnnotations(); // Update existing annotation for (Annotation a : annotations) { if (a.getTypeName().equals( org.apache.uima.fit.descriptor.ConfigurationParameter.class.getName()) || a.getTypeName().equals( org.apache.uima.fit.descriptor.ExternalResource.class.getName()) || a.getTypeName().equals("org.uimafit.descriptor.ConfigurationParameter") || a.getTypeName().equals("org.uimafit.descriptor.ExternalResource")) { if (a.getMemberValue("description") == null) { a.addMemberValue("description", new StringMemberValue(pdesc, aCtClazz .getClassFile().getConstPool())); getLog().debug("Enhanced description of " + type + " [" + pname + "]"); // Replace updated annotation annoAttr.addAnnotation(a); } else { // Extract configuration parameter information from the uimaFIT annotation // We only want to override if the description is not set yet. getLog().debug("Not overwriting description of " + type + " [" + pname + "] "); } } } } // Replace annotations ctField.getFieldInfo().addAttribute(annoAttr); } catch (NotFoundException e) { throw new MojoExecutionException("Field [" + field.getName() + "] not found in byte code: " + ExceptionUtils.getRootCauseMessage(e), e); } } }
Example #7
Source File: Util.java From uima-uimafit with Apache License 2.0 | 4 votes |
public static JavaSource parseSource(String aSourceFile, String aEncoding) throws IOException { JavaDocBuilder builder = new JavaDocBuilder(); builder.setEncoding(aEncoding); builder.addSource(new FileReader(aSourceFile)); return builder.getSources()[0]; }
Example #8
Source File: JavadocTextExtractorTest.java From uima-uimafit with Apache License 2.0 | 4 votes |
private String getJavadoc(String aParameter, String aNameConstant) throws IOException { // Create the Java parser and parse the source code into an abstract syntax tree JavaSource source = Util.parseSource("src/test/resources/TestComponent.java", "UTF-8"); return Util.getParameterDocumentation(source, aParameter, aNameConstant); }