[go: up one dir, main page]

CN106484489A - A kind of method and device of extension programming language characteristic - Google Patents

A kind of method and device of extension programming language characteristic Download PDF

Info

Publication number
CN106484489A
CN106484489A CN201510551440.0A CN201510551440A CN106484489A CN 106484489 A CN106484489 A CN 106484489A CN 201510551440 A CN201510551440 A CN 201510551440A CN 106484489 A CN106484489 A CN 106484489A
Authority
CN
China
Prior art keywords
programming language
code
characteristic
markup information
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201510551440.0A
Other languages
Chinese (zh)
Inventor
杨扬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201510551440.0A priority Critical patent/CN106484489A/en
Publication of CN106484489A publication Critical patent/CN106484489A/en
Pending legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

This application discloses a kind of method of extension programming language characteristic, including:According to the entity carrying described characteristic in programming language characteristic to be extended and source code, generate the code operationally behavior operating described entity being intercepted and add the sentence realizing described programming language characteristic wherein;The code generating is merged with source code, operationally to extend the characteristic of source code programming language.The application provides a kind of device of extension programming language characteristic simultaneously.The method being provided using the application, do not need to make any modification to programming language itself, but employ the mode intercepting operation behavior and adding respective code, thus function that is quick, easily achieving operationally enhancing source code programming language characteristic, reach the purpose meeting programming framework demand.

Description

