package org.eclipse.core.internal.expressions;
import org.eclipse.core.expressions.IPropertyTester;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class Property {
private final Class<?> fType;
private final String fNamespace;
private final String fName;
private IPropertyTester fTester;
Property(Class<?> type, String namespace, String name) {
Assert.isNotNull(type);
Assert.isNotNull(namespace);
Assert.isNotNull(name);
fType= type;
fNamespace= namespace;
fName= name;
}
void setPropertyTester(IPropertyTester tester) {
Assert.isNotNull(tester);
fTester= tester;
}
public boolean isInstantiated() {
return fTester.isInstantiated();
}
public boolean isDeclaringPluginActive() {
return fTester.isDeclaringPluginActive();
}
public boolean isValidCacheEntry(boolean forcePluginActivation) {
if (forcePluginActivation) {
return isInstantiated() && isDeclaringPluginActive();
} else {
return (isInstantiated() && isDeclaringPluginActive()) ||
(!isInstantiated() && !isDeclaringPluginActive());
}
}
public boolean test(Object receiver, Object[] args, Object expectedValue) throws CoreException {
try {
return fTester.test(receiver, fName, args, expectedValue);
} catch (Exception e) {
String message = "Error evaluating " + this;
throw new CoreException(new Status(IStatus.ERROR, ExpressionPlugin.getPluginId(), message, e));
}
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Property))
return false;
Property other= (Property)obj;
return fType.equals(other.fType) && fNamespace.equals(other.fNamespace) && fName.equals(other.fName);
}
@Override
public int hashCode() {
return (fType.hashCode() << 16) | fNamespace.hashCode() << 8 | fName.hashCode();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Property [");
builder.append(fNamespace);
builder.append(".");
builder.append(fName);
builder.append(", type=");
builder.append(fType);
if (fTester != null) {
builder.append(", tester=");
builder.append(fTester);
}
builder.append("]");
return builder.toString();
}
}