Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Sources formatted #359
Browse files Browse the repository at this point in the history
  • Loading branch information
ujhelyiz committed Nov 30, 2012
1 parent f3c4383 commit d5a4842
Show file tree
Hide file tree
Showing 470 changed files with 34,211 additions and 34,116 deletions.
Expand Up @@ -9,8 +9,8 @@
* Zoltan Ujhelyi, Tamas Szabo - initial API and implementation
*******************************************************************************/

package org.eclipse.incquery.databinding.runtime.adapter;

package org.eclipse.incquery.databinding.runtime.adapter;

import java.util.Map;

import org.eclipse.core.databinding.observable.value.IObservableValue;
Expand All @@ -19,28 +19,28 @@
import org.eclipse.incquery.runtime.api.IPatternMatch;

import com.google.common.base.Preconditions;

public class BaseGeneratedDatabindingAdapter<T extends IPatternMatch> extends DatabindingAdapter<T> {

protected Map<String, String> parameterMap;
@Override
public String[] getParameterNames() {
return parameterMap.keySet().toArray(new String[parameterMap.keySet().size()]);
}

@Override
public IObservableValue getObservableParameter(T match, String parameterName) {
if (parameterMap.size() > 0) {
String expression = parameterMap.get(parameterName);
return IncQueryObservables.getObservableValue(match, expression);
}
return null;
}

public class BaseGeneratedDatabindingAdapter<T extends IPatternMatch> extends DatabindingAdapter<T> {

protected Map<String, String> parameterMap;

@Override
public String[] getParameterNames() {
return parameterMap.keySet().toArray(new String[parameterMap.keySet().size()]);
}

@Override
public IObservableValue getObservableParameter(T match, String parameterName) {
if (parameterMap.size() > 0) {
String expression = parameterMap.get(parameterName);
return IncQueryObservables.getObservableValue(match, expression);
}
return null;
}

public IValueProperty getProperty(String parameterName) {
Preconditions.checkArgument(parameterMap.containsKey(parameterName), "Invalid parameter name");
return new MatcherProperty(parameterMap.get(parameterName));
}

}
}

}
Expand Up @@ -9,25 +9,26 @@
* Tamas Szabo - initial API and implementation
*******************************************************************************/

package org.eclipse.incquery.databinding.runtime.adapter;

package org.eclipse.incquery.databinding.runtime.adapter;

import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.property.value.ValueProperty;
import org.eclipse.incquery.databinding.runtime.api.IncQueryObservables;
import org.eclipse.incquery.runtime.api.IPatternMatch;

import com.google.common.base.Preconditions;

/**
* The class is used to observe given parameters of a pattern.
*
* @author Tamas Szabo
*
* @param <T> the type parameter of the match
*/
public abstract class DatabindingAdapter<T extends IPatternMatch> {


/**
* The class is used to observe given parameters of a pattern.
*
* @author Tamas Szabo
*
* @param <T>
* the type parameter of the match
*/
public abstract class DatabindingAdapter<T extends IPatternMatch> {

protected class MatcherProperty extends ValueProperty {

private String expression;
Expand Down Expand Up @@ -60,20 +61,22 @@ public IObservableValue observe(Realm realm, Object source) {
}

}

/**
* Returns the array of observable values.
*
* @return the array of values
*/
public abstract String[] getParameterNames();

/**
* Returns an observable value for the given match and parameterName.
*
* @param match the match object
* @param parameterName the parameter name
* @return an observable value
*/
public abstract IObservableValue getObservableParameter(T match, String parameterName);
}

/**
* Returns the array of observable values.
*
* @return the array of values
*/
public abstract String[] getParameterNames();

/**
* Returns an observable value for the given match and parameterName.
*
* @param match
* the match object
* @param parameterName
* the parameter name
* @return an observable value
*/
public abstract IObservableValue getObservableParameter(T match, String parameterName);
}
Expand Up @@ -9,8 +9,8 @@
* Tamas Szabo - initial API and implementation
*******************************************************************************/

package org.eclipse.incquery.databinding.runtime.adapter;

package org.eclipse.incquery.databinding.runtime.adapter;

import java.util.List;
import java.util.Map;

Expand All @@ -30,116 +30,122 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;


