protected SearchMatch createSearchMatch(IFile file, Attr attributeNode) { int start = 0; int length = 0; if(attributeNode instanceof IDOMAttr){ IDOMAttr domAttr = (IDOMAttr)attributeNode; start = domAttr.getValueRegionStartOffset(); length = domAttr.getValueRegionText().length(); } SearchMatch match = new SearchMatch(attributeNode, start, length, file); return match; }
public static IRegion getNameRegion(IDOMAttr attr) { int regOffset = attr.getNameRegionStartOffset(); int regLength = attr.getNameRegionText().length(); return new Region(regOffset, regLength); }
boolean located = attrNode.contains(offset); if (located) if (attrNode.hasNameOnly())
String oldAttrValue = eachAttr.getValueRegionText(); if (oldAttrValue == null) { IDOMModel structuredModel = node.getModel(); if (isXMLType(structuredModel)) { String newAttrValue = "\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ if (eachAttr.getEqualRegion() != null) structuredDocument.replaceText(structuredDocument, eachAttr.getEndOffset(), 0, newAttrValue); else structuredDocument.replaceText(structuredDocument, eachAttr.getNameRegionTextEndOffset(), 0, "=".concat(newAttrValue)); //$NON-NLS-1$ int attrValueStartOffset = eachAttr.getValueRegionStartOffset(); int attrValueLength = oldAttrValue.length(); int startTagStartOffset = node.getStartOffset();
private IRegion getHyperlinkRegion(Node node) { IRegion hyperRegion = null; if (node != null) { short nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_TYPE_NODE) { // handle doc type node IDOMNode docNode = (IDOMNode) node; hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); } else if (nodeType == Node.ATTRIBUTE_NODE) { // handle attribute nodes IDOMAttr att = (IDOMAttr) node; // do not include quotes in attribute value region int regOffset = att.getValueRegionStartOffset(); ITextRegion valueRegion = att.getValueRegion(); if (valueRegion != null) { int regLength = valueRegion.getTextLength(); String attValue = att.getValueRegionText(); if (StringUtils.isQuoted(attValue)) { ++regOffset; regLength = regLength - 2; } hyperRegion = new Region(regOffset, regLength); } } } return hyperRegion; }
IDOMAttr eachAttr = (IDOMAttr) attributes.item(i); String oldAttrValue = eachAttr.getValueRegionText(); if (oldAttrValue == null) { IDOMModel structuredModel = node.getModel(); String newAttrValue = "=\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ replaceSource(structuredModel, structuredDocument, eachAttr.getNameRegionEndOffset(), 0, newAttrValue); int attrValueStartOffset = eachAttr.getValueRegionStartOffset(); int attrValueLength = oldAttrValue.length(); int startTagStartOffset = node.getStartOffset();
IDOMAttr attributeNode = (IDOMAttr) (element.getAttributeNode(nameOrValue)); if (attributeNode != null) { startEndPositions[0] = attributeNode.getValueRegionStartOffset(); startEndPositions[1] = startEndPositions[0] + attributeNode.getValueRegionText().length(); for (int i = 0; i < attributes.getLength(); i++) { IDOMAttr attr = (IDOMAttr) attributes.item(i); String nodeValue = attr.getNodeValue(); int index = nodeValue.indexOf(entity); if (index != -1) { startEndPositions[0] = attr.getValueRegionStartOffset() + index + 1; startEndPositions[1] = startEndPositions[0] + entity.length(); for (int i = 0; i < attributes.getLength(); i++) { IDOMAttr attr = (IDOMAttr) attributes.item(i); String nodeValue = attr.getNodeValue().trim(); if (nodeValue.equals(nameOrValue)) { startEndPositions[0] = attr.getValueRegionStartOffset() + 1; startEndPositions[1] = startEndPositions[0] + nodeValue.length(); break;
if (isXMLAttr) { IDOMAttr xmlattr = (IDOMAttr) a; if (!xmlattr.isGlobalAttr()) continue; // skip futher validation and begin next loop. if (CMUtil.isBooleanAttr(adec) && ((IDOMAttr) a).hasNameOnly()) continue; // OK, keep going. No more check is needed String source = ((IDOMAttr) a).getValueRegionText(); if (source != null) { char firstChar = source.charAt(0);
private boolean checkUnknownAttributes(IDOMElement element, CMNamedNodeMap cmAttrs, IReporter reporter, IFile file, IStructuredDocument document, IStructuredDocumentRegion documentRegion) { boolean foundjspattribute = false; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr a = (Attr) attrs.item(i); CMAttributeDeclaration adec = (CMAttributeDeclaration) cmAttrs.getNamedItem(a.getName()); if (adec == null) { // No attr declaration was found. That is, the attr name is // undefined. // but not regard it as undefined name if it includes JSP if (!hasJSPRegion(((IDOMNode) a).getNameRegion())) { String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_6, a.getName()); LocalizedMessage message = new LocalizedMessage(fSeverityUnknownAttribute, msgText, file); int start = ((IDOMAttr) a).getNameRegionStartOffset(); int length = ((IDOMAttr) a).getNameRegionEndOffset() - start; int lineNo = document.getLineOfOffset(start); message.setLineNo(lineNo); message.setOffset(start); message.setLength(length); reporter.addMessage(fMessageOriginator, message); } else { foundjspattribute = true; } } } return foundjspattribute; }
continue; IDOMAttr a = (IDOMAttr) n; String prefix = a.getPrefix(); if ((prefix != null) && isUnknownAttr(a, target)) { ITextRegion r = a.getNameRegion(); if (r == null) continue; int a_offset = a.getNameRegionStartOffset(); int a_length = a.getNameRegion().getLength(); reporter.report(MessageFactory.createMessage(new ErrorInfoImpl(UNDEFINED_NAME_ERROR, new Segment(a_offset, a_length), a)));
private static boolean isAngularElementExists(IDOMAttr attr, IFile file, IDocument document, IIDETernProject ternProject, final AngularType angularType) throws CoreException, IOException, Exception { TernAngularQuery query = new TernAngularTypeQuery(angularType); query.setExpression(AngularScopeHelper.getAngularValue(attr, angularType)); ITernScriptPath scriptPath = AngularScopeHelper.populateScope(attr.getOwnerElement(), file, angularType, query); ValidationTernTypeCollector collector = new ValidationTernTypeCollector(); if (scriptPath != null) { ternProject.request(query, null, scriptPath, null, null, collector); } else { ITernFile tf = new TernDocumentFile(file, document); ternProject.request(query, null, null, attr, tf, collector); } return collector.isExists(); } }
/** * Determines whether a node is "linkable" that is, the component it refers to * can be the target of a "go to definition" navigation. * * @param node the node to test, must not be null; * @return true if the node is linkable, false otherwise. */ private boolean isLinkable(IDOMNode node) { if (node == null) { return false; } short nodeType = node.getNodeType(); boolean isLinkable = false; if (nodeType == Node.ATTRIBUTE_NODE) { IDOMAttr attr = (IDOMAttr) node; String name = attr.getName(); // isLinkableAttribute is a template method. Derived classes should // override. isLinkable = isLinkableAttribute(name); } return isLinkable; }
/** */ public String generateAttrName(Attr attr) { if (attr == null) return null; String attrName = attr.getName(); if (attrName == null) return null; if (attrName.startsWith(JSPTag.TAG_OPEN)) { if (!attrName.endsWith(JSPTag.TAG_CLOSE)) { // close JSP return (attrName + JSPTag.TAG_CLOSE); } } if (((IDOMAttr) attr).isGlobalAttr() && CMNodeUtil.getAttributeDeclaration(attr) != null) { switch (getAttrNameCase(attr)) { case DocumentTypeAdapter.UPPER_CASE : attrName = attrName.toUpperCase(); break; case DocumentTypeAdapter.LOWER_CASE : attrName = attrName.toLowerCase(); break; default : // ASIS_CASE break; } } return attrName; }
int regOffset = att.getValueRegionStartOffset(); ITextRegion valueRegion = att.getValueRegion(); if (valueRegion != null) String attValue = att.getValueRegionText();
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { for (Iterator iter = matches.iterator(); iter.hasNext();) { SearchMatch match = (SearchMatch) iter.next(); TextChange textChange = getChangeManager().get(match.getFile()); String newName = getArguments().getNewName(); String qualifier = ""; if(getArguments() instanceof ComponentRenameArguments){ qualifier = ((ComponentRenameArguments)getArguments()).getQualifier(); } if(match.getObject() instanceof Node){ Node node = (Node)match.getObject(); if(node instanceof IDOMAttr){ IDOMAttr attr = (IDOMAttr)node; IDOMElement element = (IDOMElement)attr.getOwnerElement() ; newName = getNewQName(element, qualifier, newName); } newName = RenameComponentProcessor.quoteString(newName); } ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName ); String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference"); TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit); } // don't create any change now, all the changes are in changeManger variable and will be combined in RenameComponentProcessor.postCreateChange method return null; }
private boolean isUnknownAttr(IDOMAttr attr, Element target) { CMElementDeclaration dec = CMUtil.getDeclaration(target); if (dec == null) return true; // unknown. CMNamedNodeMap adecls = dec.getAttributes(); CMAttributeDeclaration adec = (CMAttributeDeclaration) adecls.getNamedItem(attr.getName()); return adec == null; }
public static IRegion getValueRegion(IDOMAttr attr) { int regOffset = attr.getValueRegionStartOffset(); int regLength = attr.getValueRegionText().length(); String attValue = attr.getValueRegionText(); if (StringUtils.isQuoted(attValue)) { regOffset++; regLength -= 2; } return new Region(regOffset, regLength); }
/** */ private Segment getErrorSegment(IDOMNode errorNode, int regionType) { ITextRegion rgn = null; switch (regionType) { case REGION_NAME : rgn = errorNode.getNameRegion(); break; case REGION_VALUE : rgn = errorNode.getValueRegion(); break; default : // nothing to do. break; } if (rgn != null) { if (errorNode instanceof IDOMAttr) { IDOMElement ownerElement = (IDOMElement) ((IDOMAttr) errorNode).getOwnerElement(); if (ownerElement != null) { int regionStartOffset = ownerElement.getFirstStructuredDocumentRegion().getStartOffset(rgn); int regionLength = rgn.getLength(); return new Segment(regionStartOffset, regionLength); } } } return new Segment(errorNode.getStartOffset(), 0); }