com.android.annotations.Nullable Java Examples

The following examples show how to use com.android.annotations.Nullable. 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: RenderScriptProcessor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void cleanOldOutput(@Nullable Collection<File> oldOutputs) {
    if (oldOutputs != null) {
        // the old output collections contains the bc and .java files that could be
        // in a folder shared with other output files, so it's useful to delete
        // those only.

        for (File file : oldOutputs) {
            file.delete();
        }
    }

    // however .o and .so from support mode are in their own folder so we delete the
    // content of those folders directly.
    deleteFolder(mObjOutputDir);
    deleteFolder(mLibOutputDir);
}
 
Example #2
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ResourceFile} matching the given name,
 * {@link ResourceFolderType} and configuration.
 * <p/>
 * This only works with files generating one resource named after the file
 * (for instance, layouts, bitmap based drawable, xml, anims).
 *
 * @param name the resource name or file name
 * @param type the folder type search for
 * @param config the folder configuration to match for
 * @return the matching file or <code>null</code> if no match was found.
 */
@Nullable
public ResourceFile getMatchingFile(
        @NonNull String name,
        @NonNull ResourceFolderType type,
        @NonNull FolderConfiguration config) {
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type);
    for (ResourceType t : types) {
        if (t == ResourceType.ID) {
            continue;
        }
        ResourceFile match = getMatchingFile(name, t, config);
        if (match != null) {
            return match;
        }
    }

    return null;
}
 
Example #3
Source File: JavaParser.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Nullable
public JCTree.JCCompilationUnit parse(final String src) {
    if (!canParse) return null;
    long time = System.currentTimeMillis();

    SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
            return src;
        }
    };
    Log.instance(context).useSource(source);
    Parser parser = parserFactory.newParser(src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    JCTree.JCCompilationUnit unit;
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
    android.util.Log.d(TAG, "parse: time " + (System.currentTimeMillis() - time) + " ms");
    return unit;
}
 
Example #4
Source File: AndroidVersion.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public int compareTo(int apiLevel, @Nullable String codename) {
    if (mCodename == null) {
        if (codename == null) {
            return mApiLevel - apiLevel;
        } else {
            if (mApiLevel == apiLevel) {
                return -1; // same api level but argument is a preview for next version
            }

            return mApiLevel - apiLevel;
        }
    } else {
        // 'this' is a preview
        if (mApiLevel == apiLevel) {
            if (codename == null) {
                return +1;
            } else {
                return mCodename.compareTo(codename);    // strange case where the 2 previews
                                                         // have different codename?
            }
        } else {
            return mApiLevel - apiLevel;
        }
    }
}
 
Example #5
Source File: BuildToolInfo.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the build-tool is valid by verifying that the expected binaries
 * are actually present. This checks that all known paths point to a valid file
 * or directory.
 *
 * @param log An optional logger. If non-null, errors will be printed there.
 * @return True if the build-tool folder contains all the expected tools.
 */
public boolean isValid(@Nullable ILogger log) {
    for (Map.Entry<PathId, String> entry : mPaths.entrySet()) {
        File f = new File(entry.getValue());
        // check if file is missing. It's only ok if the revision of the build-tools
        // is lower than the min rev of the element.
        if (!f.exists() && entry.getKey().isPresentIn(mRevision)) {
            if (log != null) {
                log.warning("Build-tool %1$s is missing %2$s at %3$s",  //$NON-NLS-1$
                        mRevision.toString(),
                        entry.getKey(), f.getAbsolutePath());
            }
            return false;
        }
    }
    return true;
}
 
Example #6
Source File: MergerXmlUtils.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the origin {@link File} that {@link #parseDocument(File, IMergerLog,
 * ManifestMerger)} added to the XML document or the string added by
 *
 * @param xmlNode Any node from a document returned by {@link #parseDocument(File, IMergerLog,
 *              ManifestMerger)}.
 * @return The {@link File} object used to create the document or null.
 */
