Example usage for org.eclipse.jdt.core.dom TagElement fragments

List of usage examples for org.eclipse.jdt.core.dom TagElement fragments

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom TagElement fragments.

Prototype

ASTNode.NodeList fragments

To view the source code for org.eclipse.jdt.core.dom TagElement fragments.

Click Source Link

Document

The list of doc elements (element type: IDocElement ).

Usage

From source file:ac.at.tuwien.dsg.uml.statemachine.export.transformation.engines.AbstractStateMachineTestStrategy.java

License:Open Source License

/**
 * Method which for any type of trigger Event, from CallEvent, to ChangeEvent, TimeEvent, etc, creates an abstract method
 * @param trigger//from  w w  w . j  a v a  2s .  c  o  m
 * @param ast
 * @return
 */
protected MethodDeclaration createAbstractTriggerInvocation(Trigger trigger, AST ast) {

    //get trigger event
    Event event = trigger.getEvent();
    //if UML operation triggers event (so CLass method)

    String methodName = GENERATE_EVENT_LEADING;
    Javadoc javadoc = ast.newJavadoc();
    TagElement tag = ast.newTagElement();
    TextElement textElement = ast.newTextElement();

    if (event instanceof CallEvent) {

        CallEvent callEvent = (CallEvent) event;
        Operation operation = callEvent.getOperation();
        Class operationClass = (Class) operation.eContainer();

        methodName = operationClass.getName().replaceAll("\\W", "") + "_"
                + operation.getName().replaceAll("\\W", "");
        textElement.setText("Method must return true if method invocation is successful."
                + " Method designed to allow particular implementation  call of \"" + operation.getName() + "\""
                + " on class \"" + operationClass.getName()
                + "\" so we can assert if transition after event is correct");

    } else if (event instanceof ChangeEvent) {

        ChangeEvent changeEvent = (ChangeEvent) event;
        OpaqueExpression changeExpression = (OpaqueExpression) changeEvent.getChangeExpression();
        if (changeExpression.getBodies().isEmpty()) {
            System.err.println("Event " + event.getName() + " has no body/expression");
        } else {
            String body = changeExpression.getBodies().iterator().next();
            body = StringFormatter.convertNonAlphanumericalSymbolsToUnderscore(
                    StringFormatter.convertMathSymbolsToText(body));

            methodName = changeEvent.getName().replaceAll("\\W", "") + "_" + body;
            textElement.setText("Method must return true if event invocation is successful"
                    + " Method designed to allow particular implementation  for forcing condition \"" + body
                    + "\" encountered on event \"" + changeEvent.getName()
                    + "\" to true so we can assert if transition after event is correct");
        }
    } else if (event instanceof TimeEvent) {

        TimeEvent timeEvent = (TimeEvent) event;

        if (timeEvent.getWhen() == null || timeEvent.getWhen().getExpr() == null) {
            System.err.println("Event " + event.getName() + " has no when/expression");
        } else {
            String expression = ((LiteralString) timeEvent.getWhen().getExpr()).getValue(); // maybe can do something more with TimeExpression
            expression = StringFormatter.convertNonAlphanumericalSymbolsToUnderscore(
                    StringFormatter.convertMathSymbolsToText(expression));

            methodName = timeEvent.getName().replaceAll("\\W", "") + "_" + expression;
            textElement.setText("Method must return true if event invocation is successful"
                    + " Method designed to allow particular implementation  for forcing the time event "
                    + timeEvent.getName() + " with body \"" + expression
                    + "\" to happen so we can assert if transition after event is correct");
        }

    } else if (event instanceof SignalEvent) {

        SignalEvent signalEvent = (SignalEvent) event;
        Signal signal = signalEvent.getSignal();

        methodName = signal.getName().replaceAll("\\W", "");
        textElement.setText("Method must return true if method invocation is successful."
                + " Method designed to allow particular implementation call of \"" + signal.getName()
                + "\" so we can assert if transition after event is correct");
    } else {

        System.err.println("Event type of " + event.getClass() + " not supported yet ");
        methodName = "invoke" + event.getName().replaceAll("\\W", "_");
        textElement.setText("Event type of " + event.getClass()
                + " not supported yet so generated javadoc not very usefull. Method must ensure the event is called so we can assert if transition after event is correct.");
    }

    tag.fragments().add(textElement);
    javadoc.tags().add(tag);

    MethodDeclaration method = createAbstractAssertMethod(javadoc, methodName, ast);
    return method;
}

