List of usage examples for org.eclipse.jdt.core.dom TextElement setText
public void setText(String text)
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 va2 s . com * @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 www .j a va2 s. c om*/ 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();/*w w w.j a v a 2s . 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();/* w ww. j a v a 2 s .co 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:com.crispico.flower.mp.codesync.code.java.adapter.JavaAbstractAstNodeModelAdapter.java
License:Open Source License
@Override protected void updateUID(Object element, Object correspondingElement) { if (element instanceof BodyDeclaration) { BodyDeclaration node = (BodyDeclaration) element; Javadoc javadoc = node.getJavadoc(); // if it doesn't have any doc, create it if (javadoc == null) { javadoc = node.getAST().newJavadoc(); node.setJavadoc(javadoc);/*from www .j a v a 2 s.c om*/ } // first remove the existing flower tag, this way we also make sure that it's the last tag // note: if we only change the id, the rewriter won't format it correctly for (Object obj : javadoc.tags()) { if (FLOWER_UID.equals(((TagElement) obj).getTagName())) { javadoc.tags().remove(obj); break; } } // create new tag element for UID TagElement tag = javadoc.getAST().newTagElement(); tag.setTagName(FLOWER_UID); javadoc.tags().add(tag); TextElement text = javadoc.getAST().newTextElement(); tag.fragments().add(text); EObject eObject = (EObject) correspondingElement; text.setText(eObject.eResource().getURIFragment(eObject)); System.out.println(javadoc); } }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.forward.ForwardJavaDeclaration.java
License:Open Source License
/** * @throws CodeSyncException /*w w w . jav a 2 s . co m*/ * @flowerModelElementId _zbgpOpiOEd6aNMdNFvR5WQ */ @SuppressWarnings("unchecked") @Override protected void setASTFeatureValue(EStructuralFeature feature, TDeclaration astElement, Object value) throws CodeSyncException { if (astElement == null) throw new IllegalArgumentException("astElement null "); AST ast = astElement.getAST(); switch (feature.getFeatureID()) { case UMLPackage.NAMED_ELEMENT__VISIBILITY: JavaSyncUtils.updateVisibilityFromModelToJavaClass(astElement, (VisibilityKind) value); break; case UMLPackage.ELEMENT__OWNED_COMMENT: List<Comment> listComments = (List<Comment>) value; if (listComments.size() > 1) throw new IllegalArgumentException("setting more than one documentation "); else if (listComments.size() == 1) { String documentation = listComments.get(0).getBody(); Javadoc javadoc = ast.newJavadoc(); if (documentation != null) { javadoc.setProperty("comment", "\r\n" + documentation + "\r\n"); documentation = documentation.replace("\n", "\n * "); } TagElement tag = ast.newTagElement(); TextElement te = ast.newTextElement(); tag.fragments().add(te); te.setText(documentation); javadoc.tags().add(tag); astElement.setJavadoc(javadoc); } else if (listComments.isEmpty()) astElement.setJavadoc(null); break; case UMLPackage.FEATURE__IS_STATIC: JavaSyncUtils.updateModifierFromModelToJavaClass(astElement, (Boolean) value, JavaSyncUtils.MODIFIER_STATIC); break; case CodeSyncPackage.FINAL_FEATURE__IS_FINAL: JavaSyncUtils.updateModifierFromModelToJavaClass(astElement, (Boolean) value, JavaSyncUtils.MODIFIER_FINAL); break; default: throw new IllegalArgumentException("Cannot get value for feature in ForwardJavaDeclaration:" + feature); } }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.forward.ForwardJavaType.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w ww.j a va 2 s. co m protected void setASTFeatureValue(EStructuralFeature feature, CompilationUnit astElement, Object value) throws CodeSyncException { if (astElement == null) throw new IllegalArgumentException("astElement null "); AST ast = astElement.getAST(); TypeDeclaration masterClass = JavaSyncUtils.getMasterClass(astElement); switch (feature.getFeatureID()) { case UMLPackage.NAMED_ELEMENT__NAME: if (value == null) throw new IllegalArgumentException("setting name to null value "); String oldName = masterClass.getName().toString(); if (!oldName.equals(value) && !oldName.equals("MISSING")) { // rename case try { SyncUtils.renameFile(oldName.toString(), (String) value, ".java", parentFolder); } catch (CoreException e) { throw new RuntimeException("Error during folder refresh: " + parentFolder, e); } catch (Exception e) { throw new RuntimeException("Error during file rename ", e); } } try { masterClass.setName(ast.newSimpleName((String) value)); } catch (Exception e) { e.printStackTrace(); } break; case UMLPackage.NAMED_ELEMENT__VISIBILITY: JavaSyncUtils.updateVisibilityFromModelToJavaClass(masterClass, (VisibilityKind) value); break; case UMLPackage.CLASSIFIER__IS_ABSTRACT: JavaSyncUtils.updateModifierFromModelToJavaClass(masterClass, (Boolean) value, JavaSyncUtils.MODIFIER_ABSTRACT); break; case UMLPackage.ELEMENT__OWNED_COMMENT: List<Comment> listComments = (List<Comment>) value; if (listComments.size() > 1) throw new IllegalArgumentException("setting more than one documentation "); else if (listComments.size() == 1) { String documentation = listComments.get(0).getBody(); Javadoc javadoc = ast.newJavadoc(); if (documentation != null) { javadoc.setProperty("comment", "\r\n" + documentation + "\r\n"); documentation = documentation.replace("\n", "\n * "); } TagElement tag = ast.newTagElement(); TextElement te = ast.newTextElement(); tag.fragments().add(te); te.setText(documentation); javadoc.tags().add(tag); JavaSyncUtils.getMasterClass(astElement).setJavadoc(javadoc); } else if (listComments.isEmpty()) JavaSyncUtils.getMasterClass(astElement).setJavadoc(null); break; default: throw new IllegalArgumentException("Cannot get value for feature in ForwardJavaType:" + feature); } }
From source file:com.google.currysrc.api.process.ast.AstNodes.java
License:Apache License
public static TextElement createTextElement(AST ast, String text) { TextElement textElement = ast.newTextElement(); textElement.setText(text); return textElement; }
From source file:com.idega.eclipse.ejbwizards.BeanCreator.java
License:Open Source License
protected Javadoc getJavadoc(AST ast, IMethod method) { Javadoc jc = ast.newJavadoc();// w w w. java2s . c om TagElement tag = ast.newTagElement(); tag.setTagName(TagElement.TAG_SEE); TextElement te = ast.newTextElement(); te.setText(getType().getFullyQualifiedName() + "#" + method.getElementName()); tag.fragments().add(te); jc.tags().add(tag); return jc; }
From source file:de.akra.idocit.java.services.JavadocGenerator.java
License:Apache License
/** * Append the information out of <code>documentations</code> to the {@link Javadoc} * block comment. If <code>tagName != null</code> the documentations are added to a * new {@link TagElement} with that name. Add first the general description text with * <code>tagName == null</code>. After that all other wished tags. * /* w w w . j av a 2 s . c om*/ * @param documentations * The list of {@link Documentation}s which should be converted to * {@link Javadoc}. * @param tagName * The name of the tag element, or <code>null</code> (@see * {@link TagElement#setTagName(String)} ). * @param paramName * The name of the described parameter, or <code>null</code> if no name is * needed. * @param javadoc * The {@link Javadoc} reference to which the {@link TagElement}s should be * added. */ @Override public void appendDocsToJavadoc(List<Documentation> documentations, String tagName, String paramName, String thematicGridName, Javadoc javadoc, List<TagElement> additionalTagElements, JavaMethod method) { @SuppressWarnings("unchecked") List<TagElement> tags = javadoc.tags(); AST jdocAST = javadoc.getAST(); boolean tagChanged = false; TagElement newTag = jdocAST.newTagElement(); if (tagName != null) { tagChanged = true; newTag.setTagName(tagName + de.akra.idocit.common.utils.StringUtils.EMPTY); } @SuppressWarnings("unchecked") List<ASTNode> fragments = newTag.fragments(); if (paramName != null) { tagChanged = true; TextElement paramNameElement = jdocAST.newTextElement(); paramNameElement.setText(paramName + de.akra.idocit.common.utils.StringUtils.EMPTY); fragments.add(paramNameElement); } final String tableStartTag = "<table name=\"" + IDOCIT_HTML_TABLE_NAME + "\" border=\"1\" cellspacing=\"0\">\n"; for (Documentation doc : documentations) { // write only if there is something to write if (doc.getThematicRole() != null || !doc.getDocumentation().isEmpty()) { tagChanged = true; StringBuffer textElem = new StringBuffer(); if (fragments.size() >= 1) { textElem.append("\n<br />"); } textElem.append(tableStartTag); if (doc.getSignatureElementIdentifier() != null) { textElem.append("<tr><td>Element:</td><td>"); textElem.append(quoteGenericsInIdentifier(doc.getSignatureElementIdentifier())); textElem.append("</td></tr>\n"); } if (doc.getThematicRole() != null) { StringBuffer thematicRoleBuffer = new StringBuffer(); thematicRoleBuffer.append(doc.getThematicRole().getName()); if (doc.isErrorCase()) { thematicRoleBuffer.append(JavadocUtils.getComplexErrorFlagPostfix()); } textElem.append("<tr><td>Role:</td><td>"); textElem.append(thematicRoleBuffer.toString()); textElem.append("</td></tr>\n"); } Map<Addressee, String> docMap = doc.getDocumentation(); for (Addressee addressee : doc.getAddresseeSequence()) { String text = docMap.get(addressee); if (!text.isEmpty()) { textElem.append("<tr><td><b>"); textElem.append(addressee.getName()); textElem.append("</b>:</td><td>"); textElem.append(StringUtils.escapeHtml(docMap.get(addressee))); textElem.append("</td></tr>\n"); } } textElem.append("</table>"); TextElement textElement = jdocAST.newTextElement(); textElement.setText(textElem.toString()); fragments.add(textElement); } } if (tagChanged) { tags.add(newTag); } }