Java 类com.intellij.psi.xml.XmlAttribute 实例源码
项目:AppleScript-IDEA
文件:AbstractDictionaryComponent.java
@NotNull
@Override
public DictionaryIdentifier getIdentifier() {
DictionaryIdentifier myIdentifier = null;
XmlAttribute nameAttr = myXmlElement.getAttribute("name");
if (nameAttr != null) {
XmlAttributeValue attrValue = nameAttr.getValueElement();
if (attrValue != null) {
myIdentifier = new DictionaryIdentifierImpl(this, getName(), attrValue);
}
} else {
for (XmlAttribute anyAttr : myXmlElement.getAttributes()) {
myIdentifier = new DictionaryIdentifierImpl(this, getName(), anyAttr);
}
}
return myIdentifier != null ? myIdentifier : new DictionaryIdentifierImpl(this, getName(), myXmlElement.getAttributes()[0]);
}
项目:hybris-integration-intellij-idea-plugin
文件:BeansUtils.java
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
@NotNull final PsiElement element,
@NotNull final Class<? extends T> domTagClass,
@NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
final DomManager domManager = DomManager.getDomManager(element.getProject());
if (!(element instanceof XmlElement)) {
return null;
}
final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
if (xmlAttribute == null) {
return null;
}
final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
DomElement domParentTag = domManager.getDomElement(xmlParentTag);
return Optional.ofNullable(domParentTag)
.map(o -> ObjectUtils.tryCast(o, domTagClass))
.map(domGetter)
.filter(val -> val == domManager.getDomElement(xmlAttribute))
.orElse(null);
}
项目:intellij-ce-playground
文件:DeletionHandler.java
@Nullable
private static String getId(@NotNull XmlAttribute attribute) {
if (attribute.getLocalName().startsWith(ATTR_LAYOUT_RESOURCE_PREFIX) &&
ANDROID_URI.equals(attribute.getNamespace()) &&
!attribute.getLocalName().startsWith(ATTR_LAYOUT_MARGIN)) {
String id = attribute.getValue();
if (id == null) {
return null;
}
// It might not be an id reference, so check manually rather than just
// calling stripIdPrefix():
if (id.startsWith(NEW_ID_PREFIX)) {
return id.substring(NEW_ID_PREFIX.length());
}
else if (id.startsWith(ID_PREFIX)) {
return id.substring(ID_PREFIX.length());
}
}
return null;
}
项目:intellij-ce-playground
文件:AndroidValueResourcesTest.java
public void testNavigationInPlatformXml1() throws Exception {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(
getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml");
myFixture.configureFromExistingVirtualFile(file);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(16, 43));
PsiElement[] targets =
GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag)targetAttrValue.getParent().getParent()).getName());
assertEquals(file, targetElement.getContainingFile().getVirtualFile());
}
项目:intellij-ce-playground
文件:AndroidUnknownAttributeInspection.java
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
if (!"xmlns".equals(attribute.getNamespacePrefix())) {
String namespace = attribute.getNamespace();
if (SdkConstants.NS_RESOURCES.equals(namespace) || namespace.isEmpty()) {
final XmlTag tag = attribute.getParent();
if (tag != null &&
tag.getDescriptor() instanceof AndroidXmlTagDescriptor &&
attribute.getDescriptor() instanceof AndroidAnyAttributeDescriptor) {
final ASTNode node = attribute.getNode();
assert node != null;
ASTNode nameNode = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node);
final PsiElement nameElement = nameNode != null ? nameNode.getPsi() : null;
if (nameElement != null) {
myResult.add(myInspectionManager.createProblemDescriptor(nameElement, AndroidBundle
.message("android.inspections.unknown.attribute.message", attribute.getName()), myOnTheFly, LocalQuickFix.EMPTY_ARRAY,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
}
}
项目:intellij-ce-playground
文件:FragmentProperty.java
@Override
public void setValue(@NotNull final RadViewComponent component, @Nullable final Object value) throws Exception {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (StringUtil.isEmpty((String)value)) {
//noinspection ConstantConditions
XmlAttribute attribute = component.getTag().getAttribute(myAttribute, myNamespace);
if (attribute != null) {
attribute.delete();
}
}
else {
//noinspection ConstantConditions
component.getTag().setAttribute(myAttribute, myNamespace, (String)value);
}
}
});
}
项目:intellij-ce-playground
文件:AttributeChildInvocationHandler.java
@Override
public final XmlAttribute ensureXmlElementExists() {
XmlAttribute attribute = (XmlAttribute)getXmlElement();
if (attribute != null) return attribute;
final DomManagerImpl manager = getManager();
final boolean b = manager.setChanging(true);
try {
attribute = ensureTagExists().setAttribute(getXmlElementName(), getXmlApiCompatibleNamespace(getParentHandler()), "");
setXmlElement(attribute);
getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
final DomElement element = getProxy();
manager.fireEvent(new DomEvent(element, true));
return attribute;
}
catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
finally {
manager.setChanging(b);
}
}
项目:intellij-ce-playground
文件:DomCompletionContributor.java
public static boolean isSchemaEnumerated(final PsiElement element) {
if (element instanceof XmlTag) {
final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag)element);
if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<String>())) {
return true;
}
}
if (element instanceof XmlAttributeValue) {
final PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute) {
final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
if (descriptor != null && descriptor.isEnumerated()) {
return true;
}
String[] enumeratedValues = XmlAttributeValueGetter.getEnumeratedValues((XmlAttribute)parent);
if (enumeratedValues != null && enumeratedValues.length > 0) {
String value = descriptor == null ? null : descriptor.getDefaultValue();
if (value == null || enumeratedValues.length != 1 || !value.equals(enumeratedValues[0])) {
return true;
}
}
}
}
return false;
}
项目:intellij-ce-playground
文件:DomChildrenTest.java
public void testAttributes() throws Throwable {
final MyElement element = createElement("<a/>");
final GenericAttributeValue<String> attr = element.getAttr();
assertSame(element.getXmlTag(), attr.getXmlTag());
assertNull(attr.getValue());
assertNull(attr.getXmlAttribute());
assertEquals(attr, element.getAttr());
attr.setValue("239");
assertEquals("239", attr.getValue());
final XmlAttribute attribute = element.getXmlTag().getAttribute("attr", null);
assertSame(attribute, attr.getXmlAttribute());
assertSame(attribute, attr.getXmlElement());
assertSame(attribute, attr.ensureXmlElementExists());
assertSame(attribute.getValueElement(), attr.getXmlAttributeValue());
attr.setValue(null);
assertFalse(attribute.isValid());
assertNull(element.getXmlTag().getAttributeValue("attr"));
assertNull(attr.getValue());
assertNull(attr.getXmlAttribute());
}
项目:intellij-ce-playground
文件:ConvertSchemaPrefixToDefaultIntention.java
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
final PsiElement parent = element.getParent();
if (parent == null) return null;
for (PsiReference ref : parent.getReferences()) {
if (ref instanceof SchemaPrefixReference) {
final PsiElement elem = ref.resolve();
if (elem != null) {
final PsiElement attr = elem.getParent();
if (attr instanceof XmlAttribute) {
final PsiElement tag = attr.getParent();
if (tag instanceof XmlTag && ((XmlTag)tag).getAttribute("xmlns") == null) {
return (XmlAttribute)attr;
}
}
}
}
}
return null;
}
项目:intellij-ce-playground
文件:HtmlLocalInspectionTool.java
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override public void visitXmlToken(final XmlToken token) {
if (token.getTokenType() == XmlTokenType.XML_NAME) {
PsiElement element = token.getPrevSibling();
while(element instanceof PsiWhiteSpace) element = element.getPrevSibling();
if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
PsiElement parent = element.getParent();
if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
XmlTag tag = (XmlTag)parent;
checkTag(tag, holder, isOnTheFly);
}
}
}
}
@Override public void visitXmlAttribute(final XmlAttribute attribute) {
checkAttribute(attribute, holder, isOnTheFly);
}
};
}
项目:intellij-ce-playground
文件:JavaFxEventHandlerReference.java
private static String getHandlerSignature(JavaFxEventHandlerReference ref) {
final XmlAttributeValue element = ref.getElement();
String canonicalText = JavaFxCommonClassNames.JAVAFX_EVENT;
final PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute) {
final XmlAttribute xmlAttribute = (XmlAttribute)parent;
final Project project = element.getProject();
final PsiField handlerField = ref.myCurrentTagClass.findFieldByName(xmlAttribute.getName(), true);
if (handlerField != null) {
final PsiClassType classType = JavaFxPsiUtil.getPropertyClassType(handlerField);
if (classType != null) {
final PsiClass eventHandlerClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_EVENT_EVENT_HANDLER, GlobalSearchScope.allScope(project));
final PsiTypeParameter[] typeParameters = eventHandlerClass != null ? eventHandlerClass.getTypeParameters() : null;
if (typeParameters != null && typeParameters.length == 1) {
final PsiTypeParameter typeParameter = typeParameters[0];
final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(eventHandlerClass, classType);
final PsiType eventType = substitutor.substitute(typeParameter);
if (eventType != null) {
canonicalText = eventType.getCanonicalText();
}
}
}
}
}
return "public void " + element.getValue().substring(1) + "(" + canonicalText + " e)";
}
项目:intellij-ce-playground
文件:DefaultXmlExtension.java
@Override
public SchemaPrefix getPrefixDeclaration(final XmlTag context, String namespacePrefix) {
@NonNls String nsDeclarationAttrName = null;
for(XmlTag t = context; t != null; t = t.getParentTag()) {
if (t.hasNamespaceDeclarations()) {
if (nsDeclarationAttrName == null) nsDeclarationAttrName = namespacePrefix.length() > 0 ? "xmlns:"+namespacePrefix:"xmlns";
XmlAttribute attribute = t.getAttribute(nsDeclarationAttrName);
if (attribute != null) {
final String attrPrefix = attribute.getNamespacePrefix();
final TextRange textRange = TextRange.from(attrPrefix.length() + 1, namespacePrefix.length());
return new SchemaPrefix(attribute, textRange, namespacePrefix);
}
}
}
return null;
}
项目:intellij-ce-playground
文件:GravityProperty.java
private void setOptions(final RadViewComponent component, @Nullable String[] setNames, @Nullable String[] unsetNames) throws Exception {
final Set<String> options = new HashSet<String>(getOptions(component));
if (unsetNames != null) {
for (String name : unsetNames) {
options.remove(name);
}
}
if (setNames != null) {
Collections.addAll(options, setNames);
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (options.isEmpty()) {
XmlAttribute attribute = getAttribute(component);
if (attribute != null) {
attribute.delete();
}
}
else {
component.getTag().setAttribute(myDefinition.getName(), getNamespace(component, true), StringUtil.join(options, "|"));
}
}
});
}
项目:intellij-ce-playground
文件:URIReferenceProvider.java
static PsiReference getUrlReference(PsiElement element, String s) {
PsiElement parent = element.getParent();
if (XmlUtil.isUrlText(s, element.getProject()) ||
(parent instanceof XmlAttribute &&
( ((XmlAttribute)parent).isNamespaceDeclaration() ||
NAMESPACE_ATTR_NAME.equals(((XmlAttribute)parent).getName())
)
)
) {
if (!s.startsWith(XmlUtil.TAG_DIR_NS_PREFIX)) {
boolean namespaceSoftRef = parent instanceof XmlAttribute &&
NAMESPACE_ATTR_NAME.equals(((XmlAttribute)parent).getName()) &&
((XmlAttribute)parent).getParent().getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT) != null;
if (!namespaceSoftRef && parent instanceof XmlAttribute && ((XmlAttribute)parent).isNamespaceDeclaration()) {
namespaceSoftRef = parent.getContainingFile().getContext() != null;
}
return new URLReference(element, null, namespaceSoftRef);
}
}
return null;
}
项目:intellij-ce-playground
文件:AbsoluteLayout.java
public static RadViewComponent RelativeLayout(RadViewComponent component, MetaModel target) throws Exception {
// *Relative*Layout here seems wrong
return new ComponentMorphingTool(component, new RadRelativeLayoutComponent(), target, new RadRelativeLayout()) {
@Override
protected void convertTag() {
for (RadComponent childComponent : myNewComponent.getChildren()) {
XmlTag tag = ((RadViewComponent)childComponent).getTag();
XmlAttribute xAttribute = tag.getAttribute("layout_x", SdkConstants.NS_RESOURCES);
if (xAttribute != null) {
tag.setAttribute("layout_alignParentLeft", SdkConstants.NS_RESOURCES, "true");
xAttribute.setName(xAttribute.getNamespacePrefix() + ":layout_marginLeft");
}
XmlAttribute yAttribute = tag.getAttribute("layout_y", SdkConstants.NS_RESOURCES);
if (yAttribute != null) {
tag.setAttribute("layout_alignParentTop", SdkConstants.NS_RESOURCES, "true");
yAttribute.setName(yAttribute.getNamespacePrefix() + ":layout_marginTop");
}
}
}
}.result();
}
项目:intellij-ce-playground
文件:MicrodataAttributeDescriptorsProvider.java
private static String[] findProperties(@NotNull XmlTag tag) {
final XmlAttribute typeAttribute = tag.getAttribute(ITEM_TYPE);
if (typeAttribute != null) {
final XmlAttributeValue valueElement = typeAttribute.getValueElement();
final PsiReference[] references = valueElement != null ? valueElement.getReferences() : PsiReference.EMPTY_ARRAY;
List<String> result = new ArrayList<String>();
for (PsiReference reference : references) {
final PsiElement target = reference != null ? reference.resolve() : null;
if (target instanceof PsiFile) {
result.addAll(extractProperties((PsiFile)target, StringUtil.stripQuotesAroundValue(reference.getCanonicalText())));
}
}
return ArrayUtil.toStringArray(result);
}
return ArrayUtil.EMPTY_STRING_ARRAY;
}
项目:intellij-ce-playground
文件:JavaFxDefaultAttributeDescriptor.java
@Nullable
@Override
public String validateValue(XmlElement context, String value) {
if (context instanceof XmlAttributeValue) {
final PsiElement parent = context.getParent();
if (parent instanceof XmlAttribute) {
final XmlAttribute attribute = (XmlAttribute)parent;
final String attributeName = attribute.getName();
if (FxmlConstants.FX_VALUE.equals(attributeName)) {
final PsiClass tagClass = JavaFxPsiUtil.getTagClass((XmlAttributeValue)context);
if (tagClass != null) {
final PsiMethod method = JavaFxPsiUtil.findValueOfMethod(tagClass);
if (method == null) {
return "Unable to coerce '" + value + "' to " + tagClass.getQualifiedName() + ".";
}
}
} else if (FxmlConstants.TYPE.equals(attributeName)) {
final PsiReference[] references = context.getReferences();
if (references.length == 0 || references[references.length - 1].resolve() == null) {
return "Cannot resolve class " + value;
}
}
}
}
return super.validateValue(context, value);
}
项目:intellij-ce-playground
文件:XsltReferenceProvider.java
private static PsiReference[] createPrefixReferences(XmlAttribute attribute, Pattern pattern) {
final Matcher matcher = pattern.matcher(attribute.getValue());
if (matcher.find()) {
final List<PsiReference> refs = new SmartList<PsiReference>();
do {
final int start = matcher.start(1);
if (start >= 0) {
refs.add(new PrefixReference(attribute, TextRange.create(start, matcher.end(1))));
}
}
while (matcher.find());
return refs.toArray(new PsiReference[refs.size()]);
}
return PsiReference.EMPTY_ARRAY;
}
项目:intellij-ce-playground
文件:AndroidXmlPolicy.java
@Override
public boolean insertLineBreakBeforeFirstAttribute(XmlAttribute attribute) {
if (!myCustomSettings.INSERT_LINE_BREAK_BEFORE_FIRST_ATTRIBUTE ||
attribute.isNamespaceDeclaration()) {
return false;
}
return attribute.getParent().getAttributes().length > 1;
}
项目:intellij-ce-playground
文件:FormReferenceProvider.java
private static void processButtonGroupReference(final XmlTag tag, final PsiReferenceProcessor processor, final PsiPlainTextFile file,
final PsiReference classReference) {
final XmlAttribute boundAttribute = tag.getAttribute(UIFormXmlConstants.ATTRIBUTE_BOUND, null);
final XmlAttribute nameAttribute = tag.getAttribute(UIFormXmlConstants.ATTRIBUTE_NAME, null);
if (boundAttribute != null && Boolean.parseBoolean(boundAttribute.getValue()) && nameAttribute != null) {
processor.execute(new FieldFormReference(file, classReference, getValueRange(nameAttribute), null, null, false));
}
}
项目:weex-language-support
文件:WeexReferenceProvider.java
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
if (!WeexFileUtil.isOnWeexFile(psiElement)) {
return new PsiReference[0];
}
String text = psiElement.getText().replaceAll("\"+", "");
if (Pattern.compile("\\{\\{.*\\}\\}").matcher(text).matches() && text.length() > 4) {
String valueType = "var";
if (psiElement.getParent() != null && psiElement.getParent().getParent() != null) {
PsiElement tag = psiElement.getParent().getParent();
String attr = null;
if (psiElement.getContext() != null) {
attr = ((XmlAttribute) psiElement.getContext()).getName();
}
if (attr != null && tag instanceof XmlTag) {
String tagName = ((XmlTag) tag).getName();
WeexTag weexTag = DirectiveLint.getWeexTag(tagName);
if (weexTag != null && weexTag.getAttribute(attr) != null) {
valueType = weexTag.getAttribute(attr).valueType;
}
}
}
return new PsiReference[]{new MustacheVarReference(psiElement, valueType.toLowerCase())};
}
return new PsiReference[0];
}
项目:intellij-ce-playground
文件:DeletionHandler.java
/**
* Updates the constraints in the layout to handle deletion of a set of
* nodes. This ensures that any constraints pointing to one of the deleted
* nodes are changed properly to point to a non-deleted node with similar
* constraints.
*/
public void updateConstraints() {
if (myChildren.size() == myDeleted.size()) {
// Deleting everything: Nothing to be done
return;
}
// Now remove incoming edges to any views that were deleted. If possible,
// don't just delete them but replace them with a transitive constraint, e.g.
// if we have "A <= B <= C" and "B" is removed, then we end up with "A <= C",
for (RadViewComponent child : RadViewComponent.getViewComponents(myChildren)) {
if (myDeleted.contains(child)) {
continue;
}
for (XmlAttribute attribute : child.getTag().getAttributes()) {
String id = getId(attribute);
if (id != null) {
if (myDeletedIds.contains(id)) {
// Unset this reference to a deleted widget. It might be
// replaced if the pointed to node points to some other node
// on the same side, but it may use a different constraint name,
// or have none at all (e.g. parent).
String name = attribute.getLocalName();
attribute.delete();
RadViewComponent deleted = myNodeMap.get(id);
if (deleted != null) {
ConstraintType type = ConstraintType.fromAttribute(name);
if (type != null) {
transfer(deleted, child, type, 0);
}
}
}
}
}
}
}
项目:intellij-ce-playground
文件:XslZenCodingFilter.java
@NotNull
@Override
public GenerationNode filterNode(@NotNull final GenerationNode node) {
TemplateToken token = node.getTemplateToken();
if (token != null) {
XmlDocument document = token.getFile().getDocument();
if (document != null) {
final XmlTag tag = document.getRootTag();
if (tag != null) {
if (token.getAttributes().containsKey(SELECT_ATTR_NAME)) {
return node;
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (isOurTag(tag, node.getChildren().size() > 0)) {
XmlAttribute attribute = tag.getAttribute(SELECT_ATTR_NAME);
if (attribute != null) {
attribute.delete();
}
}
}
});
return node;
}
}
}
return node;
}
项目:intellij-ce-playground
文件:XmlNamedElementPattern.java
protected XmlAttributePattern() {
super(new InitialPatternCondition<XmlAttribute>(XmlAttribute.class) {
@Override
public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
return o instanceof XmlAttribute;
}
});
}
项目:intellij-ce-playground
文件:XsltImplicitUsagesProvider.java
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof XmlAttribute)) {
return false;
}
final XmlAttribute attr = (XmlAttribute)element;
if (!attr.isNamespaceDeclaration()) {
return false;
}
final PsiFile file = attr.getContainingFile();
if (!(file instanceof XmlFile)) {
return false;
}
// also catch namespace declarations in "normal" XML files that have XPath injected into some attributes
// ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files
if (!ContextProvider.hasXPathInjections((XmlFile)file) && !XsltSupport.isXsltFile(file)) {
return false;
}
// This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references:
// <xsl:template match="*" mode="prefix:name" />
// BTW: Almost the same logic applies to other XML dialects (RELAX-NG).
// Pull this class into the platform?
final String prefix = attr.getLocalName();
final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix);
final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent()));
return !q.forEach(new Processor<PsiReference>() {
public boolean process(PsiReference psiReference) {
if (psiReference.getElement() == attr) {
return true;
}
return false;
}
});
}
项目:intellij-ce-playground
文件:NamedTemplateMatcher.java
protected boolean matches (XmlTag element) {
if (XsltSupport.isTemplate(element, true)) {
final XmlAttribute attribute = element.getAttribute("name", null);
if (myName == null || (attribute != null && myName.equals(attribute.getValue()))) {
return true;
}
}
return false;
}
项目:intellij-ce-playground
文件:OrientationAction.java
@Override
protected void performWriteAction() {
String value = myHorizontal ? VALUE_HORIZONTAL : VALUE_VERTICAL;
if (myHorizontal == myDefaultHorizontal) {
XmlAttribute attribute = myLayout.getTag().getAttribute(ATTR_ORIENTATION, ANDROID_URI);
if (attribute != null) {
attribute.delete();
}
} else {
myLayout.getTag().setAttribute(ATTR_ORIENTATION, ANDROID_URI, value);
}
}
项目:intellij-ce-playground
文件:StyleProperty.java
@Override
public Object getValue(@NotNull RadViewComponent component) throws Exception {
Object value = null;
XmlAttribute attribute = getAttribute(component);
if (attribute != null) {
value = attribute.getValue();
}
return value == null ? "" : value;
}
项目:intellij-ce-playground
文件:DefineAttributeQuickFix.java
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
try {
final XmlTag tag = (XmlTag)descriptor.getPsiElement();
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement().getContainingFile())) return;
final XmlAttribute attribute = tag.setAttribute(myAttrName, myNamespace, "");
new OpenFileDescriptor(project, tag.getContainingFile().getVirtualFile(),
attribute.getValueElement().getTextRange().getStartOffset() + 1).navigate(true);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
项目:intellij-ce-playground
文件:BaselineAction.java
private static boolean isBaselineAligned(RadViewComponent component) {
XmlTag tag = component.getTag();
XmlAttribute attribute = tag.getAttribute(ATTR_BASELINE_ALIGNED, ANDROID_URI);
if (attribute != null) {
String value = attribute.getValue();
return Boolean.valueOf(value);
} else {
return true;
}
}
项目:intellij-ce-playground
文件:AndroidExtractStyleAction.java
@NotNull
static List<XmlAttribute> getExtractableAttributes(@NotNull XmlTag viewTag) {
final List<XmlAttribute> extractableAttributes = new ArrayList<XmlAttribute>();
for (XmlAttribute attribute : viewTag.getAttributes()) {
if (canBeExtracted(attribute)) {
extractableAttributes.add(attribute);
}
}
return extractableAttributes;
}
项目:intellij-ce-playground
文件:XsltRefactoringActionBase.java
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
final int offset = editor.getCaretModel().getOffset();
final XmlAttribute context = PsiTreeUtil.getContextOfType(file, XmlAttribute.class, true);
if (context != null) {
if (actionPerformedImpl(file, editor, context, offset)) {
return;
}
}
final String message = getErrorMessage(editor, file, context);
CommonRefactoringUtil.showErrorHint(editor.getProject(), editor, "Cannot perform refactoring.\n" +
(message != null ? message : getRefactoringName() + " is not available in the current context."), "XSLT - " + getRefactoringName(), null);
}
项目:intellij-ce-playground
文件:ConvertContext.java
@Nullable
public XmlElement getReferenceXmlElement() {
final XmlElement element = getXmlElement();
if (element instanceof XmlTag) {
return element;
}
if (element instanceof XmlAttribute) {
return ((XmlAttribute)element).getValueElement();
}
return null;
}
项目:intellij-ce-playground
文件:ResourceReferenceConverter.java
@Override
@NotNull
public PsiReference[] createReferences(GenericDomValue<ResourceValue> value, PsiElement element, ConvertContext context) {
if (NULL_RESOURCE.equals(value.getStringValue())) {
return PsiReference.EMPTY_ARRAY;
}
Module module = context.getModule();
if (module != null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
ResourceValue resValue = value.getValue();
if (resValue != null && resValue.isReference()) {
String resType = resValue.getResourceType();
if (resType == null) {
return PsiReference.EMPTY_ARRAY;
}
// Don't treat "+id" as a reference if it is actually defining an id locally; e.g.
// android:layout_alignLeft="@+id/foo"
// is a reference to R.id.foo, but
// android:id="@+id/foo"
// is not; it's the place we're defining it.
if (resValue.getPackage() == null && "+id".equals(resType)
&& element != null && element.getParent() instanceof XmlAttribute) {
XmlAttribute attribute = (XmlAttribute)element.getParent();
if (ATTR_ID.equals(attribute.getLocalName()) && ANDROID_URI.equals(attribute.getNamespace())) {
// When defining an id, don't point to another reference
// TODO: Unless you use @id instead of @+id!
return PsiReference.EMPTY_ARRAY;
}
}
return new PsiReference[]{new AndroidResourceReference(value, facet, resValue, null)};
}
}
}
return PsiReference.EMPTY_ARRAY;
}
项目:intellij-ce-playground
文件:HtmlUnknownElementInspection.java
protected static void registerProblemOnAttributeName(@NotNull XmlAttribute attribute,
String message, @NotNull ProblemsHolder holder,
LocalQuickFix... quickfixes) {
final ASTNode node = attribute.getNode();
assert node != null;
final ASTNode nameNode = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node);
if (nameNode != null) {
final PsiElement nameElement = nameNode.getPsi();
if (nameElement.getTextLength() > 0) {
holder.registerProblem(nameElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickfixes);
}
}
}
项目:intellij-ce-playground
文件:QNameUtil.java
public static QName createQName(@NotNull XmlAttribute attribute) {
final String name = attribute.getName();
if (name.indexOf(':') != -1) {
return new QName(attribute.getNamespace(), attribute.getLocalName());
} else {
return new QName(null, attribute.getLocalName());
}
}
项目:intellij-ce-playground
文件:RemoveAttributeQuickFix.java
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class);
if (attribute != null) {
attribute.getParent().setAttribute(attribute.getName(), null);
}
}
项目:intellij-ce-playground
文件:AbstractTagInjection.java
@Override
public boolean acceptForReference(PsiElement element) {
if (element instanceof XmlAttributeValue) {
PsiElement parent = element.getParent();
return parent instanceof XmlAttribute && acceptsPsiElement(parent);
}
else return element instanceof XmlTag && acceptsPsiElement(element);
}
项目:intellij-ce-playground
文件:SetAttributeQuickFix.java
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
final XmlTag tag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class, false);
if (tag == null) {
return;
}
String value = myValue;
if (value == null && context instanceof AndroidQuickfixContexts.DesignerContext) {
value = askForAttributeValue(tag);
if (value == null) {
return;
}
}
final XmlAttribute attribute = tag.setAttribute(myAttributeName, SdkConstants.NS_RESOURCES, "");
if (attribute != null) {
if (value != null) {
attribute.setValue(value);
}
if (context instanceof AndroidQuickfixContexts.EditorContext) {
final Editor editor = ((AndroidQuickfixContexts.EditorContext)context).getEditor();
final XmlAttributeValue valueElement = attribute.getValueElement();
final TextRange valueTextRange = attribute.getValueTextRange();
if (valueElement != null && valueTextRange != null) {
final int valueElementStart = valueElement.getTextRange().getStartOffset();
editor.getCaretModel().moveToOffset(valueElementStart + valueTextRange.getStartOffset());
if (valueTextRange.getStartOffset() < valueTextRange.getEndOffset()) {
editor.getSelectionModel().setSelection(valueElementStart + valueTextRange.getStartOffset(),
valueElementStart + valueTextRange.getEndOffset());
}
}
}
}
}