From source file:ac.at.tuwien.dsg.uml.statemachine.export.transformation.engines.AbstractStateMachineTestStrategy.java

License:Open Source License

protected MethodDeclaration createAbstractMethodForState(StateMachineState state, AST ast) {

    String stateName = state.equals(StateMachineState.INITIAL_STATE) ? "InitialState"
            : state.getName().replaceAll("\\W", "");

    Javadoc javadoc = ast.newJavadoc();/*from   w w w.j  a va2  s  .  c  o  m*/
    TagElement tag = ast.newTagElement();
    TextElement textElement = ast.newTextElement();
    textElement.setText("Method must return true if the current state is " + stateName);
    tag.fragments().add(textElement);
    javadoc.tags().add(tag);

    MethodDeclaration method = createAbstractAssertMethod(javadoc, ASSERT_STATE_LEADING + stateName, ast);
    return method;
}

From source file:ac.at.tuwien.dsg.uml.statemachine.export.transformation.engines.AbstractStateMachineTestStrategy.java

License:Open Source License

protected MethodDeclaration createAbstractMethodForGuard(String condition, AST ast) {

    String conditionName = StringFormatter
            .convertNonAlphanumericalSymbolsToUnderscore(StringFormatter.convertMathSymbolsToText(condition));

    Javadoc javadoc = ast.newJavadoc();/*from   w ww . j a v a2 s  .  c  o m*/
    TagElement tag = ast.newTagElement();
    TextElement textElement = ast.newTextElement();
    textElement.setText(
            "Method must evaluate and return true if the following condition is true:  state is " + condition);
    tag.fragments().add(textElement);
    javadoc.tags().add(tag);

    MethodDeclaration method = createAbstractAssertMethod(javadoc,
            ASSERT_GUARD_LEADING + (conditionName.substring(0, 1).toUpperCase() + conditionName.substring(1)),
            ast);
    return method;
}

From source file:ac.at.tuwien.dsg.uml.statemachine.export.transformation.engines.AbstractStateMachineTestStrategy.java

License:Open Source License

protected MethodDeclaration createAbstractForceConditionMethod(String condition, AST ast) {

    String conditionName = StringFormatter
            .convertNonAlphanumericalSymbolsToUnderscore(StringFormatter.convertMathSymbolsToText(condition));

    Javadoc javadoc = ast.newJavadoc();//from  w ww  .  ja va  2  s .c  o  m
    TagElement tag = ast.newTagElement();
    TextElement textElement = ast.newTextElement();
    textElement.setText(
            "Method must call tested system and ensure the following condition is true so the test can progress on the current test branch: "
                    + condition);
    tag.fragments().add(textElement);
    javadoc.tags().add(tag);

    MethodDeclaration method = createAbstractAssertMethod(javadoc,
            FORCE_GUARD_LEADING + (conditionName.substring(0, 1).toUpperCase() + conditionName.substring(1)),
            ast);
    return method;
}

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(TagElement node) {
    if (node.isNested()) {
        // nested tags are always enclosed in braces
        this.fBuffer.append("{");//$NON-NLS-1$
    } else {//from   w w  w  . ja v  a2s  .  c  o  m
        // top-level tags always begin on a new line
        this.fBuffer.append("\n * ");//$NON-NLS-1$
    }
    boolean previousRequiresWhiteSpace = false;
    if (node.getTagName() != null) {
        this.fBuffer.append(node.getTagName());
        previousRequiresWhiteSpace = true;
    }
    boolean previousRequiresNewLine = false;
    for (Iterator<? extends ASTNode> it = node.fragments().iterator(); it.hasNext();) {
        ASTNode e = it.next();
        // assume text elements include necessary leading and trailing whitespace
        // but Name, MemberRef, MethodRef, and nested TagElement do not include white space
        boolean currentIncludesWhiteSpace = (e instanceof TextElement);
        if (previousRequiresNewLine && currentIncludesWhiteSpace) {
            this.fBuffer.append("\n * ");//$NON-NLS-1$
        }
        previousRequiresNewLine = currentIncludesWhiteSpace;
        // add space if required to separate
        if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
            this.fBuffer.append(" "); //$NON-NLS-1$
        }
        e.accept(this);
        previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
    }
    if (node.isNested()) {
        this.fBuffer.append("}");//$NON-NLS-1$
    }
    return false;
}

