All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.core.resources.ResourceAttributes Maven / Gradle / Ivy

Go to download

AspectJ tools most notably contains the AspectJ compiler (AJC). AJC applies aspects to Java classes during compilation, fully replacing Javac for plain Java classes and also compiling native AspectJ or annotation-based @AspectJ syntax. Furthermore, AJC can weave aspects into existing class files in a post-compile binary weaving step. This library is a superset of AspectJ weaver and hence also of AspectJ runtime.

There is a newer version: 1.9.22.1
Show newest version
/*******************************************************************************
 * Copyright (c) 2004, 2014 Red Hat Incorporated and others
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API
 *     Red Hat Incorporated - initial implementation
 *     Martin Oberhuber (Wind River) - [44107] Add symbolic links to ResourceAttributes API
 *******************************************************************************/

package org.eclipse.core.resources;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileSystem;
import org.eclipse.core.internal.utils.FileUtil;
import org.eclipse.core.runtime.CoreException;

/**
 * This class represents platform specific attributes of files.
 * Any attributes can be added, but only the attributes that are
 * supported by the platform will be used. These methods do not set the
 * attributes in the file system.
 *
 * @author Red Hat Incorporated
 * @see IResource#getResourceAttributes()
 * @see IResource#setResourceAttributes(ResourceAttributes)
 * @since 3.1
 * @noextend This class is not intended to be subclassed by clients.
 */
public class ResourceAttributes {
	private int attributes;

	/**
	 * Creates a new resource attributes instance with attributes
	 * taken from the specified file in the file system.  If the specified
	 * file does not exist or is not accessible, this method has the
	 * same effect as calling the default constructor.
	 *
	 * @param file The file to get attributes from
	 * @return A resource attributes object
	 */
	public static ResourceAttributes fromFile(java.io.File file) {
		try {
			return FileUtil.fileInfoToAttributes(EFS.getStore(file.toURI()).fetchInfo());
		} catch (CoreException e) {
			//file could not be accessed
			return new ResourceAttributes();
		}
	}

	/**
	 * Creates a new instance of ResourceAttributes.
	 */
	public ResourceAttributes() {
		super();
	}

	/**
	 * Returns whether this ResourceAttributes object is marked archive.
	 * 

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_ARCHIVE}.

* * @return true if this resource is marked archive, * false otherwise * @see #setArchive(boolean) * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_ARCHIVE */ public boolean isArchive() { return (attributes & EFS.ATTRIBUTE_ARCHIVE) != 0; } /** * Returns whether this ResourceAttributes object is marked executable. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_EXECUTABLE}.

* * @return true if this resource is marked executable, * false otherwise * @see #setExecutable(boolean) * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_EXECUTABLE */ public boolean isExecutable() { return (attributes & EFS.ATTRIBUTE_EXECUTABLE) != 0; } /** * Returns whether this ResourceAttributes object is marked hidden. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_HIDDEN}.

* * @return true if this resource is marked hidden, * false otherwise * @see #setHidden(boolean) * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_HIDDEN * @since 3.2 */ public boolean isHidden() { return (attributes & EFS.ATTRIBUTE_HIDDEN) != 0; } /** * Returns whether this ResourceAttributes object is marked read only. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_READ_ONLY}.

* * @return true if this resource is marked as read only, * false otherwise * @see #setReadOnly(boolean) * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_READ_ONLY */ public boolean isReadOnly() { return (attributes & EFS.ATTRIBUTE_READ_ONLY) != 0; } /** * Returns whether this ResourceAttributes object is marked as symbolic link. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_SYMLINK}.

* * @return true if this resource is marked as symbolic link, * false otherwise * @see #setSymbolicLink(boolean) * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_SYMLINK * @since 3.4 */ public boolean isSymbolicLink() { return (attributes & EFS.ATTRIBUTE_SYMLINK) != 0; } /** * Sets or unsets whether this ResourceAttributes object is marked archive. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_ARCHIVE}.

* * @param archive true to set it to be archive, * false to unset * @see #isArchive() * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_ARCHIVE */ public void setArchive(boolean archive) { set(EFS.ATTRIBUTE_ARCHIVE, archive); } /** * Clears all of the bits indicated by the mask. * @nooverride This method is not intended to be re-implemented or extended by clients. * @noreference This method is not intended to be referenced by clients. */ public void set(int mask, boolean value) { if (value) attributes |= mask; else attributes &= ~mask; } /** * Returns whether this ResourceAttributes object has the given mask set. * @nooverride This method is not intended to be re-implemented or extended by clients. * @noreference This method is not intended to be referenced by clients. */ public boolean isSet(int mask) { return (attributes & mask) != 0; } /** * Sets or unsets whether this ResourceAttributes object is marked executable. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_EXECUTABLE}.

* * @param executable true to set it to be executable, * false to unset * @see #isExecutable() * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_EXECUTABLE */ public void setExecutable(boolean executable) { set(EFS.ATTRIBUTE_EXECUTABLE, executable); } /** * Sets or unsets whether this ResourceAttributes object is marked hidden *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_HIDDEN}.

* * @param hidden true to set it to be marked hidden, * false to unset * @see #isHidden() * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_HIDDEN * @since 3.2 */ public void setHidden(boolean hidden) { set(EFS.ATTRIBUTE_HIDDEN, hidden); } /** * Sets or unsets whether this ResourceAttributes object is marked read only. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_READ_ONLY}.

* * @param readOnly true to set it to be marked read only, * false to unset * @see #isReadOnly() * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_READ_ONLY */ public void setReadOnly(boolean readOnly) { set(EFS.ATTRIBUTE_READ_ONLY, readOnly); } /** * Sets or unsets whether this ResourceAttributes object is marked as symbolic link. *

This attribute is used only on file systems supporting {@link EFS#ATTRIBUTE_SYMLINK}.

* * @param symLink true to set it to be marked as symbolic link, * false to unset * @see #isSymbolicLink() * @see IFileSystem#attributes() * @see EFS#ATTRIBUTE_SYMLINK * @since 3.4 */ public void setSymbolicLink(boolean symLink) { set(EFS.ATTRIBUTE_SYMLINK, symLink); } /** * Returns a string representation of the attributes, suitable * for debugging purposes only. */ @Override public String toString() { return "ResourceAttributes(" + attributes + ')'; //$NON-NLS-1$ } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy