com.android.tools.lint.detector.api.LintUtils Java Examples

The following examples show how to use com.android.tools.lint.detector.api.LintUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstalledBeforeSuperDetector.java    From Folivora with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visitCallExpression(UCallExpression node) {
  if (node == target || node.getPsi() != null && node.getPsi() == target.getPsi()) {
    if (onCreateFound) {
      ok = true;
      return true;
    }
  } else {
    if ("onCreate".equals(LintUtils.getMethodName(node))
      && node.getReceiver() != null
      && "super".equals(node.getReceiver().toString())) {
      onCreateFound = true;
    }
  }
  return super.visitCallExpression(node);
}
 
Example #2
Source File: GridLayoutDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Given an error message produced by this lint detector,
 * returns the old value to be replaced in the source code.
 * <p>
 * Intended for IDE quickfix implementations.
 *
 * @param errorMessage the error message associated with the error
 * @param format the format of the error message
 * @return the corresponding old value, or null if not recognized
 */
@Nullable
public static String getOldValue(@NonNull String errorMessage,
        @NonNull TextFormat format) {
    errorMessage = format.toText(errorMessage);
    String attribute = LintUtils.findSubstring(errorMessage, " should use ", " ");
    if (attribute == null) {
        attribute = LintUtils.findSubstring(errorMessage, " should use ", null);
    }
    if (attribute != null) {
        int index = attribute.indexOf(':');
        if (index != -1) {
            return ANDROID_NS_NAME + attribute.substring(index);
        }
    }

    return null;
}
 
Example #3
Source File: LayoutInflationDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitDocument(@NonNull XmlContext context, @NonNull Document document) {
    Element root = document.getDocumentElement();
    if (root != null) {
        NamedNodeMap attributes = root.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            if (attribute.getLocalName() != null
                    && attribute.getLocalName().startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) {
                if (mLayoutsWithRootLayoutParams == null) {
                    mLayoutsWithRootLayoutParams = Sets.newHashSetWithExpectedSize(20);
                }
                mLayoutsWithRootLayoutParams.add(LintUtils.getBaseName(context.file.getName()));
                break;
            }
        }
    }
}
 
Example #4
Source File: ChildCountDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    int childCount = LintUtils.getChildCount(element);
    String tagName = element.getTagName();
    if (tagName.equals(SCROLL_VIEW) || tagName.equals(HORIZONTAL_SCROLL_VIEW)) {
        if (childCount > 1 && getAccurateChildCount(element) > 1) {
            context.report(SCROLLVIEW_ISSUE, element,
                    context.getLocation(element), "A scroll view can have only one child");
        }
    } else {
        // Adapter view
        if (childCount > 0 && getAccurateChildCount(element) > 0) {
            context.report(ADAPTER_VIEW_ISSUE, element,
                    context.getLocation(element),
                    "A list/grid should have no children declared in XML");
        }
    }
}
 
Example #5
Source File: ScrollViewChildDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Element> children = LintUtils.getChildren(element);
    boolean isHorizontal = HORIZONTAL_SCROLL_VIEW.equals(element.getTagName());
    String attributeName = isHorizontal ? ATTR_LAYOUT_WIDTH : ATTR_LAYOUT_HEIGHT;
    for (Element child : children) {
        Attr sizeNode = child.getAttributeNodeNS(ANDROID_URI, attributeName);
        if (sizeNode == null) {
            return;
        }
        String value = sizeNode.getValue();
        if (VALUE_FILL_PARENT.equals(value) || VALUE_MATCH_PARENT.equals(value)) {
            String msg = String.format("This %1$s should use `android:%2$s=\"wrap_content\"`",
                    child.getTagName(), attributeName);
            context.report(ISSUE, sizeNode, context.getLocation(sizeNode), msg);
        }
    }
}
 
Example #6
Source File: SecurityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isStandardReceiver(Element element) {
    // Play Services also the following receiver which we'll consider standard
    // in the sense that it doesn't require a separate permission
    String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
    if ("com.google.android.gms.tagmanager.InstallReferrerReceiver".equals(name)) {
        return true;
    }

    // Checks whether a broadcast receiver receives a standard Android action
    for (Element child : LintUtils.getChildren(element)) {
        if (child.getTagName().equals(TAG_INTENT_FILTER)) {
            for (Element innerChild : LintUtils.getChildren(child)) {
                if (innerChild.getTagName().equals(NODE_ACTION)) {
                    String categoryString = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    return categoryString.startsWith("android."); //$NON-NLS-1$
                }
            }
        }
    }

    return false;
}
 