From source file:at.bestsolution.fxide.jdt.editor.JDTJavaDocSupport.java

License:Open Source License

private static void handleContents(StringBuilder b, TagElement e) {
    List<ASTNode> l = e.fragments();
    for (ASTNode child : l) {
        if (child instanceof TextElement) {
            b.append(((TextElement) child).getText() + "\n");
        } else {//from   w w w .ja  v  a 2 s. co  m
            b.append(child.toString() + "\n");
        }

    }
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

private void parameterToHTML() {
    String elementName = fElement.getElementName();
    List<TagElement> tags = fJavadoc.tags();
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
        TagElement tag = iter.next();
        String tagName = tag.getTagName();
        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();
                    if (elementName.equals(name)) {
                        handleContentElements(fragments.subList(1, size));
                        return;
                    }//from w  ww.  j a v a 2s  .  c  o  m
                } else if (size > 2 && fElement instanceof ITypeParameter && 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 (elementName.equals(name) && ">".equals(thirdText)) { //$NON-NLS-1$
                                handleContentElements(fragments.subList(3, size));
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    if (fElement instanceof ILocalVariable) {
        List<String> parameterNames = initParameterNames();
        int i = parameterNames.indexOf(elementName);
        if (i != -1) {
            CharSequence inheritedParamDescription = fJavadocLookup.getInheritedParamDescription(fMethod, i);
            handleInherited(inheritedParamDescription);
        }
    } else if (fElement instanceof ITypeParameter) {
        List<String> typeParameterNames = initTypeParameterNames();
        int i = typeParameterNames.indexOf(elementName);
        if (i != -1) {
            CharSequence inheritedTypeParamDescription = fJavadocLookup
                    .getInheritedTypeParamDescription(fMethod, i);
            handleInherited(inheritedTypeParamDescription);
        }
    }
}

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;/*  w  ww.j a  va 2s. c om*/
    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

private void handleDeprecatedTag(TagElement tag) {
    fBuf.append("<p><b>"); //$NON-NLS-1$
    fBuf.append(JavaDocMessages.JavaDoc2HTMLTextReader_deprecated_section);
    fBuf.append("</b> <i>"); //$NON-NLS-1$
    handleContentElements(tag.fragments());
    fBuf.append("</i><p>"); //$NON-NLS-1$ TODO: Why not </p>? See https://bugs.eclipse.org/bugs/show_bug.cgi?id=243318 .
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

CharSequence getMainDescription() {
    if (fMainDescription == null) {
        fMainDescription = new StringBuffer();
        fBuf = fMainDescription;//from   w w  w  . ja v  a 2s  .com
        fLiteralContent = 0;

        List<TagElement> tags = fJavadoc.tags();
        for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
            TagElement tag = iter.next();
            String tagName = tag.getTagName();
            if (tagName == null) {
                handleContentElements(tag.fragments());
                break;
            }
        }

        fBuf = null;
    }
    return fMainDescription.length() > 0 ? fMainDescription : null;
}