List of usage examples for org.eclipse.jdt.core.dom TagElement TAG_THROWS
String TAG_THROWS
To view the source code for org.eclipse.jdt.core.dom TagElement TAG_THROWS.
Click Source Link
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavaDoc2HTMLTextReader.java
License:Open Source License
private void handleTag(String tag, String tagContent) { tagContent = tagContent.trim();//www .j a va 2 s . c o m if (TagElement.TAG_PARAM.equals(tag)) fParameters.add(tagContent); else if (TagElement.TAG_RETURN.equals(tag)) fReturn = tagContent; else if (TagElement.TAG_EXCEPTION.equals(tag)) fExceptions.add(tagContent); else if (TagElement.TAG_THROWS.equals(tag)) fExceptions.add(tagContent); else if (TagElement.TAG_AUTHOR.equals(tag)) fAuthors.add(substituteQualification(tagContent)); else if (TagElement.TAG_SEE.equals(tag)) fSees.add(substituteQualification(tagContent)); else if (TagElement.TAG_SINCE.equals(tag)) fSince.add(substituteQualification(tagContent)); else if (tagContent != null) fRest.add(new Pair(tag, tagContent)); }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private void elementToHTML() { // After first loop, non-null entries in the following two lists are missing and need to be inherited: List<String> typeParameterNames = initTypeParameterNames(); List<String> parameterNames = initParameterNames(); List<String> exceptionNames = initExceptionNames(); TagElement deprecatedTag = null; TagElement start = null;//from w w w .ja v a 2s. co m List<TagElement> typeParameters = new ArrayList<>(); List<TagElement> parameters = new ArrayList<>(); TagElement returnTag = null; List<TagElement> exceptions = new ArrayList<>(); List<TagElement> versions = new ArrayList<>(); List<TagElement> authors = new ArrayList<>(); List<TagElement> sees = new ArrayList<>(); List<TagElement> since = new ArrayList<>(); List<TagElement> rest = new ArrayList<>(); List<TagElement> tags = fJavadoc.tags(); for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) { TagElement tag = iter.next(); String tagName = tag.getTagName(); if (tagName == null) { start = tag; } else if (TagElement.TAG_PARAM.equals(tagName)) { List<? extends ASTNode> fragments = tag.fragments(); int size = fragments.size(); if (size > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); int paramIndex = parameterNames.indexOf(name); if (paramIndex != -1) { parameterNames.set(paramIndex, null); } parameters.add(tag); } else if (size > 2 && first instanceof TextElement) { String firstText = ((TextElement) first).getText(); if ("<".equals(firstText)) { //$NON-NLS-1$ Object second = fragments.get(1); Object third = fragments.get(2); if (second instanceof SimpleName && third instanceof TextElement) { String name = ((SimpleName) second).getIdentifier(); String thirdText = ((TextElement) third).getText(); if (">".equals(thirdText)) { //$NON-NLS-1$ int paramIndex = typeParameterNames.indexOf(name); if (paramIndex != -1) { typeParameterNames.set(paramIndex, null); } typeParameters.add(tag); } } } } } } else if (TagElement.TAG_RETURN.equals(tagName)) { if (returnTag == null) returnTag = tag; // the Javadoc tool only shows the first return tag } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) { exceptions.add(tag); List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); int exceptionIndex = exceptionNames.indexOf(name); if (exceptionIndex != -1) { exceptionNames.set(exceptionIndex, null); } } } } else if (TagElement.TAG_SINCE.equals(tagName)) { since.add(tag); } else if (TagElement.TAG_VERSION.equals(tagName)) { versions.add(tag); } else if (TagElement.TAG_AUTHOR.equals(tagName)) { authors.add(tag); } else if (TagElement.TAG_SEE.equals(tagName)) { sees.add(tag); } else if (TagElement.TAG_DEPRECATED.equals(tagName)) { if (deprecatedTag == null) deprecatedTag = tag; // the Javadoc tool only shows the first deprecated tag } else { rest.add(tag); } } //TODO: @Documented annotations before header if (deprecatedTag != null) handleDeprecatedTag(deprecatedTag); if (start != null) handleContentElements(start.fragments()); else if (fMethod != null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); // The Javadoc tool adds "Description copied from class: ..." (only for the main description). // We don't bother doing that. handleInherited(inherited); } CharSequence[] typeParameterDescriptions = new CharSequence[typeParameterNames.size()]; boolean hasInheritedTypeParameters = inheritTypeParameterDescriptions(typeParameterNames, typeParameterDescriptions); boolean hasTypeParameters = typeParameters.size() > 0 || hasInheritedTypeParameters; CharSequence[] parameterDescriptions = new CharSequence[parameterNames.size()]; boolean hasInheritedParameters = inheritParameterDescriptions(parameterNames, parameterDescriptions); boolean hasParameters = parameters.size() > 0 || hasInheritedParameters; CharSequence returnDescription = null; if (returnTag == null && needsReturnTag()) returnDescription = fJavadocLookup.getInheritedReturnDescription(fMethod); boolean hasReturnTag = returnTag != null || returnDescription != null; CharSequence[] exceptionDescriptions = new CharSequence[exceptionNames.size()]; boolean hasInheritedExceptions = inheritExceptionDescriptions(exceptionNames, exceptionDescriptions); boolean hasExceptions = exceptions.size() > 0 || hasInheritedExceptions; if (hasParameters || hasTypeParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0 || (fBuf.length() > 0 && (parameterDescriptions.length > 0 || exceptionDescriptions.length > 0))) { handleSuperMethodReferences(); fBuf.append(BLOCK_TAG_START); handleParameterTags(typeParameters, typeParameterNames, typeParameterDescriptions, true); handleParameterTags(parameters, parameterNames, parameterDescriptions, false); handleReturnTag(returnTag, returnDescription); handleExceptionTags(exceptions, exceptionNames, exceptionDescriptions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_since_section, since); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_version_section, versions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_author_section, authors); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_see_section, sees); handleBlockTags(rest); fBuf.append(BLOCK_TAG_END); } else if (fBuf.length() > 0) { handleSuperMethodReferences(); } }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getExceptionDescription(String simpleName) {
if (fMethod != null) {
if (fExceptionDescriptions == null) {
fExceptionDescriptions = new HashMap<>();
} else {/*from ww w . j av a2 s . c o m*/
StringBuffer description = fExceptionDescriptions.get(simpleName);
if (description != null) {
return description.length() > 0 ? description : null;
}
}
StringBuffer description = new StringBuffer();
fExceptionDescriptions.put(simpleName, description);
fBuf = description;
fLiteralContent = 0;
List<TagElement> tags = fJavadoc.tags();
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
TagElement tag = iter.next();
String tagName = tag.getTagName();
if (TagElement.TAG_THROWS.equals(tagName) || TagElement.TAG_EXCEPTION.equals(tagName)) {
List<? extends ASTNode> fragments = tag.fragments();
if (fragments.size() > 0) {
Object first = fragments.get(0);
if (first instanceof Name) {
String name = ASTNodes.getSimpleNameIdentifier((Name) first);
if (name.equals(simpleName)) {
if (fragments.size() > 1)
handleContentElements(fragments.subList(1, fragments.size()));
break;
}
}
}
}
}
fBuf = null;
return description.length() > 0 ? description : null;
}
return null;
}
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Handle {@inheritDoc}./*from w w w . java 2 s . c o m*/ * * @param node the node * @return <code>true</code> iff the node was an {@inheritDoc} node and has been handled */ private boolean handleInheritDoc(TagElement node) { if (!TagElement.TAG_INHERITDOC.equals(node.getTagName())) return false; try { if (fMethod == null) return false; TagElement blockTag = (TagElement) node.getParent(); String blockTagName = blockTag.getTagName(); if (blockTagName == null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_PARAM.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); int size = fragments.size(); if (size > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); String[] parameterNames = fMethod.getParameterNames(); for (int i = 0; i < parameterNames.length; i++) { if (name.equals(parameterNames[i])) { CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i); return handleInherited(inherited); } } } else if (size > 2 && first instanceof TextElement) { String firstText = ((TextElement) first).getText(); if ("<".equals(firstText)) { //$NON-NLS-1$ Object second = fragments.get(1); Object third = fragments.get(2); if (second instanceof SimpleName && third instanceof TextElement) { String thirdText = ((TextElement) third).getText(); if (">".equals(thirdText)) { //$NON-NLS-1$ String name = ((SimpleName) second).getIdentifier(); ITypeParameter[] typeParameters = fMethod.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (name.equals(typeParameter.getElementName())) { CharSequence inherited = fJavadocLookup .getInheritedTypeParamDescription(fMethod, i); return handleInherited(inherited); } } } } } } } } else if (TagElement.TAG_RETURN.equals(blockTagName)) { CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_THROWS.equals(blockTagName) || TagElement.TAG_EXCEPTION.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name); return handleInherited(inherited); } } } } catch (JavaModelException e) { //TODO e.printStackTrace(); } return false; }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
private String toHTML() { fBuf = new StringBuffer(); fLiteralContent = 0;/*from w ww.j a va 2s . c om*/ // After first loop, non-null entries in the following two lists are missing and need to be inherited: List<String> parameterNames = initParameterNames(); List<String> exceptionNames = initExceptionNames(); TagElement deprecatedTag = null; TagElement start = null; List<TagElement> parameters = new ArrayList<TagElement>(); TagElement returnTag = null; List<TagElement> exceptions = new ArrayList<TagElement>(); List<TagElement> versions = new ArrayList<TagElement>(); List<TagElement> authors = new ArrayList<TagElement>(); List<TagElement> sees = new ArrayList<TagElement>(); List<TagElement> since = new ArrayList<TagElement>(); List<TagElement> rest = new ArrayList<TagElement>(); List<TagElement> tags = fJavadoc.tags(); for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) { TagElement tag = iter.next(); String tagName = tag.getTagName(); if (tagName == null) { start = tag; } else if (TagElement.TAG_PARAM.equals(tagName)) { parameters.add(tag); List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); int paramIndex = parameterNames.indexOf(name); if (paramIndex != -1) { parameterNames.set(paramIndex, null); } } } } else if (TagElement.TAG_RETURN.equals(tagName)) { if (returnTag == null) returnTag = tag; // the Javadoc tool only shows the first return tag } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) { exceptions.add(tag); List<? extends ASTNode> fragments = tag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); int exceptionIndex = exceptionNames.indexOf(name); if (exceptionIndex != -1) { exceptionNames.set(exceptionIndex, null); } } } } else if (TagElement.TAG_SINCE.equals(tagName)) { since.add(tag); } else if (TagElement.TAG_VERSION.equals(tagName)) { versions.add(tag); } else if (TagElement.TAG_AUTHOR.equals(tagName)) { authors.add(tag); } else if (TagElement.TAG_SEE.equals(tagName)) { sees.add(tag); } else if (TagElement.TAG_DEPRECATED.equals(tagName)) { if (deprecatedTag == null) deprecatedTag = tag; // the Javadoc tool only shows the first deprecated tag } else { rest.add(tag); } } //TODO: @Documented annotations before header if (deprecatedTag != null) handleDeprecatedTag(deprecatedTag); if (start != null) handleContentElements(start.fragments()); else if (fMethod != null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); // The Javadoc tool adds "Description copied from class: ..." (only for the main description). // We don't bother doing that. handleInherited(inherited); } CharSequence[] parameterDescriptions = new CharSequence[parameterNames.size()]; boolean hasInheritedParameters = inheritParameterDescriptions(parameterNames, parameterDescriptions); boolean hasParameters = parameters.size() > 0 || hasInheritedParameters; CharSequence returnDescription = null; if (returnTag == null && needsReturnTag()) returnDescription = fJavadocLookup.getInheritedReturnDescription(fMethod); boolean hasReturnTag = returnTag != null || returnDescription != null; CharSequence[] exceptionDescriptions = new CharSequence[exceptionNames.size()]; boolean hasInheritedExceptions = inheritExceptionDescriptions(exceptionNames, exceptionDescriptions); boolean hasExceptions = exceptions.size() > 0 || hasInheritedExceptions; if (hasParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0 || (fBuf.length() > 0 && (parameterDescriptions.length > 0 || exceptionDescriptions.length > 0))) { handleSuperMethodReferences(); fBuf.append(BLOCK_TAG_START); handleParameterTags(parameters, parameterNames, parameterDescriptions); handleReturnTag(returnTag, returnDescription); handleExceptionTags(exceptions, exceptionNames, exceptionDescriptions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_since_section, since); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_version_section, versions); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_author_section, authors); handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_see_section, sees); handleBlockTags(rest); fBuf.append(BLOCK_TAG_END); } else if (fBuf.length() > 0) { handleSuperMethodReferences(); } String result = fBuf.toString(); fBuf = null; return result; }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
CharSequence getExceptionDescription(String simpleName) {
if (fMethod != null) {
if (fExceptionDescriptions == null) {
fExceptionDescriptions = new HashMap<String, StringBuffer>();
} else {/*from ww w . ja va 2 s . com*/
StringBuffer description = fExceptionDescriptions.get(simpleName);
if (description != null) {
return description.length() > 0 ? description : null;
}
}
StringBuffer description = new StringBuffer();
fExceptionDescriptions.put(simpleName, description);
fBuf = description;
fLiteralContent = 0;
List<TagElement> tags = fJavadoc.tags();
for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
TagElement tag = iter.next();
String tagName = tag.getTagName();
if (TagElement.TAG_THROWS.equals(tagName) || TagElement.TAG_EXCEPTION.equals(tagName)) {
List<? extends ASTNode> fragments = tag.fragments();
if (fragments.size() > 0) {
Object first = fragments.get(0);
if (first instanceof Name) {
String name = ASTNodes.getSimpleNameIdentifier((Name) first);
if (name.equals(simpleName)) {
if (fragments.size() > 1)
handleContentElements(fragments.subList(1, fragments.size()));
break;
}
}
}
}
}
fBuf = null;
return description.length() > 0 ? description : null;
}
return null;
}
From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Handle {@inheritDoc}.// w ww . ja v a 2 s. com * * @param node * the node * @return <code>true</code> iff the node was an {@inheritDoc} node and has been handled */ private boolean handleInheritDoc(TagElement node) { if (!TagElement.TAG_INHERITDOC.equals(node.getTagName())) return false; try { if (fMethod == null) return false; TagElement blockTag = (TagElement) node.getParent(); String blockTagName = blockTag.getTagName(); if (blockTagName == null) { CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_PARAM.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof SimpleName) { String name = ((SimpleName) first).getIdentifier(); String[] parameterNames = fMethod.getParameterNames(); for (int i = 0; i < parameterNames.length; i++) { if (name.equals(parameterNames[i])) { CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i); return handleInherited(inherited); } } } } } else if (TagElement.TAG_RETURN.equals(blockTagName)) { CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod); return handleInherited(inherited); } else if (TagElement.TAG_THROWS.equals(blockTagName) || TagElement.TAG_EXCEPTION.equals(blockTagName)) { List<? extends ASTNode> fragments = blockTag.fragments(); if (fragments.size() > 0) { Object first = fragments.get(0); if (first instanceof Name) { String name = ASTNodes.getSimpleNameIdentifier((Name) first); CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name); return handleInherited(inherited); } } } } catch (JavaModelException e) { LOG.error(e.getMessage(), e); } return false; }
From source file:de.akra.idocit.java.services.JavadocParserTest.java
License:Apache License
/** * Test for {@link JavadocParser#parseIDocItJavadoc(Javadoc)}. * //from w ww . jav a 2 s . co m * @throws ParserConfigurationException * @throws IOException * @throws SAXException * @throws ParsingException * * @throws Exception */ @Test public void testParse() throws SAXException, IOException, ParserConfigurationException, ParsingException { { AST a = AST.newAST(AST.JLS3); Javadoc javadoc = a.newJavadoc(); List<Documentation> paramDocumentations = createParamDocumentations(); List<Documentation> returnDocumentations = createReturnDocumentations(); JavaMethod methodWithParams = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method", "Searching Operations", Numerus.SINGULAR); for (Documentation documentation : paramDocumentations) { methodWithParams.addDocpart(documentation); } JavaMethod methodWithReturn = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method", "Searching Operations", Numerus.SINGULAR); for (Documentation documentation : returnDocumentations) { methodWithReturn.addDocpart(documentation); } JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(), null, null, "Searching Operations", javadoc, new ArrayList<TagElement>(), null); JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(), TagElement.TAG_PARAM, "person", "Searching Operations", javadoc, new ArrayList<TagElement>(), null); JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithReturn.getDocumentations(), TagElement.TAG_RETURN, null, "Searching Operations", javadoc, new ArrayList<TagElement>(), null); JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(), TagElement.TAG_THROWS, "IllegalArgException", "Searching Operations", javadoc, new ArrayList<TagElement>(), null); // add the number of used documentations to this list, to make an assertion List<Documentation> allUsedDocs = new ArrayList<Documentation>(paramDocumentations.size() * 4); allUsedDocs.addAll(paramDocumentations); allUsedDocs.addAll(paramDocumentations); allUsedDocs.addAll(returnDocumentations); allUsedDocs.addAll(paramDocumentations); logger.log(Level.FINE, javadoc.toString()); List<Documentation> convertedDocs = JavadocParser.INSTANCE.parseIDocItJavadoc(javadoc, TestUtils.createReferenceAddressees(), TestUtils.createReferenceThematicRoles(), methodWithParams); logger.log(Level.FINE, allUsedDocs.toString()); logger.log(Level.FINE, convertedDocs.toString()); Assert.assertEquals(allUsedDocs, convertedDocs); } }
From source file:de.akra.idocit.java.services.JavaInterfaceGenerator.java
License:Apache License
/** * Create a list of {@link JavadocTagElement}s to convert them to a {@link Javadoc} * comment./*from w w w .j a v a 2 s . co m*/ * * @param method * The {@link JavaMethod} that should be processed to extract the needed * information to generate a Javadoc. * @return List of {@link JavadocTagElement}s. */ private static List<JavadocTagElement> createMethodJavadocTagElements(JavaMethod method) { final List<JavadocTagElement> jDocTags = new ArrayList<JavadocTagElement>(); final List<Documentation> documentations = sortDocumenations(method.getDocumentations(), method.getThematicGridName()); final JavadocTagElement tagElem = new JavadocTagElement(documentations, method); jDocTags.add(tagElem); final Parameters inputParams = method.getInputParameters(); if (inputParams != null) { collectParametersDocumentations(inputParams.getParameters(), TagElement.TAG_PARAM, jDocTags, CustomTaglets.SUB_PARAM.getTagName()); } final Parameters returnType = method.getOutputParameters(); if (returnType != null) { collectParametersDocumentations(returnType.getParameters(), TagElement.TAG_RETURN, jDocTags, CustomTaglets.SUB_RETURN.getTagName()); } for (final Parameters exception : method.getExceptions()) { if (exception != null) { collectParametersDocumentations(exception.getParameters(), TagElement.TAG_THROWS, jDocTags, null); } } return jDocTags; }
From source file:de.akra.idocit.java.services.JavaParserTest.java
License:Apache License
/** * Tests {@link JavaParser#parse(org.eclipse.core.resources.IFile)} * //from w ww . j a v a 2s. c om * @throws Exception */ @Test public void testJavaParserWithSimpleParser() throws Exception { /* * Positive tests */ { // ######################################################################### // # Test case #1: parser the customer service correctly. Then store it and // # parse it again. Both objects must be equal. // ######################################################################### { final ParserOutput output = JavaTestUtils .createCompilationUnit(AllIDocItJavaTests.SOURCE_DIR + "CustomerService.java"); final CompilationUnit cu = output.getCompilationUnit(); final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "CustomerService.java"); final JavaInterfaceArtifact refInterfaceArtifact = TestDataFactory .createCustomerService("Developer", false, cu); JavaInterfaceArtifact actInterfaceArtifact = (JavaInterfaceArtifact) ServiceManager.getInstance() .getPersistenceService().loadInterface(testSourceFolder); final JavaInterface refInterface = (JavaInterface) refInterfaceArtifact.getInterfaces().get(0); final JavaInterface actInterface = (JavaInterface) actInterfaceArtifact.getInterfaces().get(0); final JavaMethod refMethod = (JavaMethod) refInterface.getOperations().get(0); final JavaMethod actMethod = (JavaMethod) actInterface.getOperations().get(0); final List<? extends Parameter> refInputParameters = refMethod.getInputParameters().getParameters(); final List<? extends Parameter> actInputParameters = actMethod.getInputParameters().getParameters(); final List<? extends Parameter> refOutputParameters = refMethod.getOutputParameters() .getParameters(); final List<? extends Parameter> actOutputParameters = actMethod.getOutputParameters() .getParameters(); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils.equalsParameters(refInputParameters, actInputParameters)); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils.equalsParameters(refOutputParameters, actOutputParameters)); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils.equalsExceptions(refMethod.getExceptions(), actMethod.getExceptions())); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils.equalsMethods(refMethod, actMethod)); Assert.assertTrue( JavaInterfaceArtifactComparatorUtils.equalsInterfaces(refInterface, actInterface)); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils .equalsInterfaceArtifacts(refInterfaceArtifact, actInterfaceArtifact)); ServiceManager.getInstance().getPersistenceService().writeInterface(actInterfaceArtifact, testSourceFolder); actInterfaceArtifact = (JavaInterfaceArtifact) ServiceManager.getInstance().getPersistenceService() .loadInterface(testSourceFolder); Assert.assertTrue(JavaInterfaceArtifactComparatorUtils .equalsInterfaceArtifacts(refInterfaceArtifact, actInterfaceArtifact)); } clearWorkspace(); setupWorkspace(); // ######################################################################### // # Test case #2: parse the source code of JavaParser.java without any error. // # In a former implementation this test causes a NullPointerException // # because of void-methods (input or output-parameters == null). // ######################################################################### { final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "JavaParser.java"); final JavaInterfaceArtifact actInterfaceArtifact = (JavaInterfaceArtifact) ServiceManager .getInstance().getPersistenceService().loadInterface(testSourceFolder); final Operation javaMethod = actInterfaceArtifact.getInterfaces().get(0).getOperations().get(0); final Documentation documentation = javaMethod.getDocumentations().get(0); final List<ThematicRole> roles = ServiceManager.getInstance().getPersistenceService() .loadThematicRoles(); final ThematicRole roleNone = ThematicRoleUtils.findRoleByName("NONE", roles); documentation.setThematicRole(roleNone); for (final Operation operation : actInterfaceArtifact.getInterfaces().get(0).getOperations()) { operation.setDocumentationChanged(true); } final ValidationReport report = ServiceManager.getInstance().getPersistenceService() .validateInterfaceArtifact(actInterfaceArtifact, testSourceFolder); Assert.assertNotNull(actInterfaceArtifact); Assert.assertNotNull(report); ServiceManager.getInstance().getPersistenceService().writeInterface(actInterfaceArtifact, testSourceFolder); } clearWorkspace(); setupWorkspace(); // ######################################################################### // # Test case #3: the description of a class or interface should have // # thematic role "NONE" in the idocit-structure and no thematic role in the // # Javadoc-structure (see reference Javadoc). // ######################################################################### { final String refJavadoc = String.format("/**%1$s" + " * Parser implementation for Java.%1$s" + " * %1$s" + " * @author Dirk Meier-Eickhoff%1$s" + " * @since 0.0.1%1$s" + " * @version 0.0.1%1$s" + " * %1$s" + " */%1$s", NEW_LINE); final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "JavaParser.java"); final JavaInterfaceArtifact actInterfaceArtifact = (JavaInterfaceArtifact) ServiceManager .getInstance().getPersistenceService().loadInterface(testSourceFolder); final Documentation documentation = actInterfaceArtifact.getInterfaces().get(0).getDocumentations() .get(0); final List<ThematicRole> roles = ServiceManager.getInstance().getPersistenceService() .loadThematicRoles(); final ThematicRole roleNone = ThematicRoleUtils.findRoleByName("NONE", roles); Assert.assertEquals(roleNone, documentation.getThematicRole()); actInterfaceArtifact.getInterfaces().get(0).setDocumentationChanged(true); ServiceManager.getInstance().getPersistenceService().validateInterfaceArtifact(actInterfaceArtifact, testSourceFolder); ServiceManager.getInstance().getPersistenceService().writeInterface(actInterfaceArtifact, testSourceFolder); final File javaFile = testSourceFolder.getRawLocation().makeAbsolute().toFile(); final String actJavadoc = readLinesFromFile(javaFile, 51, 59); Assert.assertEquals(refJavadoc, actJavadoc); } clearWorkspace(); setupWorkspace(); // ######################################################################### // # Test case #4: javadoc with line-wrapped texts is correctly parsed. Line // # breaks or empty lines in iDocIt!'s GUI are correctly mapped to empty rows // # in the generated javadoc (starting with a '*'). // ######################################################################### { final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "JavaParser.java"); final JavaInterfaceArtifact actInterfaceArtifact = (JavaInterfaceArtifact) ServiceManager .getInstance().getPersistenceService().loadInterface(testSourceFolder); JavaMethod parseMethod = (JavaMethod) actInterfaceArtifact.getInterfaces().get(0).getOperations() .get(0); final List<Documentation> refDocumentations = TestDataFactory.createDocsForParseMethod("Developer", parseMethod.getQualifiedIdentifier()); parseMethod.getDocumentations().clear(); for (final Documentation documentation : refDocumentations) { parseMethod.addDocpart(documentation); } parseMethod.setDocumentationChanged(true); ServiceManager.getInstance().getPersistenceService().validateInterfaceArtifact(actInterfaceArtifact, testSourceFolder); ServiceManager.getInstance().getPersistenceService().writeInterface(actInterfaceArtifact, testSourceFolder); final File javaFile = testSourceFolder.getRawLocation().makeAbsolute().toFile(); final String actJavadoc = readLinesFromFile(javaFile, 87, 111); final String refJavadoc = String.format("\t/**%1$s" + "\t * Reads the java- and javadoc code from the given <b>file and<br/>%1$s" + "\t * creates</b> the returned {@link JavaInterfaceArtifact} from it.<br/>%1$s" + "\t * Escape Test: Ö%1$s" + "\t * %1$s" + "\t * @source_format Java and Javadoc according to their current specifications:<br/>%1$s" + "\t * <br/>%1$s" + "\t * <a href=\"http://docs.oracle.com/javase/specs/\">Java</a><br/>%1$s" + "\t * Javadoc%1$s" + "\t * %1$s" + "\t * @instrument To parse the Java and Javadoc code, the parser provided by the Eclipse Java Development Tools is used.%1$s" + "\t * @instrument iDocIt! supports two different representations of thematicgrids in Javadoc:<br/>%1$s" + "\t * <br/>%1$s" + "\t * The simplified version is very compact, but supports only the addressee "Developer".<br/>%1$s" + "\t * The complex version supports all addressees, but uses a lot of HTML-code.%1$s" + "\t * %1$s" + "\t * @param iFile [SOURCE] (" + Constants.ERROR_CASE_DOCUMENTATION_TEXT + ")%1$s" + "\t * %1$s" + "\t * @return [OBJECT]%1$s" + "\t * %1$s" + "\t * @throws Exception%1$s" + "\t * @see de.akra.idocit.core.extensions.Parser#parse(IFile)%1$s" + "\t * @thematicgrid Parsing Operations%1$s" + "\t */%1$s", NEW_LINE); Assert.assertEquals(refJavadoc, actJavadoc); final JavaInterfaceArtifact loadedArtifact = (JavaInterfaceArtifact) ServiceManager.getInstance() .getPersistenceService().loadInterface(testSourceFolder); parseMethod = (JavaMethod) loadedArtifact.getInterfaces().get(0).getOperations().get(0); final List<Documentation> actDocumentations = parseMethod.getDocumentations(); Assert.assertEquals(refDocumentations.toString(), actDocumentations.toString()); } clearWorkspace(); setupWorkspace(); // ######################################################################### // # Test case #5: the void- and parameterless method "foo" could be parsed // # without a NullPointerException // ######################################################################### { final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "VeryInconsistentService.java"); ServiceManager.getInstance().getPersistenceService().loadInterface(testSourceFolder); } clearWorkspace(); setupWorkspace(); // ######################################################################### // # Test case #6: Methods that are documented with raw Javadoc must be read // # without any exception. The '@throws IllegalArgumentException' tag must // # be added to the additionalTags of the method. // ######################################################################### { final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "JavadocRawComment.java"); final InterfaceArtifact artifact = ServiceManager.getInstance().getPersistenceService() .loadInterface(testSourceFolder); final JavaMethod method = (JavaMethod) artifact.getInterfaces().get(0).getOperations().get(0); assertNotNull(method); assertNotNull(method.getAdditionalTags()); assertEquals(4, method.getAdditionalTags().size()); assertEquals("There must be 0 documentations, because nothing is documented.", 0, method.getDocumentations().size()); final List<TagElement> additionalTags = method.getAdditionalTags(); assertEquals(4, additionalTags.size()); final List<TagElement> foundThrowsTags = findTagByName(additionalTags, TagElement.TAG_THROWS); assertEquals(1, foundThrowsTags.size()); final SimpleName name = (SimpleName) foundThrowsTags.get(0).fragments().get(0); assertEquals("IllegalArgumentException", name.getIdentifier()); assertEquals(1, findTagByName(additionalTags, TagElement.TAG_SEE).size()); assertEquals(1, findTagByName(additionalTags, TagElement.TAG_AUTHOR).size()); final JavaMethod method2 = (JavaMethod) artifact.getInterfaces().get(0).getOperations().get(1); assertNotNull(method2); assertNotNull(method2.getAdditionalTags()); assertEquals(4, method2.getAdditionalTags().size()); final List<Documentation> docs2 = TestUtils.collectAllDocumentations(method2); assertEquals("There must be 4 documentations.", 4, docs2.size()); final List<TagElement> additionalTags2 = method2.getAdditionalTags(); assertEquals(4, additionalTags2.size()); final List<TagElement> foundThrowsTags2 = findTagByName(additionalTags2, TagElement.TAG_THROWS); assertEquals(1, foundThrowsTags2.size()); final SimpleName name2 = (SimpleName) foundThrowsTags2.get(0).fragments().get(0); assertEquals("IllegalArgumentException", name2.getIdentifier()); assertEquals("maybe if illegal arg is inserted", ((TextElement) foundThrowsTags2.get(0).fragments().get(1)).getText()); assertEquals(1, findTagByName(additionalTags2, TagElement.TAG_SEE).size()); assertEquals(1, findTagByName(additionalTags2, TagElement.TAG_AUTHOR).size()); } } /* * Negative tests */ { // ######################################################################### // # Test case #1: a documented, but not existent parameter causes a // # ParsingException. // ######################################################################### { final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "InconsistentService.java"); boolean parsingExceptionOccured = false; try { ServiceManager.getInstance().getPersistenceService().loadInterface(testSourceFolder); } catch (ParsingException pEx) { parsingExceptionOccured = true; } assertTrue(parsingExceptionOccured); } // ######################################################################### // # Test case #2: If a method has no return type, but the Javadoc contains a // # '@return ...' a ParsingException must be thrown. // ######################################################################### { final String expectedErrorMsg = "de.akra.idocit.java.exceptions.ParsingException: For method 'foo' there is documented a return type although it does not exist. Please delete the '@return ...' tag from Javadoc comment and open the file again."; final IFile testSourceFolder = this.project .getFile(JavaTestUtils.REL_SOURCE_PATH + "InconsistentService2.java"); boolean err = false; try { ServiceManager.getInstance().getPersistenceService().loadInterface(testSourceFolder); } catch (final ParsingException e) { err = expectedErrorMsg.equals(e.toString()); } Assert.assertTrue("ParsingException is expected.", err); } } }