List of usage examples for org.eclipse.jdt.core.dom TagElement setProperty
public final void setProperty(String propertyName, Object data)
null
to clear it. From source file:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java
License:Open Source License
/** * Evaluates value of expression specified in JavaDoc comments like this: * //from w w w .j av a2s . c o m * @wbp.eval.method.parameter someName someExpression * * @param javadoc * the {@link Javadoc} that should be checked. * @param tagName * the name of tag, "@wbp.eval.method.parameter" in example above. * @param expectedName * the name of expression, "someName" in example above. */ public static Object evaluateJavadocTagExpression(AstEditor editor, EvaluationContext context, Javadoc javadoc, String tagName, String expectedName) throws Exception { if (javadoc != null) { for (TagElement tag : DomGenerics.tags(javadoc)) { if (tagName.equals(tag.getTagName())) { // extract <name> and <expression text> String name; String expressionText; { String errorMessage = "'" + tagName + " <name> = <expression>' expected but '" + tag + "' found."; Assert.isLegal(tag.fragments().size() == 1, errorMessage); // prepare TextElement parts TextElement textElement = (TextElement) tag.fragments().get(0); String text = textElement.getText().trim(); String[] parts = StringUtils.split(text); Assert.isLegal(parts.length >= 2, errorMessage); // assign parts name = parts[0]; expressionText = text.substring(name.length()).trim(); } // check that we found expected <name> if (name.equals(expectedName)) { Object value = tag.getProperty(KEY_EXPRESSION_VALUE); // evaluate value only one time if (value == null) { Expression expression = editor.getParser().parseExpression(javadoc.getStartPosition(), expressionText); value = AstEvaluationEngine.evaluate(context, expression); tag.setProperty(KEY_EXPRESSION_VALUE, value); } // return value return value; } } } } // no value found return AstEvaluationEngine.UNKNOWN; }