private void addLayoutReplacements( @NonNull List<TextEdit> edits, @NonNull Element element, @NonNull IStructuredDocument document) { String tag = element.getTagName(); if (tag.equals(mOldFqcn)) { int start = RefactoringUtil.getTagNameRangeStart(element, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } else if (tag.equals(VIEW_TAG)) { Attr classNode = element.getAttributeNode(ATTR_CLASS); if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } else if (tag.equals(VIEW_FRAGMENT)) { Attr classNode = element.getAttributeNode(ATTR_CLASS); if (classNode == null) { classNode = element.getAttributeNodeNS(ANDROID_URI, ATTR_NAME); } if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } else if (element.hasAttributeNS(TOOLS_URI, ATTR_CONTEXT)) { Attr classNode = element.getAttributeNodeNS(TOOLS_URI, ATTR_CONTEXT); if (classNode != null && classNode.getValue().equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(classNode, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } NodeList children = element.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { addLayoutReplacements(edits, (Element) child, document); } } }
private void addManifestReplacements( @NonNull List<TextEdit> edits, @NonNull Element element, @NonNull IStructuredDocument document) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Attr attr = (Attr) attributes.item(i); if (!RefactoringUtil.isManifestClassAttribute(attr)) { continue; } String value = attr.getValue(); if (value.equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(attr, document); if (start != -1) { int end = start + mOldFqcn.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } else if (value.startsWith(".")) { // $NON-NLS-1$ String fqcn = mAppPackage + value; if (fqcn.equals(mOldFqcn)) { int start = RefactoringUtil.getAttributeValueRangeStart(attr, document); if (start != -1) { int end = start + value.length(); edits.add(new ReplaceEdit(start, end - start, mNewFqcn)); } } } } NodeList children = element.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { addManifestReplacements(edits, (Element) child, document); } } }