idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
34,200
@ SuppressWarnings ( "static-method" ) protected String getGeneratedMemberAccessor ( MemberDescription description ) { return "get" + Strings . toFirstUpper ( description . getElementDescription ( ) . getElementType ( ) . getSimpleName ( ) ) + "()" ; }
Replies the name of the accessor that replies the generated member .
34,201
protected Binding bindAnnotatedWith ( TypeReference bind , TypeReference annotatedWith , TypeReference to , String functionName ) { final StringConcatenationClient client = new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation builder ) { builder . append ( "binder.bind(" ) ; builder . append ( bind ) ; builder . append ( ".class).annotatedWith(" ) ; builder . append ( annotatedWith ) ; builder . append ( ".class).to(" ) ; builder . append ( to ) ; builder . append ( ".class);" ) ; } } ; String fctname = functionName ; if ( Strings . isEmpty ( fctname ) ) { fctname = bind . getSimpleName ( ) ; } final BindKey key = new GuiceModuleAccess . BindKey ( formatFunctionName ( fctname ) , null , false , false ) ; final BindValue statements = new BindValue ( null , null , false , Collections . singletonList ( client ) ) ; return new Binding ( key , statements , true , this . name ) ; }
Bind an annotated element .
34,202
protected Binding bindAnnotatedWithNameToInstance ( TypeReference bind , String name , String to , String functionName ) { String tmpName = Strings . emptyIfNull ( name ) ; if ( tmpName . startsWith ( REFERENCE_PREFIX ) ) { tmpName = tmpName . substring ( REFERENCE_PREFIX . length ( ) ) . trim ( ) ; } else { tmpName = "\"" + tmpName + "\"" ; } final String unferencedName = tmpName ; final StringConcatenationClient client = new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation builder ) { builder . append ( "binder.bind(" ) ; builder . append ( bind ) ; builder . append ( ".class).annotatedWith(Names.named(" ) ; builder . append ( unferencedName ) ; builder . append ( ")).toInstance(" ) ; builder . append ( to ) ; builder . append ( ".class);" ) ; } } ; String fctname = functionName ; if ( Strings . isEmpty ( fctname ) ) { fctname = name ; } final BindKey key = new GuiceModuleAccess . BindKey ( formatFunctionName ( fctname ) , null , false , false ) ; final BindValue statements = new BindValue ( null , null , false , Collections . singletonList ( client ) ) ; return new Binding ( key , statements , true , this . name ) ; }
Bind a type annotated with a name of the given value .
34,203
protected Binding bindToInstance ( TypeReference bind , String functionName , String instanceExpression , boolean isSingleton , boolean isEager ) { final BindKey type ; final BindValue value ; if ( ! Strings . isEmpty ( functionName ) && functionName . startsWith ( CONFIGURE_PREFIX ) ) { final String fname = functionName . substring ( CONFIGURE_PREFIX . length ( ) ) ; type = new BindKey ( Strings . toFirstUpper ( fname ) , null , isSingleton , isEager ) ; final StringConcatenationClient client = new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation builder ) { builder . append ( "binder.bind(" ) ; builder . append ( bind ) ; builder . append ( ".class).toInstance(" ) ; builder . append ( instanceExpression ) ; builder . append ( ");" ) ; } } ; value = new BindValue ( null , null , false , Collections . singletonList ( client ) ) ; } else { String fname = functionName ; if ( fname != null && fname . startsWith ( BIND_PREFIX ) ) { fname = fname . substring ( BIND_PREFIX . length ( ) ) ; } type = new BindKey ( Strings . toFirstUpper ( fname ) , bind , isSingleton , isEager ) ; final StringConcatenationClient client = new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation builder ) { builder . append ( instanceExpression ) ; } } ; value = new BindValue ( client , null , false , Collections . emptyList ( ) ) ; } return new Binding ( type , value , true , this . name ) ; }
Bind a type to an instance expression .
34,204
public void add ( Binding binding , boolean override ) { final Set < Binding > moduleBindings = this . module . get ( ) . getBindings ( ) ; final Binding otherBinding = findBinding ( moduleBindings , binding ) ; if ( ! override ) { if ( otherBinding != null ) { throw new IllegalArgumentException ( MessageFormat . format ( "Forbidden override of {0} by {1}." , otherBinding , binding ) ) ; } } else if ( otherBinding != null ) { this . removableBindings . add ( otherBinding ) ; } if ( ! this . bindings . add ( binding ) ) { throw new IllegalArgumentException ( MessageFormat . format ( "Duplicate binding for {0} in {1}" , binding . getKey ( ) , this . name ) ) ; } }
Add the binding .
34,205
public void contributeToModule ( ) { final GuiceModuleAccess module = this . module . get ( ) ; if ( ! this . removableBindings . isEmpty ( ) ) { try { final Field field = module . getClass ( ) . getDeclaredField ( "bindings" ) ; final boolean accessible = field . isAccessible ( ) ; try { field . setAccessible ( true ) ; final Collection < ? > hiddenBindings = ( Collection < ? > ) field . get ( module ) ; hiddenBindings . removeAll ( this . removableBindings ) ; } finally { field . setAccessible ( accessible ) ; } } catch ( Exception exception ) { throw new IllegalStateException ( exception ) ; } } module . addAll ( this . bindings ) ; }
Put the bindings to the associated module .
34,206
public Binding toBinding ( BindingElement element ) { final TypeReference typeReference = typeRef ( element . getBind ( ) ) ; final String annotatedWith = element . getAnnotatedWith ( ) ; final String annotatedWithName = element . getAnnotatedWithName ( ) ; if ( ! Strings . isEmpty ( annotatedWith ) ) { final TypeReference annotationType = typeRef ( annotatedWith ) ; if ( element . isInstance ( ) ) { return bindAnnotatedWithToInstance ( typeReference , annotationType , element . getTo ( ) , element . getFunctionName ( ) ) ; } final TypeReference typeReference2 = typeRef ( element . getTo ( ) ) ; return bindAnnotatedWith ( typeReference , annotationType , typeReference2 , element . getFunctionName ( ) ) ; } if ( ! Strings . isEmpty ( annotatedWithName ) ) { if ( element . isInstance ( ) ) { return bindAnnotatedWithNameToInstance ( typeReference , annotatedWithName , element . getTo ( ) , element . getFunctionName ( ) ) ; } final TypeReference typeReference2 = typeRef ( element . getTo ( ) ) ; return bindAnnotatedWithName ( typeReference , annotatedWithName , typeReference2 , element . getFunctionName ( ) ) ; } if ( element . isInstance ( ) ) { return bindToInstance ( typeReference , element . getFunctionName ( ) , element . getTo ( ) , element . isSingleton ( ) , element . isEager ( ) ) ; } final TypeReference typeReference2 = typeRef ( element . getTo ( ) ) ; return bindToType ( typeReference , element . getFunctionName ( ) , typeReference2 , element . isSingleton ( ) , element . isEager ( ) , element . isProvider ( ) ) ; }
Convert a binding element to a Guive binding .
34,207
protected void enableNature ( IProject project ) { final IFile pom = project . getFile ( IMavenConstants . POM_FILE_NAME ) ; final Job job ; if ( pom . exists ( ) ) { job = createJobForMavenProject ( project ) ; } else { job = createJobForJavaProject ( project ) ; } if ( job != null ) { job . schedule ( ) ; } }
Enable the SARL Maven nature .
34,208
@ SuppressWarnings ( "static-method" ) protected Job createJobForMavenProject ( IProject project ) { return new Job ( Messages . EnableSarlMavenNatureAction_0 ) { protected IStatus run ( IProgressMonitor monitor ) { final SubMonitor mon = SubMonitor . convert ( monitor , 3 ) ; try { final IPath descriptionFilename = project . getFile ( new Path ( IProjectDescription . DESCRIPTION_FILE_NAME ) ) . getLocation ( ) ; final File projectDescriptionFile = descriptionFilename . toFile ( ) ; final IPath classpathFilename = project . getFile ( new Path ( FILENAME_CLASSPATH ) ) . getLocation ( ) ; final File classpathFile = classpathFilename . toFile ( ) ; project . close ( mon . newChild ( 1 ) ) ; project . delete ( false , true , mon . newChild ( 1 ) ) ; if ( projectDescriptionFile . exists ( ) ) { projectDescriptionFile . delete ( ) ; } if ( classpathFile . exists ( ) ) { classpathFile . delete ( ) ; } MavenImportUtils . importMavenProject ( project . getWorkspace ( ) . getRoot ( ) , project . getName ( ) , true , mon . newChild ( 1 ) ) ; } catch ( CoreException exception ) { SARLMavenEclipsePlugin . getDefault ( ) . log ( exception ) ; } return Status . OK_STATUS ; } } ; }
Create the configuration job for a Maven project .
34,209
@ SuppressWarnings ( "static-method" ) protected Job createJobForJavaProject ( IProject project ) { return new Job ( Messages . EnableSarlMavenNatureAction_0 ) { protected IStatus run ( IProgressMonitor monitor ) { final SubMonitor mon = SubMonitor . convert ( monitor , 3 ) ; SARLProjectConfigurator . configureSARLProject ( project , true , true , true , mon . newChild ( 3 ) ) ; return Status . OK_STATUS ; } } ; }
Create the configuration job for a Java project .
34,210
protected void fireAgentSpawnedOutsideAgent ( UUID spawningAgent , AgentContext context , Class < ? extends Agent > agentClazz , List < Agent > agents , Object ... initializationParameters ) { for ( final SpawnServiceListener l : this . globalListeners . getListeners ( SpawnServiceListener . class ) ) { l . agentSpawned ( spawningAgent , context , agents , initializationParameters ) ; } final EventSpace defSpace = context . getDefaultSpace ( ) ; assert defSpace != null : "A context does not contain a default space" ; final UUID spawner = spawningAgent == null ? context . getID ( ) : spawningAgent ; final Address source = new Address ( defSpace . getSpaceID ( ) , spawner ) ; assert source != null ; final Collection < UUID > spawnedAgentIds = Collections3 . serializableCollection ( Collections2 . transform ( agents , it -> it . getID ( ) ) ) ; final AgentSpawned event = new AgentSpawned ( source , agentClazz . getName ( ) , spawnedAgentIds ) ; final Scope < Address > scope = address -> { final UUID receiver = address . getUUID ( ) ; return ! spawnedAgentIds . parallelStream ( ) . anyMatch ( it -> it . equals ( receiver ) ) ; } ; defSpace . emit ( null , event , scope ) ; }
Notify the listeners about the agents spawning .
34,211
protected void fireAgentSpawnedInAgent ( UUID spawningAgent , AgentContext context , Agent agent , Object ... initializationParameters ) { final ListenerCollection < SpawnServiceListener > list ; synchronized ( this . agentLifecycleListeners ) { list = this . agentLifecycleListeners . get ( agent . getID ( ) ) ; } if ( list != null ) { final List < Agent > singleton = Collections . singletonList ( agent ) ; for ( final SpawnServiceListener l : list . getListeners ( SpawnServiceListener . class ) ) { l . agentSpawned ( spawningAgent , context , singleton , initializationParameters ) ; } } }
Notify the agent s listeners about its spawning .
34,212
public SynchronizedSet < UUID > getAgents ( ) { final Object mutex = getAgentRepositoryMutex ( ) ; synchronized ( mutex ) { return Collections3 . synchronizedSet ( this . agents . keySet ( ) , mutex ) ; } }
Replies the registered agents .
34,213
Agent getAgent ( UUID id ) { assert id != null ; synchronized ( getAgentRepositoryMutex ( ) ) { return this . agents . get ( id ) ; } }
Replies the registered agent .
34,214
@ SuppressWarnings ( "static-method" ) public boolean canKillAgent ( Agent agent ) { try { final AgentContext ac = BuiltinCapacityUtil . getContextIn ( agent ) ; if ( ac != null ) { final SynchronizedSet < UUID > participants = ac . getDefaultSpace ( ) . getParticipants ( ) ; if ( participants != null ) { synchronized ( participants . mutex ( ) ) { if ( participants . size ( ) > 1 || ( participants . size ( ) == 1 && ! participants . contains ( agent . getID ( ) ) ) ) { return false ; } } } } return true ; } catch ( Throwable exception ) { return false ; } }
Replies if the given agent can be killed .
34,215
@ SuppressWarnings ( { "checkstyle:npathcomplexity" } ) protected void fireAgentDestroyed ( Agent agent ) { final ListenerCollection < SpawnServiceListener > list ; synchronized ( getAgentLifecycleListenerMutex ( ) ) { list = this . agentLifecycleListeners . get ( agent . getID ( ) ) ; } final SpawnServiceListener [ ] ilisteners ; if ( list != null ) { ilisteners = list . getListeners ( SpawnServiceListener . class ) ; } else { ilisteners = null ; } final SpawnServiceListener [ ] ilisteners2 = this . globalListeners . getListeners ( SpawnServiceListener . class ) ; final List < Pair < AgentContext , Address > > contextRegistrations = new ArrayList < > ( ) ; try { final SynchronizedIterable < AgentContext > allContexts = BuiltinCapacityUtil . getContextsOf ( agent ) ; synchronized ( allContexts . mutex ( ) ) { for ( final AgentContext context : allContexts ) { final EventSpace defSpace = context . getDefaultSpace ( ) ; final Address address = defSpace . getAddress ( agent . getID ( ) ) ; contextRegistrations . add ( Pair . of ( context , address ) ) ; } } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } if ( ilisteners != null ) { for ( final SpawnServiceListener l : ilisteners ) { l . agentDestroy ( agent ) ; } } for ( final SpawnServiceListener l : ilisteners2 ) { l . agentDestroy ( agent ) ; } try { final UUID killedAgentId = agent . getID ( ) ; final Scope < Address > scope = address -> { final UUID receiver = address . getUUID ( ) ; return ! receiver . equals ( killedAgentId ) ; } ; final String killedAgentType = agent . getClass ( ) . getName ( ) ; for ( final Pair < AgentContext , Address > registration : contextRegistrations ) { final EventSpace defSpace = registration . getKey ( ) . getDefaultSpace ( ) ; defSpace . emit ( null , new AgentKilled ( registration . getValue ( ) , killedAgentId , killedAgentType ) , scope ) ; } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Notifies the listeners about the agent destruction .
34,216
protected void initFields ( ) { final IEclipsePreferences prefs = SARLEclipsePlugin . getDefault ( ) . getPreferences ( ) ; this . trackerLogin . setText ( prefs . get ( PREFERENCE_LOGIN , "" ) ) ; }
Set the initial values to the fields .
34,217
protected void updatePageStatus ( ) { final boolean ok ; if ( Strings . isEmpty ( this . titleField . getText ( ) ) ) { ok = false ; setMessage ( Messages . IssueInformationPage_5 , IMessageProvider . ERROR ) ; } else if ( Strings . isEmpty ( this . trackerLogin . getText ( ) ) ) { ok = false ; setMessage ( Messages . IssueInformationPage_6 , IMessageProvider . ERROR ) ; } else if ( Strings . isEmpty ( this . trackerPassword . getText ( ) ) ) { ok = false ; setMessage ( Messages . IssueInformationPage_7 , IMessageProvider . ERROR ) ; } else { ok = true ; if ( Strings . isEmpty ( this . descriptionField . getText ( ) ) ) { setMessage ( Messages . IssueInformationPage_8 , IMessageProvider . WARNING ) ; } else { setMessage ( null , IMessageProvider . NONE ) ; } } setPageComplete ( ok ) ; }
Update the page status and change the finish state button .
34,218
public boolean performFinish ( ) { final IEclipsePreferences prefs = SARLEclipsePlugin . getDefault ( ) . getPreferences ( ) ; final String login = this . trackerLogin . getText ( ) ; if ( Strings . isEmpty ( login ) ) { prefs . remove ( PREFERENCE_LOGIN ) ; } else { prefs . put ( PREFERENCE_LOGIN , login ) ; } try { prefs . sync ( ) ; return true ; } catch ( BackingStoreException e ) { ErrorDialog . openError ( getShell ( ) , e . getLocalizedMessage ( ) , e . getLocalizedMessage ( ) , SARLEclipsePlugin . getDefault ( ) . createStatus ( IStatus . ERROR , e ) ) ; return false ; } }
Invoked when the wizard is closed with the Finish button .
34,219
public String format ( String sarlCode , ResourceSet resourceSet ) { try { final URI createURI = URI . createURI ( "synthetic://to-be-formatted." + this . fileExtension ) ; final Resource res = this . resourceFactory . createResource ( createURI ) ; if ( res instanceof XtextResource ) { final XtextResource resource = ( XtextResource ) res ; final EList < Resource > resources = resourceSet . getResources ( ) ; resources . add ( resource ) ; try ( StringInputStream stringInputStream = new StringInputStream ( sarlCode ) ) { resource . load ( stringInputStream , Collections . emptyMap ( ) ) ; return formatResource ( resource ) ; } finally { resources . remove ( resource ) ; } } return sarlCode ; } catch ( Exception exception ) { throw Exceptions . sneakyThrow ( exception ) ; } }
Format the given code .
34,220
@ SuppressWarnings ( "static-method" ) public Boolean toBooleanPrimitiveWrapperConstant ( XExpression expression ) { if ( expression instanceof XBooleanLiteral ) { return ( ( XBooleanLiteral ) expression ) . isIsTrue ( ) ? Boolean . TRUE : Boolean . FALSE ; } if ( expression instanceof XMemberFeatureCall ) { final XMemberFeatureCall call = ( XMemberFeatureCall ) expression ; final XExpression receiver = call . getMemberCallTarget ( ) ; if ( receiver instanceof XFeatureCall ) { final XFeatureCall call2 = ( XFeatureCall ) receiver ; final String call2Identifier = call2 . getConcreteSyntaxFeatureName ( ) ; if ( Boolean . class . getSimpleName ( ) . equals ( call2Identifier ) || Boolean . class . getName ( ) . equals ( call2Identifier ) ) { final String callIdentifier = call . getConcreteSyntaxFeatureName ( ) ; if ( "TRUE" . equals ( callIdentifier ) ) { return Boolean . TRUE ; } else if ( "FALSE" . equals ( callIdentifier ) ) { return Boolean . FALSE ; } } } } return null ; }
Convert the boolean constant to the object equivalent if possible .
34,221
public boolean isFrom ( UUID entityId ) { final Address iSource = getSource ( ) ; return ( entityId != null ) && ( iSource != null ) && entityId . equals ( iSource . getUUID ( ) ) ; }
Replies if the event was emitted by an entity with the given identifier .
34,222
protected void generateClosureDefinition ( XClosure closure , IAppendable it , IExtraLanguageGeneratorContext context ) { if ( ! it . hasName ( closure ) ) { final LightweightTypeReference closureType0 = getExpectedType ( closure ) ; LightweightTypeReference closureType = closureType0 ; if ( closureType0 . isFunctionType ( ) ) { final FunctionTypeReference fctRef = closureType0 . tryConvertToFunctionTypeReference ( true ) ; if ( fctRef != null ) { closureType = Utils . toLightweightTypeReference ( fctRef . getType ( ) , this . typeServices ) . getRawTypeReference ( ) ; } } final String closureName = it . declareSyntheticVariable ( closure , "__Jclosure_" + closureType . getSimpleName ( ) ) ; final JvmDeclaredType rawType = ( JvmDeclaredType ) closureType . getType ( ) ; final JvmOperation function = rawType . getDeclaredOperations ( ) . iterator ( ) . next ( ) ; final JvmTypeReference objType = getTypeReferences ( ) . getTypeForName ( Object . class , closure ) ; it . openPseudoScope ( ) ; it . append ( "class " ) . append ( closureName ) . append ( "(" ) . append ( closureType ) . append ( "," ) . append ( objType . getType ( ) ) . append ( "):" ) . increaseIndentation ( ) . newLine ( ) . append ( "def " ) . append ( function . getSimpleName ( ) ) . append ( "(" ) . append ( getExtraLanguageKeywordProvider ( ) . getThisKeywordLambda ( ) . apply ( ) ) ; for ( final JvmFormalParameter param : closure . getFormalParameters ( ) ) { it . append ( ", " ) ; final String name = it . declareUniqueNameVariable ( param , param . getName ( ) ) ; it . append ( name ) ; } it . append ( "):" ) ; it . increaseIndentation ( ) . newLine ( ) ; if ( closure . getExpression ( ) != null ) { LightweightTypeReference returnType = closureType0 ; if ( returnType . isFunctionType ( ) ) { final FunctionTypeReference fctRef = returnType . tryConvertToFunctionTypeReference ( true ) ; if ( fctRef != null ) { returnType = fctRef . getReturnType ( ) ; } else { returnType = null ; } } else { returnType = null ; } generate ( closure . getExpression ( ) , returnType , it , context ) ; } else { it . append ( "pass" ) ; } it . decreaseIndentation ( ) . decreaseIndentation ( ) . newLine ( ) ; it . closeScope ( ) ; } }
Generate the closure definition .
34,223
protected void generateAnonymousClassDefinition ( AnonymousClass anonClass , IAppendable it , IExtraLanguageGeneratorContext context ) { if ( ! it . hasName ( anonClass ) && it instanceof PyAppendable ) { final LightweightTypeReference jvmAnonType = getExpectedType ( anonClass ) ; final String anonName = it . declareSyntheticVariable ( anonClass , jvmAnonType . getSimpleName ( ) ) ; QualifiedName anonQualifiedName = QualifiedName . create ( jvmAnonType . getType ( ) . getQualifiedName ( ) . split ( Pattern . quote ( "." ) ) ) ; anonQualifiedName = anonQualifiedName . skipLast ( 1 ) ; if ( anonQualifiedName . isEmpty ( ) ) { assert anonClass . getDeclaringType ( ) == null : "The Xtend API has changed the AnonymousClass definition!" ; final XtendTypeDeclaration container = EcoreUtil2 . getContainerOfType ( anonClass . eContainer ( ) , XtendTypeDeclaration . class ) ; anonQualifiedName = anonQualifiedName . append ( this . qualifiedNameProvider . getFullyQualifiedName ( container ) ) ; } anonQualifiedName = anonQualifiedName . append ( anonName ) ; it . openPseudoScope ( ) ; final IRootGenerator rootGenerator = context . getRootGenerator ( ) ; assert rootGenerator instanceof PyGenerator ; final List < JvmTypeReference > types = new ArrayList < > ( ) ; for ( final JvmTypeReference superType : anonClass . getConstructorCall ( ) . getConstructor ( ) . getDeclaringType ( ) . getSuperTypes ( ) ) { if ( ! Object . class . getCanonicalName ( ) . equals ( superType . getIdentifier ( ) ) ) { types . add ( superType ) ; } } ( ( PyGenerator ) rootGenerator ) . generateTypeDeclaration ( anonQualifiedName . toString ( ) , anonName , false , types , getTypeBuilder ( ) . getDocumentation ( anonClass ) , false , anonClass . getMembers ( ) , ( PyAppendable ) it , context , null ) ; it . closeScope ( ) ; } }
Generate the anonymous class definition .
34,224
@ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:booleanexpressioncomplexity" , "checkstyle:npathcomplexity" } ) public static String toDefaultValue ( JvmTypeReference type ) { final String id = type . getIdentifier ( ) ; if ( ! "void" . equals ( id ) ) { if ( Strings . equal ( Boolean . class . getName ( ) , id ) || Strings . equal ( Boolean . TYPE . getName ( ) , id ) ) { return "False" ; } if ( Strings . equal ( Float . class . getName ( ) , id ) || Strings . equal ( Float . TYPE . getName ( ) , id ) || Strings . equal ( Double . class . getName ( ) , id ) || Strings . equal ( Double . TYPE . getName ( ) , id ) ) { return "0.0" ; } if ( Strings . equal ( Integer . class . getName ( ) , id ) || Strings . equal ( Integer . TYPE . getName ( ) , id ) || Strings . equal ( Long . class . getName ( ) , id ) || Strings . equal ( Long . TYPE . getName ( ) , id ) || Strings . equal ( Byte . class . getName ( ) , id ) || Strings . equal ( Byte . TYPE . getName ( ) , id ) || Strings . equal ( Short . class . getName ( ) , id ) || Strings . equal ( Short . TYPE . getName ( ) , id ) ) { return "0" ; } if ( Strings . equal ( Character . class . getName ( ) , id ) || Strings . equal ( Character . TYPE . getName ( ) , id ) ) { return "\"\\0\"" ; } } return "None" ; }
Replies the Python default value for the given type .
34,225
protected PyFeatureCallGenerator newFeatureCallGenerator ( IExtraLanguageGeneratorContext context , IAppendable it ) { return new PyFeatureCallGenerator ( context , ( ExtraLanguageAppendable ) it ) ; }
Generate a feature call .
34,226
protected String readSarlEclipseSetting ( String sourceDirectory ) { if ( this . propertiesFileLocation != null ) { final File file = new File ( this . propertiesFileLocation ) ; if ( file . canRead ( ) ) { final Properties sarlSettings = new Properties ( ) ; try ( FileInputStream stream = new FileInputStream ( file ) ) { sarlSettings . load ( stream ) ; final String sarlOutputDirProp = sarlSettings . getProperty ( "outlet.DEFAULT_OUTPUT.directory" , null ) ; if ( sarlOutputDirProp != null ) { final File srcDir = new File ( sourceDirectory ) ; getLog ( ) . debug ( MessageFormat . format ( Messages . AbstractSarlBatchCompilerMojo_7 , srcDir . getPath ( ) , srcDir . exists ( ) ) ) ; if ( srcDir . exists ( ) && srcDir . getParent ( ) != null ) { final String path = new File ( srcDir . getParent ( ) , sarlOutputDirProp ) . getPath ( ) ; getLog ( ) . debug ( MessageFormat . format ( Messages . AbstractSarlBatchCompilerMojo_8 , sarlOutputDirProp ) ) ; return path ; } } } catch ( FileNotFoundException e ) { getLog ( ) . warn ( e ) ; } catch ( IOException e ) { getLog ( ) . warn ( e ) ; } } else { getLog ( ) . debug ( MessageFormat . format ( Messages . AbstractSarlBatchCompilerMojo_9 , this . propertiesFileLocation ) ) ; } } return null ; }
Read the SARL Eclipse settings for the project if existing .
34,227
protected List < File > getClassPath ( ) throws MojoExecutionException { if ( this . bufferedClasspath == null ) { final Set < String > classPath = new LinkedHashSet < > ( ) ; final MavenProject project = getProject ( ) ; classPath . add ( project . getBuild ( ) . getSourceDirectory ( ) ) ; try { classPath . addAll ( project . getCompileClasspathElements ( ) ) ; } catch ( DependencyResolutionRequiredException e ) { throw new MojoExecutionException ( e . getLocalizedMessage ( ) , e ) ; } for ( final Artifact dep : project . getArtifacts ( ) ) { classPath . add ( dep . getFile ( ) . getAbsolutePath ( ) ) ; } classPath . remove ( project . getBuild ( ) . getOutputDirectory ( ) ) ; final List < File > files = new ArrayList < > ( ) ; for ( final String filename : classPath ) { final File file = new File ( filename ) ; if ( file . exists ( ) ) { files . add ( file ) ; } else { getLog ( ) . warn ( MessageFormat . format ( Messages . AbstractSarlBatchCompilerMojo_10 , filename ) ) ; } } this . bufferedClasspath = files ; } return this . bufferedClasspath ; }
Replies the classpath for the standard code .
34,228
protected boolean executeExportOperation ( IJarExportRunnable op , IStatus wizardPageStatus ) { try { getContainer ( ) . run ( true , true , op ) ; } catch ( InterruptedException e ) { return false ; } catch ( InvocationTargetException ex ) { if ( ex . getTargetException ( ) != null ) { ExceptionHandler . handle ( ex , getShell ( ) , FatJarPackagerMessages . JarPackageWizard_jarExportError_title , FatJarPackagerMessages . JarPackageWizard_jarExportError_message ) ; return false ; } } IStatus status = op . getStatus ( ) ; if ( ! status . isOK ( ) ) { if ( ! wizardPageStatus . isOK ( ) ) { if ( ! ( status instanceof MultiStatus ) ) status = new MultiStatus ( status . getPlugin ( ) , status . getCode ( ) , status . getMessage ( ) , status . getException ( ) ) ; ( ( MultiStatus ) status ) . add ( wizardPageStatus ) ; } ErrorDialog . openError ( getShell ( ) , FatJarPackagerMessages . JarPackageWizard_jarExport_title , null , status ) ; return ! ( status . matches ( IStatus . ERROR ) ) ; } else if ( ! wizardPageStatus . isOK ( ) ) { ErrorDialog . openError ( getShell ( ) , FatJarPackagerMessages . JarPackageWizard_jarExport_title , null , wizardPageStatus ) ; } return true ; }
Exports the JAR package .
34,229
public void init ( IWorkbench workbench , JarPackageData jarPackage ) { Assert . isNotNull ( workbench ) ; Assert . isNotNull ( jarPackage ) ; fJarPackage = jarPackage ; setInitializeFromJarPackage ( true ) ; setWindowTitle ( FatJarPackagerMessages . JarPackageWizard_windowTitle ) ; setDefaultPageImageDescriptor ( JavaPluginImages . DESC_WIZBAN_FAT_JAR_PACKAGER ) ; setNeedsProgressMonitor ( true ) ; }
Initializes this wizard from the given JAR package description .
34,230
protected Image convertToImage ( Object imageDescription ) { if ( imageDescription instanceof Image ) { return ( Image ) imageDescription ; } else if ( imageDescription instanceof ImageDescriptor ) { return this . imageHelper . getImage ( ( ImageDescriptor ) imageDescription ) ; } else if ( imageDescription instanceof String ) { return this . imageHelper . getImage ( ( String ) imageDescription ) ; } return null ; }
Replies the image that corresponds to the given object .
34,231
@ SuppressWarnings ( "static-method" ) protected int getIssueAdornment ( XtendMember element ) { final ICompositeNode node = NodeModelUtils . getNode ( element ) ; if ( node == null ) { return 0 ; } final Resource resource = element . eResource ( ) ; if ( ! resource . getURI ( ) . isArchive ( ) ) { if ( hasParserIssue ( node , resource . getErrors ( ) ) ) { return JavaElementImageDescriptor . ERROR ; } final Diagnostic diagnostic = Diagnostician . INSTANCE . validate ( element ) ; switch ( diagnostic . getSeverity ( ) ) { case Diagnostic . ERROR : return JavaElementImageDescriptor . ERROR ; case Diagnostic . WARNING : return JavaElementImageDescriptor . WARNING ; default : } if ( hasParserIssue ( node , resource . getWarnings ( ) ) ) { return JavaElementImageDescriptor . WARNING ; } } return 0 ; }
Replies the diagnotic adornment for the given element .
34,232
@ SuppressWarnings ( "static-method" ) public IJavaElement getSelectedResource ( IStructuredSelection selection ) { IJavaElement elem = null ; if ( selection != null && ! selection . isEmpty ( ) ) { final Object object = selection . getFirstElement ( ) ; if ( object instanceof IAdaptable ) { final IAdaptable adaptable = ( IAdaptable ) object ; elem = adaptable . getAdapter ( IJavaElement . class ) ; if ( elem == null ) { elem = getPackage ( adaptable ) ; } } } if ( elem == null ) { final IWorkbenchPage activePage = PlatformUI . getWorkbench ( ) . getActiveWorkbenchWindow ( ) . getActivePage ( ) ; IWorkbenchPart part = activePage . getActivePart ( ) ; if ( part instanceof ContentOutline ) { part = activePage . getActiveEditor ( ) ; } if ( part instanceof XtextEditor ) { final IXtextDocument doc = ( ( XtextEditor ) part ) . getDocument ( ) ; final IFile file = doc . getAdapter ( IFile . class ) ; elem = getPackage ( file ) ; } } if ( elem == null || elem . getElementType ( ) == IJavaElement . JAVA_MODEL ) { try { final IJavaProject [ ] projects = JavaCore . create ( ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ) . getJavaProjects ( ) ; if ( projects . length == 1 ) { elem = projects [ 0 ] ; } } catch ( JavaModelException e ) { throw new RuntimeException ( e . getMessage ( ) ) ; } } return elem ; }
Replies the Java element that corresponds to the given selection .
34,233
public String getBasePackage ( ) { final Grammar grammar = getGrammar ( ) ; final String basePackage = this . naming . getRuntimeBasePackage ( grammar ) ; return basePackage + ".services" ; }
Replies the base package for the language .
34,234
protected static Iterable < Keyword > getAllKeywords ( Grammar grammar ) { final Map < String , Keyword > keywords = new HashMap < > ( ) ; final List < ParserRule > rules = GrammarUtil . allParserRules ( grammar ) ; for ( final ParserRule parserRule : rules ) { final List < Keyword > list = typeSelect ( eAllContentsAsList ( parserRule ) , Keyword . class ) ; for ( final Keyword keyword : list ) { keywords . put ( keyword . getValue ( ) , keyword ) ; } } final List < EnumRule > enumRules = GrammarUtil . allEnumRules ( grammar ) ; for ( final EnumRule enumRule : enumRules ) { final List < Keyword > list = typeSelect ( eAllContentsAsList ( enumRule ) , Keyword . class ) ; for ( final Keyword keyword : list ) { keywords . put ( keyword . getValue ( ) , keyword ) ; } } return keywords . values ( ) ; }
Replies the keywords in the given grammar .
34,235
protected StringConcatenationClient generateKeyword ( final String keyword , final String comment , Map < String , String > getters ) { final String fieldName = keyword . toUpperCase ( ) . replaceAll ( "[^a-zA-Z0-9_]+" , "_" ) ; final String methodName = Strings . toFirstUpper ( keyword . replaceAll ( "[^a-zA-Z0-9_]+" , "_" ) ) + "Keyword" ; if ( getters != null ) { getters . put ( methodName , keyword ) ; } return new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation it ) { it . append ( "\tprivate static final String " ) ; it . append ( fieldName ) ; it . append ( " = \"" ) ; it . append ( Strings . convertToJavaString ( keyword ) ) ; it . append ( "\";" ) ; it . newLineIfNotEmpty ( ) ; it . newLine ( ) ; it . append ( "\t/** Keyword: {@code " ) ; it . append ( protectCommentKeyword ( keyword ) ) ; it . append ( "}." ) ; it . newLine ( ) ; if ( ! Strings . isEmpty ( comment ) ) { it . append ( "\t * Source: " ) ; it . append ( comment ) ; it . newLine ( ) ; } it . append ( "\t */" ) ; it . newLine ( ) ; it . append ( "\tpublic String get" ) ; it . append ( methodName ) ; it . append ( "() {" ) ; it . newLine ( ) ; it . append ( "\t\treturn " ) ; it . append ( fieldName ) ; it . append ( ";" ) ; it . newLine ( ) ; it . append ( "\t}" ) ; it . newLineIfNotEmpty ( ) ; it . newLine ( ) ; } } ; }
Generate a basic keyword .
34,236
protected StringConcatenationClient generateKeyword ( final Keyword keyword , final String comment , Map < String , String > getters ) { try { final String methodName = getIdentifier ( keyword ) ; final String accessor = GrammarKeywordAccessFragment2 . this . grammarAccessExtensions . gaAccessor ( keyword ) ; if ( ! Strings . isEmpty ( methodName ) && ! Strings . isEmpty ( accessor ) ) { if ( getters != null ) { getters . put ( methodName , keyword . getValue ( ) ) ; } return new StringConcatenationClient ( ) { protected void appendTo ( TargetStringConcatenation it ) { it . append ( "\t/** Keyword: {@code " ) ; it . append ( protectCommentKeyword ( keyword . getValue ( ) ) ) ; it . append ( "}." ) ; it . newLine ( ) ; if ( ! Strings . isEmpty ( comment ) ) { it . append ( "\t * Source: " ) ; it . append ( comment ) ; it . newLine ( ) ; } it . append ( "\t */" ) ; it . newLine ( ) ; it . append ( "\tpublic String get" ) ; it . append ( methodName ) ; it . append ( "() {" ) ; it . newLine ( ) ; it . append ( "\t\treturn this.grammarAccess." ) ; it . append ( accessor ) ; it . append ( ".getValue();" ) ; it . newLine ( ) ; it . append ( "\t}" ) ; it . newLineIfNotEmpty ( ) ; it . newLine ( ) ; } } ; } } catch ( Exception e ) { } return null ; }
Generate a grammar keyword .
34,237
@ SuppressWarnings ( "static-method" ) protected String protectCommentKeyword ( String keyword ) { if ( "*/" . equals ( keyword ) ) { return "* /" ; } if ( "/*" . equals ( keyword ) ) { return "/ *" ; } if ( "//" . equals ( keyword ) ) { return "/ /" ; } return keyword ; }
Protect the keywword for Java comments .
34,238
@ SuppressWarnings ( { "checkstyle:npathcomplexity" , "checkstyle:cyclomaticcomplexity" } ) protected boolean isIgnorableCallToFeature ( ILinkingCandidate candidate ) { final JvmIdentifiableElement feature = candidate . getFeature ( ) ; if ( feature instanceof JvmOperation ) { JvmAnnotationTarget target = ( JvmOperation ) feature ; JvmAnnotationReference reference = this . annotationLookup . findAnnotation ( target , Deprecated . class ) ; if ( reference == null ) { do { target = EcoreUtil2 . getContainerOfType ( target . eContainer ( ) , JvmAnnotationTarget . class ) ; if ( target != null ) { reference = this . annotationLookup . findAnnotation ( target , Deprecated . class ) ; } } while ( reference == null && target != null ) ; } if ( reference != null ) { return true ; } } return false ; }
Replies if ambiguity could be removed for the given feature .
34,239
protected void _computeTypes ( SarlBreakExpression object , ITypeComputationState state ) { final LightweightTypeReference primitiveVoid = getPrimitiveVoid ( state ) ; state . acceptActualType ( primitiveVoid ) ; }
Compute the type of a break expression .
34,240
protected void _computeTypes ( SarlAssertExpression object , ITypeComputationState state ) { state . withExpectation ( getTypeForName ( Boolean . class , state ) ) . computeTypes ( object . getCondition ( ) ) ; }
Compute the type of an assert expression .
34,241
@ SuppressWarnings ( "checkstyle:nestedifdepth" ) protected void _computeTypes ( SarlCastedExpression cast , ITypeComputationState state ) { if ( state instanceof AbstractTypeComputationState ) { final JvmTypeReference type = cast . getType ( ) ; if ( type != null ) { state . withNonVoidExpectation ( ) . computeTypes ( cast . getTarget ( ) ) ; try { final AbstractTypeComputationState computationState = ( AbstractTypeComputationState ) state ; final CastedExpressionTypeComputationState astate = new CastedExpressionTypeComputationState ( cast , computationState , this . castOperationValidator ) ; astate . resetFeature ( cast ) ; if ( astate . isCastOperatorLinkingEnabled ( cast ) ) { final List < ? extends ILinkingCandidate > candidates = astate . getLinkingCandidates ( cast ) ; if ( ! candidates . isEmpty ( ) ) { final ILinkingCandidate best = getBestCandidate ( candidates ) ; if ( best != null ) { best . applyToModel ( computationState . getResolvedTypes ( ) ) ; } } } } catch ( Throwable exception ) { final Throwable cause = Throwables . getRootCause ( exception ) ; state . addDiagnostic ( new EObjectDiagnosticImpl ( Severity . ERROR , IssueCodes . INTERNAL_ERROR , cause . getLocalizedMessage ( ) , cast , null , - 1 , null ) ) ; } state . acceptActualType ( state . getReferenceOwner ( ) . toLightweightTypeReference ( type ) ) ; } else { state . computeTypes ( cast . getTarget ( ) ) ; } } else { super . _computeTypes ( cast , state ) ; } }
Compute the type of a casted expression .
34,242
@ SuppressWarnings ( "unchecked" ) protected void fireEntryRemoved ( K key , V value ) { if ( this . listeners != null ) { for ( final DMapListener < ? super K , ? super V > listener : this . listeners . getListeners ( DMapListener . class ) ) { listener . entryRemoved ( key , value ) ; } } }
Fire the removal event .
34,243
@ SuppressWarnings ( "unchecked" ) protected void fireEntryUpdated ( K key , V value ) { for ( final DMapListener < ? super K , ? super V > listener : this . listeners . getListeners ( DMapListener . class ) ) { listener . entryUpdated ( key , value ) ; } }
Fire the update event .
34,244
@ SuppressWarnings ( "unchecked" ) protected void fireCleared ( boolean localClearing ) { for ( final DMapListener < ? super K , ? super V > listener : this . listeners . getListeners ( DMapListener . class ) ) { listener . mapCleared ( localClearing ) ; } }
Fire the clearing event .
34,245
protected Xpp3Dom createSREConfiguration ( ) throws MojoExecutionException , MojoFailureException { final Xpp3Dom xmlConfiguration = new Xpp3Dom ( "configuration" ) ; final Xpp3Dom xmlArchive = new Xpp3Dom ( "archive" ) ; xmlConfiguration . addChild ( xmlArchive ) ; final String mainClass = getMainClass ( ) ; if ( mainClass . isEmpty ( ) ) { throw new MojoFailureException ( "the main class of the SRE is missed" ) ; } final Xpp3Dom xmlManifest = new Xpp3Dom ( "manifest" ) ; xmlArchive . addChild ( xmlManifest ) ; final Xpp3Dom xmlManifestMainClass = new Xpp3Dom ( "mainClass" ) ; xmlManifestMainClass . setValue ( mainClass ) ; xmlManifest . addChild ( xmlManifestMainClass ) ; final Xpp3Dom xmlSections = new Xpp3Dom ( "manifestSections" ) ; xmlArchive . addChild ( xmlSections ) ; final Xpp3Dom xmlSection = new Xpp3Dom ( "manifestSection" ) ; xmlSections . addChild ( xmlSection ) ; final Xpp3Dom xmlSectionName = new Xpp3Dom ( "name" ) ; xmlSectionName . setValue ( SREConstants . MANIFEST_SECTION_SRE ) ; xmlSection . addChild ( xmlSectionName ) ; final Xpp3Dom xmlManifestEntries = new Xpp3Dom ( "manifestEntries" ) ; xmlSection . addChild ( xmlManifestEntries ) ; ManifestUpdater updater = getManifestUpdater ( ) ; if ( updater == null ) { updater = new ManifestUpdater ( ) { public void addSREAttribute ( String name , String value ) { assert name != null && ! name . isEmpty ( ) ; if ( value != null && ! value . isEmpty ( ) ) { getLog ( ) . debug ( "Adding to SRE manifest: " + name + " = " + value ) ; final Xpp3Dom xmlManifestEntry = new Xpp3Dom ( name ) ; xmlManifestEntry . setValue ( value ) ; xmlManifestEntries . addChild ( xmlManifestEntry ) ; } } public void addMainAttribute ( String name , String value ) { } } ; } buildManifest ( updater , mainClass ) ; return xmlConfiguration ; }
Create the configuration of the SRE with the maven archive format .
34,246
private void runInitializationStage ( Event event ) { try { setOwnerState ( OwnerState . INITIALIZING ) ; try { this . eventDispatcher . immediateDispatch ( event ) ; } finally { setOwnerState ( OwnerState . ALIVE ) ; } this . agentAsEventListener . fireEnqueuedEvents ( this ) ; if ( this . agentAsEventListener . isKilled . get ( ) ) { this . agentAsEventListener . killOwner ( InternalEventBusSkill . this ) ; } } catch ( Exception e ) { final Logging loggingCapacity = getLoggingSkill ( ) ; if ( loggingCapacity != null ) { loggingCapacity . error ( Messages . InternalEventBusSkill_3 , e ) ; } else { final LogRecord record = new LogRecord ( Level . SEVERE , Messages . InternalEventBusSkill_3 ) ; this . logger . getKernelLogger ( ) . log ( this . logger . prepareLogRecord ( record , this . logger . getKernelLogger ( ) . getName ( ) , Throwables . getRootCause ( e ) ) ) ; } setOwnerState ( OwnerState . ALIVE ) ; this . agentAsEventListener . killOrMarkAsKilled ( ) ; } }
This function runs the initialization of the agent .
34,247
private void runDestructionStage ( Event event ) { try { setOwnerState ( OwnerState . DYING ) ; try { this . eventDispatcher . immediateDispatch ( event ) ; } finally { setOwnerState ( OwnerState . DEAD ) ; } } catch ( Exception e ) { final Logging loggingCapacity = getLoggingSkill ( ) ; if ( loggingCapacity != null ) { loggingCapacity . error ( Messages . InternalEventBusSkill_4 , e ) ; } else { final LogRecord record = new LogRecord ( Level . SEVERE , Messages . InternalEventBusSkill_4 ) ; this . logger . getKernelLogger ( ) . log ( this . logger . prepareLogRecord ( record , this . logger . getKernelLogger ( ) . getName ( ) , Throwables . getRootCause ( e ) ) ) ; } } }
This function runs the destruction of the agent .
34,248
protected boolean isCapacityMethodCall ( JvmOperation feature ) { if ( feature != null ) { final JvmDeclaredType container = feature . getDeclaringType ( ) ; if ( container instanceof JvmGenericType ) { return this . inheritanceHelper . isSarlCapacity ( ( JvmGenericType ) container ) ; } } return false ; }
Replies if the given call is for a capacity function call .
34,249
protected void completeJavaTypes ( ContentAssistContext context , ITypesProposalProvider . Filter filter , ICompletionProposalAcceptor acceptor ) { completeJavaTypes ( context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , true , getQualifiedNameValueConverter ( ) , filter , acceptor ) ; }
Complete for Java types .
34,250
protected void completeSarlEvents ( boolean allowEventType , boolean isExtensionFilter , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Event . class , allowEventType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , isExtensionFilter ? createExtensionFilter ( context , IJavaSearchConstants . CLASS ) : createVisibilityFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } }
Complete for obtaining SARL events if the proposals are enabled .
34,251
protected void completeSarlCapacities ( boolean allowCapacityType , boolean isExtensionFilter , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Capacity . class , allowCapacityType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , isExtensionFilter ? createExtensionFilter ( context , IJavaSearchConstants . INSTANCEOF_TYPE_REFERENCE ) : createVisibilityFilter ( context , IJavaSearchConstants . INTERFACE ) , acceptor ) ; } }
Complete for obtaining SARL capacities if the proposals are enabled .
34,252
protected void completeSarlAgents ( boolean allowAgentType , boolean isExtensionFilter , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Agent . class , allowAgentType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , isExtensionFilter ? createExtensionFilter ( context , IJavaSearchConstants . CLASS ) : createVisibilityFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } }
Complete for obtaining SARL agents if the proposals are enabled .
34,253
protected void completeSarlBehaviors ( boolean allowBehaviorType , boolean isExtensionFilter , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Behavior . class , allowBehaviorType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , isExtensionFilter ? createExtensionFilter ( context , IJavaSearchConstants . CLASS ) : createVisibilityFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } }
Complete for obtaining SARL behaviors if the proposals are enabled .
34,254
protected void completeSarlSkills ( boolean allowSkillType , boolean isExtensionFilter , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Skill . class , allowSkillType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , isExtensionFilter ? createExtensionFilter ( context , IJavaSearchConstants . CLASS ) : createVisibilityFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } }
Complete for obtaining SARL skills if proposals are enabled .
34,255
protected void completeExceptions ( boolean allowExceptionType , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { completeSubJavaTypes ( Exception . class , allowExceptionType , context , TypesPackage . Literals . JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE , getQualifiedNameValueConverter ( ) , createVisibilityFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } }
Complete for obtaining exception types if proposals are enabled .
34,256
protected void completeSubJavaTypes ( Class < ? > superType , boolean allowSuperTypeItself , ContentAssistContext context , EReference reference , IValueConverter < String > valueConverter , final ITypesProposalProvider . Filter filter , ICompletionProposalAcceptor acceptor ) { assert superType != null ; final INode lastCompleteNode = context . getLastCompleteNode ( ) ; if ( lastCompleteNode instanceof ILeafNode && ! ( ( ILeafNode ) lastCompleteNode ) . isHidden ( ) ) { if ( lastCompleteNode . getLength ( ) > 0 && lastCompleteNode . getTotalEndOffset ( ) == context . getOffset ( ) ) { final String text = lastCompleteNode . getText ( ) ; final char lastChar = text . charAt ( text . length ( ) - 1 ) ; if ( Character . isJavaIdentifierPart ( lastChar ) ) { return ; } } } final ITypesProposalProvider . Filter subTypeFilter ; if ( allowSuperTypeItself ) { subTypeFilter = filter ; } else { final String superTypeQualifiedName = superType . getName ( ) ; subTypeFilter = new ITypesProposalProvider . Filter ( ) { public boolean accept ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path ) { final String fullName = JavaModelUtil . concatenateName ( packageName , simpleTypeName ) ; if ( Objects . equals ( superTypeQualifiedName , fullName ) ) { return false ; } return filter . accept ( modifiers , packageName , simpleTypeName , enclosingTypeNames , path ) ; } public int getSearchFor ( ) { return filter . getSearchFor ( ) ; } } ; } getTypesProposalProvider ( ) . createSubTypeProposals ( this . typeReferences . findDeclaredType ( superType , context . getCurrentModel ( ) ) , this , context , reference , subTypeFilter , valueConverter , acceptor ) ; }
Complete for obtaining SARL types that are subtypes of the given type .
34,257
protected String getExpectedPackageName ( EObject model ) { final URI fileURI = model . eResource ( ) . getURI ( ) ; for ( final Pair < IStorage , IProject > storage : this . storage2UriMapper . getStorages ( fileURI ) ) { if ( storage . getFirst ( ) instanceof IFile ) { final IPath fileWorkspacePath = storage . getFirst ( ) . getFullPath ( ) ; final IJavaProject javaProject = JavaCore . create ( storage . getSecond ( ) ) ; return extractProjectPath ( fileWorkspacePath , javaProject ) ; } } return null ; }
Replies the expected package for the given model .
34,258
protected void completeExtends ( EObject model , ContentAssistContext context , ICompletionProposalAcceptor acceptor ) { if ( isSarlProposalEnabled ( ) ) { if ( model instanceof SarlAgent ) { completeSarlAgents ( false , true , context , acceptor ) ; } else if ( model instanceof SarlBehavior ) { completeSarlBehaviors ( false , true , context , acceptor ) ; } else if ( model instanceof SarlCapacity ) { completeSarlCapacities ( false , true , context , acceptor ) ; } else if ( model instanceof SarlSkill ) { completeSarlSkills ( false , true , context , acceptor ) ; } else if ( model instanceof SarlEvent ) { completeSarlEvents ( false , true , context , acceptor ) ; } else if ( model instanceof SarlClass ) { completeJavaTypes ( context , createExtensionFilter ( context , IJavaSearchConstants . CLASS ) , acceptor ) ; } else if ( model instanceof SarlInterface ) { completeJavaTypes ( context , createExtensionFilter ( context , IJavaSearchConstants . INTERFACE ) , acceptor ) ; } } }
Complete the extends if the proposals are enabled .
34,259
protected void _createChildren ( DocumentRootNode parentNode , SarlScript modelElement ) { if ( ! Strings . isNullOrEmpty ( modelElement . getPackage ( ) ) ) { createEStructuralFeatureNode ( parentNode , modelElement , XtendPackage . Literals . XTEND_FILE__PACKAGE , this . imageDispatcher . invoke ( getClass ( ) . getPackage ( ) ) , modelElement . getPackage ( ) , true ) ; } for ( final XtendTypeDeclaration topElement : modelElement . getXtendTypes ( ) ) { createNode ( parentNode , topElement ) ; } }
Create a node for the SARL script .
34,260
@ SuppressWarnings ( "checkstyle:cyclomaticcomplexity" ) protected void _createNode ( DocumentRootNode parentNode , XtendTypeDeclaration modelElement ) { final boolean isFeatureSet = modelElement . eIsSet ( XtendPackage . Literals . XTEND_TYPE_DECLARATION__NAME ) ; final EStructuralFeatureNode elementNode = new EStructuralFeatureNode ( modelElement , XtendPackage . Literals . XTEND_TYPE_DECLARATION__NAME , parentNode , this . imageDispatcher . invoke ( modelElement ) , this . textDispatcher . invoke ( modelElement ) , modelElement . getMembers ( ) . isEmpty ( ) || ! isFeatureSet ) ; final EObject primarySourceElement = this . associations . getPrimarySourceElement ( modelElement ) ; final ICompositeNode parserNode = NodeModelUtils . getNode ( ( primarySourceElement == null ) ? modelElement : primarySourceElement ) ; elementNode . setTextRegion ( parserNode . getTextRegion ( ) ) ; boolean hasConstructor = false ; if ( ! modelElement . getMembers ( ) . isEmpty ( ) ) { EObjectNode capacityUseNode = null ; EObjectNode capacityRequirementNode = null ; for ( final EObject feature : modelElement . getMembers ( ) ) { if ( feature instanceof SarlConstructor ) { hasConstructor = true ; createNode ( elementNode , feature ) ; } else if ( feature instanceof SarlField ) { final SarlField field = ( SarlField ) feature ; createNode ( elementNode , field ) ; createAutomaticAccessors ( elementNode , field ) ; } else if ( feature instanceof SarlAction || feature instanceof SarlBehaviorUnit || feature instanceof XtendTypeDeclaration ) { createNode ( elementNode , feature ) ; } else if ( feature instanceof SarlCapacityUses ) { capacityUseNode = createCapacityUseNode ( elementNode , ( SarlCapacityUses ) feature , capacityUseNode ) ; } else if ( feature instanceof SarlRequiredCapacity ) { capacityRequirementNode = createRequiredCapacityNode ( elementNode , ( SarlRequiredCapacity ) feature , capacityRequirementNode ) ; } } } if ( ! hasConstructor && modelElement instanceof XtendClass ) { createInheritedConstructors ( elementNode , ( XtendClass ) modelElement ) ; } }
Create a node for the given feature container .
34,261
protected Image _image ( XtendMember modelElement ) { final Image img = super . _image ( modelElement ) ; return this . diagnoticDecorator . decorateImage ( img , modelElement ) ; }
Get the image for the Xtend members .
34,262
public IFormalParameterBuilder addParameter ( String name ) { IFormalParameterBuilder builder = this . parameterProvider . get ( ) ; builder . eInit ( this . sarlConstructor , name , getTypeResolutionContext ( ) ) ; return builder ; }
Add a formal parameter .
34,263
@ SuppressWarnings ( "static-method" ) protected boolean isValidResource ( IResource resource ) { return resource . isAccessible ( ) && ! resource . isHidden ( ) && ! resource . isPhantom ( ) && ! resource . isDerived ( ) ; }
Replies if the given resource could be considered for discovering an agent to be launched .
34,264
public ElementDescription searchAndSelect ( boolean showEmptySelectionError , Object ... scope ) { try { final List < ElementDescription > elements = findElements ( scope , PlatformUI . getWorkbench ( ) . getProgressService ( ) ) ; ElementDescription element = null ; if ( elements == null || elements . isEmpty ( ) ) { if ( showEmptySelectionError ) { SARLEclipsePlugin . getDefault ( ) . openError ( getShell ( ) , Messages . AbstractSarlScriptInteractiveSelector_1 , MessageFormat . format ( Messages . AbstractSarlScriptInteractiveSelector_2 , getElementLabel ( ) ) , null ) ; } } else if ( elements . size ( ) > 1 ) { element = chooseElement ( elements ) ; } else { element = elements . get ( 0 ) ; } return element ; } catch ( InterruptedException exception ) { } catch ( Exception exception ) { SARLEclipsePlugin . getDefault ( ) . openError ( getShell ( ) , Messages . AbstractSarlScriptInteractiveSelector_1 , null , exception ) ; } return null ; }
Search the elements based on the given scope and select one . If more than one element was found the user selects interactively one .
34,265
private ElementDescription chooseElement ( List < ElementDescription > elements ) { final ElementListSelectionDialog dialog = new ElementListSelectionDialog ( getShell ( ) , new LabelProvider ( ) ) ; dialog . setElements ( elements . toArray ( ) ) ; dialog . setTitle ( MessageFormat . format ( Messages . AbstractSarlScriptInteractiveSelector_3 , getElementLabel ( ) ) ) ; dialog . setMessage ( MessageFormat . format ( Messages . AbstractSarlScriptInteractiveSelector_3 , getElementLongLabel ( ) ) ) ; dialog . setMultipleSelection ( false ) ; final int result = dialog . open ( ) ; if ( result == Window . OK ) { return ( ElementDescription ) dialog . getFirstResult ( ) ; } return null ; }
Prompts the user to select an element from the given element types .
34,266
public String getValidationDescription ( ) { final JvmOperation feature = getOperation ( ) ; String message = null ; if ( ! getDeclaredTypeParameters ( ) . isEmpty ( ) ) { message = MessageFormat . format ( Messages . CastOperatorLinkingCandidate_0 , getFeatureTypeParametersAsString ( true ) , feature . getSimpleName ( ) , getFeatureParameterTypesAsString ( ) , feature . getDeclaringType ( ) . getSimpleName ( ) ) ; } else { message = MessageFormat . format ( Messages . CastOperatorLinkingCandidate_1 , feature . getSimpleName ( ) , getFeatureParameterTypesAsString ( ) , feature . getDeclaringType ( ) . getSimpleName ( ) ) ; } return message ; }
Replies the string representation of the candidate .
34,267
private JvmAnnotationReference annotationClassRef ( Class < ? extends Annotation > type , List < ? extends JvmTypeReference > values ) { try { final JvmAnnotationReference annot = this . _annotationTypesBuilder . annotationRef ( type ) ; final JvmTypeAnnotationValue annotationValue = this . services . getTypesFactory ( ) . createJvmTypeAnnotationValue ( ) ; for ( final JvmTypeReference value : values ) { annotationValue . getValues ( ) . add ( this . typeBuilder . cloneWithProxies ( value ) ) ; } annot . getExplicitValues ( ) . add ( annotationValue ) ; return annot ; } catch ( IllegalArgumentException exception ) { } return null ; }
Create an annotation with classes as values .
34,268
protected void initializeLocalTypes ( GenerationContext context , JvmFeature feature , XExpression expression ) { if ( expression != null ) { int localTypeIndex = context . getLocalTypeIndex ( ) ; final TreeIterator < EObject > iterator = EcoreUtil2 . getAllNonDerivedContents ( expression , true ) ; final String nameStub = "__" + feature . getDeclaringType ( ) . getSimpleName ( ) + "_" ; while ( iterator . hasNext ( ) ) { final EObject next = iterator . next ( ) ; if ( next . eClass ( ) == XtendPackage . Literals . ANONYMOUS_CLASS ) { inferLocalClass ( ( AnonymousClass ) next , nameStub + localTypeIndex , feature ) ; iterator . prune ( ) ; ++ localTypeIndex ; } } context . setLocalTypeIndex ( localTypeIndex ) ; } }
Initialize the local class to the given expression .
34,269
protected void setBody ( JvmExecutable executable , Procedure1 < ITreeAppendable > expression ) { this . typeBuilder . setBody ( executable , expression ) ; }
Set the body of the executable .
34,270
protected final synchronized GenerationContext openContext ( EObject sarlObject , JvmDeclaredType type , final Iterable < Class < ? extends XtendMember > > supportedMemberTypes ) { assert type != null ; assert supportedMemberTypes != null ; this . sarlSignatureProvider . clear ( type ) ; final GenerationContext context = new GenerationContext ( sarlObject , type ) { public boolean isSupportedMember ( XtendMember member ) { for ( final Class < ? extends XtendMember > supportedMemberType : supportedMemberTypes ) { if ( supportedMemberType . isInstance ( member ) ) { return true ; } } return false ; } } ; this . contextInjector . injectMembers ( context ) ; this . bufferedContexes . push ( context ) ; return context ; }
Open the context for the generation of a SARL - specific element .
34,271
protected final void closeContext ( GenerationContext context ) { boolean runPostElements = false ; GenerationContext selectedContext = null ; synchronized ( this ) { final Iterator < GenerationContext > iterator = this . bufferedContexes . iterator ( ) ; while ( selectedContext == null && iterator . hasNext ( ) ) { final GenerationContext candidate = iterator . next ( ) ; if ( Objects . equal ( candidate . getTypeIdentifier ( ) , context . getTypeIdentifier ( ) ) ) { runPostElements = candidate . getParentContext ( ) == null ; selectedContext = candidate ; } } } if ( selectedContext == null ) { throw new IllegalStateException ( "Not same contexts when closing" ) ; } if ( runPostElements ) { for ( final Runnable handler : selectedContext . getPostFinalizationElements ( ) ) { handler . run ( ) ; } } synchronized ( this ) { final Iterator < GenerationContext > iterator = this . bufferedContexes . iterator ( ) ; while ( iterator . hasNext ( ) ) { final GenerationContext candidate = iterator . next ( ) ; if ( selectedContext == candidate ) { candidate . setParentContext ( null ) ; iterator . remove ( ) ; return ; } } } }
Close a generation context .
34,272
protected final synchronized GenerationContext getContext ( JvmIdentifiableElement type ) { for ( final GenerationContext candidate : this . bufferedContexes ) { if ( Objects . equal ( candidate . getTypeIdentifier ( ) , type . getIdentifier ( ) ) ) { return candidate ; } } throw new GenerationContextNotFoundInternalError ( type ) ; }
Replies the SARL - specific generation context .
34,273
protected void appendDefaultConstructors ( XtendTypeDeclaration source , JvmGenericType target ) { final GenerationContext context = getContext ( target ) ; if ( ! context . hasConstructor ( ) ) { final boolean notInitializedValueField = Iterables . any ( source . getMembers ( ) , it -> { if ( it instanceof XtendField ) { final XtendField op = ( XtendField ) it ; if ( op . isFinal ( ) && op . getInitialValue ( ) == null ) { return true ; } } return false ; } ) ; if ( ! notInitializedValueField ) { final JvmTypeReference reference = target . getExtendedClass ( ) ; if ( reference != null ) { final JvmType type = reference . getType ( ) ; if ( type instanceof JvmGenericType ) { copyVisibleJvmConstructors ( ( JvmGenericType ) type , target , source , Sets . newTreeSet ( ) , JvmVisibility . PUBLIC ) ; } } } } }
Add the default constructors .
34,274
protected void initialize ( SarlSkill source , JvmGenericType inferredJvmType ) { assert source != null ; assert inferredJvmType != null ; if ( Strings . isNullOrEmpty ( source . getName ( ) ) ) { return ; } final GenerationContext context = openContext ( source , inferredJvmType , Arrays . asList ( SarlField . class , SarlConstructor . class , SarlAction . class , SarlBehaviorUnit . class , SarlCapacityUses . class , SarlRequiredCapacity . class ) ) ; try { this . typeBuilder . copyDocumentationTo ( source , inferredJvmType ) ; setVisibility ( inferredJvmType , source ) ; inferredJvmType . setStatic ( false ) ; final boolean isAbstract = source . isAbstract ( ) || Utils . hasAbstractMember ( source ) ; inferredJvmType . setAbstract ( isAbstract ) ; inferredJvmType . setStrictFloatingPoint ( false ) ; inferredJvmType . setFinal ( ! isAbstract && source . isFinal ( ) ) ; translateAnnotationsTo ( source . getAnnotations ( ) , inferredJvmType ) ; appendConstrainedExtends ( context , inferredJvmType , Skill . class , SarlSkill . class , source . getExtends ( ) ) ; appendConstrainedImplements ( context , inferredJvmType , Capacity . class , SarlCapacity . class , source . getImplements ( ) ) ; if ( Utils . isCompatibleSARLLibraryOnClasspath ( this . typeReferences , source ) ) { appendAOPMembers ( inferredJvmType , source , context ) ; } appendComparisonFunctions ( context , source , inferredJvmType ) ; appendCloneFunctionIfCloneable ( context , source , inferredJvmType ) ; appendDefaultConstructors ( source , inferredJvmType ) ; appendSerialNumberIfSerializable ( context , source , inferredJvmType ) ; appendSARLSpecificationVersion ( context , source , inferredJvmType ) ; appendSARLElementType ( source , inferredJvmType ) ; this . nameClashResolver . resolveNameClashes ( inferredJvmType ) ; } finally { closeContext ( context ) ; } }
Initialize the SARL skill type .
34,275
protected void initialize ( SarlCapacity source , JvmGenericType inferredJvmType ) { assert source != null ; assert inferredJvmType != null ; if ( Strings . isNullOrEmpty ( source . getName ( ) ) ) { return ; } final GenerationContext context = openContext ( source , inferredJvmType , Collections . singleton ( SarlAction . class ) ) ; try { this . typeBuilder . copyDocumentationTo ( source , inferredJvmType ) ; inferredJvmType . setInterface ( true ) ; inferredJvmType . setAbstract ( true ) ; setVisibility ( inferredJvmType , source ) ; inferredJvmType . setStatic ( false ) ; inferredJvmType . setStrictFloatingPoint ( false ) ; inferredJvmType . setFinal ( false ) ; translateAnnotationsTo ( source . getAnnotations ( ) , inferredJvmType ) ; appendConstrainedExtends ( context , inferredJvmType , Capacity . class , SarlCapacity . class , source . getExtends ( ) ) ; if ( Utils . isCompatibleSARLLibraryOnClasspath ( this . typeReferences , source ) ) { appendAOPMembers ( inferredJvmType , source , context ) ; } appendFunctionalInterfaceAnnotation ( inferredJvmType ) ; appendSARLSpecificationVersion ( context , source , inferredJvmType ) ; appendSARLElementType ( source , inferredJvmType ) ; this . nameClashResolver . resolveNameClashes ( inferredJvmType ) ; } finally { closeContext ( context ) ; } appendCapacityContextAwareWrapper ( source , inferredJvmType ) ; }
Initialize the SARL capacity type .
34,276
@ SuppressWarnings ( "static-method" ) protected void initialize ( SarlSpace source , JvmGenericType inferredJvmType ) { assert source != null ; assert inferredJvmType != null ; if ( Strings . isNullOrEmpty ( source . getName ( ) ) ) { return ; } }
Initialize the SARL space type .
34,277
protected void transform ( XtendField source , JvmGenericType container ) { super . transform ( source , container ) ; final JvmField field = ( JvmField ) this . sarlAssociations . getPrimaryJvmElement ( source ) ; setVisibility ( field , source ) ; final GenerationContext context = getContext ( container ) ; if ( context != null ) { final String name = source . getName ( ) ; if ( ! Strings . isNullOrEmpty ( name ) ) { context . incrementSerial ( name . hashCode ( ) ) ; } final JvmTypeReference type = source . getType ( ) ; if ( type != null ) { context . incrementSerial ( type . getIdentifier ( ) . hashCode ( ) ) ; } } }
Transform the field .
34,278
protected void appendAOPMembers ( JvmGenericType featureContainerType , XtendTypeDeclaration container , GenerationContext context ) { Utils . populateInheritanceContext ( featureContainerType , context . getInheritedFinalOperations ( ) , context . getInheritedOverridableOperations ( ) , null , context . getInheritedOperationsToImplement ( ) , null , this . sarlSignatureProvider ) ; final List < XtendMember > delayedMembers = new LinkedList < > ( ) ; for ( final XtendMember feature : container . getMembers ( ) ) { if ( context . isSupportedMember ( feature ) ) { if ( ( feature instanceof SarlCapacityUses ) || ( feature instanceof SarlRequiredCapacity ) ) { delayedMembers . add ( feature ) ; } else { transform ( feature , featureContainerType , true ) ; } } } for ( final XtendMember feature : delayedMembers ) { transform ( feature , featureContainerType , false ) ; } appendEventGuardEvaluators ( featureContainerType ) ; appendSyntheticDispatchMethods ( container , featureContainerType ) ; appendSyntheticDefaultValuedParameterMethods ( container , featureContainerType , context ) ; }
Generate the code for the given SARL members in a agent - oriented container .
34,279
private static StringConcatenationClient toStringConcatenation ( final String ... javaCodeLines ) { return new StringConcatenationClient ( ) { protected void appendTo ( StringConcatenationClient . TargetStringConcatenation builder ) { for ( final String line : javaCodeLines ) { builder . append ( line ) ; builder . newLineIfNotEmpty ( ) ; } } } ; }
Create a string concatenation client from a set of Java code lines .
34,280
protected void appendConstrainedImplements ( GenerationContext context , JvmGenericType owner , Class < ? > defaultJvmType , Class < ? extends XtendTypeDeclaration > defaultSarlType , List < ? extends JvmParameterizedTypeReference > implementedtypes ) { boolean explicitType = false ; for ( final JvmParameterizedTypeReference superType : implementedtypes ) { if ( ! Objects . equal ( owner . getIdentifier ( ) , superType . getIdentifier ( ) ) && superType . getType ( ) instanceof JvmGenericType ) { owner . getSuperTypes ( ) . add ( this . typeBuilder . cloneWithProxies ( superType ) ) ; context . incrementSerial ( superType . getIdentifier ( ) . hashCode ( ) ) ; explicitType = true ; } } if ( ! explicitType ) { final JvmTypeReference type = this . _typeReferenceBuilder . typeRef ( defaultJvmType ) ; owner . getSuperTypes ( ) . add ( type ) ; context . incrementSerial ( type . getIdentifier ( ) . hashCode ( ) ) ; } }
Generate the implemented types for the given SARL statement .
34,281
protected void appendEventGuardEvaluators ( JvmGenericType container ) { final GenerationContext context = getContext ( container ) ; if ( context != null ) { final Collection < Pair < SarlBehaviorUnit , Collection < Procedure1 < ? super ITreeAppendable > > > > allEvaluators = context . getGuardEvaluationCodes ( ) ; if ( allEvaluators == null || allEvaluators . isEmpty ( ) ) { return ; } final JvmTypeReference voidType = this . _typeReferenceBuilder . typeRef ( Void . TYPE ) ; final JvmTypeReference runnableType = this . _typeReferenceBuilder . typeRef ( Runnable . class ) ; final JvmTypeReference collectionType = this . _typeReferenceBuilder . typeRef ( Collection . class , runnableType ) ; for ( final Pair < SarlBehaviorUnit , Collection < Procedure1 < ? super ITreeAppendable > > > evaluators : allEvaluators ) { final SarlBehaviorUnit source = evaluators . getKey ( ) ; final String behName = Utils . createNameForHiddenGuardGeneralEvaluatorMethod ( source . getName ( ) . getSimpleName ( ) ) ; final JvmOperation operation = this . typesFactory . createJvmOperation ( ) ; appendGeneratedAnnotation ( operation , context ) ; addAnnotationSafe ( operation , PerceptGuardEvaluator . class ) ; JvmFormalParameter jvmParam = this . typesFactory . createJvmFormalParameter ( ) ; jvmParam . setName ( this . grammarKeywordAccess . getOccurrenceKeyword ( ) ) ; jvmParam . setParameterType ( this . typeBuilder . cloneWithProxies ( source . getName ( ) ) ) ; this . associator . associate ( source , jvmParam ) ; operation . getParameters ( ) . add ( jvmParam ) ; jvmParam = this . typesFactory . createJvmFormalParameter ( ) ; jvmParam . setName ( RUNNABLE_COLLECTION ) ; jvmParam . setParameterType ( this . typeBuilder . cloneWithProxies ( collectionType ) ) ; operation . getParameters ( ) . add ( jvmParam ) ; operation . setAbstract ( false ) ; operation . setNative ( false ) ; operation . setSynchronized ( false ) ; operation . setStrictFloatingPoint ( false ) ; operation . setFinal ( false ) ; operation . setVisibility ( JvmVisibility . PRIVATE ) ; operation . setStatic ( false ) ; operation . setSimpleName ( behName ) ; operation . setReturnType ( this . typeBuilder . cloneWithProxies ( voidType ) ) ; container . getMembers ( ) . add ( operation ) ; setBody ( operation , it -> { it . append ( "assert " ) ; it . append ( this . grammarKeywordAccess . getOccurrenceKeyword ( ) ) ; it . append ( " != null;" ) ; it . newLine ( ) ; it . append ( "assert " ) ; it . append ( RUNNABLE_COLLECTION ) ; it . append ( " != null;" ) ; for ( final Procedure1 < ? super ITreeAppendable > code : evaluators . getValue ( ) ) { it . newLine ( ) ; code . apply ( it ) ; } } ) ; this . associator . associatePrimary ( source , operation ) ; this . typeBuilder . copyDocumentationTo ( source , operation ) ; } } }
Append the guard evaluators .
34,282
protected void appendSerialNumber ( GenerationContext context , XtendTypeDeclaration source , JvmGenericType target ) { if ( ! isAppendSerialNumbersEnable ( context ) ) { return ; } for ( final JvmField field : target . getDeclaredFields ( ) ) { if ( SERIAL_FIELD_NAME . equals ( field . getSimpleName ( ) ) ) { return ; } } final JvmField field = this . typesFactory . createJvmField ( ) ; field . setSimpleName ( SERIAL_FIELD_NAME ) ; field . setVisibility ( JvmVisibility . PRIVATE ) ; field . setStatic ( true ) ; field . setTransient ( false ) ; field . setVolatile ( false ) ; field . setFinal ( true ) ; target . getMembers ( ) . add ( field ) ; field . setType ( this . typeBuilder . cloneWithProxies ( this . _typeReferenceBuilder . typeRef ( long . class ) ) ) ; final long serial = context . getSerial ( ) ; this . typeBuilder . setInitializer ( field , toStringConcatenation ( serial + "L" ) ) ; appendGeneratedAnnotation ( field , context ) ; this . readAndWriteTracking . markInitialized ( field , null ) ; }
Append the serial number field .
34,283
protected void appendSerialNumberIfSerializable ( GenerationContext context , XtendTypeDeclaration source , JvmGenericType target ) { if ( ! target . isInterface ( ) && this . inheritanceHelper . isSubTypeOf ( target , Serializable . class , null ) ) { appendSerialNumber ( context , source , target ) ; } }
Append the serial number field if and only if the container type is serializable .
34,284
protected void appendCloneFunction ( GenerationContext context , XtendTypeDeclaration source , JvmGenericType target ) { if ( ! isAppendCloneFunctionsEnable ( context ) ) { return ; } for ( final JvmOperation operation : target . getDeclaredOperations ( ) ) { if ( CLONE_FUNCTION_NAME . equals ( operation . getSimpleName ( ) ) ) { return ; } } final ActionPrototype standardPrototype = new ActionPrototype ( CLONE_FUNCTION_NAME , this . sarlSignatureProvider . createParameterTypesForVoid ( ) , false ) ; final Map < ActionPrototype , JvmOperation > finalOperations = new TreeMap < > ( ) ; Utils . populateInheritanceContext ( target , finalOperations , null , null , null , null , this . sarlSignatureProvider ) ; if ( ! finalOperations . containsKey ( standardPrototype ) ) { final JvmTypeReference [ ] genericParameters = new JvmTypeReference [ target . getTypeParameters ( ) . size ( ) ] ; for ( int i = 0 ; i < target . getTypeParameters ( ) . size ( ) ; ++ i ) { final JvmTypeParameter typeParameter = target . getTypeParameters ( ) . get ( i ) ; genericParameters [ i ] = this . _typeReferenceBuilder . typeRef ( typeParameter ) ; } final JvmTypeReference myselfReference = this . _typeReferenceBuilder . typeRef ( target , genericParameters ) ; final JvmOperation operation = this . typeBuilder . toMethod ( source , CLONE_FUNCTION_NAME , myselfReference , null ) ; target . getMembers ( ) . add ( operation ) ; operation . setVisibility ( JvmVisibility . PUBLIC ) ; addAnnotationSafe ( operation , Override . class ) ; if ( context . getGeneratorConfig2 ( ) . isGeneratePureAnnotation ( ) ) { addAnnotationSafe ( operation , Pure . class ) ; } final LightweightTypeReference myselfReference2 = Utils . toLightweightTypeReference ( operation . getReturnType ( ) , this . services ) ; setBody ( operation , it -> { it . append ( "try {" ) ; it . increaseIndentation ( ) . newLine ( ) ; it . append ( "return (" ) . append ( myselfReference2 ) . append ( ") super." ) ; it . append ( CLONE_FUNCTION_NAME ) . append ( "();" ) ; it . decreaseIndentation ( ) . newLine ( ) ; it . append ( "} catch (" ) . append ( Throwable . class ) . append ( " exception) {" ) ; it . increaseIndentation ( ) . newLine ( ) ; it . append ( "throw new " ) . append ( Error . class ) . append ( "(exception);" ) ; it . decreaseIndentation ( ) . newLine ( ) ; it . append ( "}" ) ; } ) ; appendGeneratedAnnotation ( operation , context ) ; } }
Append the clone function .
34,285
protected void appendSARLSpecificationVersion ( GenerationContext context , XtendTypeDeclaration source , JvmDeclaredType target ) { addAnnotationSafe ( target , SarlSpecification . class , SARLVersion . SPECIFICATION_RELEASE_VERSION_STRING ) ; }
Append the SARL specification version as an annotation to the given container .
34,286
protected void appendSARLElementType ( XtendTypeDeclaration source , JvmDeclaredType target ) { addAnnotationSafe ( target , SarlElementType . class , source . eClass ( ) . getClassifierID ( ) ) ; }
Append the SARL element type as an annotation to the given container .
34,287
protected JvmTypeReference skipTypeParameters ( JvmTypeReference type , Notifier context ) { final LightweightTypeReference ltr = Utils . toLightweightTypeReference ( type , this . services ) ; return ltr . getRawTypeReference ( ) . toJavaCompliantTypeReference ( ) ; }
Remove the type parameters from the given type .
34,288
@ SuppressWarnings ( "static-method" ) protected void translateAnnotationsTo ( List < JvmAnnotationReference > annotations , JvmAnnotationTarget target , Class < ? > ... exceptions ) { final Set < String > excepts = new HashSet < > ( ) ; for ( final Class < ? > type : exceptions ) { excepts . add ( type . getName ( ) ) ; } final List < JvmAnnotationReference > addition = new ArrayList < > ( ) ; for ( final JvmAnnotationReference annotation : Iterables . filter ( annotations , an -> { if ( ! ANNOTATION_TRANSLATION_FILTER . apply ( an ) ) { return false ; } return ! excepts . contains ( an . getAnnotation ( ) . getIdentifier ( ) ) ; } ) ) { addition . add ( annotation ) ; } target . getAnnotations ( ) . addAll ( addition ) ; }
Copy the annotations except the ones given as parameters .
34,289
@ SuppressWarnings ( "static-method" ) protected List < JvmTypeParameter > getTypeParametersFor ( XtendTypeDeclaration type ) { if ( type instanceof XtendClass ) { return ( ( XtendClass ) type ) . getTypeParameters ( ) ; } if ( type instanceof XtendInterface ) { return ( ( XtendInterface ) type ) . getTypeParameters ( ) ; } return Collections . emptyList ( ) ; }
Replies the type parameters for the given type .
34,290
protected JvmTypeReference cloneWithTypeParametersAndProxies ( JvmTypeReference type , JvmExecutable forExecutable ) { assert forExecutable . getDeclaringType ( ) != null ; final Map < String , JvmTypeReference > superTypeParameterMapping = new HashMap < > ( ) ; Utils . getSuperTypeParameterMap ( forExecutable . getDeclaringType ( ) , superTypeParameterMapping ) ; return Utils . cloneWithTypeParametersAndProxies ( type , forExecutable . getTypeParameters ( ) , superTypeParameterMapping , this . _typeReferenceBuilder , this . typeBuilder , this . typeReferences , this . typesFactory ) ; }
Clone the given type reference that for being link to the given executable component .
34,291
protected JvmTypeReference cloneWithProxiesFromOtherResource ( JvmTypeReference type , JvmOperation target ) { if ( type == null ) { return this . _typeReferenceBuilder . typeRef ( Void . TYPE ) ; } if ( InferredTypeIndicator . isInferred ( type ) ) { return type ; } final String id = type . getIdentifier ( ) ; if ( Objects . equal ( id , Void . TYPE . getName ( ) ) ) { return this . _typeReferenceBuilder . typeRef ( Void . TYPE ) ; } if ( this . services . getPrimitives ( ) . isPrimitive ( type ) ) { return this . _typeReferenceBuilder . typeRef ( id ) ; } if ( target != null ) { return cloneWithTypeParametersAndProxies ( type , target ) ; } return this . typeBuilder . cloneWithProxies ( type ) ; }
Clone the given type reference that is associated to another Xtext resource .
34,292
@ SuppressWarnings ( "checkstyle:npathcomplexity" ) protected void copyNonStaticPublicJvmOperations ( JvmGenericType source , JvmGenericType target , Set < ActionPrototype > createdActions , Procedure2 < ? super JvmOperation , ? super ITreeAppendable > bodyBuilder ) { final Iterable < JvmOperation > operations = Iterables . transform ( Iterables . filter ( source . getMembers ( ) , it -> { if ( it instanceof JvmOperation ) { final JvmOperation op = ( JvmOperation ) it ; return ! op . isStatic ( ) && op . getVisibility ( ) == JvmVisibility . PUBLIC ; } return false ; } ) , it -> ( JvmOperation ) it ) ; for ( final JvmOperation operation : operations ) { final ActionParameterTypes types = this . sarlSignatureProvider . createParameterTypesFromJvmModel ( operation . isVarArgs ( ) , operation . getParameters ( ) ) ; final ActionPrototype actSigKey = this . sarlSignatureProvider . createActionPrototype ( operation . getSimpleName ( ) , types ) ; if ( createdActions . add ( actSigKey ) ) { final JvmOperation newOp = this . typesFactory . createJvmOperation ( ) ; target . getMembers ( ) . add ( newOp ) ; newOp . setAbstract ( false ) ; newOp . setFinal ( false ) ; newOp . setNative ( false ) ; newOp . setStatic ( false ) ; newOp . setSynchronized ( false ) ; newOp . setVisibility ( JvmVisibility . PUBLIC ) ; newOp . setDefault ( operation . isDefault ( ) ) ; newOp . setDeprecated ( operation . isDeprecated ( ) ) ; newOp . setSimpleName ( operation . getSimpleName ( ) ) ; newOp . setStrictFloatingPoint ( operation . isStrictFloatingPoint ( ) ) ; copyTypeParametersFromJvmOperation ( operation , newOp ) ; for ( final JvmTypeReference exception : operation . getExceptions ( ) ) { newOp . getExceptions ( ) . add ( cloneWithTypeParametersAndProxies ( exception , newOp ) ) ; } for ( final JvmFormalParameter parameter : operation . getParameters ( ) ) { final JvmFormalParameter newParam = this . typesFactory . createJvmFormalParameter ( ) ; newOp . getParameters ( ) . add ( newParam ) ; newParam . setName ( parameter . getSimpleName ( ) ) ; newParam . setParameterType ( cloneWithTypeParametersAndProxies ( parameter . getParameterType ( ) , newOp ) ) ; } newOp . setVarArgs ( operation . isVarArgs ( ) ) ; newOp . setReturnType ( cloneWithTypeParametersAndProxies ( operation . getReturnType ( ) , newOp ) ) ; setBody ( newOp , it -> bodyBuilder . apply ( operation , it ) ) ; } } }
Copy the JVM operations from the source to the destination .
34,293
protected JvmTypeReference inferFunctionReturnType ( XExpression body ) { XExpression expr = body ; boolean stop = false ; while ( ! stop && expr instanceof XBlockExpression ) { final XBlockExpression block = ( XBlockExpression ) expr ; switch ( block . getExpressions ( ) . size ( ) ) { case 0 : expr = null ; break ; case 1 : expr = block . getExpressions ( ) . get ( 0 ) ; break ; default : stop = true ; } } if ( expr == null || expr instanceof XAssignment || expr instanceof XVariableDeclaration || expr instanceof SarlBreakExpression || expr instanceof SarlContinueExpression || expr instanceof SarlAssertExpression ) { return this . _typeReferenceBuilder . typeRef ( Void . TYPE ) ; } return this . typeBuilder . inferredType ( body ) ; }
Infer the function s return type .
34,294
protected JvmTypeReference inferFunctionReturnType ( XtendFunction source , JvmOperation target , JvmOperation overriddenOperation ) { if ( source . getReturnType ( ) != null ) { return ensureValidType ( source . eResource ( ) , source . getReturnType ( ) ) ; } if ( overriddenOperation != null ) { final JvmTypeReference type = overriddenOperation . getReturnType ( ) ; return this . typeReferences . createDelegateTypeReference ( type ) ; } final XExpression expression = source . getExpression ( ) ; JvmTypeReference returnType = null ; if ( expression != null && ( ( ! ( expression instanceof XBlockExpression ) ) || ( ! ( ( XBlockExpression ) expression ) . getExpressions ( ) . isEmpty ( ) ) ) ) { returnType = inferFunctionReturnType ( expression ) ; } return ensureValidType ( source . eResource ( ) , returnType ) ; }
Infer the return type for the given source function .
34,295
@ SuppressWarnings ( "checkstyle:npathcomplexity" ) public void setFrom ( SARLConfiguration config ) { if ( this . input == null ) { this . input = config . getInput ( ) ; } if ( this . output == null ) { this . output = config . getOutput ( ) ; } if ( this . binOutput == null ) { this . binOutput = config . getBinOutput ( ) ; } if ( this . testInput == null ) { this . testInput = config . getTestInput ( ) ; } if ( this . testOutput == null ) { this . testOutput = config . getTestOutput ( ) ; } if ( this . testBinOutput == null ) { this . testBinOutput = config . getTestBinOutput ( ) ; } if ( this . inputCompliance == null ) { this . inputCompliance = config . getInputCompliance ( ) ; } if ( this . outputCompliance == null ) { this . outputCompliance = config . getOutputCompliance ( ) ; } if ( this . encoding == null ) { this . encoding = config . getEncoding ( ) ; } }
Set the uninitialized field with given configuration .
34,296
@ SuppressWarnings ( { "static-method" , "checkstyle:npathcomplexity" } ) public SarlBatchCompiler provideSarlBatchCompiler ( Injector injector , Provider < SarlConfig > config , Provider < SARLBootClasspathProvider > defaultBootClasspath , Provider < IssueMessageFormatter > issueMessageFormater , Provider < IJavaBatchCompiler > javaCompilerProvider ) { final SarlConfig cfg = config . get ( ) ; final CompilerConfig compilerConfig = cfg . getCompiler ( ) ; final ValidatorConfig validatorConfig = cfg . getValidator ( ) ; final SarlBatchCompiler compiler = new SarlBatchCompiler ( ) ; injector . injectMembers ( compiler ) ; String fullClassPath = cfg . getBootClasspath ( ) ; if ( Strings . isEmpty ( fullClassPath ) ) { fullClassPath = defaultBootClasspath . get ( ) . getClasspath ( ) ; } final String userClassPath = cfg . getClasspath ( ) ; if ( ! Strings . isEmpty ( userClassPath ) && ! Strings . isEmpty ( fullClassPath ) ) { fullClassPath = fullClassPath + File . pathSeparator + userClassPath ; } compiler . setClassPath ( fullClassPath ) ; if ( ! Strings . isEmpty ( cfg . getJavaBootClasspath ( ) ) ) { compiler . setBootClassPath ( cfg . getJavaBootClasspath ( ) ) ; } if ( ! Strings . isEmpty ( compilerConfig . getFileEncoding ( ) ) ) { compiler . setFileEncoding ( compilerConfig . getFileEncoding ( ) ) ; } if ( ! Strings . isEmpty ( compilerConfig . getJavaVersion ( ) ) ) { compiler . setJavaSourceVersion ( compilerConfig . getJavaVersion ( ) ) ; } final JavaCompiler jcompiler = compilerConfig . getJavaCompiler ( ) ; compiler . setJavaPostCompilationEnable ( jcompiler != JavaCompiler . NONE ) ; compiler . setJavaCompiler ( javaCompilerProvider . get ( ) ) ; compiler . setOptimizationLevel ( cfg . getCompiler ( ) . getOptimizationLevel ( ) ) ; compiler . setWriteTraceFiles ( compilerConfig . getOutputTraceFiles ( ) ) ; compiler . setWriteStorageFiles ( compilerConfig . getOutputTraceFiles ( ) ) ; compiler . setGenerateInlineAnnotation ( compilerConfig . getGenerateInlines ( ) ) ; compiler . setUseExpressionInterpreterForInlineAnnotation ( compilerConfig . getCompressInlineExpressions ( ) ) ; compiler . setGeneratePureAnnotation ( compilerConfig . getGeneratePures ( ) ) ; compiler . setGenerateEqualityTestFunctions ( compilerConfig . getGenerateEqualityTests ( ) ) ; compiler . setGenerateToStringFunctions ( compilerConfig . getGenerateToString ( ) ) ; compiler . setGenerateCloneFunctions ( compilerConfig . getGenerateClone ( ) ) ; compiler . setGenerateSerialNumberFields ( compilerConfig . getGenerateSerialIds ( ) ) ; if ( validatorConfig . getAllErrors ( ) ) { compiler . setAllWarningSeverities ( Severity . ERROR ) ; } else if ( validatorConfig . getIgnoreWarnings ( ) ) { compiler . setAllWarningSeverities ( Severity . IGNORE ) ; } for ( final Entry < String , Severity > entry : validatorConfig . getWarningLevels ( ) . entrySet ( ) ) { compiler . setWarningSeverity ( entry . getKey ( ) , entry . getValue ( ) ) ; } compiler . setIssueMessageFormatter ( issueMessageFormater . get ( ) ) ; return compiler ; }
Replies the SARL batch compiler .
34,297
@ SuppressWarnings ( "static-method" ) protected Visibility applyMinMaxVisibility ( Visibility visibility , MutableFieldDeclaration it , TransformationContext context ) { if ( context . findTypeGlobally ( Agent . class ) . isAssignableFrom ( it . getDeclaringType ( ) ) ) { if ( visibility . compareTo ( Visibility . PROTECTED ) > 0 ) { return Visibility . PROTECTED ; } } return visibility ; }
Apply the minimum and maximum visibilities to the given one .
34,298
public static < RT , T > ReflectMethod < RT , T > of ( Class < RT > receiverType , Class < T > returnType , String methodName ) { return new ReflectMethod < > ( receiverType , returnType , methodName ) ; }
Static constructor .
34,299
public T invoke ( RT receiver , Object ... arguments ) { assert receiver != null ; final Method method ; synchronized ( this ) { if ( this . method == null ) { this . method = getMethod ( receiver , arguments ) ; method = this . method ; } else { method = this . method ; } } try { return this . returnType . cast ( method . invoke ( receiver , arguments ) ) ; } catch ( RuntimeException | Error exception ) { throw exception ; } catch ( Throwable exception ) { throw new RuntimeException ( exception ) ; } }
Invoke the method .