Example #7
Source File: SecurityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isWearableBindListener(@NonNull Element element) {
    // Checks whether a service has an Android Wear bind listener
    for (Element child : LintUtils.getChildren(element)) {
        if (child.getTagName().equals(TAG_INTENT_FILTER)) {
            for (Element innerChild : LintUtils.getChildren(child)) {
                if (innerChild.getTagName().equals(NODE_ACTION)) {
                    String name = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    if ("com.google.android.gms.wearable.BIND_LISTENER".equals(name)) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
Example #8
Source File: PrivateKeyDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isPrivateKeyFile(File file) {
    if (!file.isFile() ||
        (!LintUtils.endsWith(file.getPath(), "pem") &&  //NON-NLS-1$
         !LintUtils.endsWith(file.getPath(), "key"))) { //NON-NLS-1$
        return false;
    }

    try {
        String firstLine = Files.readFirstLine(file, Charsets.US_ASCII);
        return firstLine != null &&
            firstLine.startsWith("---") &&     //NON-NLS-1$
            firstLine.contains("PRIVATE KEY"); //NON-NLS-1$
    } catch (IOException ex) {
        // Don't care
    }

    return false;
}
 
Example #9
Source File: ApiLookup.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting
@NonNull
static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) {
    if (LintUtils.endsWith(xmlFileName, DOT_XML)) {
        xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length());
    }

    StringBuilder sb = new StringBuilder(100);
    sb.append(xmlFileName);

    // Incorporate version number in the filename to avoid upgrade filename
    // conflicts on Windows (such as issue #26663)
    sb.append('-').append(BINARY_FORMAT_VERSION);

    if (platformVersion != null) {
        sb.append('-').append(platformVersion);
    }

    sb.append(".bin"); //$NON-NLS-1$
    return sb.toString();
}
 
Example #10
Source File: LayoutConsistencyDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitDocument(@NonNull XmlContext context, @NonNull Document document) {
    Element root = document.getDocumentElement();
    if (root != null) {
        if (context.getPhase() == 1) {
            // Map from ids to types
            Map<String,String> fileMap = Maps.newHashMapWithExpectedSize(10);
            addIds(root, fileMap);

            getFileMapList(context).add(Pair.of(context.file, fileMap));
        } else {
            String name = LintUtils.getLayoutName(context.file);
            Map<String, List<Location>> map = mLocations.get(name);
            if (map != null) {
                lookupLocations(context, root, map);
            }
        }
    }
}
 
Example #11
Source File: ResourcePrefixDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    if (mPrefix == null || context.getResourceFolderType() != ResourceFolderType.VALUES) {
        return;
    }

    for (Element item : LintUtils.getChildren(element)) {
        Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
        if (nameAttribute != null) {
            String name = nameAttribute.getValue();
            if (!name.startsWith(mPrefix)) {
                String message = getErrorMessage(name);
                context.report(ISSUE, nameAttribute, context.getLocation(nameAttribute),
                        message);
            }
        }
    }
}
 
Example #12
Source File: ResourcePrefixDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void beforeCheckFile(@NonNull Context context) {
    if (mPrefix != null && context instanceof XmlContext) {
        XmlContext xmlContext = (XmlContext) context;
        ResourceFolderType folderType = xmlContext.getResourceFolderType();
        if (folderType != null && folderType != ResourceFolderType.VALUES) {
            String name = LintUtils.getBaseName(context.file.getName());
            if (!name.startsWith(mPrefix)) {
                // Attempt to report the error on the root tag of the associated
                // document to make suppressing the error with a tools:suppress
                // attribute etc possible
                if (xmlContext.document != null) {
                    Element root = xmlContext.document.getDocumentElement();
                    if (root != null) {
                        xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
                                getErrorMessage(name));
                        return;
                    }
                }
                context.report(ISSUE, Location.create(context.file),
                        getErrorMessage(name));
            }
        }
    }
}
 
Example #13
Source File: ManifestDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("SpellCheckingInspection")
private static boolean isLaunchableActivity(@NonNull Element element) {
    if (!TAG_ACTIVITY.equals(element.getTagName())) {
        return false;
    }

    for (Element child : LintUtils.getChildren(element)) {
        if (child.getTagName().equals(TAG_INTENT_FILTER)) {
            for (Element innerChild : LintUtils.getChildren(child)) {
                if (innerChild.getTagName().equals("category")) { //$NON-NLS-1$
                    String categoryString = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    return "android.intent.category.LAUNCHER".equals(categoryString);
                }
            }
        }
    }

    return false;
}
 
Example #14
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public AndroidVersion getMinSdkVersion() {
    if (mMinSdkVersion == null) {
        ApiVersion minSdk = mVariant.getMergedFlavor().getMinSdkVersion();
        if (minSdk == null) {
            ProductFlavor flavor = mProject.getDefaultConfig().getProductFlavor();
            minSdk = flavor.getMinSdkVersion();
        }
        if (minSdk != null) {
            mMinSdkVersion = LintUtils.convertVersion(minSdk, mClient.getTargets());
        } else {
            mMinSdkVersion = super.getMinSdkVersion(); // from manifest
        }
    }

    return mMinSdkVersion;
}
 
Example #15
Source File: ViewTypeDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void addViewTags(Multimap<String, String> map, Element element) {
    String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
    if (id != null && !id.isEmpty()) {
        id = LintUtils.stripIdPrefix(id);
        if (!map.containsEntry(id, element.getTagName())) {
            map.put(id, element.getTagName());
        }
    }

    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) {
            addViewTags(map, (Element) child);
        }
    }
}
 
