Java Code Examples for com.android.tools.lint.detector.api.LintUtils#endsWith()

The following examples show how to use com.android.tools.lint.detector.api.LintUtils#endsWith() . 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: 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 2
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 3
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 4
Source File: OverdrawDetector.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean appliesTo(@NonNull Context context, @NonNull File file) {
    return LintUtils.isXmlFile(file) || LintUtils.endsWith(file.getName(), DOT_JAVA);
}
 
Example 5
Source File: MergeRootFrameLayoutDetector.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean appliesTo(@NonNull Context context, @NonNull File file) {
    return LintUtils.isXmlFile(file) || LintUtils.endsWith(file.getName(), DOT_JAVA);
}
 
Example 6
Source File: TypoLookup.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns an instance of the typo database
 *
 * @param client  the client to associate with this database - used only for
 *                logging
 * @param xmlFile the XML file containing configuration data to use for this
 *                database
 * @return a (possibly shared) instance of the typo database, or null
 * if its data can't be found
 */
@Nullable
private static TypoLookup get(LintClient client, File xmlFile) {
    if (!xmlFile.exists()) {
        client.log(null, "The typo database file %1$s does not exist", xmlFile);
        return null;
    }

    String name = xmlFile.getName();
    if (LintUtils.endsWith(name, DOT_XML)) {
        name = name.substring(0, name.length() - DOT_XML.length());
    }
    File cacheDir = client.getCacheDir(true/*create*/);
    if (cacheDir == null) {
        cacheDir = xmlFile.getParentFile();
    }

    File binaryData = new File(cacheDir, name
            // Incorporate version number in the filename to avoid upgrade filename
            // conflicts on Windows (such as issue #26663)
            + '-' + BINARY_FORMAT_VERSION + ".bin"); //$NON-NLS-1$

    if (DEBUG_FORCE_REGENERATE_BINARY) {
        System.err.println("\nTemporarily regenerating binary data unconditionally \nfrom "
                + xmlFile + "\nto " + binaryData);
        if (!createCache(client, xmlFile, binaryData)) {
            return null;
        }
    } else if (!binaryData.exists() || binaryData.lastModified() < xmlFile.lastModified()) {
        if (!createCache(client, xmlFile, binaryData)) {
            return null;
        }
    }

    if (!binaryData.exists()) {
        client.log(null, "The typo database file %1$s does not exist", binaryData);
        return null;
    }

    return new TypoLookup(client, xmlFile, binaryData);
}