| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
A creator of new source code parts of the model with the specified contents/properties.
Methods in this interface are very similar to those defined in the SciFactory
interface, but unlike SciFactory's methods they create an element not with some default
contents/properties, but with contents/properties basing on the string you pass them. For example,
to create a new attibutue "public String myLastName" using methods of the SciFactory, you have to
write this:
The beauty of
SciAttribute newAttribute = SciModelAccess.getModel().getFactory(SciLanguage.JAVA).newAttribute(); //creating a new attribute with default name and type
newAttribute.setName("myLastName"); //setting the name
newAttribute.getType().setText("String"); //setting the type
newAttribute.setProperty(SciProperty.PUBLIC, true); //setting the public modifier
someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
SciGenericFactory is that if you know the singature for a member
a priori, you can create it like this:
SciAttribute newAttribute=null;
try{
newAttribute = (SciAttribute)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public String myLastName;", someSciClass);
}
catch( SciGenericFactoryException e ) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
return;
}
someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
All methods in this interface have a string parameter which contains a piece of a source code
with a complete definition of
object being created. If an object cannot be created basing on this information, the
SciGenericFactoryException is thrown (it can be dued, for example, by the wrong
systax construction in this string). During the process of creation, the source code
in this string will be formatted accoring to the settings of the formatter. It is possible
also to specify formatting style in operations with additioal parameter or disable formatting.
Currently only null and empty string values of that parameter supported.
In the first case no any formatting performed. In the second case currently defined set of
formatter options is used.
After creation (see example), a newly created element can be pasted into SciContainer using the
paste method.
| Method Summary | |
SciClass | newClass(String text)Creates a new SciClass basing on the specified string. |
SciClass | newClass(String text, String formatStyle) |
SciClassEnumeration | newClasses(String text)Creates a set of SciClasses basing on the specified string. |
SciClassEnumeration | newClasses(String text, String formatStyle) |
SciCodeBlock | newCodeBlock(String text)Creates a new SciCodeBlock basing on the specified string. |
SciCodeBlock | newCodeBlock(String text, String formatStyle) |
SciExpression | newExpression(String text)Creates a new SciExpression basing on the specified string. |
SciExpression | newExpression(String text, String formatStyle) |
SciFile | newFile(String text)Creates a new SciFile with the specified contents. |
SciFile | newFile(String text, String formatStyle) |
SciMember | newMember(String text, SciClass context)Creates a new SciMember basing on the specified string. |
SciMember | newMember(String text, SciClass context, String formatStyle) |
SciMemberDefinition | newMemberDefinition(String text)Creates a new SciMemberDefinition basing on the specified string. |
SciMemberDefinition | newMemberDefinition(String text, String formatStyle) |
SciMemberEnumeration | newMembers(String text, SciClass context)Creates a set of SciMembers basing on the specified string. |
SciMemberEnumeration | newMembers(String text, SciClass context, String formatStyle) |
SciParameter | newParameter(String text)Creates a new SciParameter with the specified content. |
SciParameter | newParameter(String text, String formatStyle) |
SciStatement | newStatement(String text)Creates a new SciStatement basing on the specified string. |
SciStatement | newStatement(String text, String formatStyle) |
| Method Detail |
public SciClass newClass(String text)
throws SciGenericFactoryException
SciClass basing on the specified string."class Class1{ void doNothing(){} }".SciClass with the specified contentpublic SciClass newClass(String text, String formatStyle)
throws SciGenericFactoryException
public SciClassEnumeration newClasses(String text)
throws SciGenericFactoryException
SciClasses basing on the specified string."public class Class1 {} class Class2{ void doNothing(){} }".SciClassespublic SciClassEnumeration newClasses(String text, String formatStyle)
throws SciGenericFactoryException
public SciCodeBlock newCodeBlock(String text)
throws SciGenericFactoryException
SciCodeBlock basing on the specified string.someSciOperation
to the "int s = getSalary(2000); return s*2;" :
SciCodeBlock newCodeBlock=null;
try{
newCodeBlock = SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newCodeBlock("int s = getSalary(2000); return s*2;");
}
catch( SciGenericFactoryException e ) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating SciCodeBlock"+e);
return;
}
someSciOperation.setBody(newCodeBlock);
SciCodeBlock with the specified contentpublic SciCodeBlock newCodeBlock(String text, String formatStyle)
throws SciGenericFactoryException
public SciExpression newExpression(String text)
throws SciGenericFactoryException
SciExpression basing on the specified string."myClassInstance.myOperation(0)".SciExpressionpublic SciExpression newExpression(String text, String formatStyle)
throws SciGenericFactoryException
public SciFile newFile(String text)
throws SciGenericFactoryException
SciFile with the specified contents.
SciFile f=null;
try{
f = SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newFile("import java.io.*; public class R{}");
}
catch( SciGenericFactoryException exc ) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a file"+e);
return;
}
f.setName("R.java");
someRwiPackage.paste(f,null,false);
will create a new file R.java containing "import java.io.*; public class R{}".SciFile with the specified contentpublic SciFile newFile(String text, String formatStyle)
throws SciGenericFactoryException
public SciMember newMember(String text, SciClass context)
throws SciGenericFactoryException
SciMember basing on the specified string.
For example, this creates a new attribute "public String myLastName":
SciAttribute newAttribute=null;
try{
newAttribute = (SciAttribute)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public String myLastName;", someSciClass);
}
catch( SciGenericFactoryException e ) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
return;
}
someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
And this creates a new operation "public int getSalary(int year){ return 100; }":
SciOperation newOperation=null;
try{
newOperation = (SciOperation)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public int getSalary(int year){ return 100; }", someSciClass);
}
catch( SciGenericFactoryException e ) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
return;
}
someSciClass.paste(newOperation, null, false); //pasting it into someSciClass
SciClass to which this member is supposed to belong. For example,
a value "public ABCD(){}" of text parameter is valid only for
the ABCD class.
For other classes this value will throw an SciGenericFactoryExcepetion exception.SciMember with the specified contentpublic SciMember newMember(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException
public SciMemberDefinition newMemberDefinition(String text)
SciMemberDefinition basing on the specified string. For C++ language only.SciMemberDefinitionpublic SciMemberDefinition newMemberDefinition(String text, String formatStyle)
public SciMemberEnumeration newMembers(String text, SciClass context)
throws SciGenericFactoryException
SciMembers basing on the specified string.SciClass to which these member is supposed to belong. For example,
a value "public ABCD(){} public ABCD(int i){}" of text parameter is valid
only for ABCD class.
For other classes this value of text will throw an SciGenericFactoryException exception.SciMemberspublic SciMemberEnumeration newMembers(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException
public SciParameter newParameter(String text)
throws SciGenericFactoryException
SciParameter with the specified content."int i".SciParameter with the specified contentpublic SciParameter newParameter(String text, String formatStyle)
throws SciGenericFactoryException
public SciStatement newStatement(String text)
throws SciGenericFactoryException
SciStatement basing on the specified string.SciStatementpublic SciStatement newStatement(String text, String formatStyle)
throws SciGenericFactoryException
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||