Example #16
Source File: LintGradleProject.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NonNull
public AndroidVersion getTargetSdkVersion() {
    if (mTargetSdkVersion == null) {
        ApiVersion targetSdk = mVariant.getMergedFlavor().getTargetSdkVersion();
        if (targetSdk == null) {
            ProductFlavor flavor = mProject.getDefaultConfig().getProductFlavor();
            targetSdk = flavor.getTargetSdkVersion();
        }
        if (targetSdk != null) {
            mTargetSdkVersion = LintUtils.convertVersion(targetSdk, mClient.getTargets());
        } else {
            mTargetSdkVersion = super.getTargetSdkVersion(); // from manifest
        }
    }

    return mTargetSdkVersion;
}
 
Example #17
Source File: LintDetectorTest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void addIds(Set<String> ids, Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
        if (id != null && !id.isEmpty()) {
            ids.add(LintUtils.stripIdPrefix(id));
        }

        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String value = attribute.getValue();
            if (value.startsWith(NEW_ID_PREFIX)) {
                ids.add(value.substring(NEW_ID_PREFIX.length()));
            }
        }
    }

    NodeList children = node.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        addIds(ids, child);
    }
}
 
Example #18
Source File: MainActivityDetector.java    From android-custom-lint-rules with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the XML node is an activity with a launcher intent.
 *
 * @param activityNode The node to check.
 * @return <code>true</code> if the node is an activity with a launcher intent.
 */
