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


Java ResourceUrl.parse方法代码示例

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


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

示例1: replaceUrlWithValue

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
private static String replaceUrlWithValue(@NonNull XmlContext context,
        @NonNull String str) {
    Project project = context.getProject();
    LintClient client = context.getClient();
    if (!client.supportsProjectResources()) {
        return str;
    }
    ResourceUrl style = ResourceUrl.parse(str);
    if (style == null || style.type != ResourceType.STRING || style.framework) {
        return str;
    }
    AbstractResourceRepository resources = client.getProjectResources(project, true);
    if (resources == null) {
        return str;
    }
    List<ResourceItem> items = resources.getResourceItem(ResourceType.STRING, style.name);
    if (items == null || items.isEmpty()) {
        return str;
    }
    ResourceValue resourceValue = items.get(0).getResourceValue(false);
    if (resourceValue == null) {
        return str;
    }
    return resourceValue.getValue() == null ? str : resourceValue.getValue();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:AppIndexingApiDetector.java

示例2: getQuickFixes

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
  PsiElement parent = startElement.getParent();
  if (parent instanceof XmlAttribute) {
    XmlAttribute attribute = (XmlAttribute)parent;
    String value = attribute.getValue();
    if (value != null) {
      ResourceUrl url = ResourceUrl.parse(value);
      if (url != null && !url.framework) {
        return new AndroidLintQuickFix[]{new MigrateDrawableToMipmapFix(url)};
      }
    }
  }
  return AndroidLintQuickFix.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidLintInspectionToolProvider.java

示例3: getViewClassNameFromLayoutReferenceTag

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
private static String getViewClassNameFromLayoutReferenceTag(XmlTag tag, AndroidFacet facet) {
  String layout = tag.getAttributeValue(SdkConstants.ATTR_LAYOUT);
  if (layout == null) {
    return null;
  }
  LocalResourceRepository moduleResources = facet.getModuleResources(false);
  if (moduleResources == null) {
    return null;
  }
  ResourceUrl resourceUrl = ResourceUrl.parse(layout);
  if (resourceUrl == null || resourceUrl.type != ResourceType.LAYOUT) {
    return null;
  }
  DataBindingInfo info = moduleResources.getDataBindingInfoForLayout(resourceUrl.name);
  if (info == null) {
    return null;
  }
  return info.getQualifiedName();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:DataBindingUtil.java

示例4: visitAttribute

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
/** Check resource references: accessing a private resource from an upstream library? */
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    String value = attribute.getNodeValue();
    if (context.getProject().isGradleProject()) {
        ResourceUrl url = ResourceUrl.parse(value);
        if (isPrivate(context, url)) {
            String message = createUsageErrorMessage(context, url.type, url.name);
            context.report(ISSUE, attribute, context.getValueLocation(attribute), message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PrivateResourceDetector.java

示例5: getResourceDocumentation

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Nullable
private static String getResourceDocumentation(PsiElement element, String value) {
  ResourceUrl url = ResourceUrl.parse(value);
  if (url != null) {
    return generateDoc(element, url);
  } else {
    // See if it's in a resource file definition: This allows you to invoke
    // documentation on <string name="cursor_here">...</string>
    // and see the various translations etc of the string
    XmlAttribute attribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (attribute != null && ATTR_NAME.equals(attribute.getName())) {
      XmlTag tag = attribute.getParent();
      String typeName = tag.getName();
      if (TAG_ITEM.equals(typeName)) {
        typeName = tag.getAttributeValue(ATTR_TYPE);
        if (typeName == null) {
          return null;
        }
      }
      ResourceType type = ResourceType.getEnum(typeName);
      if (type != null) {
        return generateDoc(element, type, value, false);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:AndroidXmlDocumentationProvider.java

示例6: findResourceReferenceUnderCaret

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Nullable
private static ResourceUrl findResourceReferenceUnderCaret(@NotNull Editor editor, @NotNull PsiFile file) {
  if (!(file instanceof XmlFile)) {
    return null;
  }

  final AndroidFacet facet = AndroidFacet.getInstance(file);
  if (facet == null) {
    return null;
  }

  if (!AndroidResourceUtil.isInResourceSubdirectory(file, ResourceFolderType.VALUES.getName())) {
    return null;
  }

  final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
  if (element == null) {
    return null;
  }

  if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
    XmlText text = PsiTreeUtil.getParentOfType(element, XmlText.class);
    if (text != null) {
      return ResourceUrl.parse(text.getText().trim());
    }
  }

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

示例7: getValue

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Override
public Object getValue() {
  JTextField text = getComboText();
  if (text == null) {
    return myBooleanResourceValue == null ? Boolean.toString(myCheckBox.isSelected()) : myBooleanResourceValue;
  }
  String value = text.getText();
  if (value == StringsComboEditor.UNSET || StringUtil.isEmpty(value)) {
    return null;
  }
  if (myIsDimension &&
      !value.startsWith(PREFIX_RESOURCE_REF) &&
      !value.endsWith(UNIT_DIP) &&
      !value.equalsIgnoreCase(VALUE_WRAP_CONTENT) &&
      !value.equalsIgnoreCase(VALUE_FILL_PARENT) &&
      !value.equalsIgnoreCase(VALUE_MATCH_PARENT)) {
    if (value.length() <= 2) {
      return value + UNIT_DP;
    }
    int index = value.length() - 2;
    String dimension = value.substring(index);
    if (ArrayUtil.indexOf(ResourceRenderer.DIMENSIONS, dimension) == -1) {
      return value + UNIT_DP;
    }
  }

  // If it looks like a reference, don't escape it.
  if (myIsString &&
      (value.startsWith(PREFIX_RESOURCE_REF) || value.startsWith(PREFIX_THEME_REF)) &&
      ResourceUrl.parse(value) == null) {
    return "\\" + value;
  }
  return value;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:ResourceEditor.java

示例8: getResourceFromUrl

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Nullable
Resource getResourceFromUrl(@NonNull String possibleUrlReference) {
  ResourceUrl url = ResourceUrl.parse(possibleUrlReference);
  if (url != null && !url.framework) {
    return addResource(url.type, LintUtils.getFieldName(url.name), null);
  }
  return null;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:9,代码来源:ResourceUsageAnalyzer.java

示例9: childAdded

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Override
public void childAdded(@NotNull PsiTreeChangeEvent event) {
  myIgnoreChildrenChanged = true;

  if (isIgnorable(event)) {
    return;
  }

  if (isRelevantFile(event)) {
    PsiElement child = event.getChild();
    PsiElement parent = event.getParent();

    if (child instanceof XmlAttribute && parent instanceof XmlTag) {
      // Typing in a new attribute. Don't need to do any rendering until there
      // is an actual value
      if (((XmlAttribute)child).getValueElement() == null) {
        return;
      }
    }
    else if (parent instanceof XmlAttribute && child instanceof XmlAttributeValue) {
      XmlAttributeValue attributeValue = (XmlAttributeValue)child;
      if (attributeValue.getValue() == null || attributeValue.getValue().isEmpty()) {
        // Just added a new blank attribute; nothing to render yet
        return;
      }
    }
    else if (parent instanceof XmlAttributeValue && child instanceof XmlToken && event.getOldChild() == null) {
      // Just added attribute value
      String text = child.getText();
      // See if this is an attribute that takes a resource!
      if (text.startsWith(PREFIX_RESOURCE_REF) && !text.startsWith(PREFIX_BINDING_EXPR)) {
        if (text.equals(PREFIX_RESOURCE_REF) || text.equals(ANDROID_PREFIX)) {
          // Using code completion to insert resource reference; not yet done
          return;
        }
        ResourceUrl url = ResourceUrl.parse(text);
        if (url != null && url.name.isEmpty()) {
          // Using code completion to insert resource reference; not yet done
          return;
        }
      }
    }
    notice(Reason.EDIT);
  }
  else {
    notice(Reason.RESOURCE_EDIT);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:ResourceNotificationManager.java

示例10: childReplaced

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
@Override
public void childReplaced(@NotNull PsiTreeChangeEvent event) {
  myIgnoreChildrenChanged = true;

  if (isIgnorable(event)) {
    return;
  }

  if (isRelevantFile(event)) {
    PsiElement child = event.getChild();
    PsiElement parent = event.getParent();
    if (parent instanceof XmlAttribute && child instanceof XmlToken) {
      // Typing in attribute name. Don't need to do any rendering until there
      // is an actual value
      XmlAttributeValue valueElement = ((XmlAttribute)parent).getValueElement();
      if (valueElement == null || valueElement.getValue() == null || valueElement.getValue().isEmpty()) {
        return;
      }
    }
    else if (parent instanceof XmlAttributeValue && child instanceof XmlToken && event.getOldChild() != null) {
      String newText = child.getText();
      String prevText = event.getOldChild().getText();
      // See if user is working on an incomplete URL, and is still not complete, e.g. typing in @string/foo manually
      if (newText.startsWith(PREFIX_RESOURCE_REF) && !newText.startsWith(PREFIX_BINDING_EXPR)) {
        ResourceUrl prevUrl = ResourceUrl.parse(prevText);
        ResourceUrl newUrl = ResourceUrl.parse(newText);
        if (prevUrl != null && prevUrl.name.isEmpty()) {
          prevUrl = null;
        }
        if (newUrl != null && newUrl.name.isEmpty()) {
          newUrl = null;
        }
        if (prevUrl == null && newUrl == null) {
          return;
        }
      }
    }
    notice(Reason.EDIT);
  }
  else {
    notice(Reason.RESOURCE_EDIT);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:44,代码来源:ResourceNotificationManager.java

示例11: isAttr

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
/**
 * Returns whether this attribute value points to an attr reference.
 */
public boolean isAttr() {
  ResourceUrl url = ResourceUrl.parse(myItemResourceValue.getRawXmlValue(), myItemResourceValue.isFramework());
  return url != null && url.type == ResourceType.ATTR;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:EditedStyleItem.java

示例12: getQualifiedValue

import com.android.ide.common.resources.ResourceUrl; //导入方法依赖的package包/类
/**
 * Returns item value, maybe with "android:" qualifier,
 * If item is inside of the framework style, "android:" qualifier will be added
 * For example: For a value "@color/black" which is inside the "Theme.Holo.Light.DarkActionBar" style,
 * will be returned as "@android:color/black"
 */
@NotNull
public static String getQualifiedValue(@NotNull ItemResourceValue item) {
  ResourceUrl url = ResourceUrl.parse(item.getRawXmlValue(), item.isFramework());
  return url == null ? item.getRawXmlValue() : url.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:StyleResolver.java


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