@Nullable
static String extractXmlFilename(@Nullable Node xmlNode) {
    if (xmlNode != null && xmlNode.getNodeType() != Node.DOCUMENT_NODE) {
        xmlNode = xmlNode.getOwnerDocument();
    }
    if (xmlNode != null) {
        Object data = xmlNode.getUserData(DATA_ORIGIN_FILE);
        if (data instanceof File) {
            return ((File) data).getPath();
        }
        data = xmlNode.getUserData(DATA_FILE_NAME);
        if (data instanceof String) {
            return (String) data;
        }
    }

    return null;
}
 
Example #7
Source File: PackageParserUtils.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to parse the {@link PkgProps#PKG_REVISION} property as a full
 * revision (major.minor.micro.preview).
 *
 * @param props The properties to parse.
 * @return A {@link FullRevision} or null if there is no such property or it couldn't be parsed.
 * @param propKey The name of the property. Must not be null.
 */
@Nullable
public static FullRevision getPropertyFull(
        @Nullable Properties props,
        @NonNull String propKey) {
    String revStr = getProperty(props, propKey, null);

    FullRevision rev = null;
    if (revStr != null) {
        try {
            rev = FullRevision.parseRevision(revStr);
        } catch (NumberFormatException ignore) {}
    }

    return rev;
}
 
Example #8
Source File: LocalPlatformToolPkgInfo.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Package getPackage() {
    Package pkg = super.getPackage();
    if (pkg == null) {
        try {
            pkg = PlatformToolPackage.create(
                    null,                       //source
                    getSourceProperties(),      //properties
                    0,                          //revision
                    null,                       //license
                    "Platform Tools",           //description
                    null,                       //descUrl
                    getLocalDir().getPath()     //archiveOsPath
                    );
            setPackage(pkg);
        } catch (Exception e) {
            appendLoadError("Failed to parse package: %1$s", e.toString());
        }
    }
    return pkg;
}
 
Example #9
Source File: LocalSdk.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves information on a package identified by an {@link AndroidVersion}.
 *
 * Note: don't use this for {@link PkgType#PKG_SYS_IMAGE} since there can be more than
 * one ABI and this method only returns a single package per filter type.
 *
 * @param filter {@link PkgType#PKG_PLATFORM}, {@link PkgType#PKG_SAMPLE}
 *                or {@link PkgType#PKG_SOURCE}.
 * @param version The {@link AndroidVersion} specific for this package type.
 * @return An existing package information or null if not found.
 */
@Nullable
public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull AndroidVersion version) {
    assert filter == PkgType.PKG_PLATFORM ||
           filter == PkgType.PKG_SAMPLE ||
           filter == PkgType.PKG_SOURCE;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
        IPkgDesc d = pkg.getDesc();
        if (d.hasAndroidVersion() && d.getAndroidVersion().equals(version)) {
            return pkg;
        }
    }

    return null;
}
 
Example #10
Source File: CommandLineRunner.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void runCmdLine(
        @NonNull String[] command,
        @Nullable Map<String, String> envVariableMap)
        throws IOException, InterruptedException, LoggedErrorException {

    // create a default CommandLineOutput
    OutputGrabber grabber = new OutputGrabber();

    runCmdLine(command, grabber, envVariableMap);
}
 
Example #11
Source File: Actions.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private Record(@NonNull ActionType actionType,
        @NonNull ActionLocation actionLocation,
        @NonNull XmlNode.NodeKey targetId,
        @Nullable String reason) {
    mActionType = Preconditions.checkNotNull(actionType);
    mActionLocation = Preconditions.checkNotNull(actionLocation);
    mTargetId = Preconditions.checkNotNull(targetId);
    mReason = reason;
}
 
Example #12
Source File: SystemImage.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Static helper method that returns the canonical path for a system-image that uses
 * the {@link ISystemImage.LocationType#IN_SYSTEM_IMAGE} location type.
 * <p/>
 * Such an image is located in {@code SDK/system-images/android-N/tag/abiType}.
 * For this reason this method requires the root SDK as well as the platform, tag abd ABI type.
 *
 * @param sdkOsPath The OS path to the SDK.
 * @param platformVersion The platform version.
 * @param tagId An optional tag. If null, not tag folder is used.
 *          For legacy, use {@code SystemImage.DEFAULT_TAG.getId()}.
 * @param addonVendorId An optional vendor-id for an add-on. If null, it's a platform sys-img.
 * @param abiType An optional ABI type. If null, the parent directory is returned.
 * @return A file that represents the location of the canonical system-image folder
 *         for this configuration.
 */
@NonNull
private static File getCanonicalFolder(
        @NonNull  String sdkOsPath,
        @NonNull  AndroidVersion platformVersion,
        @Nullable String tagId,
        @Nullable String addonVendorId,
        @Nullable String abiType) {
    File root;
    if (addonVendorId == null) {
        root = FileOp.append(
                sdkOsPath,
                SdkConstants.FD_SYSTEM_IMAGES,
                AndroidTargetHash.getPlatformHashString(platformVersion));
        if (tagId != null) {
            root = FileOp.append(root, tagId);
        }
    } else {
        root = FileOp.append(
                sdkOsPath,
                SdkConstants.FD_SYSTEM_IMAGES,
                AndroidTargetHash.getAddonHashString(addonVendorId, tagId, platformVersion));
    }
    if (abiType == null) {
        return root;
    } else {
        return FileOp.append(root, abiType);
    }
}
 
Example #13
Source File: ResourceItemResolver.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public ResourceItemResolver(
        @NonNull FolderConfiguration configuration,
        @NonNull ResourceRepository frameworkResources,
        @NonNull AbstractResourceRepository appResources,
        @Nullable LayoutLog logger) {
    mConfiguration = configuration;
    mResourceProvider = null;
    mLogger = logger;
    mFrameworkResources = frameworkResources;
    myAppResources = appResources;
}
 
Example #14
Source File: LocalSdk.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the highest build-tool revision known, or null if there are are no build-tools.
 * <p/>
 * If no specific build-tool package is installed but the platform-tools is lower than 17,
 * then this creates and returns a "legacy" built-tool package using platform-tools.
 * (We only split build-tools out of platform-tools starting with revision 17,
 *  before they were both the same thing.)
 *
 * @return The highest build-tool revision known, or null.
 */
@Nullable
public BuildToolInfo getLatestBuildTool() {
    if (mLegacyBuildTools != null) {
        return mLegacyBuildTools;
    }

    LocalPkgInfo[] pkgs = getPkgsInfos(PkgType.PKG_BUILD_TOOLS);

    if (pkgs.length == 0) {
        LocalPkgInfo ptPkg = getPkgInfo(PkgType.PKG_PLATFORM_TOOLS);
        if (ptPkg instanceof LocalPlatformToolPkgInfo &&
                ptPkg.getDesc().getFullRevision().compareTo(new FullRevision(17)) < 0) {
            // older SDK, create a compatible build-tools
            mLegacyBuildTools = createLegacyBuildTools((LocalPlatformToolPkgInfo) ptPkg);
            return mLegacyBuildTools;
        }
        return null;
    }

    assert pkgs.length > 0;

    // Note: the pkgs come from a TreeMultimap so they should already be sorted.
    // Just in case, sort them again.
    Arrays.sort(pkgs);

    // LocalBuildToolPkgInfo's comparator sorts on its FullRevision so we just
    // need to take the latest element.
    LocalPkgInfo pkg = pkgs[pkgs.length - 1];
    if (pkg instanceof LocalBuildToolPkgInfo) {
        return ((LocalBuildToolPkgInfo) pkg).getBuildToolInfo();
    }

    return null;
}
 
Example #15
Source File: LocalBuildToolPkgInfo.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public LocalBuildToolPkgInfo(@NonNull LocalSdk localSdk,
                             @NonNull File localDir,
                             @NonNull Properties sourceProps,
                             @NonNull FullRevision revision,
                             @Nullable BuildToolInfo btInfo) {
    super(localSdk, localDir, sourceProps);
    mDesc = PkgDesc.Builder.newBuildTool(revision).create();
    mBuildToolInfo = btInfo;
}
 
Example #16
Source File: MergedAssetWriter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void removeItem(@NonNull AssetItem removedItem, @Nullable AssetItem replacedBy)
        throws ConsumerException {
    if (replacedBy == null) {
        File removedFile = new File(getRootFolder(), removedItem.getName());
        removedFile.delete();
    }
}
 
Example #17
Source File: LocalSdk.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves information on a package identified by its {@link FullRevision}.
 * <p/>
 * Note that {@link PkgType#PKG_TOOLS} and {@link PkgType#PKG_PLATFORM_TOOLS}
 * are unique in a local SDK so you'll want to use {@link #getPkgInfo(PkgType)}
 * to retrieve them instead.
 *
 * @param filter {@link PkgType#PKG_BUILD_TOOLS}.
 * @param revision The {@link FullRevision} uniquely identifying this package.
 * @return An existing package information or null if not found.
 */
@Nullable
public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull FullRevision revision) {

    assert filter == PkgType.PKG_BUILD_TOOLS;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
        IPkgDesc d = pkg.getDesc();
        if (d.hasFullRevision() && d.getFullRevision().equals(revision)) {
            return pkg;
        }
    }
    return null;
}
 
Example #18
Source File: FolderConfiguration.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first invalid qualifier, or <code>null<code> if they are all valid (or if none
 * exists).
 */
@Nullable
public ResourceQualifier getInvalidQualifier() {
    for (int i = 0 ; i < INDEX_COUNT ; i++) {
        if (mQualifiers[i] != null && !mQualifiers[i].isValid()) {
            return mQualifiers[i];
        }
    }

    // all allocated qualifiers are valid, we return null.
    return null;
}
 
Example #19
Source File: ActionRecorder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Records an attribute action taken by the merging tool
 *
 * @param attribute              the attribute in question.
 * @param actionType             the action's type
 * @param attributeOperationType the original tool annotation leading to the merging tool
 *                               decision.
 */
synchronized void recordAttributeAction(
        @NonNull XmlAttribute attribute,
        @NonNull Actions.ActionType actionType,
        @Nullable AttributeOperationType attributeOperationType) {

    recordAttributeAction(
            attribute, attribute.getPosition(), actionType, attributeOperationType);
}
 
Example #20
Source File: LocalAddonPkgInfo.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an AddonPackage wrapping the IAndroidTarget if defined.
 * Invoked by {@link #getPackage()}.
 *
 * @return A Package or null if target isn't available.
 */
@Override
@Nullable
protected Package createPackage() {
    IAndroidTarget target = getAndroidTarget();
    if (target != null) {
        return AddonPackage.create(target, getSourceProperties());
    }
    return null;
}
 
Example #21
Source File: LocalSourcePkgInfo.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Package getPackage() {
    Package pkg = super.getPackage();
    if (pkg == null) {
        try {
            pkg = SourcePackage.create(getLocalDir(), getSourceProperties());
            setPackage(pkg);
        } catch (Exception e) {
            appendLoadError("Failed to parse package: %1$s", e.toString());
        }
    }
    return pkg;
}
 
Example #22
Source File: PkgDesc.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
protected PkgDesc(@NonNull PkgType type,
                  @Nullable License license,
                  @Nullable String listDisplay,
                  @Nullable String descriptionShort,
                  @Nullable String descriptionUrl,
                  boolean isObsolete,
                  @Nullable FullRevision fullRevision,
                  @Nullable MajorRevision majorRevision,
                  @Nullable AndroidVersion androidVersion,
                  @Nullable String path,
                  @Nullable IdDisplay tag,
                  @Nullable IdDisplay vendor,
                  @Nullable FullRevision minToolsRev,
                  @Nullable FullRevision minPlatformToolsRev,
                  @Nullable IIsUpdateFor customIsUpdateFor,
                  @Nullable IGetPath customPath) {
    mType = type;
    mIsObsolete = isObsolete;
    mLicense = license;
    mListDisplay = listDisplay;
    mDescriptionShort = descriptionShort;
    mDescriptionUrl = descriptionUrl;
    mFullRevision = fullRevision;
    mMajorRevision = majorRevision;
    mAndroidVersion = androidVersion;
    mPath = path;
    mTag = tag;
    mVendor = vendor;
    mMinToolsRev = minToolsRev;
    mMinPlatformToolsRev = minPlatformToolsRev;
    mCustomIsUpdateFor = customIsUpdateFor;
    mCustomPath = customPath;
}
 
Example #23
Source File: Actions.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
private static AttributeRecord findAttributeRecord(
        DecisionTreeRecord decisionTreeRecord,
        XmlAttribute xmlAttribute) {
    for (AttributeRecord attributeRecord : decisionTreeRecord
            .getAttributeRecords(xmlAttribute.getName())) {
        if (attributeRecord.getActionType() == ActionType.ADDED) {
            return attributeRecord;
        }
    }
    return null;
}
 
Example #24
Source File: ActionRecorder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the record for an attribute creation event. The attribute is "created" when it is
 * added for the first time into the resulting merged xml document.
 */
@Nullable
synchronized Actions.AttributeRecord getAttributeCreationRecord(XmlAttribute attribute) {
    for (Actions.AttributeRecord attributeRecord : getAttributeRecords(attribute)) {
        if (attributeRecord.getActionType() == Actions.ActionType.ADDED) {
            return attributeRecord;
        }
    }
    return null;
}
 
Example #25
Source File: XmlUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the given XML string as a DOM document, using the JDK parser. The parser does not
 * validate, and is optionally namespace aware. Any parsing errors are silently ignored.
 *
 * @param xml            the XML content to be parsed (must be well formed)
 * @param namespaceAware whether the parser is namespace aware
 * @return the DOM document, or null
 */
@Nullable
public static Document parseDocumentSilently(@NonNull String xml, boolean namespaceAware) {
    try {
        return parseDocument(xml, namespaceAware);
    } catch (Exception e) {
        // pass
        // This method is deliberately silent; will return null
    }

    return null;
}
 
Example #26
Source File: FolderConfiguration.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link FolderConfiguration} matching the folder segments.
 * @param folderSegments The segments of the folder name. The first segments should contain
 * the name of the folder
 * @return a FolderConfiguration object, or null if the folder name isn't valid..
 */
@Nullable
public static FolderConfiguration getConfig(@NonNull String[] folderSegments) {
    Iterator<String> iterator = Iterators.forArray(folderSegments);
    if (iterator.hasNext()) {
        // Skip the first segment: it should be just the base folder, such as "values" or
        // "layout"
        iterator.next();
    }

    return getConfigFromQualifiers(iterator);
}
 
Example #27
Source File: Message.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
public String getSourcePath() {
    File file = mSourceFilePositions.get(0).getFile().getSourceFile();
    if (file == null) {
        return null;
    }
    return file.getAbsolutePath();
}
 
Example #28
Source File: ResourceMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
private ResourceItem getMergedItem(@NonNull String qualifiers, @NonNull String name) {
    Map<String, ResourceItem> map = mMergedItems.get(qualifiers);
    if (map != null) {
        return map.get(name);
    }

    return null;
}
 
Example #29
Source File: DesugarTask.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void cacheMissAction(
        @Nullable FileCache cache,
        @Nullable FileCache.Inputs inputs,
        @NonNull Path input,
        @NonNull Path output)
        throws IOException, ProcessException {
    // add it to the list of cache misses, that will be processed
    cacheMisses.add(new InputEntry(cache, inputs, input, output));
}
 
Example #30
Source File: ManifestModel.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
AttributeModel getAttributeModel(XmlNode.NodeName attributeName) {
    // mAttributeModels could be replaced with a Map if the number of models grows.
    for (AttributeModel attributeModel : mAttributeModels) {
        if (attributeModel.getName().equals(attributeName)) {
            return attributeModel;
        }
    }
    return null;
}