org.eclipse.xtext.xbase.lib.Procedures Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.lib.Procedures.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Creates a getter method for the given property name and the field name. * * Example: <code> * public String getPropertyName() { * return this.fieldName; * } * </code> * * @return a getter method for a JavaBeans property, <code>null</code> if sourceElement or name are <code>null</code>. */ /* @Nullable */ public JvmOperation toGetter(/* @Nullable */ final EObject sourceElement, /* @Nullable */ final String propertyName, /* @Nullable */ final String fieldName, /* @Nullable */ JvmTypeReference typeRef) { if(sourceElement == null || propertyName == null || fieldName == null) return null; JvmOperation result = typesFactory.createJvmOperation(); result.setVisibility(JvmVisibility.PUBLIC); String prefix = (isPrimitiveBoolean(typeRef) ? "is" : "get"); result.setSimpleName(prefix + Strings.toFirstUpper(propertyName)); result.setReturnType(cloneWithProxies(typeRef)); setBody(result, new Procedures.Procedure1<ITreeAppendable>() { @Override public void apply(/* @Nullable */ ITreeAppendable p) { if(p != null) { p = p.trace(sourceElement); p.append("return this."); p.append(javaKeywords.isJavaKeyword(fieldName) ? fieldName+"_" : fieldName); p.append(";"); } } }); return associate(sourceElement, result); }
Example #2
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * Creates a setter method for the given properties name with the standard implementation assigning the passed * parameter to a similarly named field. * * Example: <code> * public void setFoo(String foo) { * this.foo = foo; * } * </code> * * @return a setter method for a JavaBeans property with the given name, <code>null</code> if sourceElement or name are <code>null</code>. */ /* @Nullable */ public JvmOperation toSetter(/* @Nullable */ final EObject sourceElement, /* @Nullable */ final String propertyName, /* @Nullable */ final String fieldName, /* @Nullable */ JvmTypeReference typeRef) { if(sourceElement == null || propertyName == null || fieldName == null) return null; JvmOperation result = typesFactory.createJvmOperation(); result.setVisibility(JvmVisibility.PUBLIC); result.setReturnType(references.getTypeForName(Void.TYPE,sourceElement)); result.setSimpleName("set" + Strings.toFirstUpper(propertyName)); result.getParameters().add(toParameter(sourceElement, propertyName, typeRef)); setBody(result, new Procedures.Procedure1<ITreeAppendable>() { @Override public void apply(/* @Nullable */ ITreeAppendable p) { if(p != null) { p = p.trace(sourceElement); p.append("this."); p.append(javaKeywords.isJavaKeyword(fieldName) ? fieldName+"_" : fieldName); p.append(" = "); p.append(javaKeywords.isJavaKeyword(propertyName) ? propertyName+"_" : propertyName); p.append(";"); } } }); return associate(sourceElement, result); }
Example #3
Source File: BlockExpressionBuilderImpl.java From sarl with Apache License 2.0 | 6 votes |
/** Add an expression inside the block. * @return the expression builder. */ public IExpressionBuilder addExpression() { final IExpressionBuilder builder = this.expressionProvider.get(); builder.eInit(getXBlockExpression(), new Procedures.Procedure1<XExpression>() { private int index = -1; public void apply(XExpression it) { if (this.index >= 0) { getXBlockExpression().getExpressions().set(index, it); } else { getXBlockExpression().getExpressions().add(it); this.index = getXBlockExpression().getExpressions().size() - 1; } } }, getTypeResolutionContext()); return builder; }
Example #4
Source File: XFunctionTypeRefs.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public static String buildUri(boolean procedure, int functionParamCount) { int paramCount = Math.min(6, functionParamCount); if (procedure) { return "java:/Objects/" + Procedures.class.getCanonicalName() + "#" + Procedures.class.getCanonicalName() + "$Procedure" + Integer.valueOf(paramCount); } return "java:/Objects/" + Functions.class.getCanonicalName() + "#" + Functions.class.getCanonicalName() + "$Function" + Integer.valueOf(paramCount); }
Example #5
Source File: SarlFieldBuilderImpl.java From sarl with Apache License 2.0 | 5 votes |
/** Change the initialValue. * @param value the value of the initialValue. It may be {@code null}. */ @Pure public IExpressionBuilder getInitialValue() { IExpressionBuilder exprBuilder = this.expressionProvider.get(); exprBuilder.eInit(getSarlField(), new Procedures.Procedure1<XExpression>() { public void apply(XExpression expr) { getSarlField().setInitialValue(expr); } }, getTypeResolutionContext()); return exprBuilder; }
Example #6
Source File: FunctionTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public FunctionTypeKind getFunctionTypeKind(ParameterizedTypeReference typeReference) { JvmType type = typeReference.getType(); if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { JvmDeclaredType outerType = ((JvmGenericType) type).getDeclaringType(); if (outerType != null) { if (Procedures.class.getName().equals(outerType.getIdentifier())) { return FunctionTypeKind.PROCEDURE; } if (Functions.class.getName().equals(outerType.getIdentifier())) { return FunctionTypeKind.FUNCTION; } } } return FunctionTypeKind.NONE; }
Example #7
Source File: FunctionTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private Class<?> loadFunctionClass(String simpleFunctionName, boolean procedure) { try { if (!procedure) { return Functions.class.getClassLoader().loadClass( Functions.class.getCanonicalName() + "$" + simpleFunctionName); } else { return Procedures.class.getClassLoader().loadClass( Procedures.class.getCanonicalName() + "$" + simpleFunctionName); } } catch (ClassNotFoundException e) { throw new WrappedException(e); } }
Example #8
Source File: SarlBehaviorUnitBuilderImpl.java From sarl with Apache License 2.0 | 5 votes |
/** Change the guard. * @param value the value of the guard. It may be {@code null}. */ @Pure public IExpressionBuilder getGuard() { IExpressionBuilder exprBuilder = this.expressionProvider.get(); exprBuilder.eInit(getSarlBehaviorUnit(), new Procedures.Procedure1<XExpression>() { public void apply(XExpression expr) { getSarlBehaviorUnit().setGuard(expr); } }, getTypeResolutionContext()); return exprBuilder; }
Example #9
Source File: FormalParameterBuilderImpl.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the default value of the parameter. * @return the default value builder. */ @Pure public IExpressionBuilder getDefaultValue() { if (this.defaultValue == null) { this.defaultValue = this.expressionProvider.get(); this.defaultValue.eInit(this.parameter, new Procedures.Procedure1<XExpression>() { public void apply(XExpression it) { getSarlFormalParameter().setDefaultValue(it); } }, getTypeResolutionContext()); } return this.defaultValue; }
Example #10
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void setCompilationStrategy(/* @Nullable */ JvmMember member, /* @Nullable */ Procedures.Procedure1<ITreeAppendable> strategy) { if(member == null || strategy == null) return; CompilationStrategyAdapter adapter = new CompilationStrategyAdapter(); adapter.setCompilationStrategy(strategy); member.eAdapters().add(adapter); }
Example #11
Source File: FunctionTypes.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public boolean isFunctionAndProcedureAvailable(ITypeReferenceOwner owner) { JvmType type = typeReferences.findDeclaredType(Procedures.Procedure1.class, owner.getContextResourceSet()); if (type == null) { return false; } if (type instanceof JvmTypeParameterDeclarator) { return !((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty(); } return false; }
Example #12
Source File: ClosureClient.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public Procedures.Procedure0 asProcedure(final Runnable runnable) { return new Procedures.Procedure0() { @Override public void apply() { runnable.run(); } }; }
Example #13
Source File: ClosureClient.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public Runnable asRunnable(final Procedures.Procedure0 procedure) { return new Runnable() { @Override public void run() { procedure.apply(); } }; }
Example #14
Source File: XtendReentrantTypeResolver.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected JvmConstructor inferAnonymousClassConstructor(AnonymousClass anonymousClass, JvmGenericType inferredLocalClass, JvmConstructor superConstructor, boolean visible) { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); inferredLocalClass.getMembers().add(constructor); associator.associatePrimary(anonymousClass.getConstructorCall(), constructor); if (visible) { constructor.setVisibility(JvmVisibility.DEFAULT); } else constructor.setVisibility(JvmVisibility.PRIVATE); constructor.setSimpleName(inferredLocalClass.getSimpleName()); constructor.setVarArgs(superConstructor.isVarArgs()); final List<JvmFormalParameter> parameters = superConstructor.getParameters(); for(JvmFormalParameter parameter: parameters) { parameter.getName(); // trigger name computation constructor.getParameters().add(typesBuilder.cloneWithProxies(parameter)); } for (JvmTypeReference exception : superConstructor.getExceptions()) constructor.getExceptions().add(typesBuilder.cloneWithProxies(exception)); if (!parameters.isEmpty()) { typesBuilder.setBody(constructor, new Procedures.Procedure1<ITreeAppendable>() { @Override public void apply(ITreeAppendable a) { a.append("super("); for(int i = 0; i < parameters.size(); i++) { if (i != 0) { a.append(", "); } a.append(parameters.get(i).getSimpleName()); } a.append(");"); } }); } return constructor; }
Example #15
Source File: ClosureClient.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public Runnable asRunnable(final Procedures.Procedure0 procedure) { return new Runnable() { @Override public void run() { procedure.apply(); } }; }
Example #16
Source File: ClosureClient.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public Procedures.Procedure0 asProcedure(final Runnable runnable) { return new Procedures.Procedure0() { @Override public void apply() { runnable.run(); } }; }
Example #17
Source File: ClosureClient.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public Procedures.Procedure0 asProcedure(final Runnable runnable) { return new Procedures.Procedure0() { @Override public void apply() { runnable.run(); } }; }
Example #18
Source File: ClosureClient.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public Runnable asRunnable(final Procedures.Procedure0 procedure) { return new Runnable() { @Override public void run() { procedure.apply(); } }; }
Example #19
Source File: ClosureClient.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public Procedures.Procedure0 asProcedure(final Runnable runnable) { return new Procedures.Procedure0() { @Override public void apply() { runnable.run(); } }; }
Example #20
Source File: ClosureClient.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public Runnable asRunnable(final Procedures.Procedure0 procedure) { return new Runnable() { @Override public void run() { procedure.apply(); } }; }
Example #21
Source File: ReferenceSearchViewPage.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected OpenAndLinkWithEditorHelper createOpenAndLinkWithEditorHandler() { return navigationService.installNavigationSupport(viewer, new Procedures.Procedure1<OpenEvent>() { @Override public void apply(OpenEvent openEvent) { handleOpen(openEvent); } }); }
Example #22
Source File: ClosureClient.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.3 */ public String useProcedureForCharSequence(Procedures.Procedure1<CharSequence> proc) { proc.apply(null); return "done"; }
Example #23
Source File: XtendCompileStrategies.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public Procedures.Procedure1<ITreeAppendable> forCacheMethod(CreateExtensionInfo createExtensionInfo, JvmField cacheField, JvmOperation initializerMethod) { CacheMethodCompileStrategy strategy = cacheMethodProvider.get(); strategy.init(createExtensionInfo, cacheField, initializerMethod); return strategy; }
Example #24
Source File: XtendCompileStrategies.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public Procedures.Procedure1<ITreeAppendable> forDispatcher(JvmOperation dispatchOperation) { DispatchMethodCompileStrategy strategy = dispatchMethodProvider.get(); strategy.initialize(dispatchOperation); return strategy; }
Example #25
Source File: XtendCompileStrategies.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public Procedures.Procedure1<ITreeAppendable> forCacheVariable(XtendFunction function) { CacheVariableCompileStrategy strategy = cacheVarProvider.get(); return strategy; }
Example #26
Source File: SampleBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public Root root(Procedures.Procedure1<? super Root> init) { Root result = new Root(); init.apply(result); return result; }
Example #27
Source File: ClosureClient.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.3 */ public String useProcedureForCharSequence(Procedures.Procedure1<CharSequence> proc) { proc.apply(null); return "done"; }
Example #28
Source File: ClosureClient.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.3 */ public String useProcedureForCharSequence(Procedures.Procedure1<CharSequence> proc) { proc.apply(null); return "done"; }
Example #29
Source File: Ack.java From cloudml with GNU Lesser General Public License v3.0 | 4 votes |
public Ack(final Procedures.Procedure1<Ack> initializer) { initializer.apply(this); }
Example #30
Source File: SampleBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public static Root staticRoot(Procedures.Procedure1<? super Root> init) { Root result = new Root(); init.apply(result); return result; }