| ||||||||||
| 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 based on the string you pass them. For example,
to create a new attribute "public String myLastName" using methods of the SciFactory, you have to
write this:
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
The beauty of SciGenericFactory is that if you know the signature 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 the
object being created. If an object cannot be created based on this information, the
SciGenericFactoryException is thrown (for example, this can be due to an incorrect
systax construction in this string). During the process of creation, the source code
in this string will be formatted according to the settings of the formatter. It is possible
also to specify formatting style in operations with additional parameters, or disable formatting.
Currently, only null and empty string values of that parameter are supported.
For null values, no formatting is performed. For empty string values, the 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 based on the specified string. |
SciClass | newClass(String text, String formatStyle) |
SciClassEnumeration | newClasses(String text)Creates a set of SciClasses based 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) |
SciComment | newComment(String text)Creates a new SciComment based on the specified string. |
SciComment | newComment(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) |
SciInitializer | newInitializer(String text)Creates a new SciInitializer based on the specified string. |
SciInitializer | newInitializer(String text, String formatStyle) |
SciMember | newMember(String text, SciClass context)Creates a new SciMember based on the specified string. |
SciMember | newMember(String text, SciClass context, String formatStyle) |
SciMemberDefinition | newMemberDefinition(String text)Creates a new SciMemberDefinition based on the specified string. |
SciMemberDefinition | newMemberDefinition(String text, String formatStyle) |
SciMemberEnumeration | newMembers(String text, SciClass context)Creates a set of SciMembers based 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 based on the specified string. |
SciStatement | newStatement(String text, String formatStyle) |
| Method Detail |
public SciClass newClass(String text)
throws SciGenericFactoryException
SciClass based 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 based 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
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 SciComment newComment(String text)
throws SciGenericFactoryException
SciComment based on the specified string.SciComment with the specified contentSciGenericFactoryException if it is not possible
public SciComment newComment(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);
SciFile with the specified contentpublic SciFile newFile(String text, String formatStyle)
throws SciGenericFactoryException
public SciInitializer newInitializer(String text)
throws SciGenericFactoryException
SciInitializer based on the specified string.SciInitializer with the specified contentSciGenericFactoryException if it is not possiblepublic SciInitializer newInitializer(String text, String formatStyle)
throws SciGenericFactoryException
public SciMember newMember(String text, SciClass context)
throws SciGenericFactoryException
SciMember based on the specified string.
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,
"public ABCD(){}" for the text parameter is valid only for
ABCD class.
SciGenericFactoryException exception.SciMember with the specified contentpublic SciMember newMember(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException
public SciMemberDefinition newMemberDefinition(String text)
SciMemberDefinition based 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 based on the specified string.SciClass to which these members are supposed to belong. For example,
"public ABCD(){} public ABCD(int i){}" for the text parameter is valid
ABCD class.
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 based 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 | |||||||||