use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable in project webtools.sourceediting by eclipse.
the class JSPTranslator method translateAttributeDirectiveAttributes.
private void translateAttributeDirectiveAttributes(Iterator regions) {
ITextRegion r = null;
String attrName, attrValue;
// $NON-NLS-1$ // the default class...
String varType = "java.lang.String";
String varName = null;
// $NON-NLS-1$
String description = "";
boolean isFragment = false;
// iterate all attributes
while (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() != DOMJSPRegionContexts.JSP_CLOSE) {
attrName = attrValue = null;
if (r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
attrName = getCurrentNode().getText(r).trim();
if (attrName.length() > 0) {
if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrValue = StringUtils.strip(getCurrentNode().getText(r));
}
// has equals, but no value?
}
if (attrName.equals(JSP11Namespace.ATTR_NAME_TYPE)) {
varType = attrValue;
} else if (attrName.equals(JSP20Namespace.ATTR_NAME_FRAGMENT)) {
isFragment = Boolean.valueOf(attrValue).booleanValue();
} else if (attrName.equals(JSP11Namespace.ATTR_NAME_NAME)) {
varName = attrValue;
} else if (attrName.equals(JSP20Namespace.ATTR_NAME_DESCRIPTION)) {
description = attrValue;
}
}
}
}
if (varName != null) {
if (isFragment) {
// 2.0:JSP.8.5.2
// $NON-NLS-1$
varType = "javax.servlet.jsp.tagext.JspFragment";
}
// $NON-NLS-1$
String declaration = new TaglibVariable(varType, varName, "", description).getDeclarationString(true, fContext, TaglibVariable.M_PRIVATE);
appendToBuffer(declaration, fUserDeclarations, false, fCurrentNode);
}
}
use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable in project webtools.sourceediting by eclipse.
the class JSPTranslator method addEndTagVariable.
private void addEndTagVariable(String tagToAdd, ITextRegionCollection customTag) {
IFile f = getFile();
if (f == null || !f.exists())
return;
// $NON-NLS-1$
String decl = "";
RegionTags regionTag = (RegionTags) fTagToVariableMap.pop(tagToAdd);
if (regionTag != null) {
// even an empty array will indicate a need for a closing brace
TaglibVariable[] taglibVars = regionTag.tag.getTagVariables();
StringBuffer text = new StringBuffer();
if (regionTag.tag.isIterationTag())
doAfterBody(text, regionTag);
// $NON-NLS-1$
text.append("} // </");
text.append(tagToAdd);
// $NON-NLS-1$
text.append(">\n");
appendToBuffer(text.toString(), fUserCode, false, customTag);
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.AT_END) {
decl = taglibVars[i].getDeclarationString(fContext);
appendToBuffer(decl, fUserCode, true, customTag);
}
}
fAtBeginVariableMap.remove(fAtBeginScopeStack.pop());
} else {
/*
* Since something should have been in the map because of a
* start tag, its absence now means an unbalanced end tag.
* Extras will be checked later to flag unbalanced start tags.
*/
IJSPProblem missingStartTag = createJSPProblem(IJSPProblem.StartCustomTagMissing, IJSPProblem.F_PROBLEM_ID_LITERAL, NLS.bind(JSPCoreMessages.JSPTranslator_4, tagToAdd), customTag.getStartOffset(), customTag.getEndOffset());
fTranslationProblems.add(missingStartTag);
}
}
use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable in project webtools.sourceediting by eclipse.
the class JSPTranslator method addStartTagVariable.
private void addStartTagVariable(String tagToAdd, ITextRegionCollection customTag, int index) {
IFile f = getFile();
if (f == null || !f.exists())
return;
TaglibHelper helper = TaglibHelperManager.getInstance().getTaglibHelper(f);
// $NON-NLS-1$
String decl = "";
List problems = new ArrayList();
CustomTag tag = helper.getCustomTag(tagToAdd, getStructuredDocument(), customTag, problems);
TaglibVariable[] taglibVars = tag.getTagVariables();
fTranslationProblems.addAll(problems);
Set scopedVarNames = new HashSet(0);
/*
* Add AT_BEGIN variables
*/
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.AT_BEGIN) {
scopedVarNames.add(taglibVars[i].getVarName());
boolean declaredInParentScope = false;
/*
* Check to see if we have already declared this variable
* once, if so then just reassign it instead. Declaring twice
* in the same scope should cause an error, so we're only
* checking parent scopes and the current scope.
*/
RegionTags[] parentTags = (RegionTags[]) fTagToVariableMap.values().toArray(new RegionTags[fTagToVariableMap.size()]);
String varName = taglibVars[i].getVarName();
for (int j = 0; j < parentTags.length && !declaredInParentScope; j++) {
declaredInParentScope |= parentTags[j].scopedVarNames.contains(varName);
}
Set currentAtBeginVars = (Set) fAtBeginVariableMap.get(fAtBeginScopeStack.peek());
boolean declaredInCurrentScope = currentAtBeginVars != null && currentAtBeginVars.contains(varName);
if (declaredInParentScope || declaredInCurrentScope) {
decl = taglibVars[i].getDeclarationString(false, fContext, TaglibVariable.M_REASSIGN);
} else {
decl = taglibVars[i].getDeclarationString(fContext);
if (currentAtBeginVars == null) {
currentAtBeginVars = new HashSet();
currentAtBeginVars.add(varName);
fAtBeginVariableMap.put(fAtBeginScopeStack.peek(), currentAtBeginVars);
} else {
currentAtBeginVars.add(varName);
}
}
appendToBuffer(decl, fUserCode, true, customTag);
}
}
boolean isEmptyTag = false;
if (index != -1)
isEmptyTag = isEmptyTag(customTag, index);
else
isEmptyTag = isEmptyTag(customTag);
/*
* Add a single { to limit the scope of NESTED variables
*/
StringBuffer text = new StringBuffer();
if (!isEmptyTag && tag.isIterationTag() && tag.getTagClassName() != null) {
// $NON-NLS-1$
text.append("\nwhile(true) ");
}
// $NON-NLS-1$
text.append("{ // <");
text.append(tagToAdd);
if (isEmptyTag)
// $NON-NLS-1$
text.append("/>\n");
else
// $NON-NLS-1$
text.append(">\n");
appendToBuffer(text.toString(), fUserCode, false, customTag);
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.NESTED) {
scopedVarNames.add(taglibVars[i].getVarName());
decl = taglibVars[i].getDeclarationString(fContext);
appendToBuffer(decl, fUserCode, true, customTag);
}
}
/*
* For empty tags, add the corresponding } and AT_END variables immediately.
*/
if (isEmptyTag) {
text = new StringBuffer();
// $NON-NLS-1$
text.append("} // <");
text.append(tagToAdd);
// $NON-NLS-1$
text.append("/>\n");
appendToBuffer(text.toString(), fUserCode, false, customTag);
/* Treat this as the end for empty tags */
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.AT_END) {
decl = taglibVars[i].getDeclarationString(fContext);
appendToBuffer(decl, fUserCode, false, customTag);
}
}
} else {
/*
* For non-empty tags, remember the variable information
*/
fTagToVariableMap.push(tagToAdd, new RegionTags(customTag, tag, scopedVarNames));
fAtBeginScopeStack.push(tagToAdd);
}
}
Aggregations