A kind of method and device of extension programming language characteristic
Technical field
The application is related to programming technique and in particular to a kind of method of extension programming language characteristic.The application is same When provide a kind of extension programming language characteristic device.
Background technology
Programming language (programming language), is used to define the formal language of computer program, custom Claim " computer language ", species is varied, is generally speaking segmented into machine language, assembler language, height Level language three major types.Wherein, simplify the instruction in program due to high-level language, to shield bottom hardware thin Section, developer can quickly and efficiently write out the program realizing required function, therefore high-level language relatively Obtain comparing and be widely applied, for example:C#, C++, Java, JavaScript etc..
Every kind of programming language, particularly high-level language, the application having the advantages that oneself and being good at, with When every kind of programming language generally also have some defects.For example, in the client application journey based on Web interaction The JavaScript script being used widely in sequence, its have succinctly, high security, dynamic and Multiple advantages such as cross-platform, but because this language itself is only based on object, in OOP Some crucial characteristic of speech sounds cannot be provided support by aspect all existing defects such as aspect and metadata mark, Also some crucial technology cannot be realized, for example:
1) that specifies the access modifier such as public, private the restriction that conducts interviews to method to be similar to Java;
2) access privilege control to certain class or certain API of certain apoplexy due to endogenous wind;
3) to same set of code, different API are assumed on dissimilar platform to be controlled;
4) to same set of code, different API are assumed on different editions platform to be controlled.
The defect that other programming languages exist may be not quite similar with JavaScript, but generally also can there is class As problem.In actual applications, because programming language is short of certain or some linguistic competence, concrete Application development process in be difficult to meet the demand of programming framework, for developing high-quality code and later stage Safeguard and all cause inconvenience.
In order to strengthen the characteristic of programming language, a kind of is modification programming language than relatively straightforward method, that is, Directly eliminate defect, strengthen the support to desirable characteristics for the language from speech level.In this way, not only The compatibility of programming language to be considered, simultaneously involved modification not only includes programming language itself, also needs to Compiler or interpreter are accordingly changed, the complexity of modification is generally relatively higher, workload also compares Greatly.Even if adopt being modified all demands being likely to be difficult to meet programming framework in this way, Still taking above-mentioned JavaScript language as a example, even if modifying to this language and interpreter, in general also very Difficult to above-mentioned 2), 3), 4) listed by characteristic provide and support.
Content of the invention
The embodiment of the present application provides a kind of method and apparatus of extension programming language characteristic, for existing programming language Speech cannot meet programming framework demand and change the high problem of programming language complexity, there is provided Yi Zhongkuo The technical scheme of exhibition programming language characteristic, can fast, easily meet the demand of programming framework.
The application provides a kind of method of extension programming language characteristic, including:
According to the entity carrying described characteristic in programming language characteristic to be extended and source code, generate in fortune Add realize described programming language to the code that intercepted of behavior operating described entity and wherein during row The sentence of characteristic;
The code generating is merged with source code, operationally to extend the characteristic of source code programming language.
Optionally, before the described code generating and operationally the behavior operating described entity being intercepted, Execution operations described below:
The default markup information for extending programming language characteristic is read from source code;
Described programming language characteristic to be extended includes:The corresponding programming language characteristic of described default markup information; The entity carrying described characteristic in described source code includes:The entity being marked by described default markup information.
Optionally, the described default markup information reading from source code for extending programming language characteristic, Including:Described default markup information is read from the annotation of source code.
Optionally, the entity carrying described characteristic in described source code includes one of following element or combination: Class, variable, function.
Optionally, the programming language of described source code is JavaScript.
Optionally, when methods described comprises to read from source code for extending the default of programming language characteristic During the step of markup information, described default markup information includes:Follow JSDoc specification default markup information, And/or follow the extension markup information of JSDoc form.
Optionally, the described default markup information reading from source code for extending programming language characteristic, Including:
JSDoc markup information is read in units of class;
Described JSDoc markup information is analyzed, therefrom extracts for extending the default of programming language characteristic Markup information.
Optionally, the code that described generation is operationally intercepted to the behavior operating described entity, adopts Following manner is realized:
The agency mechanism being provided according to ECMAScript6, generates described code.
Optionally, the described code by generation is merged with source code, including:
The code of described generation is added in the constructed fuction of the affiliated class of described entity.
Optionally, described programming language characteristic to be extended includes one below or combination:
The access that the method for apoplexy due to endogenous wind is implemented based on privately owned mode limits;
Access privilege control to class or apoplexy due to endogenous wind application programming interface;
To same set of code, different application DLL is assumed on dissimilar platform to be controlled;
To same set of code, different application DLL is assumed on different editions platform to be controlled.
Accordingly, the application also provides a kind of device of extension programming language characteristic, including:
Code generating unit, for carrying described spy according in programming language characteristic to be extended and source code Property entity, generate and operationally the code that intercepted of behavior operating described entity simultaneously added wherein Plus realize the sentence of described programming language characteristic;
Code combining unit is for merging the code generating with source code, original operationally to extend The characteristic of code programming language.
Optionally, described device includes:
Markup information reading unit, for, before triggering described code generating unit, reading from source code Take in the default markup information of extension programming language characteristic;
The programming language characteristic to be extended that described code generating unit is adopted includes:Described markup information reads The default markup information corresponding programming language characteristic that unit reads;The reality that described code generating unit is adopted Body includes:The entity being marked by described default markup information.
Optionally, described markup information reading unit is specifically for reading described from the annotation of source code Default markup information.
Optionally, the programming language of described source code is JavaScript, described markup information reading unit tool Body is used for, and reads and follow the default markup information of JSDoc specification and/or follow JSDoc from source code The extension markup information of form.
Optionally, described markup information reading unit includes:
JSDoc markup information reads subelement, for reading JSDoc markup information in units of class;
Default markup information extracts subelement, for being analyzed, Cong Zhongti to described JSDoc markup information Take in the default markup information of extension programming language characteristic.
Optionally, the programming language of described source code is JavaScript, and described code generating unit is specifically used According to the agency mechanism generation that ECMAScript6 provides, operationally the behavior to the described entity of operation is entered The code of row interception simultaneously adds the sentence realizing described programming language characteristic wherein.
Optionally, described code combining unit is specifically for the code generating described code generating unit adds It is added in the constructed fuction of the affiliated class of described entity.
Compared with prior art, the application has advantages below:
A kind of method of extension programming language characteristic that the application provides, according to programming language characteristic to be extended With the entity carrying described characteristic in source code, generate and operationally the behavior operating described entity is carried out The code of interception simultaneously adds the sentence realizing described programming language characteristic wherein, the code that finally will generate Merge with source code, operationally to extend the characteristic of source code programming language.Using this method, no Need to make any modification to programming language itself, but employ interception operation behavior and add respective code Mode, thus fast, easily achieving the function of operationally strengthening source code programming language characteristic, Reach the purpose meeting programming framework demand.Further, developer can add in source code and preset The said method that markup information and the application provide can be implemented on the basis of reading default markup information, So as to realize extending the function of programming language characteristic automatically according to markup information, simplify the code of developer Write work, improve development efficiency.
Brief description
Fig. 1 is a kind of flow chart of the first embodiment of method of extension programming language characteristic of the application;
Fig. 2 is a kind of schematic diagram of the first embodiment of device of extension programming language characteristic of the application;
Fig. 3 is a kind of flow chart of the second embodiment of method of extension programming language characteristic of the application;
Fig. 4 is a kind of schematic diagram of the second embodiment of device of extension programming language characteristic of the application.
Specific embodiment
Elaborate a lot of details in order to fully understand the application in the following description.But, this Shen Please be much to implement different from alternate manner described here, those skilled in the art can not disobey Similar popularization is done, therefore, the application is not subject to following public being embodied as in the case of back of the body the application intension Limit.
In this application, each provide a kind of method of extension programming language characteristic, and a kind of extension is compiled The device of journey characteristic of speech sounds, is described in detail in the following embodiments one by one.Embodiment is being retouched Before stating, first the technical scheme and embodiment of the application is briefly described.
For programming language because the reasons such as self-defect lead to not meet the problem of programming framework demand, example As:Cannot support the privately owned access modifier of private the restriction that conducts interviews, cannot be carried out access privilege control, Or cannot be carried out Version Control etc., the mode being easier to expect is that programming language is modified, not only Complexity is high, workload is big, but also possibly cannot meet whole demands of programming framework.For this problem, Present inventor finds in R&D work, can abandon above-mentioned routine thinking, and using a kind of extension The new approaches of programming language characteristic:Generate on the basis of source code and possess the code intercepting function and giving birth to The support to required characteristic of speech sounds is realized, such that it is able to operationally strengthen source code programming in the code becoming The characteristic of language, demand that is easy, quickly meeting programming framework.
Further, on the basis of above-mentioned core technology scheme, inventor further provides expansion technique Scheme:The markup information for extending programming language characteristic can be pre-defined, developer write original Only need to during code be marked accordingly according to agreement, the technical program then can read markup information On the basis of, using aforesaid way generate in source code support needed for characteristic of speech sounds spreading code, thus Achieve the function of extending programming language characteristic automatically according to markup information, simplify the written in code work of developer Make, improve development efficiency.
In order to fully be illustrated to the embodiment of technical scheme, will be for upper in follow-up word The core technology scheme stated and enlargement technology, provide two embodiments to be been described by respectively.
It should be noted that because JavaScript language has obtained relatively extensively at present in Internet application and development General application, and this language there is also the demand extending some characteristic of speech sounds, therefore in the follow-up reality of this paper Apply in example and taking JavaScript language be as a example described.But the technical scheme of the application is not limited only to The characteristic of extension JavaScript language, has the programming language of similar demand for other, as long as possessing to reality The ability that body operation behavior is intercepted, equally can also adopt the technical scheme of the application to carry out respective extension. Below embodiments herein is described in detail.
Refer to Fig. 1, it is a kind of stream of the first embodiment of method of extension programming language characteristic of the application Cheng Tu.Methods described comprises the steps:
Step 101:According to the entity carrying described characteristic in programming language characteristic to be extended and source code, Generate the code operationally behavior operating described entity being intercepted, and it is described to add realization wherein The sentence of programming language characteristic.
In the specific implementation, described programming language characteristic to be extended, can according to described programming language from The demand of body feature and concrete programming framework is determining.Described entity can be comprise in source code with One of lower element or combination:Class, variable, function.
, because this language itself is object-based rather than object-oriented taking JavaScript programming language as a example , in terms of OOP, therefore there are some defects, for example, do not possess as the object-oriented language such as Java Member is claimed as public (public) or the built-in mechanism of privately owned (private) by speech like that, therefore naturally also cannot Conduct interviews control to the member of private type;Additionally, JavaScript programming language does not possess following characteristic yet: Access privilege control to class or apoplexy due to endogenous wind application programming interface;To same set of code dissimilar flat Different application DLL is presented on platform be controlled;To same set of code on different editions platform it is in Existing different application DLL is controlled.For JavaScript, above-mentioned listed broadly falling into waits to expand The programming language characteristic of exhibition, and the demand according to different programming frameworks, it is right that JavaScript language may also lack The support of other characteristics, does not enumerate herein.
Carry the entity of programming language characteristic to be extended (referred to as treating extended attribute), typically refer to treat that extension is special The target entity that property is had an effect, for example, it is desirable to right in the source code write with JavaScript language Certain member function method1 (also referred to as method) in class ClassA carries out the access of similar private mode Limit.So, treat that extended attribute is:The access that the method for apoplexy due to endogenous wind is implemented based on privately owned mode limits, and Carry the entity that this treats extended attribute to be:The method1 method of described ClassA apoplexy due to endogenous wind.
In this step, according to the reality carrying described characteristic in programming language characteristic to be extended and source code Body, generates the code that can operationally intercept the operation behavior to described entity and adds in this code Realize the sentence of described programming language characteristic.It is also understood that in the operation phase behaviour to described entity Make behavior, for example:Access (including get and set) to attribute, calling to method, can be generated Code intercept, and wherein be used for realize treat that the sentence of extended attribute also can be executed accordingly.
The above-mentioned code having and intercepting function can be generated for different programming languages in different ways. In the present embodiment, the programming language of source code is JavaScript, therefore can be according to ECMAScript6 The agency mechanism providing has, described in generating, the code intercepting function.
JavaScript is to by ECMA (European Computer Manufacturer's Association, Europe Continent computer maker community) realization of ECMAScript standard that defines, and ECMAScript6 (letter Claim ES6) provide a kind of new mechanism:Proxy (acts on behalf of), for changing the default behavior of some operations, It is equal to and makes modification in speech level, belong to " metaprogramming " (meta programming).Wherein, to genus The access of property, Proxy provide get (target, propKey, receiver) and set (target, propKey, value, Receiver) two methods are intercepted;Method is called, Proxy provides apply (receiver ... args) Method is intercepted;And the construction to class itself, Proxy provides construct (receiver ... args) method Intercepted.Additionally, for some other access to class, Proxy also has corresponding mechanism can carry out Intercept.
The basic definition mode of Proxy is as follows:Var proxy=new Proxy (target, handler).Its Cardinal principle is that the operation behavior of target (destination object) will be redirect in handler (processor), After carrying out above-mentioned agency's encapsulation to target, all operations to target can be taken over by handler, if Provide the customized treatment to specific operation in handler, then execute respective handling, otherwise by this operation behavior Still transfer to target process.Proxy has interception function as can be seen here, and the present embodiment then can utilize Proxy This characteristic of mechanism, realizes required programming language characteristic, for example in handler:Based on privately owned mode Access restriction, Version Control etc..
In order to make it easy to understand, following reality taking specific JavaScript source code fragment as a example, to this step Apply and be further illustrated.Source code fragment is as follows:
In order to member function privateMethod () in member variable _ name and ClassB in ClassA Realize the access based on privately owned mode to limit, it is possible to use Proxy mechanism is respectively ClassA and ClassB life Become code as follows:
And add the judgement to name and corresponding in the above-mentioned code for ClassA and ClassB respectively Process sentence, for be unsatisfactory for the access mode that requires can direct throw exception, privately owned to realize being based on The access of mode limits.Code after adding above-mentioned judgement and processing sentence is as follows:
It should be noted that JavaScript code fragment given above simply generates to according to Proxy mechanism The simple signal of code, in a particular application, can generate increasingly complex or more excellent according to real needs The code changed, and it is not necessarily limited to the form of above-mentioned code snippet.
Step 102:The code generating is merged with source code, operationally to extend source code programming language The characteristic of speech.
The code generating in a step 101 is added in source code, so that source code programming language The characteristic of speech is enhanced.If source code programming language needs Complied executing in the specific implementation, So with corresponding compiler, the source code after merging can be compiled, obtain executable target literary composition Part, if source code programming language is explanatory programming language, can directly solve in corresponding environment Release execution.
For adding the described particular location generating code in source code, can be programmed according to source code The composite factors such as the grammar request of language, the correctness of operation function, run-time overhead are selected, in choosing After determining the appropriate location in source code, described spreading code can be inserted in this position, script is located at Source code after this position and this position accordingly moves afterwards.
In the present embodiment, source code programming language is JavaScript language, and the grammer according to this language will Ask and the composite factor such as run-time overhead, the code that step 101 generates can be added to carrying programming In the constructed fuction of the affiliated class of entity of characteristic of speech sounds, on the one hand can operationally reduce the occupancy to internal memory, One object of every construction is avoided all to create a Proxy;On the other hand, due to being added in constructed fuction, just In correctly quoting this keyword in JavaScript, it is to avoid occur because context change leads to quote mistake Problem by mistake.
Still continue to use the specific example of the extension JavaScript language characteristic providing in a step 101, can be by pin The code that ClassA and ClassB is generated, is added at the ending of respective constructed fuction in source code.
Operation source code can be explained, if there being pin in source code after completing above-mentioned code union operation Following operation to above-mentioned two class is it will be seen that corresponding output information.In order to make it easy to understand, will be described After output information is listed in access operation, and with " // " symbol is separated:
As can be seen here, by, in the spreading code that operation behavior is intercepted, adding the judgement to name And respective handling is it is achieved that the access of right _ name variable and privateMethod () method limits, thus strengthening The characteristic of JavaScript language implements the access limit based on privately owned mode so as to be provided with the member to apoplexy due to endogenous wind The characteristic of system, compensate for the defect of JavaScript language.
In sum, the method for the extension programming language characteristic being provided using the present embodiment is it is not necessary to programming Language itself makes any modification, but employ generate have the spreading code intercepting operation behavior function and Add the mode of respective handling sentence for programming language characteristic to be extended, thus fast, easily achieve Operationally strengthen the function of source code programming language characteristic, reach the purpose meeting programming framework demand.
It is in the above-described embodiment, there is provided a kind of method of extension programming language characteristic, corresponding, The application also provides a kind of device of extension programming language characteristic.Refer to Fig. 2, it is a kind of expansion of the application The schematic diagram of the first embodiment of device of exhibition programming language characteristic.Due to the device embodiment side of being substantially similar to Method embodiment, so describing fairly simple, in place of correlation, the part referring to embodiment of the method illustrates. Device embodiment described below is only schematically.
A kind of device of the extension programming language characteristic of the present embodiment, including:Code generating unit 201, is used for According to the entity carrying described characteristic in programming language characteristic to be extended and source code, generate operationally Add to the code that intercepted of behavior operating described entity and wherein and realize described programming language characteristic Sentence;Code combining unit 202, for merging the code generating with source code, operationally to expand The characteristic of exhibition source code programming language.
Optionally, described device includes:
Markup information reading unit, for, before triggering described code generating unit, reading from source code Take in the default markup information of extension programming language characteristic;
The programming language characteristic to be extended that described code generating unit is adopted includes:Described markup information reads The default markup information corresponding programming language characteristic that unit reads;The reality that described code generating unit is adopted Body includes:The entity being marked by described default markup information.
Optionally, described markup information reading unit is specifically for reading described from the annotation of source code Default markup information.
Optionally, the programming language of described source code is JavaScript, described markup information reading unit tool Body is used for, and reads and follow the default markup information of JSDoc specification and/or follow JSDoc from source code The extension markup information of form.
Optionally, described markup information reading unit includes:
JSDoc markup information reads subelement, for reading JSDoc markup information in units of class;
Default markup information extracts subelement, for being analyzed, Cong Zhongti to described JSDoc markup information Take in the default markup information of extension programming language characteristic.
Optionally, the programming language of described source code is JavaScript, and described code generating unit is specifically used According to the agency mechanism generation that ECMAScript6 provides, operationally the behavior to the described entity of operation is entered The code of row interception simultaneously adds the sentence realizing described programming language characteristic wherein.
Optionally, described code combining unit is specifically for the code generating described code generating unit adds It is added in the constructed fuction of the affiliated class of described entity.
On the basis of a kind of first embodiment of the method for extension programming language characteristic of above-mentioned offer, this Shen Please additionally provide the second embodiment of methods described.In the present embodiment, read for expanding from source code The default markup information of exhibition programming language characteristic, and corresponding volume is realized according to the default markup information generation read The code of journey characteristic of speech sounds.The present embodiment is repeated no more with said method embodiment step identical part, under Face emphasis describes difference.
Refer to Fig. 3, it is a kind of stream of the second embodiment of method of extension programming language characteristic of the application Cheng Tu.Methods described comprises the steps:
Step 301:The default markup information for extending programming language characteristic is read from source code.
In order to simplify the workload of developer, can make an appointment and mark the tool of programming language characteristic to be extended Body mode, developer is labeled to corresponding entity in this mode when writing source code, and this reality Apply example and then can extract markup information from source code in this mode, and add support in source code The code of corresponding language characteristic, it is achieved thereby that extend the function of programming language characteristic automatically according to markup information.
This step reads the default markup information for extending programming language characteristic from source code, according to pre- The notation methods first arranged are different, and this step can adopt corresponding reading manner.For example:If be about scheduled on (such as name variable or method name) additional markup information in entity name, then this step can pass through Default markup information is extracted in analysis to entity name in source code.
In order to avoid changing to naming method, as a kind of more generally applicable mode, can about be scheduled on former Default markup information is comprised, the present embodiment is adopted in this way, that is, from source code in the annotation of beginning code Annotation in read default markup information.
The form of default markup information can also be made an appointment, for example:Can be made using symbol set in advance For prefix, be followed by keyword set in advance, for example show programming language characteristic to be extended full name or Person's abbreviation etc. and required parameter etc..
In the present embodiment, the programming language of described source code is JavaScript it is contemplated that using The developer of JavaScript language is generally annotated to source code using JSDoc, in order to reduce exploitation The learning cost of personnel, therefore the present embodiment are labeled the expansion of information on the basis of following JSDoc form Exhibition, developer is labeled according to JSDoc form, and the technical program then reads according to JSDoc form.
Described JSDoc is one and is used for marking the language of JavaScript source code, as long as developer follows JSDoc specification adds corresponding annotation it is possible to utilize corresponding JSDoc instrument in JavaScript code Automatically generate the API document of HTML or Rich Text Format form.
Because JSDoc has been provided for the primary mark such as@public ,@private in itself, implement this technology side This part mark can be multiplexed during case, and without additionally being re-defined the (ClassA in first embodiment Employ primary mark with the member in ClassB).Source code therefore in the present embodiment can comprise with Lower two kinds of markup informations:The markup information following JSDoc specification, the extension mark letter following JSDoc form Above-mentioned two class markup informations are referred to as JSDoc by breath (also referred to as self-defined markup information) in the present embodiment Markup information.
In order to make it easy to understand, following reality taking specific JavaScript source code fragment as a example, to this step Apply and be further illustrated.Source code fragment is as follows:
Above-mentioned code snippet is the code snippet after developer's mark, wherein@accessLevel system It is to extend JavaScript language " access privilege control to class or apoplexy due to endogenous wind application programming interface " This characteristic and the default markup information that marks, show that a permission system application accesses the entity being marked systemInvoke().Wherein, described application programming interface (abbreviation API) refers to, in certain apoplexy due to endogenous wind Entity definition, being available for extraneous access, can include:Member variable, member function (also referred to as method) Deng.
In the present embodiment, for the source code with written in JavaScript, can be read in units of class JSDoc markup information, reads information from the annotation starting with "/* * ", and extracts JSDoc according to@character Markup information, is then further analyzed to JSDoc markup information again, according to the keyword after@character Discern whether to be the default markup information for extending programming language characteristic, if it is extract this markup information.
It should be noted that when being embodied as the technical program, if by the way of the present embodiment provides Treat extension programming language characteristic according to JSDoc form to be labeled, because this part markup information is also assembled Become in the source code to after process via subsequent step, such that it is able to allow code accomplish " self-explanatory ", for the present The supporting IDE of programming framework supports the means of " smart code prompt facility " provides convenient afterwards.
Step 302:According to described default markup information and the entity that is marked, generate operationally to operation Code that the behavior of described entity is intercepted simultaneously adds that to realize described default markup information corresponding wherein The sentence of programming language characteristic.
Step 301 by default markup information be have read to the parsing of source code, according to default markup information Programming language characteristic to be extended can be known, can also be obtained and default mark by the parsing of source code Information is corresponding to be marked entity, and this step, according to above- mentioned information, generates operationally to the described entity of operation The code that intercepted of behavior and add the sentence realizing described programming language characteristic.
Still continue to use the specific example providing in step 301, the default markup information for reading and being marked Entity the systemInvoke () method of note, is generated using Proxy mechanism and intercepts code and add phase wherein The sentence of the realization " access privilege control " answered, obtains code snippet as follows:
In above-mentioned code snippet, the rank of the application implementing access is judged, and according to judged result Processed accordingly, if implementing application the nonsystematic application accessing, can direct throw exception, Thus realizing the access privilege control to API.
Step 303:The code generating is merged with source code, operationally to extend source code programming language The characteristic of speech.
The code of generation is added in source code this step, and the particular location of interpolation can be according to original generation The composite factors such as the grammar request of code programming language, the correctness of operation function, run-time overhead are selected. For example, the code of generation can be added to the construction of ClassA by the specific example being given for step 302 In function.
In the specific example being given above, for how extending " access privilege control " this characteristic of speech sounds It is illustrated, when being embodied as the technical program, can also be using above-mentioned similar mode to programming language Other characteristics of speech are extended, for example:Different API are presented on dissimilar platform to same set of code It is controlled, or to same set of code, different API is assumed on different editions platform being controlled.
For " to same set of code, different API being assumed on dissimilar platform to be controlled " this characteristic, Can generate the code that API Access is intercepted in, current platform type is checked (described Platform Type can include device type, as wrist-watch, mobile phone, TV etc. it is also possible to include software system Type), if current platform type is not corresponded with accessed API, can be processed accordingly, for example: Directly throw exception;Otherwise allow the access to this API for the execution.Programming language is made by above-mentioned extended mode After possessing this characteristic, just can be directed to a set of code of dissimilar platform maintenance on stream, and not Many set codes must be developed, code development and the workload safeguarded can be reduced.For " existing to same set of code Different API are presented on different editions platform be controlled " this characteristic, its implementation is also similar, Here is omitted.
In the specific implementation, for the JavaScript source code comprising multiple classes, can be in a step 101 Read the default markup information for each class in units of class, be then respectively directed to each in a step 102 Class generates corresponding code segment, then in step 103 each code segment generating is merged in source code.
So far, by the description of step 301 to step 303, there is provided a kind of extension programming language of the application The another embodiment of the method for speech characteristic.In concrete application, can be by step 301- step 303 Operation is encapsulated as an independent preprocessor (being referred to as " compiler "), by the place of preprocessor Reason, can generate inter-process code according to the markup information automatic conversion in source code and update former In beginning code.Adopt in this way, for developer, extra coding work need not be carried out, only Need according to predetermined manner, the entity in code to be labeled when writing source code, then utilize this pre- Processor is processed to source code it is possible to be realized by dynamic interception mechanism when running source code Control to the entity being marked, strengthens the ability of programming language, meets the demand of programming framework.
Corresponding with a kind of second embodiment of the method for above-mentioned extension programming language characteristic, the application also carries For a kind of second embodiment of the device of extension programming language characteristic.Refer to Fig. 4, it is one kind of the application The schematic diagram of the second embodiment of device of extension programming language characteristic.Because device embodiment is substantially similar to Embodiment of the method, so describing fairly simple, in place of correlation, the part referring to embodiment of the method illustrates. Device embodiment described below is only schematically.
A kind of device of the extension programming language characteristic of the present embodiment, including:Markup information reading unit 401, For, before triggering described code generating unit, reading from source code for extending programming language characteristic Default markup information;Code generating unit 402, for according to described default markup information and be marked Entity, generates the code operationally behavior operating described entity being intercepted, and adds real wherein Show the sentence of the corresponding programming language characteristic of described default markup information;Code combining unit 403, for giving birth to The code becoming is merged with source code, operationally to extend the characteristic of source code programming language.
Optionally, described markup information reading unit is specifically for reading described from the annotation of source code Default markup information.
Optionally, the programming language of described source code is JavaScript, described markup information reading unit tool Body is used for, and reads and follow the default markup information of JSDoc specification and/or follow JSDoc from source code The extension markup information of form.
Optionally, described markup information reading unit includes:
JSDoc markup information reads subelement, for reading JSDoc markup information in units of class;
Default markup information extracts subelement, for being analyzed, Cong Zhongti to described JSDoc markup information Take in the default markup information of extension programming language characteristic.
Optionally, the programming language of described source code is JavaScript, and described code generating unit is specifically used According to the agency mechanism generation that ECMAScript6 provides, operationally the behavior to the described entity of operation is entered The code of row interception simultaneously adds the language realizing the corresponding programming language characteristic of described default markup information wherein Sentence.
Optionally, described code combining unit is specifically for the code generating described code generating unit adds It is added in the constructed fuction of the affiliated class of described entity.
Although the application is open as above with preferred embodiment, it is not for limiting the application, Ren Heben Skilled person, without departing from spirit and scope, can make possible variation and modification, The protection domain of therefore the application should be defined by the scope that the application claim is defined.
In a typical configuration, computing device includes one or more processors (CPU), input/output Interface, network interface and internal memory.
Internal memory potentially includes the volatile memory in computer-readable medium, random access memory (RAM) and/or the form such as Nonvolatile memory, such as read only memory (ROM) or flash memory (flash RAM). Internal memory is the example of computer-readable medium.
1st, computer-readable medium include permanent and non-permanent, removable and non-removable media can be by Any method or technique is realizing information Store.Information can be computer-readable instruction, data structure, journey The module of sequence or other data.The example of the storage medium of computer includes, but are not limited to phase transition internal memory (PRAM), static RAM (SRAM), dynamic random access memory (DRAM), its The random access memory (RAM) of his type, read only memory (ROM), electrically erasable is read-only deposits Reservoir (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tape, tape magnetic magnetic Disk storage or other magnetic storage apparatus or any other non-transmission medium, can be used for storage can be set by calculating The standby information accessing.Define according to herein, computer-readable medium does not include non-temporary computer-readable matchmaker Body (transitory media), the such as data signal of modulation and carrier wave.
2 it will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer Program product.Therefore, the application using complete hardware embodiment, complete software embodiment or can combine software Form with the embodiment of hardware aspect.And, the application can adopt and wherein include meter one or more Calculation machine usable program code computer-usable storage medium (including but not limited to disk memory, CD-ROM, optical memory etc.) the upper computer program implemented form.

Claims (17)

1. a kind of method of extension programming language characteristic is it is characterised in that include:
According to the entity carrying described characteristic in programming language characteristic to be extended and source code, generate in fortune Add realize described programming language to the code that intercepted of behavior operating described entity and wherein during row The sentence of characteristic;
The code generating is merged with source code, operationally to extend the characteristic of source code programming language.
2. the method for extension programming language characteristic according to claim 1 is it is characterised in that described Before generating the code operationally behavior operating described entity being intercepted, execute operations described below:
The default markup information for extending programming language characteristic is read from source code;
Described programming language characteristic to be extended includes:The corresponding programming language characteristic of described default markup information; The entity carrying described characteristic in described source code includes:The entity being marked by described default markup information.
3. according to claim 2 extension programming language characteristic method it is characterised in that described from The default markup information for extending programming language characteristic is read in source code, including:From source code Described default markup information is read in annotation.
4. the method for extension programming language characteristic according to claim 1 is it is characterised in that described former The entity carrying described characteristic in beginning code includes one of following element or combination:Class, variable, function.
5. according to any one of claim 1-4 extension programming language characteristic method it is characterised in that The programming language of described source code is JavaScript.
6. the method for extension programming language characteristic according to claim 5 is it is characterised in that work as described When method comprises to read the step of default markup information for extending programming language characteristic from source code, Described default markup information includes:Follow the default markup information of JSDoc specification and/or follow JSDoc lattice The extension markup information of formula.
7. according to claim 6 extension programming language characteristic method it is characterised in that described from The default markup information for extending programming language characteristic is read in source code, including:
JSDoc markup information is read in units of class;
Described JSDoc markup information is analyzed, therefrom extracts for extending the default of programming language characteristic Markup information.
8. the method for extension programming language characteristic according to claim 5 is it is characterised in that described life Become the code operationally behavior operating described entity being intercepted, realize in the following way:
The agency mechanism being provided according to ECMAScript6, generates described code.
9. the method for extension programming language characteristic according to claim 8 will be it is characterised in that described will The code generating is merged with source code, including:
The code of described generation is added in the constructed fuction of the affiliated class of described entity.
10. the method for extension programming language characteristic according to claim 5 is it is characterised in that described Programming language characteristic to be extended includes one below or combination:
The access that the method for apoplexy due to endogenous wind is implemented based on privately owned mode limits;
Access privilege control to class or apoplexy due to endogenous wind application programming interface;
To same set of code, different application DLL is assumed on dissimilar platform to be controlled;
To same set of code, different application DLL is assumed on different editions platform to be controlled.
A kind of 11. devices of extension programming language characteristic are it is characterised in that include:
Code generating unit, for carrying described spy according in programming language characteristic to be extended and source code Property entity, generate and operationally the code that intercepted of behavior operating described entity simultaneously added wherein Plus realize the sentence of described programming language characteristic;
Code combining unit is for merging the code generating with source code, original operationally to extend The characteristic of code programming language.
The devices of 12. extension programming language characteristics according to claim 11 are it is characterised in that described Device includes:
Markup information reading unit, for, before triggering described code generating unit, reading from source code Take in the default markup information of extension programming language characteristic;
The programming language characteristic to be extended that described code generating unit is adopted includes:Described markup information reads The default markup information corresponding programming language characteristic that unit reads;The reality that described code generating unit is adopted Body includes:The entity being marked by described default markup information.
The devices of 13. extension programming language characteristics according to claim 12 are it is characterised in that described Markup information reading unit is specifically for reading described default markup information from the annotation of source code.
The devices of 14. extension programming language characteristics according to claim 12 are it is characterised in that described The programming language of source code is JavaScript, and described markup information reading unit is specifically for from original generation The default markup information following JSDoc specification and/or the extension mark letter following JSDoc form is read in code Breath.
The devices of 15. extension programming language characteristics according to claim 14 are it is characterised in that described Markup information reading unit includes:
JSDoc markup information reads subelement, for reading JSDoc markup information in units of class;
Default markup information extracts subelement, for being analyzed, Cong Zhongti to described JSDoc markup information Take in the default markup information of extension programming language characteristic.
The devices of 16. extension programming language characteristics according to claim 11 are it is characterised in that described The programming language of source code be JavaScript, described code generating unit specifically for, according to The agency mechanism generation that ECMAScript6 provides operationally is intercepted to the behavior operating described entity Code simultaneously adds the sentence realizing described programming language characteristic wherein.
The devices of 17. extension programming language characteristics according to claim 16 are it is characterised in that described Code combining unit is specifically for the code generating described code generating unit is added to belonging to described entity In the constructed fuction of class.
CN201510551440.0A 2015-09-01 2015-09-01 A kind of method and device of extension programming language characteristic Pending CN106484489A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510551440.0A CN106484489A (en) 2015-09-01 2015-09-01 A kind of method and device of extension programming language characteristic

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510551440.0A CN106484489A (en) 2015-09-01 2015-09-01 A kind of method and device of extension programming language characteristic

Publications (1)

Publication Number Publication Date
CN106484489A true CN106484489A (en) 2017-03-08

Family

ID=58237670

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510551440.0A Pending CN106484489A (en) 2015-09-01 2015-09-01 A kind of method and device of extension programming language characteristic

Country Status (1)

Country Link
CN (1) CN106484489A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111078566A (en) * 2019-12-20 2020-04-28 大唐网络有限公司 ES 6-based object self-checking method
CN115328544A (en) * 2022-10-14 2022-11-11 统信软件技术有限公司 Environment customization method, computing device and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100478874C (en) * 2003-07-23 2009-04-15 微软公司 Method and system for enlarge and configuing corresponding extensible sofrware
CN103440440A (en) * 2013-08-27 2013-12-11 浙江大学城市学院 Method for strengthening JavaScript function encapsulation
CN104572072A (en) * 2014-12-01 2015-04-29 北京百度网讯科技有限公司 MVC (model view controller) mode-based language transformation method and equipment for program
CN104657189A (en) * 2013-11-20 2015-05-27 财团法人资讯工业策进会 Hybrid dynamic code compiling device, method and service system thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100478874C (en) * 2003-07-23 2009-04-15 微软公司 Method and system for enlarge and configuing corresponding extensible sofrware
CN103440440A (en) * 2013-08-27 2013-12-11 浙江大学城市学院 Method for strengthening JavaScript function encapsulation
CN104657189A (en) * 2013-11-20 2015-05-27 财团法人资讯工业策进会 Hybrid dynamic code compiling device, method and service system thereof
CN104572072A (en) * 2014-12-01 2015-04-29 北京百度网讯科技有限公司 MVC (model view controller) mode-based language transformation method and equipment for program

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111078566A (en) * 2019-12-20 2020-04-28 大唐网络有限公司 ES 6-based object self-checking method
CN115328544A (en) * 2022-10-14 2022-11-11 统信软件技术有限公司 Environment customization method, computing device and storage medium
CN115328544B (en) * 2022-10-14 2023-02-28 统信软件技术有限公司 Environment customization method, computing device and storage medium

Similar Documents

Publication Publication Date Title
CN109597661B (en) Service function configuration method and device
Mellor et al. Guest editors' introduction: Model-driven development
US8245186B2 (en) Techniques for offering and applying code modifications
WO2020173128A1 (en) Method and device for generating software development kit, and terminal device
US8479283B2 (en) Generating security validation code automatically
CN105229603B (en) Controlling runtime access to application programming interfaces
WO2019233293A1 (en) Method and apparatus for developing application program
US11048885B2 (en) Cognitive translation service integrated with context-sensitive derivations for determining program-integrated information relationships
JP2009070372A (en) Server-side code generation from dynamic web page content file
CN102023856A (en) Method for outputting and operating data at server in formatting way according to demands of user
CN107943465B (en) Method and device for generating HTML form
US20140157247A1 (en) Enabling Symbol Resolution of Private Symbols in Legacy Programs and Optimizing Access to the Private Symbols
US12321423B2 (en) Software license-based code suggestions
CN101208690B (en) Translating Expressions in Computing Environments
CN105373536A (en) DAO interface realizing method and device
CN101859246A (en) System and method for converting corresponding scripts according to different browsers
US8195766B2 (en) Dynamic implicit localization of web content
CN106484489A (en) A kind of method and device of extension programming language characteristic
US20160062748A1 (en) Embedded domain specific languages as first class code artifacts
Shetty et al. Crust: AC/C++ to Rust transpiler using a “nano-parser methodology” to avoid C/C++ safety issues in legacy code
CN108089852B (en) Method, medium, apparatus and computing device for establishing attribute access
Bystrický et al. Preserving use case flows in source code: Approach, context, and challenges
CN103744687B (en) Access method and device for input/output port
US7917893B2 (en) Using a system of annotations to generate views and adapters
Niemiec et al. Mobilex: a generic framework for cross-platform mobile development based on web language

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20170308

RJ01 Rejection of invention patent application after publication