当前位置: 首页>>代码示例>>Java>>正文


Java XmlAttributeValue.getParent方法代码示例

本文整理汇总了Java中com.intellij.psi.xml.XmlAttributeValue.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java XmlAttributeValue.getParent方法的具体用法?Java XmlAttributeValue.getParent怎么用?Java XmlAttributeValue.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.xml.XmlAttributeValue的用法示例。


在下文中一共展示了XmlAttributeValue.getParent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: domKnowsBetter

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
private boolean domKnowsBetter(final CompletionParameters parameters, final CompletionResultSet result) {
  final XmlAttributeValue element = PsiTreeUtil.getParentOfType(parameters.getPosition(), XmlAttributeValue.class);
  if (element == null) {
    return false;
  }

  if (isSchemaEnumerated(element)) {
    return false;
  }
  final PsiElement parent = element.getParent();
  if (parent instanceof XmlAttribute) {
    XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor != null && descriptor.getDefaultValue() != null) {
      final PsiReference[] references = myProvider.getReferencesByElement(element, new ProcessingContext());
      if (references.length > 0) {
        return LegacyCompletionContributor.completeReference(parameters, result);
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DomCompletionContributor.java

示例2: getReferencesByElement

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
  XmlAttributeValue attributeValue = (XmlAttributeValue)element;
  String value = attributeValue.getValue();
  if (value == null) return PsiReference.EMPTY_ARRAY;
  int i = value.indexOf(':');
  if (i <= 0) return PsiReference.EMPTY_ARRAY;
  PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute && !XmlNSDescriptorImpl.checkSchemaNamespace(((XmlAttribute)parent).getParent())) {
    XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor instanceof XmlAttributeDescriptorImpl) {
      String type = ((XmlAttributeDescriptorImpl)descriptor).getType();
      if (type != null && type.endsWith(":QName")) {
        String prefix = XmlUtil.findPrefixByQualifiedName(type);
        String ns = ((XmlTag)descriptor.getDeclaration()).getNamespaceByPrefix(prefix);
        if (XmlNSDescriptorImpl.checkSchemaNamespace(ns)) {
          return new PsiReference[] {
            new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null)
          };
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:XmlPrefixReferenceProvider.java

示例3: getHandlerSignature

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
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)";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaFxEventHandlerReference.java

示例4: getReferencesByElement

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
                                             @NotNull ProcessingContext context) {
  final XmlAttributeValue attributeValue = (XmlAttributeValue)element;
  final PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute) {
    final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
    if (descriptor instanceof JavaFxPropertyAttributeDescriptor) {
      final PsiElement declaration = descriptor.getDeclaration();
      if (declaration instanceof PsiField) {
        final PsiField field = (PsiField)declaration;
        final PsiClassType propertyClassType = JavaFxPsiUtil.getPropertyClassType(field);
        if (propertyClassType != null && InheritanceUtil.isInheritor(propertyClassType, JavaFxCommonClassNames.JAVAFX_SCENE_PAINT)) {
          return new PsiReference[] {new JavaFxColorReference(attributeValue)};
        }
      }
    }
  }
  return PsiReference.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaFxColorReferenceProvider.java

示例5: buildVisitor

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
  return new XmlElementVisitor() {
    @Override
    public void visitXmlAttributeValue(final XmlAttributeValue value) {
      if (value.getTextRange().isEmpty()) {
        return;
      }
      final PsiFile file = value.getContainingFile();
      if (!(file instanceof XmlFile)) {
        return;
      }
      PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
      if (baseFile != file && !(baseFile instanceof XmlFile)) {
        return;
      }
      final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile)file);
      if (refHolder == null) return;

      final PsiElement parent = value.getParent();
      if (!(parent instanceof XmlAttribute)) return;

      final XmlTag tag = (XmlTag)parent.getParent();
      if (tag == null) return;

      checkValue(value, (XmlFile)file, refHolder, tag, holder);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:XmlDuplicatedIdInspection.java

示例6: createJspPrefix

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
public static SchemaPrefix createJspPrefix(XmlAttributeValue element, String prefix) {
  TextRange range = ElementManipulators.getValueTextRange(element).shiftRight(element.getStartOffsetInParent());
  return new SchemaPrefix((XmlAttribute)element.getParent(), range, prefix) {
    @Override
    protected String getNamespace() {
      return ((XmlAttribute)getParent()).getParent().getAttributeValue("uri");
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SchemaPrefix.java

示例7: handleToolsNamespaceReferences

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
/**
 * Handle go-to-declaration on {@code tools:} namespace attributes, such
 * as {@code tools:context=".MyActivity"}.
 * <p>
 * This is not the Right Way To Do It; ideally, we should get the resource resolver
 * to work on the tools attributes such that they are treated as references.
 * However, until this is done properly, this method makes goto-handling
 * for tools attributes better (see issue b.android.com/75702)
 */
@Nullable
private static PsiElement[] handleToolsNamespaceReferences(@NotNull XmlToken token) {
  if (!(token.getParent() instanceof XmlAttributeValue)) {
    return null;
  }
  XmlAttributeValue valueElement = (XmlAttributeValue)token.getParent();
  if (!(valueElement.getParent() instanceof XmlAttribute)) {
    return null;
  }
  String value = valueElement.getValue();
  if (value == null || value.isEmpty()) {
    return null;
  }
  XmlAttribute attribute = (XmlAttribute)valueElement.getParent();
  if (!ATTR_CONTEXT.equals(attribute.getLocalName()) || !TOOLS_URI.equals(attribute.getNamespace())) {
    return null;
  }
  AndroidFacet facet = AndroidFacet.getInstance(token);
  if (facet == null) {
    return null;
  }
  boolean startsWithDot = value.charAt(0) == '.';
  if (startsWithDot || value.indexOf('.') == -1) {
    Module module = facet.getModule();
    String pkg = ManifestInfo.get(module, false).getPackage();
    String fqn = startsWithDot ? pkg + value : pkg + '.' + value;
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(module.getProject());
    return psiFacade.findClasses(fqn, GlobalSearchScope.moduleScope(module));
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:AndroidGotoDeclarationHandler.java

示例8: isAvailable

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  if (editor == null || !(file instanceof XmlFile)) {
    return false;
  }
  final AndroidFacet facet = AndroidFacet.getInstance(file);

  if (facet == null) {
    return false;
  }
  final XmlAttributeValue attrValue = getXmlAttributeValue(file, editor);

  if (attrValue == null) {
    return false;
  }
  final PsiElement parent = attrValue.getParent();

  if (!(parent instanceof XmlAttribute)) {
    return false;
  }
  final GenericAttributeValue domValue = DomManager.getDomManager(project).getDomElement((XmlAttribute)parent);

  if (domValue == null || !(domValue.getConverter() instanceof OnClickConverter)) {
    return false;
  }
  final String methodName = attrValue.getValue();
  return methodName != null && StringUtil.isJavaIdentifier(methodName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:AndroidCreateOnClickHandlerAction.java

示例9: findIdFields

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
@NotNull
public static PsiField[] findIdFields(@NotNull XmlAttributeValue value) {
  if (value.getParent() instanceof XmlAttribute) {
    return findIdFields((XmlAttribute)value.getParent());
  }
  return PsiField.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:AndroidResourceUtil.java

示例10: checkContext

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
protected static PsiClass checkContext(final XmlAttributeValue attributeValue) {
  if (attributeValue == null) return null;
  final PsiElement parent = attributeValue.getParent();
  if (parent instanceof XmlAttribute) {
    return checkClass(((XmlAttribute)parent).getParent());
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:JavaFxUnresolvedFxIdReferenceInspection.java

示例11: visitXmlTag

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
public void visitXmlTag(XmlTag tag) {
  final PsiFile file = tag.getContainingFile();
  if (file.getFileType() != StdFileTypes.XML) {
    return;
  }
  if (!tag.getLocalName().equals("define")) {
    return;
  }
  if (!tag.getNamespace().equals(ApplicationLoader.RNG_NAMESPACE)) {
    return;
  }
  if (tag.getAttribute("combine") != null) {
    return; // ?
  }

  final XmlAttribute attr = tag.getAttribute("name");
  if (attr == null) return;

  final XmlAttributeValue value = attr.getValueElement();
  if (value == null) return;

  final String s = value.getValue();
  if (s == null || s.length() == 0) {
    return;
  }
  final PsiElement parent = value.getParent();
  if (!(parent instanceof XmlAttribute)) {
    return;
  }
  if (!"name".equals(((XmlAttribute)parent).getName())) {
    return;
  }
  final PsiElement grandParent = parent.getParent();
  if (!(grandParent instanceof XmlTag)) {
    return;
  }

  final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
  if (element == null) {
    return;
  }

  final RngGrammar rngGrammar = element.getParentOfType(RngGrammar.class, true);
  if (rngGrammar != null) {
    if (processUsages(tag, value, new LocalSearchScope(rngGrammar.getXmlTag()))) return;
  } else {
    if (processUsages(tag, value, new LocalSearchScope(file))) return;
  }

  final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<XmlFile>();
  RelaxIncludeIndex.processBackwardDependencies((XmlFile)file, collector);

  if (processUsages(tag, value, new LocalSearchScope(collector.toArray()))) return;

  myHolder.registerProblem(value, "Unreferenced define", ProblemHighlightType.LIKE_UNUSED_SYMBOL, new MyFix<XmlTag>(tag));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:UnusedDefineInspection.java

示例12: prepareResourceFieldRenaming

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
private static void prepareResourceFieldRenaming(PsiField field, String newName, Map<PsiElement, String> allRenames) {
  new RenameJavaVariableProcessor().prepareRenaming(field, newName, allRenames);

  List<PsiElement> resources = AndroidResourceUtil.findResourcesByField(field);

  PsiElement res = resources.get(0);
  String resName = res instanceof XmlAttributeValue ? ((XmlAttributeValue)res).getValue() : ((PsiFile)res).getName();
  final String newResName = getResourceName(field.getProject(), newName, resName);

  for (PsiElement resource : resources) {
    if (resource instanceof PsiFile) {
      PsiFile file = (PsiFile)resource;
      String extension = FileUtilRt.getExtension(file.getName());
      allRenames.put(resource, newResName + '.' + extension);
    }
    else if (resource instanceof XmlAttributeValue) {
      XmlAttributeValue value = (XmlAttributeValue)resource;
      final String s = AndroidResourceUtil.isIdDeclaration(value)
                       ? NEW_ID_PREFIX + newResName
                       : newResName;
      allRenames.put(new ValueResourceElementWrapper(value), s);

      // Also rename the dependent fields, e.g. if you rename <declare-styleable name="Foo">,
      // we have to rename not just R.styleable.Foo but the also R.styleable.Foo_* attributes
      if (value.getParent() instanceof XmlAttribute) {
        XmlAttribute parent = (XmlAttribute)value.getParent();
        XmlTag tag = parent.getParent();
        if (tag.getName().equals(TAG_DECLARE_STYLEABLE)) {
          AndroidFacet facet = AndroidFacet.getInstance(tag);
          String oldName = tag.getAttributeValue(ATTR_NAME);
          if (facet != null && oldName != null) {
            for (XmlTag attr : tag.getSubTags()) {
              if (attr.getName().equals(TAG_ATTR)) {
                String name = attr.getAttributeValue(ATTR_NAME);
                if (name != null) {
                  String oldAttributeName = oldName + '_' + name;
                  PsiField[] fields = AndroidResourceUtil.findResourceFields(facet, STYLEABLE.getName(), oldAttributeName, true);
                  if (fields.length > 0) {
                    String newAttributeName = newName + '_' + name;
                    for (PsiField f : fields) {
                      allRenames.put(f, newAttributeName);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:AndroidResourceRenameResourceProcessor.java

示例13: isApplicable

import com.intellij.psi.xml.XmlAttributeValue; //导入方法依赖的package包/类
public boolean isApplicable(@NotNull XmlAttributeValue value) {
  final PsiElement element = value.getParent();
  return element instanceof XmlAttribute && matches((XmlAttribute)element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:XmlAttributeInjection.java


注:本文中的com.intellij.psi.xml.XmlAttributeValue.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。