Package: EmfParsleyDslScopeProvider$2

EmfParsleyDslScopeProvider$2

nameinstructionbranchcomplexitylinemethod
apply(JvmOperation)
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
{...}
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * generated by Xtext 2.10.0-SNAPSHOT
3: */
4: package org.eclipse.emf.parsley.dsl.scoping;
5:
6: import com.google.common.base.Function;
7: import com.google.common.base.Objects;
8: import com.google.common.collect.Iterables;
9: import java.beans.Introspector;
10: import java.util.Arrays;
11: import org.eclipse.emf.ecore.EClass;
12: import org.eclipse.emf.ecore.EClassifier;
13: import org.eclipse.emf.ecore.EObject;
14: import org.eclipse.emf.ecore.EReference;
15: import org.eclipse.emf.parsley.dsl.model.EmfFeatureAccess;
16: import org.eclipse.emf.parsley.dsl.scoping.AbstractEmfParsleyDslScopeProvider;
17: import org.eclipse.emf.parsley.dsl.util.EmfParsleyDslModelUtil;
18: import org.eclipse.xtext.common.types.JvmGenericType;
19: import org.eclipse.xtext.common.types.JvmOperation;
20: import org.eclipse.xtext.common.types.JvmType;
21: import org.eclipse.xtext.common.types.JvmTypeReference;
22: import org.eclipse.xtext.common.types.TypesPackage;
23: import org.eclipse.xtext.naming.QualifiedName;
24: import org.eclipse.xtext.resource.IEObjectDescription;
25: import org.eclipse.xtext.scoping.IScope;
26: import org.eclipse.xtext.scoping.Scopes;
27: import org.eclipse.xtext.scoping.impl.SimpleScope;
28: import org.eclipse.xtext.xbase.lib.Functions.Function1;
29: import org.eclipse.xtext.xbase.lib.IterableExtensions;
30:
31: /**
32: * This class contains custom scoping description.
33: *
34: * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping
35: * on how and when to use it.
36: */
37: @SuppressWarnings("all")
38: public class EmfParsleyDslScopeProvider extends AbstractEmfParsleyDslScopeProvider {
39: @Override
40: public IScope getScope(final EObject context, final EReference reference) {
41: IScope _xblockexpression = null;
42: {
43: final IScope scope = this.createCustomScope(context, reference);
44: if ((scope != null)) {
45: return scope;
46: }
47: _xblockexpression = super.getScope(context, reference);
48: }
49: return _xblockexpression;
50: }
51:
52: public IScope createCustomScope(final EObject context, final EReference reference) {
53: EClassifier _eType = reference.getEType();
54: EClass _jvmMember = TypesPackage.eINSTANCE.getJvmMember();
55: boolean _equals = Objects.equal(_eType, _jvmMember);
56: if (_equals) {
57: EmfFeatureAccess _containingEmfFeatureAccess = EmfParsleyDslModelUtil.containingEmfFeatureAccess(context);
58: JvmTypeReference _parameterType = null;
59: if (_containingEmfFeatureAccess!=null) {
60: _parameterType=_containingEmfFeatureAccess.getParameterType();
61: }
62: JvmType _type = null;
63: if (_parameterType!=null) {
64: _type=_parameterType.getType();
65: }
66: IScope _customScope = null;
67: if (_type!=null) {
68: _customScope=this.customScope(_type);
69: }
70: return _customScope;
71: }
72: return null;
73: }
74:
75: protected IScope _customScope(final JvmType t) {
76: return null;
77: }
78:
79: protected IScope _customScope(final JvmGenericType t) {
80: final Function1<JvmOperation, Boolean> _function = new Function1<JvmOperation, Boolean>() {
81: @Override
82: public Boolean apply(final JvmOperation it) {
83: boolean _isStatic = it.isStatic();
84: return Boolean.valueOf((!_isStatic));
85: }
86: };
87: final Function<JvmOperation, QualifiedName> _function_1 = new Function<JvmOperation, QualifiedName>() {
88: @Override
89: public QualifiedName apply(final JvmOperation it) {
90: QualifiedName _xifexpression = null;
91: boolean _isGetterMethod = EmfParsleyDslScopeProvider.this.isGetterMethod(it.getSimpleName());
92:• if (_isGetterMethod) {
93: _xifexpression = QualifiedName.create(EmfParsleyDslScopeProvider.this.getPropertyNameForGetterMethod(it.getSimpleName()));
94: } else {
95: _xifexpression = null;
96: }
97: return _xifexpression;
98: }
99: };
100: Iterable<IEObjectDescription> _scopedElementsFor = Scopes.<JvmOperation>scopedElementsFor(IterableExtensions.<JvmOperation>filter(Iterables.<JvmOperation>filter(t.getAllFeatures(), JvmOperation.class), _function), _function_1);
101: return new SimpleScope(_scopedElementsFor);
102: }
103:
104: public boolean isGetterMethod(final String opName) {
105: return (this.getterMethodForNonBoolean(opName) || this.getterMethodForBoolean(opName));
106: }
107:
108: public String getPropertyNameForGetterMethod(final String opName) {
109: boolean _terMethodForNonBoolean = this.getterMethodForNonBoolean(opName);
110: if (_terMethodForNonBoolean) {
111: return Introspector.decapitalize(opName.substring(3));
112: }
113: boolean _terMethodForBoolean = this.getterMethodForBoolean(opName);
114: if (_terMethodForBoolean) {
115: return Introspector.decapitalize(opName.substring(2));
116: }
117: return null;
118: }
119:
120: private boolean getterMethodForBoolean(final String opName) {
121: return this.getterMethodInternal(opName, "is");
122: }
123:
124: private boolean getterMethodForNonBoolean(final String opName) {
125: return this.getterMethodInternal(opName, "get");
126: }
127:
128: private boolean getterMethodInternal(final String opName, final String prefix) {
129: return ((opName.startsWith(prefix) && (opName.length() > prefix.length())) &&
130: Character.isUpperCase(opName.charAt(prefix.length())));
131: }
132:
133: public IScope customScope(final JvmType t) {
134: if (t instanceof JvmGenericType) {
135: return _customScope((JvmGenericType)t);
136: } else if (t != null) {
137: return _customScope(t);
138: } else {
139: throw new IllegalArgumentException("Unhandled parameter types: " +
140: Arrays.<Object>asList(t).toString());
141: }
142: }
143: }