private boolean isMainActivity(Node activityNode) {
    if (TAG_ACTIVITY.equals(activityNode.getNodeName())) {
        // Loop through all <intent-filter> tags
        for (Element activityChild : LintUtils.getChildren(activityNode)) {
            if (TAG_INTENT_FILTER.equals(activityChild.getNodeName())) {
                // Check for these children nodes:
                //
                // <category android:name="android.intent.category.LAUNCHER" />
                // <action android:name="android.intent.action.MAIN" />
                boolean hasLauncherCategory = false;
                boolean hasMainAction = false;

                for (Element intentFilterChild : LintUtils.getChildren(activityChild)) {
                    // Check for category tag)
                    if (NODE_CATEGORY.equals(intentFilterChild.getNodeName())
                            && CATEGORY_NAME_LAUNCHER.equals(
                            intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
                        hasLauncherCategory = true;
                    }
                    // Check for action tag
                    if (NODE_ACTION.equals(intentFilterChild.getNodeName())
                            && ACTION_NAME_MAIN.equals(
                            intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
                        hasMainAction = true;
                    }
                }

                if (hasLauncherCategory && hasMainAction) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #19
Source File: ButtonDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/** Is the given target id the id of a {@code <Button>} within this RelativeLayout? */
private static boolean isButtonId(Element parent, String targetId) {
    for (Element child : LintUtils.getChildren(parent)) {
        String id = child.getAttributeNS(ANDROID_URI, ATTR_ID);
        if (LintUtils.idReferencesMatch(id, targetId)) {
            return child.getTagName().equals(BUTTON);
        }
    }
    return false;
}
 
Example #20
Source File: LintDriver.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the given issue is suppressed in the given method.
 *
 * @param issue the issue to be checked, or null to just check for "all"
 * @param classNode the class containing the issue
 * @param method the method containing the issue
 * @param instruction the instruction within the method, if any
 * @return true if there is a suppress annotation covering the specific
 *         issue on this method
 */
public boolean isSuppressed(
        @Nullable Issue issue,
        @NonNull ClassNode classNode,
        @NonNull MethodNode method,
        @Nullable AbstractInsnNode instruction) {
    if (method.invisibleAnnotations != null) {
        @SuppressWarnings("unchecked")
        List<AnnotationNode> annotations = method.invisibleAnnotations;
        return isSuppressed(issue, annotations);
    }

    // Initializations of fields end up placed in generated methods (<init>
    // for members and <clinit> for static fields).
    if (instruction != null && method.name.charAt(0) == '<') {
        AbstractInsnNode next = LintUtils.getNextInstruction(instruction);
        if (next != null && next.getType() == AbstractInsnNode.FIELD_INSN) {
            FieldInsnNode fieldRef = (FieldInsnNode) next;
            FieldNode field = findField(classNode, fieldRef.owner, fieldRef.name);
            if (field != null && isSuppressed(issue, field)) {
                return true;
            }
        } else if (classNode.outerClass != null && classNode.outerMethod == null
                    && isAnonymousClass(classNode)) {
            if (isSuppressed(issue, classNode)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #21
Source File: GridLayoutDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given an error message produced by this lint detector,
 * returns the new value to be put into the source code.
 * <p>
 * Intended for IDE quickfix implementations.
 *
 * @param errorMessage the error message associated with the error
 * @param format the format of the error message
 * @return the corresponding new value, or null if not recognized
 */
@Nullable
public static String getNewValue(@NonNull String errorMessage,
        @NonNull TextFormat format) {
    errorMessage = format.toText(errorMessage);
    String attribute = LintUtils.findSubstring(errorMessage, " should use ", " ");
    if (attribute == null) {
        attribute = LintUtils.findSubstring(errorMessage, " should use ", null);
    }
    return attribute;
}
 
Example #22
Source File: InvalidR2UsageDetector.java    From butterknife with Apache License 2.0 5 votes vote down vote up
private static boolean isR2Expression(UElement node) {
  UElement parentNode = node.getUastParent();
  if (parentNode == null) {
    return false;
  }
  String text = node.asSourceString();
  UElement parent = LintUtils.skipParentheses(parentNode);
  return (text.equals(R2) || text.contains(".R2"))
      && parent instanceof UExpression
      && endsWithAny(parent.asSourceString(), SUPPORTED_TYPES);
}
 
Example #23
Source File: UseCompoundDrawableDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    int childCount = LintUtils.getChildCount(element);
    if (childCount == 2) {
        List<Element> children = LintUtils.getChildren(element);
        Element first = children.get(0);
        Element second = children.get(1);
        if ((first.getTagName().equals(IMAGE_VIEW) &&
                second.getTagName().equals(TEXT_VIEW) &&
                !first.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)) ||
            ((second.getTagName().equals(IMAGE_VIEW) &&
                    first.getTagName().equals(TEXT_VIEW) &&
                    !second.hasAttributeNS(ANDROID_URI, ATTR_LAYOUT_WEIGHT)))) {
            // If the layout has a background, ignore since it would disappear from
            // the TextView
            if (element.hasAttributeNS(ANDROID_URI, ATTR_BACKGROUND)) {
                return;
            }

            // Certain scale types cannot be done with compound drawables
            String scaleType = first.getTagName().equals(IMAGE_VIEW)
                    ? first.getAttributeNS(ANDROID_URI, ATTR_SCALE_TYPE)
                    : second.getAttributeNS(ANDROID_URI, ATTR_SCALE_TYPE);
            if (scaleType != null && !scaleType.isEmpty()) {
                // For now, ignore if any scale type is set
                return;
            }

            context.report(ISSUE, element, context.getLocation(element),
                    "This tag and its children can be replaced by one `<TextView/>` and " +
                            "a compound drawable");
        }
    }
}
 
Example #24
Source File: ResourceUsageAnalyzer.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Nullable
public 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;
}
 
Example #25
Source File: ProtoResourceUsageAnalyzer.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public ResourcePackageVisitor enteringPackage(int pkgId, String packageName) {
  packageIds.add(pkgId);
  return (typeId, resourceType) ->
      (name, resourceId) -> {
        String hexId =
            String.format(
                "0x%s", Integer.toHexString(((pkgId << 24) | (typeId << 16) | resourceId)));
        model.addDeclaredResource(resourceType, LintUtils.getFieldName(name), hexId, true);
        // Skip visiting the definition when collecting declarations.
        return null;
      };
}
 
Example #26
Source File: DialogExtendLintDetector.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public void visitClass(JavaContext context, UClass declaration) {
    PsiModifierList classModifiers = declaration.getModifierList();
    if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
        // check for static build method
        boolean hasBuildMethod = false;
        for (PsiMethod method : declaration.getMethods()) {
            if ("build".equals(method.getName()) && method.getModifierList()
                    .hasModifierProperty("static")) {
                hasBuildMethod = true;
                break;
            }
        }
        if (!hasBuildMethod){
            context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
                    BUILD_OVERWRITE_MESSAGE);
        }

        // check for public static String TAG
        boolean hasTag = false;
        for (UField field : declaration.getFields()) {
            PsiModifierList modifiers = field.getModifierList();
            if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
                    modifiers != null && modifiers.hasModifierProperty("public") &&
                    modifiers.hasModifierProperty("static")) {
                hasTag = true;
                break;
            }
        }
        if (!hasTag) {
            context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
        }

    }
}
 
Example #27
Source File: UselessViewDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    int childCount = LintUtils.getChildCount(element);
    if (childCount == 0) {
        // Check to see if this is a leaf layout that can be removed
        checkUselessLeaf(context, element);
    } else {
        // Check to see if this is a middle-man layout which can be removed
        checkUselessMiddleLayout(context, element);
    }
}
 
Example #28
Source File: StringFormatDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean appliesTo(@NonNull Context context, @NonNull File file) {
    if (LintUtils.endsWith(file.getName(), DOT_JAVA)) {
        return mFormatStrings != null;
    }

    return super.appliesTo(context, file);
}
 
Example #29
Source File: DialogExtendLintDetector.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public void visitClass(JavaContext context, UClass declaration) {
    PsiModifierList classModifiers = declaration.getModifierList();
    if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
        // check for static build method
        boolean hasBuildMethod = false;
        for (PsiMethod method : declaration.getMethods()) {
            if ("build".equals(method.getName()) && method.getModifierList()
                    .hasModifierProperty("static")) {
                hasBuildMethod = true;
                break;
            }
        }
        if (!hasBuildMethod){
            context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
                    BUILD_OVERWRITE_MESSAGE);
        }

        // check for public static String TAG
        boolean hasTag = false;
        for (UField field : declaration.getFields()) {
            PsiModifierList modifiers = field.getModifierList();
            if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
                    modifiers != null && modifiers.hasModifierProperty("public") &&
                    modifiers.hasModifierProperty("static")) {
                hasTag = true;
                break;
            }
        }
        if (!hasTag) {
            context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
        }

    }
}
 
Example #30
Source File: LintCliClient.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public String readFile(@NonNull File file) {
    try {
        return LintUtils.getEncodedString(this, file);
    } catch (IOException e) {
        return ""; //$NON-NLS-1$
    }
}