public class DatabindingAdapterUtil {
public static final String OBSERVABLEVALUE_ANNOTATION = "ObservableValue";

private DatabindingAdapterUtil() {}
/**
* Returns an IObservableValue for the given match based on the given expression.
* If an attribute is not present in the expression than it tries with the 'name' attribute.
* If it is not present the returned value will be null.

public static final String OBSERVABLEVALUE_ANNOTATION = "ObservableValue";

private DatabindingAdapterUtil() {
}

/**
* Returns an IObservableValue for the given match based on the given expression. If an attribute is not present in
* the expression than it tries with the 'name' attribute. If it is not present the returned value will be null.
*
* @param match the match object
* @param expression the expression
* @return IObservableValue instance or null
* @param match
* the match object
* @param expression
* the expression
* @return IObservableValue instance or null
* @deprecated Use {@link IncQueryObservables#getObservableValue(IPatternMatch,String)} instead
*/
@Deprecated
public static IObservableValue getObservableValue(IPatternMatch match, String expression) {
return IncQueryObservables.getObservableValue(match, expression);
}
/**
* Registers the given changeListener for the appropriate features of the given signature.
* The features will be computed based on the message parameter.
}

/**
* Registers the given changeListener for the appropriate features of the given signature. The features will be
* computed based on the message parameter.
*
* @param signature the signature instance
* @param changeListener the changle listener
* @param message the message which can be found in the appropriate PatternUI annotation
* @param signature
* the signature instance
* @param changeListener
* the changle listener
* @param message
* the message which can be found in the appropriate PatternUI annotation
* @return the list of IObservableValue instances for which the IValueChangeListener was registered
* @deprecated Use {@link IncQueryObservables#observeFeatures(IPatternMatch,IValueChangeListener,String)} instead
*/
@Deprecated
public static List<IObservableValue> observeFeatures(IPatternMatch match, IValueChangeListener changeListener, String message) {
public static List<IObservableValue> observeFeatures(IPatternMatch match, IValueChangeListener changeListener,
String message) {
return IncQueryObservables.observeFeatures(match, changeListener, message);
}
/**
* Registers the given change listener on the given object's all accessible fields.
* This function uses Java Reflection.
}

/**
* Registers the given change listener on the given object's all accessible fields. This function uses Java
* Reflection.
*
* @param changeListener the changle listener
* @param object the observed object
* @param changeListener
* the changle listener
* @param object
* the observed object
* @return the list of IObservableValue instances for which the IValueChangeListener was registered
* @deprecated Use {@link IncQueryObservables#observeAllAttributes(IValueChangeListener,Object)} instead
*/
@Deprecated
public static List<IObservableValue> observeAllAttributes(IValueChangeListener changeListener, Object object) {
return IncQueryObservables.observeAllAttributes(changeListener, object);
}

/**
* Get the structural feature with the given name of the given object.
*
* @param o the object (must be an EObject)
* @param featureName the name of the feature
* @return the EStructuralFeature of the object or null if it can not be found
*/
public static EStructuralFeature getFeature(Object o, String featureName) {
if (o instanceof EObject) {
EStructuralFeature feature = ((EObject) o).eClass().getEStructuralFeature(featureName);
return feature;
}
return null;
}

public static String getMessage(IPatternMatch match, String message) {
String[] tokens = message.split("\\$");
StringBuilder newText = new StringBuilder();

for (int i = 0;i<tokens.length;i++) {
if (i % 2 == 0) {
newText.append(tokens[i]);
}
else {
String[] objectTokens = tokens[i].split("\\.");
if (objectTokens.length > 0) {
Object o = null;
EStructuralFeature feature = null;

if (objectTokens.length == 1) {
o = match.get(objectTokens[0]);
feature = DatabindingAdapterUtil.getFeature(o, "name");
}
if (objectTokens.length == 2) {
o = match.get(objectTokens[0]);
feature = DatabindingAdapterUtil.getFeature(o, objectTokens[1]);
}

if (o != null && feature != null) {
Object value = ((EObject) o).eGet(feature);
if (value != null) {
newText.append(value.toString());
}
else {
newText.append("null");
}
}
else if (o != null) {
newText.append(o.toString());
}
}
else {
newText.append("[no such parameter]");
}
}
}

return newText.toString();
}
}

/**
* Get the structural feature with the given name of the given object.
*
* @param o
* the object (must be an EObject)
* @param featureName
* the name of the feature
* @return the EStructuralFeature of the object or null if it can not be found
*/
public static EStructuralFeature getFeature(Object o, String featureName) {
if (o instanceof EObject) {
EStructuralFeature feature = ((EObject) o).eClass().getEStructuralFeature(featureName);
return feature;
}
return null;
}

public static String getMessage(IPatternMatch match, String message) {
String[] tokens = message.split("\\$");
StringBuilder newText = new StringBuilder();

for (int i = 0; i < tokens.length; i++) {
if (i % 2 == 0) {
newText.append(tokens[i]);
} else {
String[] objectTokens = tokens[i].split("\\.");
if (objectTokens.length > 0) {
Object o = null;
EStructuralFeature feature = null;

if (objectTokens.length == 1) {
o = match.get(objectTokens[0]);
feature = DatabindingAdapterUtil.getFeature(o, "name");
}
if (objectTokens.length == 2) {
o = match.get(objectTokens[0]);
feature = DatabindingAdapterUtil.getFeature(o, objectTokens[1]);
}

if (o != null && feature != null) {
Object value = ((EObject) o).eGet(feature);
if (value != null) {
newText.append(value.toString());
} else {
newText.append("null");
}
} else if (o != null) {
newText.append(o.toString());
}
} else {
newText.append("[no such parameter]");
}
}
}

return newText.toString();
}

/**
* @param pattern
Expand All @@ -152,7 +158,7 @@ public static Map<String, String> calculateObservableValues(Pattern pattern) {
}
for (Annotation annotation : CorePatternLanguageHelper
.getAnnotationsByName(pattern, OBSERVABLEVALUE_ANNOTATION)) {

ListMultimap<String, ValueReference> parameterMap = CorePatternLanguageHelper
.getAnnotationParameters(annotation);
List<ValueReference> nameAttributes = parameterMap.get("name");
Expand All @@ -170,7 +176,7 @@ public static Map<String, String> calculateObservableValues(Pattern pattern) {
propertyMap.put(key, value);
}
}
}
}
return propertyMap;
}
}
}
}

0 comments on commit d5a4842

Please sign in to comment.