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

org.eclipse.core.expressions.PropertyTester Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2000, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.expressions;

import org.osgi.framework.Bundle;

import org.eclipse.core.internal.expressions.PropertyTesterDescriptor;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;

/**
 * Abstract superclass of all property testers. Implementation classes of
 * the extension point org.eclipse.core.expresssions.propertyTesters
 *  must extend PropertyTester.
 * 

* A property tester implements the property tests enumerated in the property * tester extension point. For the following property test extension *

 *   <propertyTester
 *     	 namespace="org.eclipse.jdt.core"
 *       id="org.eclipse.jdt.core.IPackageFragmentTester"
 *       properties="isDefaultPackage"
 *       type="org.eclipse.jdt.core.IPackageFragment"
 *       class="org.eclipse.demo.MyPackageFragmentTester">
 *     </propertyTester>
 * 
* the corresponding implementation class looks like: *
 *   public class MyPackageFragmentTester extends PropertyTester {
 *       public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
 *           IPackageFragment fragment= (IPackageFragment)receiver;
 *	         if ("isDefaultPackage".equals(property)) {
 *               return expectedValue == null
 *               	? fragment.isDefaultPackage()
 *               	: fragment.isDefaultPackage() == ((Boolean)expectedValue).booleanValue();
 *           }
 *           Assert.isTrue(false);
 *           return false;
 *       }
 *   }
 * 
* The property can then be used in a test expression as follows: *
 *   <instanceof value="org.eclipse.core.IPackageFragment"/>
 *   <test property="org.eclipse.jdt.core.isDefaultPackage"/>
 * 
*

*

* There is no guarantee that the same instance of a property tester is used * to handle <test property="..."/> requests. So property testers * should always be implemented in a stateless fashion. *

* @since 3.0 */ public abstract class PropertyTester implements IPropertyTester { private IConfigurationElement fConfigElement; private String fNamespace; private String fProperties; /** * Initialize the property tester with the given name space and property. *

* Note: this method is for internal use only. Clients must not call * this method. *

* @param descriptor the descriptor object for this tester * * @noreference This method is not intended to be referenced by clients. */ public final void internalInitialize(PropertyTesterDescriptor descriptor) { fProperties= descriptor.getProperties(); fNamespace= descriptor.getNamespace(); fConfigElement= descriptor.getConfigurationElement(); } /** * Note: this method is for internal use only. Clients must not call * this method. * * @return the property tester descriptor * * @noreference This method is not intended to be referenced by clients. */ public final PropertyTesterDescriptor internalCreateDescriptor() { return new PropertyTesterDescriptor(fConfigElement, fNamespace, fProperties); } /** * {@inheritDoc} */ public final boolean handles(String namespace, String property) { return fNamespace.equals(namespace) && fProperties.indexOf("," + property + ",") != -1; //$NON-NLS-1$//$NON-NLS-2$ } /** * {@inheritDoc} */ public final boolean isInstantiated() { return true; } /** * {@inheritDoc} */ public boolean isDeclaringPluginActive() { Bundle bundle= Platform.getBundle(fConfigElement.getContributor().getName()); return bundle.getState() == Bundle.ACTIVE; } /** * {@inheritDoc} */ public final IPropertyTester instantiate() { return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy