package org . vaadin . teemu . clara . demo ; import java . io . BufferedReader ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import org . vaadin . teemu . clara . Clara ; import org . vaadin . teemu . clara . inflater . LayoutInflaterException ; import com . vaadin . Application ; import com . vaadin . terminal . ThemeResource ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . Component ; import com . vaadin . ui . Embedded ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . HorizontalSplitPanel ; import com . vaadin . ui . TextArea ; import com . vaadin . ui . VerticalLayout ; import com . vaadin . ui . Window ; import com . vaadin . ui . Window . Notification ; @ SuppressWarnings ( "" ) public class DemoApplication extends Application { private DemoController controller ; private TextArea xmlArea ; private HorizontalSplitPanel split = new HorizontalSplitPanel ( ) ; private Window mainWindow ; @ Override public void init ( ) { setTheme ( "" ) ; setMainWindow ( mainWindow = new Window ( ) ) ; controller = new DemoController ( mainWindow ) ; mainWindow . setContent ( split ) ; VerticalLayout editor = new VerticalLayout ( ) ; editor . setSpacing ( true ) ; editor . setMargin ( false , false , false , true ) ; editor . setHeight ( "" ) ; editor . addComponent ( xmlArea = createXmlArea ( ) ) ; editor . setExpandRatio ( xmlArea , ) ; editor . addComponent ( createUpdateButton ( ) ) ; HorizontalLayout wrapper = new HorizontalLayout ( ) ; wrapper . setMargin ( true ) ; wrapper . setSizeFull ( ) ; wrapper . addComponent ( createLogo ( ) ) ; wrapper . addComponent ( editor ) ; wrapper . setExpandRatio ( editor , ) ; split . setFirstComponent ( wrapper ) ; updateLayout ( ) ; } private Component createLogo ( ) { Embedded logo = new Embedded ( null , new ThemeResource ( "" ) ) ; logo . setHeight ( "" ) ; logo . setWidth ( "" ) ; return logo ; } private TextArea createXmlArea ( ) { TextArea area = new TextArea ( ) ; area . setStyleName ( "" ) ; area . setSizeFull ( ) ; area . setValue ( readStartingPoint ( ) ) ; return area ; } private Button createUpdateButton ( ) { return new Button ( "" , new Button . ClickListener ( ) { public void buttonClick ( ClickEvent event ) { updateLayout ( ) ; } } ) ; } private String readStartingPoint ( ) { BufferedReader reader = null ; try { reader = new BufferedReader ( new InputStreamReader ( getClass ( ) . getClassLoader ( ) . getResourceAsStream ( "" ) ) ) ; StringBuilder xml = new StringBuilder ( ) ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { xml . append ( line ) ; xml . append ( "" ) ; } return xml . toString ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } return null ; } private void updateLayout ( ) { try { Component c = Clara . create ( new ByteArrayInputStream ( xmlArea . getValue ( ) . toString ( ) . getBytes ( ) ) , controller ) ; split . replaceComponent ( split . getSecondComponent ( ) , c ) ; } catch ( LayoutInflaterException e ) { mainWindow . showNotification ( e . getMessage ( ) , Notification . TYPE_ERROR_MESSAGE ) ; } } }
package org . vaadin . teemu . clara . demo ; import java . util . Date ; import org . vaadin . teemu . clara . binder . annotation . DataSource ; import org . vaadin . teemu . clara . binder . annotation . EventHandler ; import com . vaadin . data . Container ; import com . vaadin . data . Property ; import com . vaadin . data . Property . ValueChangeEvent ; import com . vaadin . data . util . IndexedContainer ; import com . vaadin . data . util . ObjectProperty ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . Window ; public class DemoController { private Window window ; public DemoController ( Window window ) { this . window = window ; } @ DataSource ( "" ) public Property getDateProperty ( ) { return new ObjectProperty < Date > ( new Date ( ) ) ; } @ DataSource ( "" ) public Container getPersonContainer ( ) { IndexedContainer container = new IndexedContainer ( ) ; container . addContainerProperty ( "" , String . class , "" ) ; container . addContainerProperty ( "" , Integer . class , ) ; Object itemId = container . addItem ( ) ; container . getItem ( itemId ) . getItemProperty ( "" ) . setValue ( "" ) ; container . getItem ( itemId ) . getItemProperty ( "" ) . setValue ( ) ; itemId = container . addItem ( ) ; container . getItem ( itemId ) . getItemProperty ( "" ) . setValue ( "" ) ; container . getItem ( itemId ) . getItemProperty ( "" ) . setValue ( ) ; return container ; } @ EventHandler ( "" ) public void handleButtonClick ( ClickEvent event ) { window . showNotification ( "" ) ; } @ EventHandler ( "" ) public void handleAnotherButtonClick ( ClickEvent event ) { window . showNotification ( "" ) ; } @ EventHandler ( "" ) public void someValueChanged ( ValueChangeEvent event ) { window . showNotification ( "" + event . getProperty ( ) . getValue ( ) ) ; } }
package org . vaadin . teemu . clara ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import org . junit . Before ; import org . junit . Test ; import org . vaadin . teemu . clara . inflater . PrimitiveAttributeParser ; public class PrimitiveAttributeParserTest { private PrimitiveAttributeParser handler ; @ Before public void setUp ( ) { handler = new PrimitiveAttributeParser ( ) ; } @ Test public void testBoolean ( ) throws Exception { assertTrue ( handler . isSupported ( Boolean . TYPE ) ) ; assertTrue ( handler . isSupported ( Boolean . class ) ) ; assertEquals ( true , handler . getValueAs ( "" , Boolean . TYPE ) ) ; assertEquals ( false , handler . getValueAs ( "" , Boolean . TYPE ) ) ; assertEquals ( true , handler . getValueAs ( "" , Boolean . class ) ) ; assertEquals ( false , handler . getValueAs ( "" , Boolean . class ) ) ; } @ Test public void testInteger ( ) throws Exception { assertTrue ( handler . isSupported ( Integer . TYPE ) ) ; assertTrue ( handler . isSupported ( Integer . class ) ) ; assertEquals ( , handler . getValueAs ( "" , Integer . TYPE ) ) ; assertEquals ( - , handler . getValueAs ( "" , Integer . TYPE ) ) ; assertEquals ( , handler . getValueAs ( "" , Integer . class ) ) ; assertEquals ( - , handler . getValueAs ( "" , Integer . class ) ) ; } @ Test public void testByte ( ) throws Exception { assertTrue ( handler . isSupported ( Byte . TYPE ) ) ; assertTrue ( handler . isSupported ( Byte . class ) ) ; assertEquals ( ( byte ) , handler . getValueAs ( "" , Byte . TYPE ) ) ; assertEquals ( ( byte ) - , handler . getValueAs ( "" , Byte . TYPE ) ) ; assertEquals ( ( byte ) , handler . getValueAs ( "" , Byte . class ) ) ; assertEquals ( ( byte ) - , handler . getValueAs ( "" , Byte . class ) ) ; } @ Test public void testShort ( ) throws Exception { assertTrue ( handler . isSupported ( Short . TYPE ) ) ; assertTrue ( handler . isSupported ( Short . class ) ) ; assertEquals ( ( short ) , handler . getValueAs ( "" , Short . TYPE ) ) ; assertEquals ( ( short ) - , handler . getValueAs ( "" , Short . TYPE ) ) ; assertEquals ( ( short ) , handler . getValueAs ( "" , Short . class ) ) ; assertEquals ( ( short ) - , handler . getValueAs ( "" , Short . class ) ) ; } @ Test public void testLong ( ) throws Exception { assertTrue ( handler . isSupported ( Long . TYPE ) ) ; assertTrue ( handler . isSupported ( Long . class ) ) ; assertEquals ( ( long ) , handler . getValueAs ( "" , Long . TYPE ) ) ; assertEquals ( ( long ) - , handler . getValueAs ( "" , Long . TYPE ) ) ; assertEquals ( ( long ) , handler . getValueAs ( "" , Long . class ) ) ; assertEquals ( ( long ) - , handler . getValueAs ( "" , Long . class ) ) ; } @ Test public void testCharacter ( ) throws Exception { assertTrue ( handler . isSupported ( Character . TYPE ) ) ; assertTrue ( handler . isSupported ( Character . class ) ) ; assertEquals ( '' , handler . getValueAs ( "" , Character . TYPE ) ) ; assertEquals ( '' , handler . getValueAs ( "" , Character . class ) ) ; } @ Test public void testFloat ( ) throws Exception { assertTrue ( handler . isSupported ( Float . TYPE ) ) ; assertTrue ( handler . isSupported ( Float . class ) ) ; assertEquals ( , handler . getValueAs ( "" , Float . TYPE ) ) ; assertEquals ( , handler . getValueAs ( "" , Float . class ) ) ; } @ Test public void testDouble ( ) throws Exception { assertTrue ( handler . isSupported ( Double . TYPE ) ) ; assertTrue ( handler . isSupported ( Double . class ) ) ; assertEquals ( , handler . getValueAs ( "" , Double . TYPE ) ) ; assertEquals ( , handler . getValueAs ( "" , Double . class ) ) ; } @ Test public void testString ( ) throws Exception { assertTrue ( handler . isSupported ( String . class ) ) ; assertEquals ( "" , handler . getValueAs ( "" , String . class ) ) ; } }
package org . vaadin . teemu . clara . util ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import org . junit . Test ; import com . vaadin . ui . Button ; public class ReflectionUtilsTest { public static class ClassToExamine { public void setFooBar ( ) { } public void setFooBar ( String foo ) { } public void setFooBar ( int foo ) { } public void setFooBar ( String foo , int bar ) { } } @ Test public void test_getMethodsByNameAndParamCount ( ) { assertEquals ( , ReflectionUtils . getMethodsByNameAndParamCount ( ClassToExamine . class , "" , ) . size ( ) ) ; assertEquals ( , ReflectionUtils . getMethodsByNameAndParamCount ( ClassToExamine . class , "" , ) . size ( ) ) ; assertEquals ( , ReflectionUtils . getMethodsByNameAndParamCount ( ClassToExamine . class , "" , ) . size ( ) ) ; assertEquals ( , ReflectionUtils . getMethodsByNameAndParamCount ( ClassToExamine . class , "" , ) . size ( ) ) ; assertEquals ( , ReflectionUtils . getMethodsByNameAndParamCount ( ClassToExamine . class , "" , ) . size ( ) ) ; } @ Test public void test_isComponent ( ) { assertTrue ( ReflectionUtils . isComponent ( Button . class ) ) ; assertFalse ( ReflectionUtils . isComponent ( ClassToExamine . class ) ) ; assertFalse ( ReflectionUtils . isComponent ( null ) ) ; } }
package org . vaadin . teemu . clara ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . io . InputStream ; import org . junit . Before ; import org . junit . Test ; import org . vaadin . teemu . clara . inflater . LayoutInflater ; import org . vaadin . teemu . clara . inflater . LayoutInflaterException ; import com . vaadin . ui . Button ; import com . vaadin . ui . Component ; import com . vaadin . ui . VerticalLayout ; public class LayoutInflaterTest { private LayoutInflater inflater ; @ Before public void setUp ( ) { inflater = new LayoutInflater ( ) ; } private InputStream getXml ( String fileName ) { return getClass ( ) . getClassLoader ( ) . getResourceAsStream ( fileName ) ; } @ Test public void inflate_singleButton_buttonInstantiated ( ) { Button button = ( Button ) inflater . inflate ( getXml ( "" ) ) ; assertEquals ( com . vaadin . ui . Button . class , button . getClass ( ) ) ; assertEquals ( "" , button . getCaption ( ) ) ; assertEquals ( true , button . isReadOnly ( ) ) ; } @ Test public void inflate_singleButtonNoNamespace_buttonInstantiated ( ) { Component button = inflater . inflate ( getXml ( "" ) ) ; assertEquals ( com . vaadin . ui . Button . class , button . getClass ( ) ) ; assertEquals ( "" , button . getCaption ( ) ) ; assertEquals ( true , button . isReadOnly ( ) ) ; } @ Test public void inflate_singleLayout_layoutWithMarginsInstantiated ( ) { Component layout = inflater . inflate ( getXml ( "" ) ) ; assertEquals ( com . vaadin . ui . VerticalLayout . class , layout . getClass ( ) ) ; assertTrue ( ( ( VerticalLayout ) layout ) . getMargin ( ) . hasTop ( ) ) ; assertFalse ( ( ( VerticalLayout ) layout ) . getMargin ( ) . hasRight ( ) ) ; assertFalse ( ( ( VerticalLayout ) layout ) . getMargin ( ) . hasBottom ( ) ) ; assertTrue ( ( ( VerticalLayout ) layout ) . getMargin ( ) . hasLeft ( ) ) ; } @ Test public void inflate_layoutAttributes_layoutAttributesApplied ( ) { Component layout = inflater . inflate ( getXml ( "" ) ) ; assertEquals ( com . vaadin . ui . VerticalLayout . class , layout . getClass ( ) ) ; VerticalLayout verticalLayout = ( VerticalLayout ) layout ; Component button = verticalLayout . getComponentIterator ( ) . next ( ) ; assertEquals ( , verticalLayout . getExpandRatio ( button ) , ) ; } @ Test public void inflate_componentHasWidth_widthAttributeApplied ( ) { Component layout = inflater . inflate ( getXml ( "" ) ) ; Button button200px = ( Button ) Clara . findComponentById ( layout , "" ) ; assertEquals ( , button200px . getWidth ( ) , ) ; } @ Test public void inflate_addAttributeInterceptor_valueInterceptedCorrectly ( ) { LayoutInflater interceptingInflater = new LayoutInflater ( ) ; AttributeInterceptor interceptor = new AttributeInterceptor ( ) { @ Override public void intercept ( AttributeContext attributeContext ) { if ( attributeContext . getValue ( ) . getClass ( ) == String . class ) { String value = ( String ) attributeContext . getValue ( ) ; if ( value . startsWith ( "" ) ) { attributeContext . setValue ( "" ) ; } } try { attributeContext . proceed ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ; interceptingInflater . addInterceptor ( interceptor ) ; Component interceptedView = interceptingInflater . inflate ( getXml ( "" ) ) ; Component view = inflater . inflate ( getXml ( "" ) ) ; Button button200px = ( Button ) Clara . findComponentById ( interceptedView , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; button200px = ( Button ) Clara . findComponentById ( view , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; } @ Test public void inflate_singleButton_findByIdWorks ( ) { Component view = inflater . inflate ( getXml ( "" ) ) ; assertEquals ( com . vaadin . ui . Button . class , Clara . findComponentById ( view , "" ) . getClass ( ) ) ; assertEquals ( null , Clara . findComponentById ( view , "" ) ) ; } @ Test ( expected = LayoutInflaterException . class ) public void inflate_nonComponent_exceptionThrown ( ) { inflater . inflate ( getXml ( "" ) ) ; } @ Test ( expected = LayoutInflaterException . class ) public void inflate_duplicateId_exceptionThrown ( ) { inflater . inflate ( getXml ( "" ) ) ; } @ Test ( expected = LayoutInflaterException . class ) public void inflate_IOException_exceptionThrown ( ) { inflater . inflate ( new InputStream ( ) { @ Override public int read ( ) throws IOException { throw new IOException ( ) ; } } ) ; } @ Test ( expected = LayoutInflaterException . class ) public void inflate_invalidXml_exceptionThrown ( ) { inflater . inflate ( new ByteArrayInputStream ( "" . getBytes ( ) ) ) ; } }
package org . vaadin . teemu . clara ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . InputStream ; import org . junit . Before ; import org . junit . Test ; import org . vaadin . teemu . clara . binder . annotation . EventHandler ; import com . vaadin . ui . Button ; import com . vaadin . ui . Component ; public class ClaraIntegrationTest { private InputStream xml ; private Controller controller ; private AttributeInterceptor firstInterceptor ; private AttributeInterceptor secondInterceptor ; public static class Controller { private boolean clicked ; @ EventHandler ( "" ) public void clicked ( Button . ClickEvent event ) { clicked = true ; } } @ Before public void setUp ( ) { xml = getXml ( "" ) ; controller = new Controller ( ) ; firstInterceptor = getInterceptor ( ) ; secondInterceptor = getSecondInterceptor ( ) ; } @ Test public void testCreateMethod_usingAllParametersWithTwoInterceptors_interceptorsAndControllerCalled ( ) { Component layout = Clara . create ( xml , controller , firstInterceptor , secondInterceptor ) ; Button button200px = ( Button ) Clara . findComponentById ( layout , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; assertFalse ( controller . clicked ) ; button200px . click ( ) ; assertTrue ( controller . clicked ) ; } @ Test public void testCreateMethod_usingAllParameters_interceptorAndControllerCalled ( ) { Component layout = Clara . create ( xml , controller , firstInterceptor ) ; Button button200px = ( Button ) Clara . findComponentById ( layout , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; assertFalse ( controller . clicked ) ; button200px . click ( ) ; assertTrue ( controller . clicked ) ; } @ Test public void testCreateMethod_usingOnlyController_controllerCalled ( ) { Component layout = Clara . create ( xml , controller ) ; Button button200px = ( Button ) Clara . findComponentById ( layout , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; assertFalse ( controller . clicked ) ; button200px . click ( ) ; assertTrue ( controller . clicked ) ; } @ Test public void testCreateMethod_usingNoParameters_componentInflatedCorrectly ( ) { Component layout = Clara . create ( xml ) ; Button button200px = ( Button ) Clara . findComponentById ( layout , "" ) ; assertEquals ( "" , button200px . getCaption ( ) ) ; } private InputStream getXml ( String fileName ) { return getClass ( ) . getClassLoader ( ) . getResourceAsStream ( fileName ) ; } public AttributeInterceptor getInterceptor ( ) { return new AttributeInterceptor ( ) { @ Override public void intercept ( AttributeContext attributeContext ) { if ( attributeContext . getValue ( ) . getClass ( ) == String . class ) { String value = ( String ) attributeContext . getValue ( ) ; if ( value . startsWith ( "" ) ) { attributeContext . setValue ( "" ) ; } } try { attributeContext . proceed ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ; } public AttributeInterceptor getSecondInterceptor ( ) { return new AttributeInterceptor ( ) { @ Override public void intercept ( AttributeContext attributeContext ) { if ( attributeContext . getValue ( ) . getClass ( ) == String . class ) { String value = ( String ) attributeContext . getValue ( ) ; if ( value . startsWith ( "" ) ) { attributeContext . setValue ( "" ) ; } } try { attributeContext . proceed ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } ; } }
package org . vaadin . teemu . clara ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import java . io . InputStream ; import java . lang . reflect . Method ; import java . util . Date ; import org . junit . Before ; import org . junit . Test ; import org . vaadin . teemu . clara . binder . Binder ; import org . vaadin . teemu . clara . binder . annotation . DataSource ; import org . vaadin . teemu . clara . binder . annotation . EventHandler ; import org . vaadin . teemu . clara . inflater . LayoutInflater ; import com . vaadin . data . Property ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; import com . vaadin . ui . DateField ; public class BinderTest { private LayoutInflater inflater ; private boolean clickCalled ; @ Before public void setUp ( ) { inflater = new LayoutInflater ( ) ; } private InputStream getXml ( String fileName ) { return getClass ( ) . getClassLoader ( ) . getResourceAsStream ( fileName ) ; } @ EventHandler ( "" ) public void handleButtonClick ( ClickEvent event ) { clickCalled = true ; } @ DataSource ( "" ) public Property getDataSource ( ) { Date date = new Date ( ) ; return new com . vaadin . data . util . ObjectProperty < Date > ( date ) ; } @ Test public void bind_clickListener_clickListenerInvoked ( ) { Button button = ( Button ) inflater . inflate ( getXml ( "" ) ) ; Binder binder = new Binder ( ) ; binder . bind ( button , this ) ; clickCalled = false ; simulateButtonClick ( button ) ; assertTrue ( "" , clickCalled ) ; } @ Test public void bind_dataSource_dataSourceAttached ( ) { DateField view = ( DateField ) inflater . inflate ( getXml ( "" ) ) ; Binder binder = new Binder ( ) ; binder . bind ( view , this ) ; Date value = ( Date ) view . getValue ( ) ; assertEquals ( , value . getTime ( ) ) ; } private void simulateButtonClick ( Button button ) { Method fireClick ; try { fireClick = Button . class . getDeclaredMethod ( "" ) ; fireClick . setAccessible ( true ) ; fireClick . invoke ( button ) ; } catch ( Exception e ) { throw new RuntimeException ( "" , e ) ; } } }
package org . vaadin . teemu . clara ; import com . vaadin . ui . Component ; public interface AttributeInterceptor { void intercept ( AttributeContext invocationContext ) ; }
package org . vaadin . teemu . clara ; import java . lang . reflect . Method ; public abstract class AttributeContext { private Object value ; private Method setter ; public AttributeContext ( Method setter , Object value ) { this . value = value ; this . setter = setter ; } public abstract void proceed ( ) throws Exception ; public Object getValue ( ) { return value ; } public void setValue ( Object value ) { this . value = value ; } public Method getSetter ( ) { return setter ; } }
package org . vaadin . teemu . clara . binder ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . lang . reflect . Proxy ; import java . util . Set ; import java . util . logging . Logger ; import org . vaadin . teemu . clara . Clara ; import org . vaadin . teemu . clara . binder . annotation . DataSource ; import org . vaadin . teemu . clara . binder . annotation . EventHandler ; import org . vaadin . teemu . clara . util . ReflectionUtils ; import com . vaadin . data . Container ; import com . vaadin . data . Item ; import com . vaadin . data . Property ; import com . vaadin . ui . Component ; public class Binder { protected Logger getLogger ( ) { return Logger . getLogger ( Binder . class . getName ( ) ) ; } public void bind ( Component componentRoot , Object controller ) { Method [ ] methods = controller . getClass ( ) . getMethods ( ) ; for ( Method method : methods ) { if ( method . isAnnotationPresent ( DataSource . class ) ) { bindDataSource ( componentRoot , controller , method , method . getAnnotation ( DataSource . class ) ) ; } if ( method . isAnnotationPresent ( EventHandler . class ) ) { bindEventHandler ( componentRoot , controller , method , method . getAnnotation ( EventHandler . class ) ) ; } } } private void bindEventHandler ( Component componentRoot , Object controller , Method method , EventHandler eventListener ) { String componentId = eventListener . value ( ) ; Component component = Clara . findComponentById ( componentRoot , componentId ) ; Class < ? > eventClass = ( method . getParameterTypes ( ) . length > ? method . getParameterTypes ( ) [ ] : null ) ; if ( eventClass != null && component != null ) { Method addListenerMethod = getAddListenerMethod ( component . getClass ( ) , eventClass ) ; if ( addListenerMethod != null ) { try { Object listener = createListenerProxy ( addListenerMethod . getParameterTypes ( ) [ ] , eventClass , method , controller ) ; addListenerMethod . invoke ( component , listener ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } } } private Object createListenerProxy ( Class < ? > listenerClass , final Class < ? > eventClass , final Method listenerMethod , final Object controller ) { Object proxy = Proxy . newProxyInstance ( listenerClass . getClassLoader ( ) , new Class < ? > [ ] { listenerClass } , new InvocationHandler ( ) { public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { if ( args != null && args . length > && eventClass . isAssignableFrom ( args [ ] . getClass ( ) ) ) { getLogger ( ) . fine ( String . format ( "" , method . getName ( ) , listenerMethod . getName ( ) ) ) ; return listenerMethod . invoke ( controller , args ) ; } getLogger ( ) . fine ( String . format ( "" , method . getName ( ) , controller . getClass ( ) ) ) ; return method . invoke ( controller , args ) ; } } ) ; getLogger ( ) . fine ( String . format ( "" , listenerClass ) ) ; return proxy ; } private Method getAddListenerMethod ( Class < ? extends Component > componentClass , Class < ? > eventClass ) { Set < Method > methods = ReflectionUtils . getMethodsByNameAndParamCount ( componentClass , "" , ) ; for ( Method method : methods ) { Class < ? > listenerClass = method . getParameterTypes ( ) [ ] ; Method [ ] listenerMethods = listenerClass . getMethods ( ) ; for ( Method listenerMethod : listenerMethods ) { if ( listenerMethod . getParameterTypes ( ) . length == && listenerMethod . getParameterTypes ( ) [ ] . equals ( eventClass ) ) { return method ; } } } return null ; } private void bindDataSource ( Component componentRoot , Object controller , Method method , DataSource dataSource ) { String componentId = dataSource . value ( ) ; Component component = Clara . findComponentById ( componentRoot , componentId ) ; Class < ? > dataSourceClass = method . getReturnType ( ) ; try { if ( isContainer ( dataSourceClass ) && component instanceof Container . Viewer ) { ( ( Container . Viewer ) component ) . setContainerDataSource ( ( Container ) method . invoke ( controller ) ) ; } else if ( isProperty ( dataSourceClass ) && component instanceof Property . Viewer ) { ( ( Property . Viewer ) component ) . setPropertyDataSource ( ( Property ) method . invoke ( controller ) ) ; } else if ( isItem ( dataSourceClass ) && component instanceof Item . Viewer ) { ( ( Item . Viewer ) component ) . setItemDataSource ( ( Item ) method . invoke ( controller ) ) ; } } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } private boolean isContainer ( Class < ? > dataSourceClass ) { return Container . class . isAssignableFrom ( dataSourceClass ) ; } private boolean isItem ( Class < ? > dataSourceClass ) { return Item . class . isAssignableFrom ( dataSourceClass ) ; } private boolean isProperty ( Class < ? > dataSourceClass ) { return Property . class . isAssignableFrom ( dataSourceClass ) ; } }
package org . vaadin . teemu . clara . binder . annotation ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import com . vaadin . ui . Button ; import com . vaadin . ui . Button . ClickEvent ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( ElementType . METHOD ) public @ interface EventHandler { String value ( ) ; }
package org . vaadin . teemu . clara . binder . annotation ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import com . vaadin . data . Container ; import com . vaadin . data . Item ; import com . vaadin . data . Property ; @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( ElementType . METHOD ) public @ interface DataSource { String value ( ) ; }
package org . vaadin . teemu . clara . util ; import java . lang . reflect . Method ; import java . util . HashSet ; import java . util . Set ; import com . vaadin . ui . Component ; public class ReflectionUtils { private ReflectionUtils ( ) { throw new AssertionError ( ) ; } public static Set < Method > getMethodsByNameAndParamCount ( Class < ? > clazz , String methodName , int numberOfParams ) { Set < Method > methods = new HashSet < Method > ( ) ; for ( Method method : clazz . getMethods ( ) ) { if ( method . getName ( ) . equals ( methodName ) && method . getParameterTypes ( ) . length == numberOfParams ) { methods . add ( method ) ; } } return methods ; } public static boolean isComponent ( Class < ? > componentClass ) { if ( componentClass != null ) { return Component . class . isAssignableFrom ( componentClass ) ; } else { return false ; } } }
package org . vaadin . teemu . clara ; import java . io . InputStream ; import java . util . Iterator ; import org . vaadin . teemu . clara . binder . Binder ; import org . vaadin . teemu . clara . inflater . LayoutInflater ; import com . vaadin . ui . Component ; import com . vaadin . ui . ComponentContainer ; public class Clara { public static Component create ( InputStream xml ) { return create ( xml , null ) ; } public static Component create ( InputStream xml , Object controller , AttributeInterceptor ... interceptors ) { LayoutInflater inflater = new LayoutInflater ( ) ; if ( interceptors != null ) { for ( AttributeInterceptor interceptor : interceptors ) { inflater . addInterceptor ( interceptor ) ; } } Component result = inflater . inflate ( xml ) ; if ( controller != null ) { Binder binder = new Binder ( ) ; binder . bind ( result , controller ) ; } return result ; } public static Component findComponentById ( Component root , String componentId ) { if ( componentId == null ) { throw new IllegalArgumentException ( "" ) ; } if ( componentId . equals ( root . getDebugId ( ) ) ) { return root ; } else if ( root instanceof ComponentContainer ) { for ( Iterator < Component > i = ( ( ComponentContainer ) root ) . getComponentIterator ( ) ; i . hasNext ( ) ; ) { Component c = findComponentById ( i . next ( ) , componentId ) ; if ( c != null ) { return c ; } } } return null ; } }
package org . vaadin . teemu . clara . inflater ; public interface AttributeParser { boolean isSupported ( Class < ? > valueType ) ; Object getValueAs ( String value , Class < ? > valueType ) ; }
package org . vaadin . teemu . clara . inflater ; import java . util . HashMap ; import java . util . Map ; import java . util . Stack ; import org . xml . sax . Attributes ; import org . xml . sax . SAXException ; import org . xml . sax . helpers . DefaultHandler ; import com . vaadin . ui . Component ; import com . vaadin . ui . ComponentContainer ; class LayoutInflaterContentHandler extends DefaultHandler { private static final String URN_NAMESPACE_ID = "" ; private static final String DEFAULT_NAMESPACE = "" + URN_NAMESPACE_ID + "" ; private static final String LAYOUT_ATTRIBUTE_NAMESPACE = "" ; private Stack < Component > componentStack = new Stack < Component > ( ) ; private ComponentContainer currentContainer ; private Component currentComponent ; private Component root ; private final ComponentManager componentFactory ; private final Map < String , Component > idMap = new HashMap < String , Component > ( ) ; public LayoutInflaterContentHandler ( ComponentManager componentFactory ) { this . componentFactory = componentFactory ; } public Component getRoot ( ) { return root ; } @ Override public void startElement ( String uri , String localName , String qName , Attributes attributes ) throws SAXException { super . startElement ( uri , localName , qName , attributes ) ; if ( uri == null || uri . length ( ) == ) { uri = DEFAULT_NAMESPACE ; } currentComponent = null ; if ( uri . startsWith ( "" + URN_NAMESPACE_ID + "" ) ) { String packageName = uri . substring ( ( "" + URN_NAMESPACE_ID + "" ) . length ( ) ) ; String className = localName ; Map < String , String > attributeMap = getAttributeMap ( attributes ) ; Map < String , String > layoutAttributeMap = getLayoutAttributeMap ( attributes ) ; currentComponent = componentFactory . createComponent ( packageName , className , attributeMap ) ; if ( currentComponent . getDebugId ( ) != null ) { idMap . put ( currentComponent . getDebugId ( ) , currentComponent ) ; } if ( root == null ) { root = currentComponent ; } if ( currentContainer != null ) { currentContainer . addComponent ( currentComponent ) ; componentFactory . applyLayoutAttributes ( currentContainer , currentComponent , layoutAttributeMap ) ; } if ( currentComponent instanceof ComponentContainer ) { currentContainer = ( ComponentContainer ) currentComponent ; } componentStack . push ( currentComponent ) ; } } private Map < String , String > getAttributeMap ( Attributes attributes ) { Map < String , String > attributeMap = new HashMap < String , String > ( attributes . getLength ( ) ) ; for ( int i = ; i < attributes . getLength ( ) ; i ++ ) { if ( ! attributes . getURI ( i ) . equals ( LAYOUT_ATTRIBUTE_NAMESPACE ) ) { String value = attributes . getValue ( i ) ; String name = attributes . getLocalName ( i ) ; if ( name . equals ( "" ) ) { if ( idMap . containsKey ( value ) ) { throw new LayoutInflaterException ( String . format ( "" , value ) ) ; } name = "" ; } attributeMap . put ( name , value ) ; } } return attributeMap ; } private Map < String , String > getLayoutAttributeMap ( Attributes attributes ) { Map < String , String > attributeMap = new HashMap < String , String > ( attributes . getLength ( ) ) ; for ( int i = ; i < attributes . getLength ( ) ; i ++ ) { if ( attributes . getURI ( i ) . equals ( LAYOUT_ATTRIBUTE_NAMESPACE ) ) { String value = attributes . getValue ( i ) ; String name = attributes . getLocalName ( i ) ; attributeMap . put ( name , value ) ; } } return attributeMap ; } @ Override public void endElement ( String uri , String localName , String qName ) throws SAXException { super . endElement ( uri , localName , qName ) ; Component component = componentStack . pop ( ) ; if ( component instanceof ComponentContainer ) { currentContainer = ( ComponentContainer ) component . getParent ( ) ; } } public Map < String , Component > getIdMap ( ) { return idMap ; } }
package org . vaadin . teemu . clara . inflater ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . util . ArrayList ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . logging . Logger ; import org . vaadin . teemu . clara . AttributeContext ; import org . vaadin . teemu . clara . AttributeInterceptor ; import org . vaadin . teemu . clara . util . ReflectionUtils ; import com . vaadin . ui . Component ; import com . vaadin . ui . ComponentContainer ; public class DefaultComponentManager implements ComponentManager { private List < AttributeParser > attributeParsers = new ArrayList < AttributeParser > ( ) ; private List < AttributeInterceptor > interceptors = new ArrayList < AttributeInterceptor > ( ) ; private Logger getLogger ( ) { return Logger . getLogger ( DefaultComponentManager . class . getName ( ) ) ; } public DefaultComponentManager ( ) { addAttributeParser ( new PrimitiveAttributeParser ( ) ) ; addAttributeParser ( new VaadinAttributeParser ( ) ) ; } public void addAttributeParser ( AttributeParser handler ) { attributeParsers . add ( handler ) ; } public void removeAttributeParser ( AttributeParser handler ) { attributeParsers . remove ( handler ) ; } public Component createComponent ( String namespace , String name , Map < String , String > attributes ) throws ComponentInstantiationException { try { Class < ? extends Component > componentClass = resolveComponentClass ( namespace , name ) ; Component newComponent = componentClass . newInstance ( ) ; handleAttributes ( newComponent , attributes ) ; return newComponent ; } catch ( Exception e ) { throw createException ( e , namespace , name ) ; } } protected ComponentInstantiationException createException ( Exception e , String namespace , String name ) { String message = String . format ( "" , namespace , name ) ; if ( e != null ) { return new ComponentInstantiationException ( message , e ) ; } else { return new ComponentInstantiationException ( message ) ; } } @ SuppressWarnings ( "" ) protected Class < ? extends Component > resolveComponentClass ( String namespace , String name ) throws ClassNotFoundException { String qualifiedClassName = namespace + "" + name ; Class < ? > componentClass = null ; componentClass = Class . forName ( qualifiedClassName ) ; if ( ReflectionUtils . isComponent ( componentClass ) ) { return ( Class < ? extends Component > ) componentClass ; } else { throw new IllegalArgumentException ( String . format ( "" , componentClass . getName ( ) , Component . class . getName ( ) ) ) ; } } protected void handleAttributes ( Component component , Map < String , String > attributes ) { getLogger ( ) . fine ( attributes . toString ( ) ) ; try { for ( Map . Entry < String , String > attribute : attributes . entrySet ( ) ) { Method setter = getSetter ( attribute . getKey ( ) , component . getClass ( ) ) ; if ( setter != null ) { AttributeParser handler = getHandlerFor ( setter . getParameterTypes ( ) [ ] ) ; if ( handler != null ) { String attributeValue = attribute . getValue ( ) ; if ( attributeValue == null || attributeValue . length ( ) == ) { invokeWithInterceptors ( setter , component , attributeValue ) ; } else { invokeWithInterceptors ( setter , component , handler . getValueAs ( attributeValue , setter . getParameterTypes ( ) [ ] ) ) ; } } } } } catch ( SecurityException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } protected void invokeWithInterceptors ( final Method methodToInvoke , final Object obj , final Object ... args ) throws IllegalArgumentException , IllegalAccessException , InvocationTargetException { if ( interceptors . isEmpty ( ) ) { methodToInvoke . invoke ( obj , args ) ; } else { final LinkedList < AttributeInterceptor > interceptorsCopy = new LinkedList < AttributeInterceptor > ( interceptors ) ; AttributeInterceptor interceptor = interceptorsCopy . pop ( ) ; interceptor . intercept ( new AttributeContext ( methodToInvoke , args . length > ? args [ ] : args [ ] ) { @ Override public void proceed ( ) throws Exception { if ( interceptorsCopy . size ( ) > ) { interceptorsCopy . pop ( ) . intercept ( this ) ; } else { if ( args . length > ) { methodToInvoke . invoke ( obj , args [ ] , this . getValue ( ) ) ; } else { methodToInvoke . invoke ( obj , this . getValue ( ) ) ; } } } } ) ; } } protected AttributeParser getHandlerFor ( Class < ? > type ) { for ( AttributeParser handler : attributeParsers ) { if ( handler . isSupported ( type ) ) { return handler ; } } return null ; } public void applyLayoutAttributes ( ComponentContainer container , Component component , Map < String , String > attributes ) { if ( ! component . getParent ( ) . equals ( container ) ) { throw new IllegalStateException ( "" ) ; } try { for ( Map . Entry < String , String > attribute : attributes . entrySet ( ) ) { Method layoutMethod = getLayoutMethod ( container . getClass ( ) , attribute . getKey ( ) ) ; if ( layoutMethod != null ) { AttributeParser handler = getHandlerFor ( layoutMethod . getParameterTypes ( ) [ ] ) ; if ( handler != null ) { invokeWithInterceptors ( layoutMethod , container , component , handler . getValueAs ( attribute . getValue ( ) , layoutMethod . getParameterTypes ( ) [ ] ) ) ; } } } } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } } private Method getSetter ( String propertyName , Class < ? extends Component > componentClass ) { Set < Method > writeMethods = ReflectionUtils . getMethodsByNameAndParamCount ( componentClass , "" + capitalize ( propertyName ) , ) ; return selectPreferredMethod ( writeMethods , ) ; } private static String capitalize ( String propertyName ) { if ( propertyName . length ( ) > ) { return propertyName . substring ( , ) . toUpperCase ( ) + propertyName . substring ( ) ; } return "" ; } private Method getLayoutMethod ( Class < ? extends ComponentContainer > layoutClass , String propertyName ) { String methodToLookFor = "" + propertyName . substring ( , ) . toUpperCase ( ) + propertyName . substring ( ) ; Set < Method > settersWithTwoParams = ReflectionUtils . getMethodsByNameAndParamCount ( layoutClass , methodToLookFor , ) ; return selectPreferredMethod ( settersWithTwoParams , ) ; } private Method selectPreferredMethod ( Set < Method > methods , int dataParamIndex ) { Method candidate = null ; for ( Method method : methods ) { if ( dataParamIndex > && ! ReflectionUtils . isComponent ( method . getParameterTypes ( ) [ ] ) ) { continue ; } Class < ? > parameterType = method . getParameterTypes ( ) [ dataParamIndex ] ; AttributeParser handler = getHandlerFor ( parameterType ) ; if ( handler != null && ! ( handler instanceof PrimitiveAttributeParser ) ) { return method ; } if ( method . isAnnotationPresent ( Deprecated . class ) || ! parameterType . equals ( String . class ) ) { candidate = method ; } else { return method ; } } return candidate ; } @ Override public void addInterceptor ( AttributeInterceptor attributeInterceptor ) { interceptors . add ( attributeInterceptor ) ; } @ Override public void removeInterceptor ( AttributeInterceptor attributeInterceptor ) { interceptors . remove ( attributeInterceptor ) ; } }
package org . vaadin . teemu . clara . inflater ; @ SuppressWarnings ( "" ) public class LayoutInflaterException extends RuntimeException { public LayoutInflaterException ( String message ) { super ( message ) ; } public LayoutInflaterException ( String message , Throwable e ) { super ( message , e ) ; } public LayoutInflaterException ( Throwable e ) { super ( e ) ; } }
package org . vaadin . teemu . clara . inflater ; @ SuppressWarnings ( "" ) public class ComponentInstantiationException extends RuntimeException { public ComponentInstantiationException ( ) { super ( ) ; } public ComponentInstantiationException ( String message ) { super ( message ) ; } public ComponentInstantiationException ( String message , Throwable e ) { super ( message , e ) ; } }
package org . vaadin . teemu . clara . inflater ; import java . util . Arrays ; import java . util . List ; public class PrimitiveAttributeParser implements AttributeParser { @ SuppressWarnings ( "" ) private static final List < Class < ? > > supportedClasses = Arrays . asList ( String . class , Object . class , Boolean . class , Integer . class , Byte . class , Short . class , Long . class , Character . class , Float . class , Double . class ) ; public boolean isSupported ( Class < ? > valueType ) { return valueType != null && ( valueType . isPrimitive ( ) || supportedClasses . contains ( valueType ) ) ; } public Object getValueAs ( String value , Class < ? > type ) { if ( type == String . class || type == Object . class ) { return value ; } if ( type == Boolean . TYPE || type == Boolean . class ) { return Boolean . valueOf ( value ) ; } if ( type == Integer . TYPE || type == Integer . class ) { return Integer . valueOf ( value ) ; } if ( type == Byte . TYPE || type == Byte . class ) { return Byte . valueOf ( value ) ; } if ( type == Short . TYPE || type == Short . class ) { return Short . valueOf ( value ) ; } if ( type == Long . TYPE || type == Long . class ) { return Long . valueOf ( value ) ; } if ( type == Character . TYPE || type == Character . class ) { return value . charAt ( ) ; } if ( type == Float . TYPE || type == Float . class ) { return Float . valueOf ( value ) ; } if ( type == Double . TYPE || type == Double . class ) { return Double . valueOf ( value ) ; } return null ; } }
package org . vaadin . teemu . clara . inflater ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . InputStream ; import org . vaadin . teemu . clara . AttributeInterceptor ; import org . xml . sax . InputSource ; import org . xml . sax . SAXException ; import org . xml . sax . XMLReader ; import org . xml . sax . helpers . XMLReaderFactory ; import com . vaadin . Application ; import com . vaadin . service . ApplicationContext ; import com . vaadin . ui . Component ; public class LayoutInflater { private ComponentManager componentManager = new DefaultComponentManager ( ) ; public void setComponentManager ( ComponentManager componentManager ) { this . componentManager = componentManager ; } public Component inflate ( Application app , String xmlFile ) throws LayoutInflaterException { File layoutFile = getLayoutFile ( app . getContext ( ) , xmlFile ) ; try { return inflate ( new FileInputStream ( layoutFile ) ) ; } catch ( FileNotFoundException e ) { throw new LayoutInflaterException ( "" + layoutFile . getAbsolutePath ( ) + "" ) ; } } public Component inflate ( InputStream xml ) throws LayoutInflaterException { try { LayoutInflaterContentHandler handler = new LayoutInflaterContentHandler ( componentManager ) ; XMLReader parser = XMLReaderFactory . createXMLReader ( ) ; parser . setContentHandler ( handler ) ; parser . parse ( new InputSource ( xml ) ) ; return handler . getRoot ( ) ; } catch ( SAXException e ) { throw new LayoutInflaterException ( e ) ; } catch ( IOException e ) { throw new LayoutInflaterException ( e ) ; } catch ( ComponentInstantiationException e ) { throw new LayoutInflaterException ( e . getMessage ( ) , e ) ; } } public void addInterceptor ( AttributeInterceptor attributeInterceptor ) { componentManager . addInterceptor ( attributeInterceptor ) ; } public void removeInterceptor ( AttributeInterceptor attributeInterceptor ) { componentManager . removeInterceptor ( attributeInterceptor ) ; } private static File getLayoutFile ( ApplicationContext context , String filepath ) { return new File ( context . getBaseDirectory ( ) . getAbsoluteFile ( ) + File . separator + "" + File . separator + "" + File . separator + filepath ) ; } }
package org . vaadin . teemu . clara . inflater ; import java . util . Map ; import org . vaadin . teemu . clara . AttributeInterceptor ; import com . vaadin . ui . Component ; import com . vaadin . ui . ComponentContainer ; public interface ComponentManager { Component createComponent ( String namespace , String name , Map < String , String > attributes ) throws ComponentInstantiationException ; void applyLayoutAttributes ( ComponentContainer container , Component component , Map < String , String > attributes ) ; void addInterceptor ( AttributeInterceptor attributeInterceptor ) ; void removeInterceptor ( AttributeInterceptor attributeInterceptor ) ; }
package org . vaadin . teemu . clara . inflater ; import java . util . HashMap ; import java . util . Map ; import com . vaadin . ui . Alignment ; import com . vaadin . ui . Layout . MarginInfo ; public class VaadinAttributeParser implements AttributeParser { protected static final Map < String , Alignment > alignmentMap ; static { alignmentMap = new HashMap < String , Alignment > ( ) ; alignmentMap . put ( "" , Alignment . BOTTOM_CENTER ) ; alignmentMap . put ( "" , Alignment . BOTTOM_LEFT ) ; alignmentMap . put ( "" , Alignment . BOTTOM_RIGHT ) ; alignmentMap . put ( "" , Alignment . MIDDLE_CENTER ) ; alignmentMap . put ( "" , Alignment . MIDDLE_LEFT ) ; alignmentMap . put ( "" , Alignment . MIDDLE_RIGHT ) ; alignmentMap . put ( "" , Alignment . TOP_CENTER ) ; alignmentMap . put ( "" , Alignment . TOP_LEFT ) ; alignmentMap . put ( "" , Alignment . TOP_RIGHT ) ; } public boolean isSupported ( Class < ? > valueType ) { return valueType != null && ( valueType == MarginInfo . class || valueType == Alignment . class ) ; } public Object getValueAs ( String value , Class < ? > valueType ) { if ( valueType == MarginInfo . class ) { return parseMarginInfo ( value ) ; } else if ( valueType == Alignment . class ) { return parseAlignment ( value ) ; } return null ; } private Object parseAlignment ( String value ) { return alignmentMap . get ( value ) ; } protected MarginInfo parseMarginInfo ( String margin ) { if ( margin . length ( ) > ) { String [ ] margins = margin . split ( "" ) ; if ( margins . length == ) { return new MarginInfo ( Boolean . valueOf ( margins [ ] ) , Boolean . valueOf ( margins [ ] ) , Boolean . valueOf ( margins [ ] ) , Boolean . valueOf ( margins [ ] ) ) ; } } return new MarginInfo ( Boolean . valueOf ( margin ) ) ; } }
package net . sf . sveditor . core . templates ; import java . io . IOException ; import java . io . InputStream ; import java . net . URL ; import org . osgi . framework . Bundle ; public class PluginInStreamProvider implements ITemplateInStreamProvider { Bundle fBundle ; public PluginInStreamProvider ( Bundle bundle ) { fBundle = bundle ; } public InputStream openStream ( String path ) { URL url = fBundle . getEntry ( path ) ; InputStream in = null ; if ( url != null ) { try { in = url . openStream ( ) ; } catch ( IOException e ) { } } return in ; } public void closeStream ( InputStream in ) { try { in . close ( ) ; } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . util . List ; public interface IExternalTemplatePathProvider { List < String > getExternalTemplatePath ( ) ; }
package net . sf . sveditor . core . templates ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; public class TemplateFSFileCreator implements ITemplateFileCreator { private File fRoot ; public TemplateFSFileCreator ( File root ) { fRoot = root ; } public void createFile ( String path , InputStream content ) { File file = new File ( fRoot , path ) ; byte tmp [ ] = new byte [ ] ; int len ; if ( ! file . getParentFile ( ) . exists ( ) ) { file . getParentFile ( ) . mkdirs ( ) ; } try { FileOutputStream fos = new FileOutputStream ( file ) ; while ( ( len = content . read ( tmp , , tmp . length ) ) > ) { fos . write ( tmp , , len ) ; } fos . close ( ) ; } catch ( IOException e ) { } } public OutputStream openStream ( String path ) { File target = new File ( fRoot , path ) ; try { return new FileOutputStream ( target ) ; } catch ( IOException e ) { } return null ; } public void closeStream ( OutputStream out ) { try { out . close ( ) ; } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . io . File ; import java . io . InputStream ; import java . util . List ; public abstract class AbstractExternalTemplateFinder extends AbstractTemplateFinder { private ITemplateInStreamProvider fInProvider ; public AbstractExternalTemplateFinder ( ITemplateInStreamProvider in_provider ) { super ( ) ; fInProvider = in_provider ; } @ Override public void find ( ) { List < String > paths = findTemplatePaths ( ) ; for ( String path : paths ) { fLog . debug ( LEVEL_MIN , "" + path ) ; InputStream in = openFile ( path ) ; File tmpl_dir = new File ( path ) . getParentFile ( ) ; if ( in == null ) { fLog . error ( "" + path + "" ) ; continue ; } SVTParser p = new SVTParser ( tmpl_dir . getPath ( ) , fInProvider ) ; try { p . parse ( in ) ; } catch ( Exception e ) { fLog . error ( "" + path + "" + e . getMessage ( ) , e ) ; } for ( TemplateCategory c : p . getCategories ( ) ) { fLog . debug ( LEVEL_MID , "" + c . getId ( ) + "" + c . getName ( ) ) ; } fCategories . addAll ( p . getCategories ( ) ) ; for ( TemplateInfo ti : p . getTemplates ( ) ) { fTemplates . add ( ti ) ; fLog . debug ( LEVEL_MID , "" + ti . getId ( ) + "" + ti . getName ( ) ) ; if ( ! ti . getTemplates ( ) . iterator ( ) . hasNext ( ) ) { List < String > files = listFiles ( tmpl_dir . getPath ( ) ) ; for ( String file : files ) { File f = new File ( file ) ; if ( ! f . getName ( ) . endsWith ( "" ) && ! f . getName ( ) . startsWith ( "" ) ) { File fn = new File ( file ) ; ti . addTemplate ( file , fn . getName ( ) ) ; } } } } closeStream ( in ) ; } } protected abstract List < String > findTemplatePaths ( ) ; protected abstract List < String > listFiles ( String path ) ; protected abstract InputStream openFile ( String path ) ; protected abstract void closeStream ( InputStream in ) ; }
package net . sf . sveditor . core . templates ; import java . io . InputStream ; public interface ITemplateFileCreator { void createFile ( String path , InputStream content ) ; }
package net . sf . sveditor . core . templates ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . List ; import net . sf . sveditor . core . log . LogFactory ; public class FSExternalTemplateFinder extends AbstractExternalTemplateFinder { private File fPath ; public FSExternalTemplateFinder ( File path ) { super ( new FSInStreamProvider ( ) ) ; fPath = path ; fLog = LogFactory . getLogHandle ( "" ) ; } @ Override protected List < String > findTemplatePaths ( ) { List < String > template_paths = new ArrayList < String > ( ) ; findTemplatePaths ( template_paths , fPath ) ; return template_paths ; } private void findTemplatePaths ( List < String > paths , File path ) { File files [ ] = path . listFiles ( ) ; if ( files != null ) { for ( File file : files ) { if ( file . isDirectory ( ) ) { findTemplatePaths ( paths , file ) ; } else if ( file . getName ( ) . endsWith ( "" ) ) { paths . add ( file . getAbsolutePath ( ) ) ; } } } } @ Override protected List < String > listFiles ( String path ) { File file = new File ( path ) ; List < String > ret = new ArrayList < String > ( ) ; if ( file . isDirectory ( ) ) { File files [ ] = file . listFiles ( ) ; if ( files != null ) { for ( File f : files ) { if ( f . isFile ( ) ) { ret . add ( f . getAbsolutePath ( ) ) ; } } } } return ret ; } @ Override protected InputStream openFile ( String path ) { InputStream in = null ; try { in = new FileInputStream ( path ) ; } catch ( IOException e ) { } return in ; } @ Override protected void closeStream ( InputStream in ) { try { if ( in != null ) { in . close ( ) ; } } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . io . InputStream ; public interface ITemplateInStreamProvider { InputStream openStream ( String path ) ; void closeStream ( InputStream in ) ; }
package net . sf . sveditor . core . templates ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . List ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import net . sf . sveditor . core . log . LogFactory ; import net . sf . sveditor . core . log . LogHandle ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . NodeList ; import org . xml . sax . ErrorHandler ; import org . xml . sax . SAXException ; import org . xml . sax . SAXParseException ; public class SVTParser { private Document fDocument ; private List < TemplateInfo > fTemplates ; private List < TemplateCategory > fCategories ; private LogHandle fLog ; private ITemplateInStreamProvider fInProvider ; private String fTemplateBase ; public SVTParser ( String template_base , ITemplateInStreamProvider in_provider ) { fTemplates = new ArrayList < TemplateInfo > ( ) ; fCategories = new ArrayList < TemplateCategory > ( ) ; fLog = LogFactory . getLogHandle ( "" ) ; fInProvider = in_provider ; fTemplateBase = template_base ; } public void parse ( InputStream in ) throws Exception { DocumentBuilderFactory f = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder b = f . newDocumentBuilder ( ) ; fTemplates . clear ( ) ; fCategories . clear ( ) ; b . setErrorHandler ( fErrorHandler ) ; fDocument = b . parse ( in ) ; NodeList sv_template_list = fDocument . getElementsByTagName ( "" ) ; if ( sv_template_list . getLength ( ) == ) { return ; } Element sv_template = ( Element ) sv_template_list . item ( ) ; NodeList category_list = sv_template . getElementsByTagName ( "" ) ; for ( int i = ; i < category_list . getLength ( ) ; i ++ ) { addCategory ( ( Element ) category_list . item ( i ) ) ; } NodeList template_list = sv_template . getElementsByTagName ( "" ) ; for ( int i = ; i < template_list . getLength ( ) ; i ++ ) { addTemplate ( ( Element ) template_list . item ( i ) ) ; } } public List < TemplateCategory > getCategories ( ) { return fCategories ; } public List < TemplateInfo > getTemplates ( ) { return fTemplates ; } private void addCategory ( Element category ) { String name = category . getAttribute ( "" ) ; String id = category . getAttribute ( "" ) ; String parent = category . getAttribute ( "" ) ; if ( parent == null ) { parent = "" ; } TemplateCategory c = new TemplateCategory ( id , name , parent ) ; NodeList dl = category . getElementsByTagName ( "" ) ; if ( dl . getLength ( ) > ) { Element desc = ( Element ) dl . item ( ) ; c . setDescription ( desc . getTextContent ( ) ) ; } if ( ! fCategories . contains ( c ) ) { fCategories . add ( c ) ; } } private void addTemplate ( Element template ) { String name = template . getAttribute ( "" ) ; String id = template . getAttribute ( "" ) ; String category = template . getAttribute ( "" ) ; TemplateInfo t = new TemplateInfo ( id , name , category , "" , fInProvider ) ; NodeList description = template . getElementsByTagName ( "" ) ; if ( description . getLength ( ) > ) { Element e = ( Element ) description . item ( ) ; t . setDescription ( e . getTextContent ( ) ) ; } NodeList files = template . getElementsByTagName ( "" ) ; if ( files . getLength ( ) > ) { Element e = ( Element ) files . item ( ) ; NodeList file_list = e . getElementsByTagName ( "" ) ; for ( int i = ; i < file_list . getLength ( ) ; i ++ ) { Element file = ( Element ) file_list . item ( i ) ; String filename = file . getAttribute ( "" ) ; String tmpl_path = file . getAttribute ( "" ) ; filename = filename . trim ( ) ; tmpl_path = tmpl_path . trim ( ) ; t . addTemplate ( fTemplateBase + "" + tmpl_path , filename ) ; } } NodeList parameters = template . getElementsByTagName ( "" ) ; if ( parameters . getLength ( ) > ) { Element e = ( Element ) parameters . item ( ) ; NodeList parameters_list = e . getElementsByTagName ( "" ) ; for ( int i = ; i < parameters_list . getLength ( ) ; i ++ ) { Element parameter = ( Element ) parameters_list . item ( i ) ; TemplateParameterType p_type = TemplateParameterType . ParameterType_Id ; String p_name = parameter . getAttribute ( "" ) ; String p_type_s = parameter . getAttribute ( "" ) ; String p_dflt = parameter . getAttribute ( "" ) ; String p_ext = parameter . getAttribute ( "" ) ; String p_restr = parameter . getAttribute ( "" ) ; if ( p_type_s . equals ( "" ) ) { p_type = TemplateParameterType . ParameterType_Class ; } else if ( p_type_s . equals ( "" ) ) { p_type = TemplateParameterType . ParameterType_Id ; } else if ( p_type_s . equals ( "" ) ) { p_type = TemplateParameterType . ParameterType_Int ; } TemplateParameter p = new TemplateParameter ( p_type , p_name , p_dflt , p_ext ) ; if ( p_restr != null && ! p_restr . trim ( ) . equals ( "" ) ) { String restr [ ] = p_restr . split ( "" ) ; for ( String r : restr ) { r = r . trim ( ) ; p . addValue ( r ) ; } } t . addParameter ( p ) ; } } fTemplates . add ( t ) ; } private ErrorHandler fErrorHandler = new ErrorHandler ( ) { public void error ( SAXParseException arg0 ) throws SAXException { throw arg0 ; } public void fatalError ( SAXParseException arg0 ) throws SAXException { throw arg0 ; } public void warning ( SAXParseException arg0 ) throws SAXException { } } ; }
package net . sf . sveditor . core . templates ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; public class FSInStreamProvider implements ITemplateInStreamProvider { public InputStream openStream ( String path ) { File file = new File ( path ) ; InputStream in = null ; try { in = new FileInputStream ( file ) ; } catch ( IOException e ) { } return in ; } public void closeStream ( InputStream in ) { try { in . close ( ) ; } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . io . IOException ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . List ; import net . sf . sveditor . core . log . LogFactory ; import org . eclipse . core . resources . IContainer ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IResource ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . NullProgressMonitor ; import org . eclipse . core . runtime . Path ; public class WSExternalTemplateFinder extends AbstractExternalTemplateFinder { private IContainer fPath ; public WSExternalTemplateFinder ( IContainer path ) { super ( new WSInStreamProvider ( ) ) ; fPath = path ; fLog = LogFactory . getLogHandle ( "" ) ; } @ Override protected List < String > findTemplatePaths ( ) { List < String > templates = new ArrayList < String > ( ) ; findTemplatePaths ( templates , fPath ) ; return templates ; } private void findTemplatePaths ( List < String > templates , IContainer parent ) { IResource resources [ ] = null ; try { resources = parent . members ( ) ; } catch ( CoreException e ) { } if ( resources != null ) { for ( IResource r : resources ) { if ( r instanceof IFile && r . getName ( ) . endsWith ( "" ) ) { templates . add ( ( ( IFile ) r ) . getFullPath ( ) . toOSString ( ) ) ; } else if ( r instanceof IContainer ) { findTemplatePaths ( templates , ( IContainer ) r ) ; } } } } @ Override protected List < String > listFiles ( String path ) { List < String > files = new ArrayList < String > ( ) ; IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IContainer c = null ; try { c = root . getFolder ( new Path ( path ) ) ; } catch ( IllegalArgumentException e ) { } if ( c == null ) { if ( path . startsWith ( "" ) ) { String pname = path . substring ( ) ; try { c = root . getProject ( pname ) ; } catch ( IllegalArgumentException e ) { } } } if ( c != null ) { IResource resources [ ] = null ; try { resources = c . members ( ) ; } catch ( CoreException e ) { } if ( resources != null ) { for ( IResource r : resources ) { if ( r instanceof IFile ) { files . add ( ( ( IFile ) r ) . getFullPath ( ) . toOSString ( ) ) ; } } } } return files ; } @ Override protected InputStream openFile ( String path ) { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; InputStream in = null ; IFile file = root . getFile ( new Path ( path ) ) ; if ( file . exists ( ) ) { for ( int i = ; i < ; i ++ ) { try { in = file . getContents ( ) ; break ; } catch ( CoreException e ) { fLog . error ( "" + path + "" + e . getMessage ( ) , e ) ; if ( e . getMessage ( ) . contains ( "" ) ) { try { file . getParent ( ) . refreshLocal ( IResource . DEPTH_INFINITE , new NullProgressMonitor ( ) ) ; } catch ( CoreException e2 ) { } } } } } else { fLog . debug ( LEVEL_MID , "" + path + "" ) ; } return in ; } @ Override protected void closeStream ( InputStream in ) { try { in . close ( ) ; } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . io . IOException ; import java . io . InputStream ; import org . eclipse . core . resources . IFile ; import org . eclipse . core . resources . IWorkspaceRoot ; import org . eclipse . core . resources . ResourcesPlugin ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . core . runtime . Path ; public class WSInStreamProvider implements ITemplateInStreamProvider { public InputStream openStream ( String path ) { IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; InputStream in = null ; try { IFile file = root . getFile ( new Path ( path ) ) ; if ( file . exists ( ) ) { in = file . getContents ( ) ; } } catch ( CoreException e ) { } return in ; } public void closeStream ( InputStream in ) { try { in . close ( ) ; } catch ( IOException e ) { } } }
package net . sf . sveditor . core . templates ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . Set ; public class DynamicTemplateParameterProvider implements ITemplateParameterProvider { public boolean providesParameter ( String id ) { return ( id . equals ( "" ) || id . equals ( "" ) ) ; } public String getParameterValue ( String id , String arg ) { if ( id . equals ( "" ) ) { return System . getProperty ( "" ) ; } else if ( id . equals ( "" ) ) { SimpleDateFormat format ; if ( arg != null ) { format = new SimpleDateFormat ( arg ) ; } else { format = new SimpleDateFormat ( "" ) ; } return format . format ( new Date ( ) ) ; } else { return null ; } } }
package net . sf . sveditor . core . templates ; import net . sf . sveditor . core . SVCorePlugin ; import net . sf . sveditor . core . Tuple ; import net . sf . sveditor . core . log . LogFactory ; import org . eclipse . core . runtime . IConfigurationElement ; import org . eclipse . core . runtime . IExtension ; import org . eclipse . core . runtime . IExtensionPoint ; import org . eclipse . core . runtime . IExtensionRegistry ; import org . eclipse . core . runtime . Platform ; import org . osgi . framework . Bundle ; public class ExtensionTemplateFinder extends AbstractTemplateFinder { public ExtensionTemplateFinder ( ) { super ( ) ; fLog = LogFactory . getLogHandle ( "" ) ; } public void find ( ) { IExtensionRegistry ext_rgy = Platform . getExtensionRegistry ( ) ; IExtensionPoint ext_pt = ext_rgy . getExtensionPoint ( SVCorePlugin . PLUGIN_ID , "" ) ; IExtension ext_list [ ] = ext_pt . getExtensions ( ) ; for ( IExtension ext : ext_list ) { IConfigurationElement ce_l [ ] = ext . getConfigurationElements ( ) ; for ( IConfigurationElement ce : ce_l ) { String name = ce . getName ( ) ; if ( name . equals ( "" ) ) { addCategory ( ce ) ; } else if ( name . equals ( "" ) ) { addTemplate ( ce ) ; } else { fLog . error ( "" + name + "" ) ; } } } } private void addCategory ( IConfigurationElement ce ) { String id = ce . getAttribute ( "" ) ; String name = ce . getAttribute ( "" ) ; String parent = ce . getAttribute ( "" ) ; TemplateCategory c = new TemplateCategory ( id , name , parent ) ; for ( IConfigurationElement ci : ce . getChildren ( ) ) { if ( ci . getName ( ) . equals ( "" ) ) { c . setDescription ( ci . getValue ( ) ) ; } } fCategories . add ( c ) ; } private void addTemplate ( IConfigurationElement ce ) { String id = ce . getAttribute ( "" ) ; String name = ce . getAttribute ( "" ) ; String category = ce . getAttribute ( "" ) ; String description = "" ; Bundle bundle = Platform . getBundle ( ce . getContributor ( ) . getName ( ) ) ; for ( IConfigurationElement ce_c : ce . getChildren ( ) ) { if ( ce_c . getName ( ) . equals ( "" ) ) { description = ce_c . getValue ( ) ; } } TemplateInfo info = new TemplateInfo ( id , name , category , description , new PluginInStreamProvider ( bundle ) ) ; fTemplates . add ( info ) ; for ( IConfigurationElement ce_c : ce . getChildren ( ) ) { if ( ce_c . getName ( ) . equals ( "" ) ) { for ( IConfigurationElement tmpl : ce_c . getChildren ( ) ) { String template = tmpl . getAttribute ( "" ) ; String tmpl_name = tmpl . getAttribute ( "" ) ; info . addTemplate ( new Tuple < String , String > ( template , tmpl_name ) ) ; } } else if ( ce_c . getName ( ) . equals ( "" ) ) { for ( IConfigurationElement p : ce_c . getChildren ( ) ) { if ( p . getName ( ) . equals ( "" ) ) { String p_type = p . getAttribute ( "" ) ; String p_name = p . getAttribute ( "" ) ; String p_dflt = p . getAttribute ( "" ) ; String p_ext_from = p . getAttribute ( "" ) ; String p_restr = p . getAttribute ( "" ) ; TemplateParameterType type = null ; if ( p_type . equals ( "" ) ) { type = TemplateParameterType . ParameterType_Int ; } else if ( p_type . equals ( "" ) ) { type = TemplateParameterType . ParameterType_Id ; } else if ( p_type . equals ( "" ) ) { type = TemplateParameterType . ParameterType_Class ; } else { fLog . error ( "" + p_type + "" ) ; continue ; } TemplateParameter tp = new TemplateParameter ( type , p_name , p_dflt , p_ext_from ) ; if ( p_restr != null && ! p_restr . trim ( ) . equals ( "" ) ) { String r [ ] = p_restr . split ( "" ) ; for ( String rs : r ) { rs = rs . trim ( ) ; if ( ! rs . equals ( "" ) ) { tp . addValue ( rs ) ; } } } info . addParameter ( tp ) ; } } } } } }
package net . sf . sveditor . core . templates ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import net . sf . sveditor . core . Tuple ; public class TemplateInfo { private String fId ; private String fName ; private String fCategoryId ; private String fDescription ; private List < Tuple < String , String > > fTemplateList ; private List < TemplateParameter > fParameters ; private ITemplateInStreamProvider fStreamProvider ; public TemplateInfo ( String id , String name , String category_id , String description , ITemplateInStreamProvider stream_provider ) { fId = id ; fName = name ; fCategoryId = ( category_id != null ) ? category_id : "" ; fDescription = description ; fTemplateList = new ArrayList < Tuple < String , String > > ( ) ; fParameters = new ArrayList < TemplateParameter > ( ) ; fStreamProvider = stream_provider ; } public String getId ( ) { return fId ; } public String getName ( ) { return fName ; } public String getCategoryId ( ) { return fCategoryId ; } public void setCategoryId ( String id ) { fCategoryId = id ; } public void setDescription ( String description ) { fDescription = description ; } public String getDescription ( ) { return fDescription ; } public Iterable < Tuple < String , String > > getTemplates ( ) { return new Iterable < Tuple < String , String > > ( ) { public Iterator < Tuple < String , String > > iterator ( ) { return fTemplateList . iterator ( ) ; } } ; } public void addTemplate ( String template , String filename ) { addTemplate ( new Tuple < String , String > ( template , filename ) ) ; } public void addTemplate ( Tuple < String , String > template ) { fTemplateList . add ( template ) ; } public void addParameter ( TemplateParameter p ) { fParameters . add ( p ) ; } public List < TemplateParameter > getParameters ( ) { return fParameters ; } public InputStream openTemplate ( String path ) { return fStreamProvider . openStream ( path ) ; } public void closeTemplate ( InputStream in ) { fStreamProvider . closeStream ( in ) ; } }
package net . sf . sveditor . core . templates ; import java . util . ArrayList ; import java . util . List ; public class TemplateParameter { private TemplateParameterType fType ; private String fName ; private String fDefault ; private String fValue ; private String fExtFrom ; private List < String > fValues ; public TemplateParameter ( TemplateParameterType type , String name , String dflt , String ext_from ) { fType = type ; fName = name ; fDefault = dflt ; fValue = dflt ; fExtFrom = ext_from ; fValues = new ArrayList < String > ( ) ; } public TemplateParameterType getType ( ) { return fType ; } public String getTypeName ( ) { switch ( fType ) { case ParameterType_Id : { if ( fValues . size ( ) == ) { return "" ; } else { return "" ; } } case ParameterType_Class : return "" ; case ParameterType_Int : return "" ; default : return "" ; } } public String getName ( ) { return fName ; } public String getDefault ( ) { return fDefault ; } public String getValue ( ) { return fValue ; } public void setValue ( String val ) { fValue = val ; } public String getExtFrom ( ) { return fExtFrom ; } public List < String > getValues ( ) { return fValues ; } public void addValue ( String value ) { if ( ! fValues . contains ( value ) ) { fValues . add ( value ) ; } } public TemplateParameter duplicate ( ) { TemplateParameter p = new TemplateParameter ( fType , fName , fDefault , fExtFrom ) ; p . setValue ( fValue ) ; for ( String v : fValues ) { p . addValue ( v ) ; } return p ; } }
package net . sf . sveditor . core . templates ; public enum TemplateParameterType { ParameterType_Id , ParameterType_Int , ParameterType_Class }
package net . sf . sveditor . core . templates ; import java . io . File ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import net . sf . sveditor . core . SVFileUtils ; import net . sf . sveditor . core . log . ILogLevel ; import net . sf . sveditor . core . log . LogFactory ; import net . sf . sveditor . core . log . LogHandle ; import org . eclipse . core . resources . IContainer ; public class TemplateRegistry implements ILogLevel { private static LogHandle fLog ; private List < TemplateCategory > fCategories ; private List < TemplateInfo > fTemplates ; private Map < String , List < TemplateInfo > > fCategoryMap ; private List < IExternalTemplatePathProvider > fPathProviders ; private boolean fLoadExtPoints ; static { fLog = LogFactory . getLogHandle ( "" ) ; } public TemplateRegistry ( boolean load_exts ) { fCategories = new ArrayList < TemplateCategory > ( ) ; fTemplates = new ArrayList < TemplateInfo > ( ) ; fCategoryMap = new HashMap < String , List < TemplateInfo > > ( ) ; fPathProviders = new ArrayList < IExternalTemplatePathProvider > ( ) ; fLoadExtPoints = load_exts ; load_extensions ( ) ; } public void addPathProvider ( IExternalTemplatePathProvider p ) { fPathProviders . add ( p ) ; } public void clearPathProviders ( ) { fPathProviders . clear ( ) ; } public List < TemplateCategory > getCategories ( ) { return fCategories ; } public List < String > getCategoryNames ( ) { List < String > ret = new ArrayList < String > ( ) ; for ( TemplateCategory c : fCategories ) { ret . add ( c . getName ( ) ) ; } return ret ; } public List < String > getCategoryIDs ( ) { List < String > ret = new ArrayList < String > ( ) ; for ( TemplateCategory c : fCategories ) { ret . add ( c . getId ( ) ) ; } return ret ; } public List < TemplateInfo > getTemplates ( String id ) { List < TemplateInfo > ret = new ArrayList < TemplateInfo > ( ) ; if ( id == null ) { id = "" ; } if ( fCategoryMap . containsKey ( id ) ) { ret . addAll ( fCategoryMap . get ( id ) ) ; } return ret ; } public TemplateInfo findTemplate ( String id ) { for ( TemplateInfo info : fTemplates ) { if ( info . getId ( ) . equals ( id ) ) { return info ; } } return null ; } public void load_extensions ( ) { fLog . debug ( LEVEL_MID , "" ) ; List < AbstractTemplateFinder > template_finders = new ArrayList < AbstractTemplateFinder > ( ) ; fTemplates . clear ( ) ; fCategories . clear ( ) ; fCategoryMap . clear ( ) ; if ( fLoadExtPoints ) { template_finders . add ( new ExtensionTemplateFinder ( ) ) ; } if ( fPathProviders . size ( ) > ) { for ( IExternalTemplatePathProvider p : fPathProviders ) { for ( String path : p . getExternalTemplatePath ( ) ) { fLog . debug ( LEVEL_MID , "" + path + "" ) ; if ( path . startsWith ( "" ) ) { path = path . substring ( "" . length ( ) ) ; IContainer c = SVFileUtils . getWorkspaceFolder ( path ) ; template_finders . add ( new WSExternalTemplateFinder ( c ) ) ; } else { template_finders . add ( new FSExternalTemplateFinder ( new File ( path ) ) ) ; } } } } for ( AbstractTemplateFinder f : template_finders ) { f . find ( ) ; List < TemplateInfo > tmpl_list = f . getTemplates ( ) ; List < TemplateCategory > category_list = f . getCategories ( ) ; fTemplates . addAll ( tmpl_list ) ; for ( TemplateCategory new_c : category_list ) { if ( ! fCategories . contains ( new_c ) ) { fCategories . add ( new_c ) ; } } } for ( int i = ; i < fCategories . size ( ) ; i ++ ) { for ( int j = i + ; j < fCategories . size ( ) ; j ++ ) { TemplateCategory c_i = fCategories . get ( i ) ; TemplateCategory c_j = fCategories . get ( j ) ; if ( c_j . getName ( ) . compareTo ( c_i . getName ( ) ) < ) { fCategories . set ( j , c_i ) ; fCategories . set ( i , c_j ) ; } } } for ( TemplateInfo t : fTemplates ) { if ( t . getCategoryId ( ) == null || t . getCategoryId ( ) . trim ( ) . equals ( "" ) ) { if ( ! fCategoryMap . containsKey ( "" ) ) { TemplateCategory c = new TemplateCategory ( "" , "" , "" ) ; c . setDescription ( "" ) ; t . setCategoryId ( "" ) ; } } if ( ! fCategoryMap . containsKey ( t . getCategoryId ( ) ) ) { fCategoryMap . put ( t . getCategoryId ( ) , new ArrayList < TemplateInfo > ( ) ) ; } fCategoryMap . get ( t . getCategoryId ( ) ) . add ( t ) ; } for ( Entry < String , List < TemplateInfo > > c : fCategoryMap . entrySet ( ) ) { List < TemplateInfo > t = c . getValue ( ) ; for ( int i = ; i < t . size ( ) ; i ++ ) { for ( int j = i + ; j < t . size ( ) ; j ++ ) { TemplateInfo t_i = t . get ( i ) ; TemplateInfo t_j = t . get ( j ) ; if ( t_j . getName ( ) . compareTo ( t_i . getName ( ) ) < ) { t . set ( i , t_j ) ; t . set ( j , t_i ) ; } } } } } }
package net . sf . sveditor . core . templates ; public class DefaultTemplateParameterProvider extends TemplateParameterProvider { public static final String FILE_HEADER = "" ; public static final String FILE_HEADER_DFLT = "" + "" + "" ; public static final String FILE_FOOTER = "" ; public static final String FILE_FOOTER_DFLT = "" ; public DefaultTemplateParameterProvider ( ITemplateParameterProvider p ) { super ( ) ; set_defaults ( ) ; if ( p . providesParameter ( FILE_HEADER ) ) { setTag ( FILE_HEADER , p . getParameterValue ( FILE_HEADER , null ) ) ; } if ( p . providesParameter ( FILE_FOOTER ) ) { setTag ( FILE_HEADER , p . getParameterValue ( FILE_FOOTER , null ) ) ; } } private void set_defaults ( ) { setTag ( FILE_HEADER , FILE_HEADER_DFLT ) ; setTag ( FILE_FOOTER , FILE_FOOTER_DFLT ) ; } }
package net . sf . sveditor . core . templates ; public class TemplateCategory implements Comparable < TemplateCategory > { private String fId ; private String fName ; private String fDescription ; private String fParent ; public TemplateCategory ( String id , String name , String parent ) { fId = id ; fName = name ; fDescription = "" ; fParent = parent ; } public String getId ( ) { return fId ; } public String getName ( ) { return fName ; } public String getDescription ( ) { return fDescription ; } public void setDescription ( String desc ) { fDescription = desc ; } public String getParent ( ) { return fParent ; } @ Override public boolean equals ( Object obj ) { if ( obj instanceof TemplateCategory ) { return fId . equals ( ( ( TemplateCategory ) obj ) . fId ) ; } else { return false ; } } public int compareTo ( TemplateCategory o ) { return fName . compareTo ( o . fName ) ; } }
package net . sf . sveditor . core . templates ; public interface ITemplateParameterProvider { boolean providesParameter ( String id ) ; String getParameterValue ( String id , String arg ) ; }
package net . sf . sveditor . core . templates ; import java . util . ArrayList ; import java . util . List ; import net . sf . sveditor . core . log . ILogLevel ; import net . sf . sveditor . core . log . LogHandle ; public abstract class AbstractTemplateFinder implements ILogLevel { protected LogHandle fLog ; protected List < TemplateInfo > fTemplates ; protected List < TemplateCategory > fCategories ; public AbstractTemplateFinder ( ) { fTemplates = new ArrayList < TemplateInfo > ( ) ; fCategories = new ArrayList < TemplateCategory > ( ) ; } public abstract void find ( ) ; public List < TemplateInfo > getTemplates ( ) { return fTemplates ; } public List < TemplateCategory > getCategories ( ) { return fCategories ; } protected void addTemplate ( TemplateInfo template ) { fTemplates . add ( template ) ; } protected void addCategory ( TemplateCategory category ) { fCategories . add ( category ) ; } }
package net . sf . sveditor . core . templates ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . ArrayList ; import java . util . List ; import net . sf . sveditor . core . SVCorePlugin ; import net . sf . sveditor . core . StringInputStream ; import net . sf . sveditor . core . Tuple ; import net . sf . sveditor . core . indent . ISVIndenter ; import net . sf . sveditor . core . indent . SVIndentScanner ; import net . sf . sveditor . core . scanutils . InputStreamTextScanner ; import net . sf . sveditor . core . text . TagProcessor ; public class TemplateProcessor { private ITemplateFileCreator fStreamProvider ; private static final String fDefaultFileHeader = "" + "" + "" ; public TemplateProcessor ( ITemplateFileCreator provider ) { fStreamProvider = provider ; } public static List < String > getOutputFiles ( TemplateInfo template , TagProcessor proc ) { List < String > ret = new ArrayList < String > ( ) ; for ( Tuple < String , String > t : template . getTemplates ( ) ) { String name = proc . process ( t . second ( ) ) ; ret . add ( name ) ; } return ret ; } public void process ( TemplateInfo template , TagProcessor proc ) { TemplateParameterProvider local_p = new TemplateParameterProvider ( ) ; proc . addParameterProvider ( local_p ) ; for ( Tuple < String , String > t : template . getTemplates ( ) ) { int n_replacements = ; String templ = t . first ( ) ; String name = proc . process ( t . second ( ) ) ; name = name . trim ( ) ; local_p . setTag ( "" , name ) ; InputStream in = template . openTemplate ( templ ) ; ByteArrayInputStream in_t = readInputStream ( in ) ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; do { try { n_replacements = proc . process ( in_t , out ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } in_t = new ByteArrayInputStream ( out . toByteArray ( ) ) ; out = new ByteArrayOutputStream ( ) ; } while ( n_replacements > ) ; InputStream in_ind = null ; if ( should_sv_indent ( name ) ) { SVIndentScanner scanner = new SVIndentScanner ( new InputStreamTextScanner ( in_t , name ) ) ; ISVIndenter indenter = SVCorePlugin . getDefault ( ) . createIndenter ( ) ; indenter . init ( scanner ) ; in_ind = new StringInputStream ( indenter . indent ( ) ) ; } else { in_ind = in_t ; } fStreamProvider . createFile ( name , in_ind ) ; template . closeTemplate ( in ) ; } proc . removeParameterProvider ( local_p ) ; } private boolean should_sv_indent ( String name ) { String ext = "" ; if ( name . lastIndexOf ( '' ) != - ) { ext = name . substring ( name . lastIndexOf ( '' ) ) ; } List < String > exts = SVCorePlugin . getDefault ( ) . getDefaultSVExts ( ) ; return exts . contains ( ext ) ; } private ByteArrayInputStream readInputStream ( InputStream in ) { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; byte tmp [ ] = new byte [ ] ; int len ; try { while ( ( len = in . read ( tmp , , tmp . length ) ) > ) { bos . write ( tmp , , len ) ; } } catch ( IOException e ) { } return new ByteArrayInputStream ( bos . toByteArray ( ) ) ; } }
package net . sf . sveditor . core . templates ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; public class SVTUtils { public static boolean ensureExpectedSections ( Document doc , Element sv_template ) { NodeList nl = sv_template . getChildNodes ( ) ; boolean ret = false ; for ( int i = ; i < nl . getLength ( ) ; i ++ ) { Node n = nl . item ( i ) ; if ( n instanceof Element ) { Element e = ( Element ) n ; if ( e . getNodeName ( ) . equals ( "" ) ) { ret |= ensureExpectedTemplateSections ( doc , e ) ; } else if ( e . getNodeName ( ) . equals ( "" ) ) { ret |= ensureExpectedCategorySections ( doc , e ) ; } } } return ret ; } private static boolean ensureExpectedTemplateSections ( Document doc , Element template ) { boolean ret = false ; ret |= addElementIfMissing ( doc , template , "" ) ; ret |= addElementIfMissing ( doc , template , "" ) ; ret |= addElementIfMissing ( doc , template , "" ) ; return ret ; } private static boolean ensureExpectedCategorySections ( Document doc , Element template ) { boolean ret = false ; ret |= addElementIfMissing ( doc , template , "" ) ; return ret ; } private static boolean addElementIfMissing ( Document doc , Element e , String elem ) { NodeList nl = e . getChildNodes ( ) ; boolean found = false ; boolean ret = false ; for ( int i = ; i < nl . getLength ( ) ; i ++ ) { Node n = nl . item ( i ) ; if ( n instanceof Element && ( ( Element ) n ) . getNodeName ( ) . equals ( elem ) ) { found = true ; break ; } } if ( ! found ) { Element new_e = doc . createElement ( elem ) ; e . appendChild ( new_e ) ; ret = true ; } return ret ; } }
package net . sf . sveditor . core . templates ; import java . util . HashMap ; import java . util . Map ; public class TemplateParameterProvider implements ITemplateParameterProvider { private Map < String , String > fTagMap ; public TemplateParameterProvider ( ) { fTagMap = new HashMap < String , String > ( ) ; } public TemplateParameterProvider ( Map < String , String > init ) { this ( ) ; fTagMap . putAll ( init ) ; } public TemplateParameterProvider ( TemplateParameterProvider init ) { this ( ) ; fTagMap . putAll ( init . fTagMap ) ; } public boolean providesParameter ( String id ) { return fTagMap . containsKey ( id ) ; } public String getParameterValue ( String id , String arg ) { return getTag ( id ) ; } public void setTag ( String tag , String value ) { if ( fTagMap . containsKey ( tag ) ) { fTagMap . remove ( tag ) ; } fTagMap . put ( tag , value ) ; } public void removeTag ( String tag ) { fTagMap . remove ( tag ) ; } public boolean hasTag ( String tag ) { return fTagMap . containsKey ( tag ) ; } public String getTag ( String tag ) { return fTagMap . get ( tag ) ; } public void appendTag ( String tag , String value ) { String val ; if ( fTagMap . containsKey ( tag ) ) { val = fTagMap . get ( tag ) ; fTagMap . remove ( tag ) ; } else { val = "" ; } val += value ; fTagMap . put ( tag , val ) ; } }
package net . sf . sveditor . core . content_assist ; import net . sf . sveditor . core . db . ISVDBItemBase ; import net . sf . sveditor . core . db . SVDBItem ; public class SVCompletionProposal { private ISVDBItemBase fItem ; private String fPrefix ; private String fReplacement ; private int fReplacementOffset ; private int fReplacementLength ; private SVCompletionProposalType fType ; public SVCompletionProposal ( ISVDBItemBase item , String prefix , int replacementOffset , int replacementLength ) { fItem = item ; fPrefix = prefix ; fReplacement = SVDBItem . getName ( item ) ; fReplacementOffset = replacementOffset ; fReplacementLength = replacementLength ; fType = SVCompletionProposalType . SVObject ; } public String getPrefix ( ) { return fPrefix ; } public String getReplacement ( ) { return fReplacement ; } public void setReplacement ( String replacement ) { fReplacement = replacement ; } public SVCompletionProposal ( String replacement , int startOffset , int replacementLength ) { fReplacement = replacement ; fReplacementOffset = startOffset ; fReplacementLength = replacementLength ; fType = SVCompletionProposalType . Unknown ; } public SVCompletionProposal ( String replacement , int startOffset , int replacementLength , SVCompletionProposalType type ) { fReplacement = replacement ; fReplacementOffset = startOffset ; fReplacementLength = replacementLength ; fType = type ; } public ISVDBItemBase getItem ( ) { return fItem ; } public SVCompletionProposalType getType ( ) { return fType ; } public int getReplacementOffset ( ) { return fReplacementOffset ; } public int getReplacementLength ( ) { return fReplacementLength ; } }
package net . sf . sveditor . core . content_assist ; import java . util . ArrayList ; import java . util . List ; import net . sf . sveditor . core . db . IFieldItemAttr ; import net . sf . sveditor . core . db . ISVDBChildItem ; import net . sf . sveditor . core . db . ISVDBChildParent ; import net . sf . sveditor . core . db . ISVDBItemBase ; import net . sf . sveditor . core . db . ISVDBNamedItem ; import net . sf . sveditor . core . db . ISVDBScopeItem ; import net . sf . sveditor . core . db . SVDBClassDecl ; import net . sf . sveditor . core . db . SVDBFile ; import net . sf . sveditor . core . db . SVDBFunction ; import net . sf . sveditor . core . db . SVDBInterfaceDecl ; import net . sf . sveditor . core . db . SVDBItem ; import net . sf . sveditor . core . db . SVDBItemType ; import net . sf . sveditor . core . db . SVDBModIfcDecl ; import net . sf . sveditor . core . db . SVDBModIfcInst ; import net . sf . sveditor . core . db . SVDBModportDecl ; import net . sf . sveditor . core . db . SVDBModportItem ; import net . sf . sveditor . core . db . SVDBModportPortsDecl ; import net . sf . sveditor . core . db . SVDBModportSimplePort ; import net . sf . sveditor . core . db . SVDBModportSimplePortsDecl ; import net . sf . sveditor . core . db . SVDBPackageDecl ; import net . sf . sveditor . core . db . SVDBTask ; import net . sf . sveditor . core . db . SVDBTypeInfo ; import net . sf . sveditor . core . db . SVDBTypeInfoEnum ; import net . sf . sveditor . core . db . SVDBTypeInfoEnumerator ; import net . sf . sveditor . core . db . expr . SVDBExpr ; import net . sf . sveditor . core . db . index . ISVDBIndexIterator ; import net . sf . sveditor . core . db . index . SVDBDeclCacheItem ; import net . sf . sveditor . core . db . search . SVDBFindByName ; import net . sf . sveditor . core . db . search . SVDBFindByNameInClassHierarchy ; import net . sf . sveditor . core . db . search . SVDBFindByNameInScopes ; import net . sf . sveditor . core . db . search . SVDBFindByNameMatcher ; import net . sf . sveditor . core . db . search . SVDBFindContentAssistNameMatcher ; import net . sf . sveditor . core . db . search . SVDBFindDefaultNameMatcher ; import net . sf . sveditor . core . db . search . SVDBFindIncludedFile ; import net . sf . sveditor . core . db . search . SVDBFindNamedModIfcClassIfc ; import net . sf . sveditor . core . db . search . SVDBFindSuperClass ; import net . sf . sveditor . core . db . stmt . SVDBParamPortDecl ; import net . sf . sveditor . core . db . stmt . SVDBStmt ; import net . sf . sveditor . core . db . stmt . SVDBTypedefStmt ; import net . sf . sveditor . core . db . stmt . SVDBVarDeclItem ; import net . sf . sveditor . core . db . stmt . SVDBVarDeclStmt ; import net . sf . sveditor . core . db . utils . SVDBSearchUtils ; import net . sf . sveditor . core . expr_utils . SVContentAssistExprVisitor ; import net . sf . sveditor . core . expr_utils . SVExprContext ; import net . sf . sveditor . core . expr_utils . SVExprContext . ContextType ; import net . sf . sveditor . core . expr_utils . SVExprScanner ; import net . sf . sveditor . core . expr_utils . SVExprUtilsParser ; import net . sf . sveditor . core . log . ILogLevel ; import net . sf . sveditor . core . log . LogHandle ; import net . sf . sveditor . core . parser . SVParseException ; import net . sf . sveditor . core . scanutils . IBIDITextScanner ; import org . eclipse . core . runtime . NullProgressMonitor ; public abstract class AbstractCompletionProcessor implements ILogLevel { protected List < SVCompletionProposal > fCompletionProposals ; protected LogHandle fLog ; public AbstractCompletionProcessor ( ) { fCompletionProposals = new ArrayList < SVCompletionProposal > ( ) ; } protected abstract ISVDBIndexIterator getIndexIterator ( ) ; protected abstract SVDBFile getSVDBFile ( ) ; protected void addProposal ( SVCompletionProposal p ) { boolean found = false ; synchronized ( fCompletionProposals ) { for ( SVCompletionProposal p_t : fCompletionProposals ) { if ( p_t . equals ( p ) ) { found = true ; break ; } } if ( ! found ) { fCompletionProposals . add ( p ) ; } } } public List < SVCompletionProposal > getCompletionProposals ( ) { return fCompletionProposals ; } public void computeProposals ( IBIDITextScanner scanner , SVDBFile active_file , int lineno ) { computeProposals ( scanner , active_file , lineno , - ) ; } public void computeProposals ( IBIDITextScanner scanner , SVDBFile active_file , int lineno , int linepos ) { SVExprScanner expr_scan = new SVExprScanner ( ) ; synchronized ( fCompletionProposals ) { fCompletionProposals . clear ( ) ; } fLog . debug ( LEVEL_MID , "" + active_file . getFilePath ( ) + "" + lineno + "" + linepos ) ; ISVDBScopeItem src_scope = SVDBSearchUtils . findActiveScope ( active_file , lineno ) ; if ( src_scope != null ) { fLog . debug ( LEVEL_MID , "" + src_scope . getType ( ) + "" + SVDBItem . getName ( src_scope ) ) ; } SVExprContext ctxt = expr_scan . extractExprContext ( scanner , false ) ; fLog . debug ( LEVEL_MID , "" + ctxt . fType + "" + ctxt . fTrigger + "" + ctxt . fRoot + "" + ctxt . fLeaf + "" + ctxt . fStart ) ; if ( ctxt . fTrigger != null ) { if ( ctxt . fTrigger . equals ( "" ) ) { findMacroItems ( ctxt , getIndexIterator ( ) ) ; } else if ( ctxt . fRoot != null && ( ctxt . fTrigger . equals ( "" ) || ctxt . fTrigger . equals ( "" ) || ctxt . fTrigger . equals ( "" ) || ctxt . fTrigger . equals ( "" ) ) ) { if ( ctxt . fTrigger . equals ( "" ) || ctxt . fTrigger . equals ( "" ) ) { SVDBExpr expr = null ; SVExprUtilsParser parser = new SVExprUtilsParser ( ctxt ) ; try { expr = parser . parsers ( ) . exprParser ( ) . expression ( ) ; } catch ( SVParseException e ) { fLog . debug ( LEVEL_MID , "" , e ) ; return ; } SVContentAssistExprVisitor v = new SVContentAssistExprVisitor ( src_scope , SVDBFindDefaultNameMatcher . getDefault ( ) , getIndexIterator ( ) ) ; ISVDBItemBase item = null ; if ( expr != null ) { item = v . findTypeItem ( expr ) ; } if ( item == null ) { fLog . debug ( LEVEL_MID , "" ) ; return ; } fLog . debug ( LEVEL_MID , "" + item . getType ( ) + "" + SVDBItem . getName ( item ) ) ; findTriggeredProposals ( ctxt , src_scope , item ) ; } else if ( ctxt . fTrigger . equals ( "" ) ) { SVDBExpr expr = null ; SVExprUtilsParser parser = new SVExprUtilsParser ( ctxt ) ; try { expr = parser . parsers ( ) . exprParser ( ) . expression ( ) ; } catch ( SVParseException e ) { fLog . debug ( LEVEL_MID , "" , e ) ; return ; } SVContentAssistExprVisitor v = new SVContentAssistExprVisitor ( src_scope , SVDBFindDefaultNameMatcher . getDefault ( ) , getIndexIterator ( ) ) ; ISVDBItemBase item = null ; if ( expr != null ) { try { item = v . findTypeItem ( expr ) ; } catch ( RuntimeException e ) { } } if ( item == null ) { fLog . debug ( LEVEL_MID , "" ) ; } fLog . debug ( LEVEL_MID , "" + ( ( item != null ) ? ( item . getType ( ) + "" + SVDBItem . getName ( item ) ) : "" ) ) ; findAssignTriggeredProposals ( ctxt , src_scope , item ) ; } else if ( ctxt . fTrigger . equals ( "" ) ) { if ( ctxt . fRoot . startsWith ( "" ) ) { findEndLabelProposals ( ctxt , src_scope ) ; } else { findUntriggeredProposals ( ctxt , src_scope ) ; } } else { } } else if ( ctxt . fTrigger . equals ( "" ) ) { fLog . debug ( LEVEL_MID , "" ) ; findPortCompletionProposals ( ctxt , src_scope , lineno , linepos ) ; } else { } } else { findUntriggeredProposals ( ctxt , src_scope ) ; } order_proposals ( ctxt . fLeaf , fCompletionProposals ) ; } private void findTriggeredProposals ( SVExprContext ctxt , ISVDBChildItem src_scope , ISVDBItemBase leaf_item ) { boolean static_ref = ctxt . fTrigger . equals ( "" ) ; fLog . debug ( "" + leaf_item . getType ( ) ) ; if ( leaf_item . getType ( ) == SVDBItemType . ClassDecl || leaf_item . getType ( ) == SVDBItemType . TypeInfoStruct || leaf_item . getType ( ) == SVDBItemType . InterfaceDecl || leaf_item . getType ( ) == SVDBItemType . ModuleDecl ) { SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; SVDBFindSuperClass super_finder = new SVDBFindSuperClass ( getIndexIterator ( ) ) ; ISVDBChildParent si = ( ISVDBChildParent ) leaf_item ; while ( si != null ) { for ( ISVDBChildItem it : si . getChildren ( ) ) { if ( it . getType ( ) == SVDBItemType . VarDeclStmt ) { SVDBVarDeclStmt v = ( SVDBVarDeclStmt ) it ; if ( ( v . getAttr ( ) & SVDBVarDeclStmt . FieldAttr_Static ) != == static_ref ) { for ( ISVDBItemBase it_1 : ( ( SVDBVarDeclStmt ) it ) . getChildren ( ) ) { debug ( "" + SVDBItem . getName ( it_1 ) ) ; if ( matcher . match ( ( ISVDBNamedItem ) it_1 , ctxt . fLeaf ) ) { addProposal ( it_1 , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } else if ( it . getType ( ) == SVDBItemType . TypedefStmt ) { SVDBTypedefStmt td_stmt = ( SVDBTypedefStmt ) it ; if ( matcher . match ( td_stmt , ctxt . fLeaf ) ) { addProposal ( td_stmt , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } if ( td_stmt . getTypeInfo ( ) != null && td_stmt . getTypeInfo ( ) . getType ( ) == SVDBItemType . TypeInfoEnum ) { SVDBTypeInfoEnum enum_type = ( SVDBTypeInfoEnum ) td_stmt . getTypeInfo ( ) ; for ( SVDBTypeInfoEnumerator enumerator : enum_type . getEnumerators ( ) ) { if ( matcher . match ( enumerator , ctxt . fLeaf ) ) { addProposal ( enumerator , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } else if ( it . getType ( ) == SVDBItemType . ModportDecl ) { for ( ISVDBItemBase it_1 : ( ( SVDBModportDecl ) it ) . getChildren ( ) ) { debug ( "" + SVDBItem . getName ( it_1 ) ) ; if ( matcher . match ( ( ISVDBNamedItem ) it_1 , ctxt . fLeaf ) ) { addProposal ( it_1 , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } else if ( it . getType ( ) == SVDBItemType . ModIfcInst ) { for ( ISVDBItemBase it_1 : ( ( SVDBModIfcInst ) it ) . getChildren ( ) ) { if ( matcher . match ( ( ISVDBNamedItem ) it_1 , ctxt . fLeaf ) ) { addProposal ( it_1 , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } else if ( it instanceof ISVDBNamedItem ) { if ( matcher . match ( ( ISVDBNamedItem ) it , ctxt . fLeaf ) ) { addProposal ( it , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } if ( si . getType ( ) == SVDBItemType . ClassDecl ) { SVDBClassDecl cls_decl = ( SVDBClassDecl ) si ; si = super_finder . find ( cls_decl ) ; } else { if ( si . getType ( ) . isElemOf ( SVDBItemType . InterfaceDecl ) ) { SVDBInterfaceDecl ifc = ( SVDBInterfaceDecl ) si ; for ( SVDBParamPortDecl p : ifc . getPorts ( ) ) { for ( ISVDBItemBase vi : p . getChildren ( ) ) { if ( matcher . match ( ( ISVDBNamedItem ) vi , ctxt . fLeaf ) ) { addProposal ( vi , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } si = null ; } } } else if ( leaf_item . getType ( ) == SVDBItemType . PackageDecl ) { SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; if ( ! static_ref ) { fLog . debug ( "" ) ; } ISVDBIndexIterator index_it = getIndexIterator ( ) ; SVDBPackageDecl pkg_decl = ( SVDBPackageDecl ) leaf_item ; List < SVDBDeclCacheItem > result = index_it . findGlobalScopeDecl ( new NullProgressMonitor ( ) , pkg_decl . getName ( ) , new SVDBFindByNameMatcher ( SVDBItemType . PackageDecl ) ) ; if ( result . size ( ) > ) { SVDBDeclCacheItem pkg_item = result . get ( ) ; List < SVDBDeclCacheItem > pkg_items = index_it . findPackageDecl ( new NullProgressMonitor ( ) , pkg_item ) ; for ( SVDBDeclCacheItem ci : pkg_items ) { ISVDBItemBase item = ci . getSVDBItem ( ) ; if ( item . getType ( ) == SVDBItemType . TypedefStmt ) { SVDBTypedefStmt td_stmt = ( SVDBTypedefStmt ) item ; if ( matcher . match ( td_stmt , ctxt . fLeaf ) ) { addProposal ( td_stmt , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } if ( td_stmt . getTypeInfo ( ) != null && td_stmt . getTypeInfo ( ) . getType ( ) == SVDBItemType . TypeInfoEnum ) { SVDBTypeInfoEnum enum_type = ( SVDBTypeInfoEnum ) td_stmt . getTypeInfo ( ) ; for ( SVDBTypeInfoEnumerator enumerator : enum_type . getEnumerators ( ) ) { if ( matcher . match ( enumerator , ctxt . fLeaf ) ) { addProposal ( enumerator , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } else if ( item instanceof ISVDBNamedItem ) { ISVDBNamedItem ni = ( ISVDBNamedItem ) item ; fLog . debug ( "" + ni . getName ( ) + "" ) ; if ( matcher . match ( ni , ctxt . fLeaf ) ) { addProposal ( item , ctxt . fLeaf , true , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { fLog . debug ( "" + SVDBItem . getName ( item ) ) ; } } } else { fLog . debug ( "" + pkg_decl . getName ( ) + "" ) ; } System . out . println ( "" ) ; } else if ( leaf_item . getType ( ) == SVDBItemType . VarDeclItem ) { ISVDBItemBase item_type = getItemType ( leaf_item ) ; if ( item_type != null && item_type . getType ( ) . isElemOf ( SVDBItemType . ClassDecl ) ) { ISVDBScopeItem si = ( ISVDBScopeItem ) item_type ; SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; for ( ISVDBItemBase it : si . getChildren ( ) ) { if ( it . getType ( ) == SVDBItemType . VarDeclStmt ) { for ( ISVDBItemBase it_1 : ( ( SVDBVarDeclStmt ) it ) . getChildren ( ) ) { debug ( "" + SVDBItem . getName ( it_1 ) ) ; if ( matcher . match ( ( ISVDBNamedItem ) it_1 , ctxt . fLeaf ) ) { addProposal ( it_1 , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } else if ( it instanceof ISVDBNamedItem ) { if ( matcher . match ( ( ISVDBNamedItem ) it , ctxt . fLeaf ) ) { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } } else if ( leaf_item . getType ( ) == SVDBItemType . ModportItem ) { SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; SVDBModportItem mpi = ( SVDBModportItem ) leaf_item ; for ( SVDBModportPortsDecl pd : mpi . getPortsList ( ) ) { if ( pd . getType ( ) == SVDBItemType . ModportSimplePortsDecl ) { SVDBModportSimplePortsDecl simple_pd = ( SVDBModportSimplePortsDecl ) pd ; for ( SVDBModportSimplePort p : simple_pd . getPortList ( ) ) { if ( matcher . match ( p , ctxt . fLeaf ) ) { addProposal ( p , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } else { fLog . debug ( LEVEL_MIN , "" + pd . getType ( ) ) ; } } } } private void findAssignTriggeredProposals ( SVExprContext ctxt , ISVDBChildItem src_scope , ISVDBItemBase item ) { fLog . debug ( "" + ctxt . fLeaf + "" ) ; List < ISVDBItemBase > result = new ArrayList < ISVDBItemBase > ( ) ; List < ISVDBItemBase > tmp = null ; SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; SVDBFindByNameInScopes finder_s = new SVDBFindByNameInScopes ( getIndexIterator ( ) , matcher ) ; tmp = finder_s . find ( src_scope , ctxt . fLeaf , false ) ; result . addAll ( tmp ) ; SVDBFindByNameInClassHierarchy finder_h = new SVDBFindByNameInClassHierarchy ( getIndexIterator ( ) , matcher ) ; tmp = finder_h . find ( src_scope , ctxt . fLeaf ) ; result . addAll ( tmp ) ; if ( result . size ( ) > ) { for ( int i = ; i < result . size ( ) ; i ++ ) { boolean add = true ; if ( result . get ( i ) . getType ( ) == SVDBItemType . Function && ( ( ISVDBNamedItem ) result . get ( i ) ) . getName ( ) . equals ( "" ) ) { add = false ; } if ( add ) { addProposal ( result . get ( i ) , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } SVDBFindNamedModIfcClassIfc finder_cls = new SVDBFindNamedModIfcClassIfc ( getIndexIterator ( ) , matcher ) ; List < ISVDBChildItem > cl_l = finder_cls . find ( ctxt . fLeaf ) ; if ( cl_l . size ( ) > ) { fLog . debug ( "" + ctxt . fLeaf + "" + cl_l . size ( ) ) ; for ( ISVDBChildItem cl : cl_l ) { fLog . debug ( "" + cl . getType ( ) + "" + SVDBItem . getName ( cl ) ) ; } for ( ISVDBItemBase it : cl_l ) { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { fLog . debug ( "" + ctxt . fLeaf + "" ) ; } SVDBFindByName finder_tf = new SVDBFindByName ( getIndexIterator ( ) , matcher ) ; List < ISVDBItemBase > it_l = finder_tf . find ( ctxt . fLeaf ) ; for ( int i = ; i < it_l . size ( ) ; i ++ ) { if ( it_l . get ( i ) . getType ( ) == SVDBItemType . Function || it_l . get ( i ) . getType ( ) == SVDBItemType . Task ) { SVDBTask tf = ( SVDBTask ) it_l . get ( i ) ; if ( ( tf . getAttr ( ) & IFieldItemAttr . FieldAttr_Extern ) == && tf . getName ( ) . contains ( "" ) ) { it_l . remove ( i ) ; i -- ; } ISVDBItemBase scope_t = tf ; while ( scope_t != null && scope_t . getType ( ) != SVDBItemType . ClassDecl && scope_t . getType ( ) != SVDBItemType . ModuleDecl ) { scope_t = ( ( ISVDBChildItem ) scope_t ) . getParent ( ) ; } if ( scope_t != null && ( scope_t . getType ( ) == SVDBItemType . ClassDecl || scope_t . getType ( ) == SVDBItemType . ModuleDecl ) ) { it_l . remove ( i ) ; i -- ; } } } if ( it_l != null && it_l . size ( ) > ) { fLog . debug ( "" + ctxt . fLeaf + "" ) ; for ( ISVDBItemBase it : it_l ) { fLog . debug ( "" + it . getType ( ) + "" + ( ( ISVDBNamedItem ) it ) . getName ( ) ) ; } for ( ISVDBItemBase it : it_l ) { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { fLog . debug ( "" + ctxt . fLeaf + "" ) ; } fLog . debug ( "" + ( ( item != null ) ? item . getType ( ) : "" ) ) ; if ( item != null && ( item . getType ( ) == SVDBItemType . ClassDecl ) && ( "" . startsWith ( ctxt . fLeaf ) || ctxt . fLeaf . equals ( "" ) ) ) { SVDBClassDecl cls = ( SVDBClassDecl ) item ; fLog . debug ( "" + SVDBItem . getName ( item ) ) ; for ( ISVDBChildItem c : cls . getChildren ( ) ) { if ( c . getType ( ) == SVDBItemType . Function ) { SVDBFunction f = ( SVDBFunction ) c ; if ( f . getName ( ) . equals ( "" ) ) { addProposal ( c , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } } } private void findPortCompletionProposals ( SVExprContext ctxt , ISVDBChildParent src_scope , int lineno , int linepos ) { fLog . debug ( "" ) ; SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; fLog . debug ( "" ) ; if ( src_scope == null || ( src_scope . getType ( ) != SVDBItemType . ModuleDecl && src_scope . getType ( ) != SVDBItemType . InterfaceDecl ) ) { fLog . debug ( "" + src_scope + "" ) ; return ; } fLog . debug ( "" ) ; SVDBModIfcInst inst = findInst ( src_scope , lineno , linepos ) ; fLog . debug ( "" ) ; if ( inst == null ) { fLog . debug ( "" ) ; return ; } fLog . debug ( "" ) ; fLog . debug ( "" + inst . getTypeName ( ) ) ; SVDBModIfcDecl decl ; SVDBFindNamedModIfcClassIfc finder = new SVDBFindNamedModIfcClassIfc ( getIndexIterator ( ) ) ; List < ISVDBChildItem > result = finder . find ( inst . getTypeName ( ) ) ; if ( result . size ( ) > && ( result . get ( ) . getType ( ) == SVDBItemType . ModuleDecl || result . get ( ) . getType ( ) == SVDBItemType . InterfaceDecl ) ) { decl = ( SVDBModIfcDecl ) result . get ( ) ; } else { fLog . debug ( "" + inst . getTypeName ( ) + "" ) ; return ; } for ( SVDBParamPortDecl p : decl . getPorts ( ) ) { for ( ISVDBChildItem pi : p . getChildren ( ) ) { if ( matcher . match ( ( ISVDBNamedItem ) pi , ctxt . fLeaf ) ) { addProposal ( pi , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } fLog . debug ( "" ) ; } private SVDBModIfcInst findInst ( ISVDBChildParent p , int lineno , int linepos ) { SVDBModIfcInst last_inst = null ; for ( ISVDBChildItem c : p . getChildren ( ) ) { if ( c . getType ( ) == SVDBItemType . ModIfcInst ) { last_inst = ( SVDBModIfcInst ) c ; if ( c . getLocation ( ) . getLine ( ) > lineno ) { break ; } } else if ( c instanceof ISVDBChildParent ) { if ( c . getLocation ( ) != null && c . getLocation ( ) . getLine ( ) > lineno ) { break ; } if ( ( last_inst = findInst ( ( ISVDBChildParent ) c , lineno , linepos ) ) != null ) { break ; } } } return last_inst ; } private void findEndLabelProposals ( SVExprContext ctxt , ISVDBChildItem src_scope ) { fLog . debug ( "" + ctxt . fLeaf + "" ) ; fLog . debug ( "" + SVDBItem . getName ( src_scope ) ) ; if ( src_scope == null || ! ( src_scope instanceof ISVDBNamedItem ) ) { return ; } ISVDBNamedItem item = ( ISVDBNamedItem ) src_scope ; if ( ctxt . fLeaf . equals ( "" ) || item . getName ( ) . startsWith ( ctxt . fLeaf ) ) { addProposal ( new SVCompletionProposal ( ( ( ISVDBNamedItem ) src_scope ) . getName ( ) , ctxt . fStart , ctxt . fLeaf . length ( ) ) ) ; } else { findUntriggeredProposals ( ctxt , src_scope ) ; } } private void findUntriggeredProposals ( SVExprContext ctxt , ISVDBChildItem src_scope ) { fLog . debug ( "" + ctxt . fLeaf + "" ) ; List < ISVDBItemBase > result = null ; SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; SVDBFindByNameInScopes finder_s = new SVDBFindByNameInScopes ( getIndexIterator ( ) , matcher ) ; fLog . debug ( "" ) ; result = finder_s . find ( src_scope , ctxt . fLeaf , false ) ; fLog . debug ( "" + result . size ( ) + "" ) ; for ( int i = ; i < result . size ( ) ; i ++ ) { if ( ! ( SVDBItem . getName ( result . get ( i ) ) . equals ( ctxt . fLeaf ) && isSameScopeVarDecl ( src_scope , result . get ( i ) ) ) ) { addProposal ( result . get ( i ) , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } SVDBFindByNameInClassHierarchy finder_h = new SVDBFindByNameInClassHierarchy ( getIndexIterator ( ) , matcher ) ; result = finder_h . find ( src_scope , ctxt . fLeaf ) ; if ( result . size ( ) > ) { for ( int i = ; i < result . size ( ) ; i ++ ) { boolean add = true ; if ( ctxt . fTrigger != null && ctxt . fTrigger . equals ( "" ) && "" . startsWith ( ctxt . fLeaf ) ) { if ( result . get ( i ) . getType ( ) == SVDBItemType . Function && ( ( ISVDBNamedItem ) result . get ( i ) ) . getName ( ) . equals ( "" ) ) { add = false ; } } if ( ctxt . fType == ContextType . Extends ) { fLog . debug ( "" + result . get ( i ) . getType ( ) ) ; if ( result . get ( i ) . getType ( ) != SVDBItemType . ClassDecl ) { add = false ; } } if ( add ) { addProposal ( result . get ( i ) , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } SVDBFindNamedModIfcClassIfc finder_cls = new SVDBFindNamedModIfcClassIfc ( getIndexIterator ( ) , matcher ) ; List < ISVDBChildItem > cl_l = finder_cls . find ( ctxt . fLeaf ) ; if ( cl_l . size ( ) > ) { fLog . debug ( "" + ctxt . fLeaf + "" + cl_l . size ( ) ) ; for ( ISVDBChildItem cl : cl_l ) { fLog . debug ( "" + cl . getType ( ) + "" + SVDBItem . getName ( cl ) ) ; } for ( ISVDBItemBase it : cl_l ) { if ( ctxt . fType == ContextType . Extends ) { if ( it . getType ( ) == SVDBItemType . ClassDecl ) { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } else { fLog . debug ( "" + ctxt . fLeaf + "" ) ; } if ( ctxt . fType != ContextType . Extends ) { SVDBFindByName finder_tf = new SVDBFindByName ( getIndexIterator ( ) , matcher ) ; List < ISVDBItemBase > it_l = finder_tf . find ( ctxt . fLeaf , SVDBItemType . Task , SVDBItemType . Function , SVDBItemType . VarDeclStmt , SVDBItemType . PackageDecl , SVDBItemType . TypedefStmt ) ; for ( int i = ; i < it_l . size ( ) ; i ++ ) { if ( it_l . get ( i ) . getType ( ) == SVDBItemType . Function || it_l . get ( i ) . getType ( ) == SVDBItemType . Task ) { SVDBTask tf = ( SVDBTask ) it_l . get ( i ) ; if ( ( tf . getAttr ( ) & IFieldItemAttr . FieldAttr_Extern ) == && tf . getName ( ) . contains ( "" ) ) { it_l . remove ( i ) ; i -- ; } ISVDBItemBase scope_t = tf ; while ( scope_t != null && scope_t . getType ( ) != SVDBItemType . ClassDecl && scope_t . getType ( ) != SVDBItemType . ModuleDecl ) { scope_t = ( ( ISVDBChildItem ) scope_t ) . getParent ( ) ; } if ( scope_t != null && ( scope_t . getType ( ) == SVDBItemType . ClassDecl || scope_t . getType ( ) == SVDBItemType . ModuleDecl ) ) { it_l . remove ( i ) ; i -- ; } } } if ( it_l != null && it_l . size ( ) > ) { fLog . debug ( "" + ctxt . fLeaf + "" ) ; for ( ISVDBItemBase it : it_l ) { fLog . debug ( "" + it . getType ( ) + "" + ( ( ISVDBNamedItem ) it ) . getName ( ) ) ; } for ( ISVDBItemBase it : it_l ) { addProposal ( it , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { fLog . debug ( "" + ctxt . fLeaf + "" ) ; } } } private boolean isSameScopeVarDecl ( ISVDBChildItem src_scope , ISVDBItemBase proposal ) { if ( proposal instanceof SVDBVarDeclItem ) { SVDBVarDeclItem v = ( SVDBVarDeclItem ) proposal ; if ( v . getParent ( ) != null && v . getParent ( ) . getParent ( ) != null ) { return ( v . getParent ( ) . getParent ( ) == src_scope ) ; } } return false ; } private void findMacroItems ( SVExprContext ctxt , ISVDBIndexIterator index_it ) { SVDBFindContentAssistNameMatcher matcher = new SVDBFindContentAssistNameMatcher ( ) ; if ( ctxt . fRoot != null && ctxt . fRoot . equals ( "" ) ) { SVDBFindIncludedFile finder = new SVDBFindIncludedFile ( index_it , matcher ) ; List < SVDBFile > it_l = finder . find ( ctxt . fLeaf ) ; if ( it_l . size ( ) > ) { addProposal ( it_l . get ( ) , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } else { List < SVDBDeclCacheItem > result = index_it . findGlobalScopeDecl ( new NullProgressMonitor ( ) , ctxt . fLeaf , new SVDBFindContentAssistNameMatcher ( SVDBItemType . MacroDef ) ) ; for ( SVDBDeclCacheItem i : result ) { fLog . debug ( LEVEL_MID , "" + i . getName ( ) ) ; addProposal ( i . getSVDBItem ( ) , ctxt . fLeaf , ctxt . fStart , ctxt . fLeaf . length ( ) ) ; } } } private ISVDBItemBase getItemType ( ISVDBItemBase item ) { SVDBTypeInfo ti = null ; if ( item . getType ( ) == SVDBItemType . VarDeclStmt ) { ti = ( ( SVDBVarDeclStmt ) item ) . getTypeInfo ( ) ; } else if ( item . getType ( ) == SVDBItemType . VarDeclItem ) { SVDBVarDeclItem vi = ( SVDBVarDeclItem ) item ; if ( vi . getParent ( ) != null ) { ti = vi . getParent ( ) . getTypeInfo ( ) ; } } if ( ti != null ) { ISVDBItemBase target = resolveType ( ti ) ; if ( target != null ) { return target ; } } return ti ; } private ISVDBItemBase resolveType ( SVDBTypeInfo ti ) { ISVDBItemBase target = null ; if ( ti . getType ( ) == SVDBItemType . TypeInfoUserDef ) { SVDBFindByName finder = new SVDBFindByName ( getIndexIterator ( ) ) ; List < ISVDBItemBase > ret = finder . find ( ti . getName ( ) ) ; if ( ret . size ( ) > ) { target = ret . get ( ) ; } } else if ( ti . getType ( ) == SVDBItemType . TypeInfoStruct ) { } else { } if ( target != null ) { if ( target . getType ( ) == SVDBItemType . TypedefStmt ) { target = resolveType ( ( ( SVDBTypedefStmt ) target ) . getTypeInfo ( ) ) ; } } return target ; } protected boolean isPrefix ( String pre , SVDBItem it ) { return it . getName ( ) . toLowerCase ( ) . startsWith ( pre . toLowerCase ( ) ) ; } private void order_proposals ( String prefix , List < SVCompletionProposal > proposals ) { synchronized ( proposals ) { for ( int i = ; i < proposals . size ( ) ; i ++ ) { SVCompletionProposal p = proposals . get ( i ) ; if ( p . getItem ( ) != null && SVDBStmt . isType ( p . getItem ( ) , SVDBItemType . TypedefStmt ) ) { boolean found = false ; for ( SVCompletionProposal p_t : proposals ) { if ( p_t != p && p_t . getItem ( ) != null && SVDBItem . getName ( p_t . getItem ( ) ) . equals ( SVDBItem . getName ( p . getItem ( ) ) ) ) { found = true ; break ; } } if ( found ) { proposals . remove ( i ) ; i -- ; } } } for ( int i = ; i < proposals . size ( ) ; i ++ ) { SVCompletionProposal p_i = proposals . get ( i ) ; for ( int j = i + ; j < proposals . size ( ) ; j ++ ) { SVCompletionProposal p_j = proposals . get ( j ) ; String s_i , s_j ; if ( p_i . getItem ( ) != null ) { s_i = SVDBItem . getName ( p_i . getItem ( ) ) ; } else { s_i = p_i . getReplacement ( ) ; } if ( p_j . getItem ( ) != null ) { s_j = SVDBItem . getName ( p_j . getItem ( ) ) ; } else { s_j = p_j . getReplacement ( ) ; } if ( s_i . compareTo ( s_j ) > ) { proposals . set ( i , p_j ) ; proposals . set ( j , p_i ) ; p_i = p_j ; } } } for ( int i = ; i < proposals . size ( ) ; i ++ ) { SVCompletionProposal p_i = proposals . get ( i ) ; for ( int j = i + ; j < proposals . size ( ) ; j ++ ) { SVCompletionProposal p_j = proposals . get ( j ) ; String s_i , s_j ; if ( p_i . getItem ( ) != null ) { s_i = SVDBItem . getName ( p_i . getItem ( ) ) ; } else { s_i = p_i . getReplacement ( ) ; } if ( p_j . getItem ( ) != null ) { s_j = SVDBItem . getName ( p_j . getItem ( ) ) ; } else { s_j = p_j . getReplacement ( ) ; } if ( prefix . compareTo ( s_i ) < prefix . compareTo ( s_j ) ) { proposals . set ( i , p_j ) ; proposals . set ( j , p_i ) ; p_i = p_j ; } } } } } protected void addProposal ( ISVDBItemBase it , String prefix , int replacementOffset , int replacementLength ) { addProposal ( it , prefix , false , replacementOffset , replacementLength ) ; } protected void addProposal ( ISVDBItemBase it , String prefix , boolean name_based_check , int replacementOffset , int replacementLength ) { boolean found = false ; synchronized ( fCompletionProposals ) { for ( SVCompletionProposal p : fCompletionProposals ) { if ( p . getItem ( ) != null ) { if ( p . getItem ( ) == it ) { found = true ; break ; } else if ( name_based_check ) { if ( p . getItem ( ) instanceof ISVDBNamedItem && it instanceof ISVDBNamedItem ) { ISVDBNamedItem i1 = ( ISVDBNamedItem ) p . getItem ( ) ; ISVDBNamedItem i2 = ( ISVDBNamedItem ) it ; if ( i1 . getName ( ) == null || i1 . getName ( ) == null ) { if ( i1 . getName ( ) == i2 . getName ( ) ) { found = true ; break ; } } else if ( i1 . getName ( ) . equals ( i2 . getName ( ) ) ) { found = true ; break ; } } } } } if ( ! found ) { debug ( "" + SVDBItem . getName ( it ) + "" + it . getType ( ) ) ; addProposal ( new SVCompletionProposal ( it , prefix , replacementOffset , replacementLength ) ) ; } } } protected void debug ( String msg ) { fLog . debug ( msg ) ; } }
package net . sf . sveditor . core . content_assist ; import java . util . ArrayList ; import net . sf . sveditor . core . db . ISVDBChildItem ; import net . sf . sveditor . core . db . SVDBItem ; import net . sf . sveditor . core . db . SVDBModIfcDecl ; import net . sf . sveditor . core . db . SVDBTask ; import net . sf . sveditor . core . db . stmt . SVDBParamPortDecl ; import net . sf . sveditor . core . db . stmt . SVDBVarDeclItem ; public class SVCompletionProposalUtils { private int fTFMaxCharsPerLine = ; private int fTFPortsPerLine = ; private boolean fTFNamedPorts = true ; private int fModIfcInstMaxCharsPerLine = ; private int fModIfcInstPortsPerLine = ; private boolean fModIfcInstNamedPorts = true ; public SVCompletionProposalUtils ( ) { } public void setTFMaxCharsPerLine ( int max ) { fTFMaxCharsPerLine = max ; } public void setTFPortsPerLine ( int max ) { fTFPortsPerLine = max ; } public void setTFNamedPorts ( boolean named ) { fTFNamedPorts = named ; } public void setModIfcInstMaxCharsPerLine ( int max ) { fModIfcInstMaxCharsPerLine = max ; } public void setModIfcInstPortsPerLine ( int max ) { fModIfcInstPortsPerLine = max ; } public void setModIfcInstNamedPorts ( boolean named ) { fModIfcInstNamedPorts = named ; } private static String escapeId ( String id ) { StringBuilder sb = new StringBuilder ( id ) ; for ( int i = ; i < sb . length ( ) ; i ++ ) { if ( sb . charAt ( i ) == '' ) { sb . insert ( i , '' ) ; i ++ ; } } return sb . toString ( ) ; } public static String getLineIndent ( String doc , String indent_incr ) { StringBuilder doc_str = new StringBuilder ( doc ) ; int last_line_idx = doc_str . lastIndexOf ( "" ) ; String indent = "" ; if ( last_line_idx != - ) { int end_line_idx = last_line_idx ; while ( end_line_idx < doc_str . length ( ) && Character . isWhitespace ( doc_str . charAt ( end_line_idx ) ) ) { end_line_idx ++ ; } indent = doc_str . substring ( last_line_idx + , end_line_idx ) ; } return indent ; } public String createTFTemplate ( SVDBTask tf , String subseq_line_indent , int first_line_pos , int subseq_line_pos ) { String newline = "" + subseq_line_indent ; StringBuilder r = new StringBuilder ( ) ; int curr_pos = first_line_pos ; int longest_string = ; int port_length = ; int port_count = ; ArrayList < String > all_ports = new ArrayList < String > ( ) ; ArrayList < String > all_types = new ArrayList < String > ( ) ; for ( int i = ; i < tf . getParams ( ) . size ( ) ; i ++ ) { SVDBParamPortDecl param = tf . getParams ( ) . get ( i ) ; for ( ISVDBChildItem c : param . getChildren ( ) ) { SVDBVarDeclItem vi = ( SVDBVarDeclItem ) c ; all_ports . add ( vi . getName ( ) ) ; all_types . add ( param . getTypeName ( ) ) ; port_count ++ ; port_length += vi . getName ( ) . length ( ) ; if ( vi . getName ( ) . length ( ) > longest_string ) { longest_string = vi . getName ( ) . length ( ) ; } } } boolean multi_line_instantiation = false ; int multiplier = fTFNamedPorts ? : ; if ( ( ( fTFMaxCharsPerLine != ) && ( ( first_line_pos + ( port_length * multiplier ) + ( * multiplier ) ) > ( ( fTFMaxCharsPerLine * ) / ) ) ) || ( ( fTFPortsPerLine != ) && ( port_count > fTFPortsPerLine ) ) ) { multi_line_instantiation = true ; curr_pos = subseq_line_pos ; } else { newline = "" ; } r . append ( escapeId ( SVDBItem . getName ( tf ) ) + "" + newline ) ; for ( int i = ; i < port_count ; i ++ ) { StringBuilder padding = new StringBuilder ( "" ) ; String name_str = all_ports . get ( i ) ; if ( multi_line_instantiation ) { for ( int cnt = name_str . length ( ) ; cnt < longest_string + ; cnt ++ ) { padding . append ( "" ) ; } } if ( fTFNamedPorts == true ) { r . append ( "" ) ; r . append ( name_str + padding . toString ( ) ) ; r . append ( "" ) ; curr_pos += + name_str . length ( ) + padding . toString ( ) . length ( ) ; } r . append ( "" + all_ports . get ( i ) + "" + padding . toString ( ) ) ; curr_pos += + all_ports . get ( i ) . length ( ) + padding . toString ( ) . length ( ) ; if ( fTFNamedPorts == true ) { r . append ( "" ) ; curr_pos ++ ; } if ( i + < port_count ) { r . append ( "" ) ; curr_pos += ; if ( ( fTFPortsPerLine != && multi_line_instantiation && ( ( ( i + ) % fTFPortsPerLine ) == ) ) || ( curr_pos > ( * fTFMaxCharsPerLine ) / ) ) { r . append ( newline ) ; curr_pos = subseq_line_pos ; } } } r . append ( "" ) ; return r . toString ( ) ; } public String createModuleTemplate ( SVDBModIfcDecl tf , String subseq_line_indent , int first_line_pos , int subseq_line_pos ) { String newline = "" + subseq_line_indent ; StringBuilder r = new StringBuilder ( ) ; int curr_pos = first_line_pos ; int longest_string = ; int port_len = ; int param_len = ; int port_count = ; int param_count = ; ArrayList < String > all_ports = new ArrayList < String > ( ) ; ArrayList < String > all_types = new ArrayList < String > ( ) ; ArrayList < String > all_params = new ArrayList < String > ( ) ; for ( int i = ; i < tf . getParameters ( ) . size ( ) ; i ++ ) { String param_name = tf . getParameters ( ) . get ( i ) . getName ( ) ; all_params . add ( param_name ) ; param_count ++ ; int len = param_name . length ( ) ; param_len += len ; if ( len > longest_string ) { longest_string = len ; } } for ( int i = ; i < tf . getPorts ( ) . size ( ) ; i ++ ) { SVDBParamPortDecl param = tf . getPorts ( ) . get ( i ) ; for ( ISVDBChildItem c : param . getChildren ( ) ) { SVDBVarDeclItem vi = ( SVDBVarDeclItem ) c ; all_ports . add ( vi . getName ( ) ) ; all_types . add ( param . getTypeName ( ) ) ; port_count ++ ; int len = vi . getName ( ) . length ( ) ; port_len += len ; if ( len > longest_string ) { longest_string = len ; } } } boolean multi_line_instantiation = false ; int multiplier = fModIfcInstNamedPorts ? : ; if ( ( ( fModIfcInstMaxCharsPerLine != ) && ( ( first_line_pos + ( ( port_len + param_len ) * multiplier ) + ( * multiplier ) ) > ( ( fModIfcInstMaxCharsPerLine * ) / ) ) ) || ( ( fModIfcInstPortsPerLine != ) && ( ( port_count > fModIfcInstPortsPerLine ) || ( param_count > fModIfcInstPortsPerLine ) ) ) ) { multi_line_instantiation = true ; curr_pos = subseq_line_pos ; } else { newline = "" ; } r . append ( escapeId ( SVDBItem . getName ( tf ) ) ) ; if ( param_count != ) { r . append ( "" + newline ) ; for ( int i = ; i < param_count ; i ++ ) { StringBuilder padding = new StringBuilder ( "" ) ; String name_str = all_params . get ( i ) ; if ( multi_line_instantiation ) { for ( int cnt = name_str . length ( ) ; cnt < longest_string + ; cnt ++ ) { padding . append ( "" ) ; } } if ( fModIfcInstNamedPorts == true ) { r . append ( "" ) ; r . append ( name_str + padding . toString ( ) ) ; r . append ( "" ) ; curr_pos += + name_str . length ( ) + padding . toString ( ) . length ( ) ; } r . append ( "" + name_str + "" + padding . toString ( ) ) ; curr_pos += + name_str . length ( ) + padding . toString ( ) . length ( ) ; if ( fModIfcInstNamedPorts == true ) { r . append ( "" ) ; curr_pos ++ ; } if ( i + < param_count ) { r . append ( "" ) ; curr_pos += ; if ( ( fModIfcInstPortsPerLine != && multi_line_instantiation && ( ( ( i + ) % fModIfcInstPortsPerLine ) == ) ) || ( curr_pos > ( * fModIfcInstMaxCharsPerLine ) / ) ) { r . append ( newline ) ; curr_pos = subseq_line_pos ; } } } r . append ( escapeId ( newline + "" ) ) ; } r . append ( "" + escapeId ( SVDBItem . getName ( tf ) ) + "" + "" + newline ) ; if ( ! newline . isEmpty ( ) ) curr_pos = subseq_line_pos ; for ( int i = ; i < port_count ; i ++ ) { StringBuilder padding = new StringBuilder ( "" ) ; String name_str = all_ports . get ( i ) ; if ( multi_line_instantiation ) { for ( int cnt = name_str . length ( ) ; cnt < longest_string + ; cnt ++ ) { padding . append ( "" ) ; } } if ( fModIfcInstNamedPorts == true ) { r . append ( "" ) ; r . append ( name_str + padding . toString ( ) ) ; r . append ( "" ) ; curr_pos += + name_str . length ( ) + padding . toString ( ) . length ( ) ; } r . append ( "" + all_ports . get ( i ) + "" + padding . toString ( ) ) ; curr_pos += + all_ports . get ( i ) . length ( ) + padding . toString ( ) . length ( ) ; if ( fModIfcInstNamedPorts == true ) { r . append ( "" ) ; curr_pos ++ ; } if ( i + < port_count ) { r . append ( "" ) ; curr_pos += ; if ( ( fModIfcInstPortsPerLine != && multi_line_instantiation && ( ( ( i + ) % fModIfcInstPortsPerLine ) == ) ) || ( curr_pos > ( * fModIfcInstMaxCharsPerLine ) / ) ) { r . append ( newline ) ; curr_pos = subseq_line_pos ; } } } r . append ( "" ) ; return r . toString ( ) ; } }
package net . sf . sveditor . core . content_assist ; public enum SVCompletionProposalType { SVObject , Keyword , Unknown }
package net . sf . sveditor . core . indent ; import java . util . List ; public class SVIndentStmt { protected List < SVIndentStmt > fStmtList ; protected SVIndentStmtType fType ; public SVIndentStmt ( SVIndentStmtType type ) { fType = type ; } public SVIndentStmtType getType ( ) { return fType ; } }
package net . sf . sveditor . core . indent ; public class SVIndentToken { protected SVIndentTokenType fType ; protected String fLeadingWS ; protected String fTrailingWS = "" ; protected String fImage ; protected boolean fEndLine ; protected boolean fStartLine ; protected boolean fDoIt ; protected int fPos ; protected int fLineno ; public SVIndentToken ( SVIndentTokenType type , String leading_ws , String image ) { fType = type ; fLeadingWS = leading_ws ; fTrailingWS = "" ; fImage = image ; fDoIt = true ; } protected SVIndentToken ( SVIndentTokenType type , String leading_ws ) { fType = type ; fLeadingWS = leading_ws ; fTrailingWS = "" ; fImage = "" ; fDoIt = true ; } public boolean isId ( String s ) { return ( getType ( ) == SVIndentTokenType . Identifier && getImage ( ) . equals ( s ) ) ; } public boolean isOp ( String ... s ) { if ( getType ( ) == SVIndentTokenType . Operator ) { if ( s . length == ) { return true ; } else { for ( String s_i : s ) { if ( getImage ( ) . equals ( s_i ) ) { return true ; } } } } return false ; } public boolean isPreProc ( ) { return ( getType ( ) == SVIndentTokenType . Identifier && getImage ( ) . startsWith ( "" ) ) ; } public void setPos ( int pos ) { fPos = pos ; } public int getPos ( ) { return fPos ; } public void setLineno ( int lineno ) { fLineno = lineno ; } public int getLineno ( ) { return fLineno ; } public SVIndentTokenType getType ( ) { return fType ; } public void setTrailingWS ( String trailing_ws ) { fTrailingWS = trailing_ws ; } public String getTrailingWS ( ) { return fTrailingWS ; } public boolean isEndLine ( ) { return fEndLine ; } public void setIsEndLine ( boolean end ) { fEndLine = end ; } public boolean isStartLine ( ) { return fStartLine ; } public void setIsStartLine ( boolean start ) { fStartLine = start ; } public String getLeadingWS ( ) { return fLeadingWS ; } public void setLeadingWS ( String leading_ws ) { fLeadingWS = leading_ws ; } public String getImage ( ) { return fImage ; } public void setImage ( String image ) { fImage = image ; } public boolean getDoIt ( ) { return fDoIt ; } public void setDoIt ( boolean doit ) { fDoIt = doit ; } public boolean isBlankLine ( ) { return ( fStartLine && fEndLine && fImage . trim ( ) . equals ( "" ) ) ; } public boolean isComment ( ) { return ( fType == SVIndentTokenType . SingleLineComment || fType == SVIndentTokenType . MultiLineComment ) ; } }
package net . sf . sveditor . core . indent ; import java . util . HashSet ; import java . util . Set ; import net . sf . sveditor . core . log . LogFactory ; import net . sf . sveditor . core . log . LogHandle ; import net . sf . sveditor . core . scanutils . ITextScanner ; public class SVIndentScanner implements ISVIndentScanner { private ITextScanner fScanner ; private int fUngetCh ; private int fLastCh [ ] = { - , - } ; private int fLastChT = - ; private int fLineno ; private boolean fStartLine ; private String fLeadingWS ; private SVIndentToken fCurrent ; private static Set < String > fScopeKeywords ; private static Set < String > fQualifiers ; private StringBuilder fTmp ; private static final boolean fDebugEn = false ; private static Set < String > fOperators ; private LogHandle fLog ; private static final String fOperatorList [ ] = { "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , ">" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" } ; static { fScopeKeywords = new HashSet < String > ( ) ; fScopeKeywords . add ( "" ) ; fScopeKeywords . add ( "" ) ; fScopeKeywords . add ( "" ) ; fScopeKeywords . add ( "" ) ; fQualifiers = new HashSet < String > ( ) ; fQualifiers . add ( "" ) ; fQualifiers . add ( "" ) ; fQualifiers . add ( "" ) ; fQualifiers . add ( "" ) ; fQualifiers . add ( "" ) ; fOperators = new HashSet < String > ( ) ; for ( String op : fOperatorList ) { if ( ! fOperators . contains ( op ) ) { fOperators . add ( op ) ; } } } public SVIndentScanner ( ITextScanner scanner ) { fTmp = new StringBuilder ( ) ; fScanner = scanner ; fUngetCh = - ; fLastCh [ ] = - ; fLastCh [ ] = '' ; fLineno = ; fLog = LogFactory . getLogHandle ( "" ) ; fStartLine = true ; } public SVIndentToken next ( ) { boolean start_line ; int pos = ; SVIndentToken token = null ; start_line = fStartLine ; fStartLine = false ; if ( fLeadingWS == null ) { pos = ( int ) fScanner . getPos ( ) ; fLeadingWS = getIndent ( ) ; } int c = get_ch ( ) ; int lineno = fLineno ; if ( fDebugEn ) { debug ( "" + ( char ) c + "" ) ; } if ( c == '' ) { token = new SVIndentToken ( SVIndentTokenType . BlankLine , fLeadingWS ) ; fStartLine = true ; token . setIsEndLine ( true ) ; } else if ( c == '' ) { int c2 = get_ch ( ) ; if ( c2 == '' ) { token = read_single_line_comment ( fLeadingWS ) ; token . setIsEndLine ( true ) ; } else if ( c2 == '' ) { token = read_multi_line_comment ( fLeadingWS ) ; } else { unget_ch ( c2 ) ; token = new SVIndentToken ( SVIndentTokenType . Operator , fLeadingWS , "" ) ; } } else if ( c == '' ) { int last_c = - ; fTmp . setLength ( ) ; fTmp . append ( ( char ) c ) ; while ( ( c = get_ch ( ) ) != - && ( c != '' || last_c == '' ) ) { fTmp . append ( ( char ) c ) ; last_c = c ; } fTmp . append ( ( char ) c ) ; token = new SVIndentToken ( SVIndentTokenType . String , fLeadingWS , fTmp . toString ( ) ) ; } else if ( c == '' || c == '' || Character . isJavaIdentifierStart ( c ) ) { boolean is_macro = ( c == '' ) ; int tmp_c = c ; if ( is_macro ) { c = get_ch ( ) ; } String id = readIdentifier ( c ) ; if ( is_macro ) { id = ( char ) tmp_c + id ; } token = new SVIndentToken ( SVIndentTokenType . Identifier , fLeadingWS , id ) ; } else if ( c == '' ) { token = new SVIndentToken ( SVIndentTokenType . Operator , fLeadingWS , "" ) ; } else if ( Character . isDigit ( c ) || c == '' ) { fTmp . setLength ( ) ; if ( c == '' ) { int c2 = get_ch ( ) ; if ( ( c2 >= '' && c2 <= '' ) || ( c2 >= '' && c2 <= '' ) ) { fTmp . append ( ( char ) c ) ; fTmp . append ( ( char ) c2 ) ; } else { unget_ch ( c2 ) ; token = new SVIndentToken ( SVIndentTokenType . Operator , fLeadingWS , "" ) ; } } else { fTmp . append ( ( char ) c ) ; } if ( token == null ) { while ( ( c = get_ch ( ) ) != - && ( c == '' || Character . isDigit ( c ) || ( c >= '' && c <= '' ) || ( c >= '' && c <= '' ) ) ) { fTmp . append ( ( char ) c ) ; } unget_ch ( c ) ; token = new SVIndentToken ( SVIndentTokenType . Number , fLeadingWS , fTmp . toString ( ) ) ; } } else if ( c == - ) { if ( fDebugEn ) { debug ( "" ) ; } token = null ; } else { fTmp . setLength ( ) ; fTmp . append ( ( char ) c ) ; while ( fOperators . contains ( fTmp . toString ( ) ) ) { if ( ( c = get_ch ( ) ) == - ) { break ; } fTmp . append ( ( char ) c ) ; } if ( fDebugEn ) { debug ( "" + fTmp . toString ( ) + "" ) ; } if ( ! fOperators . contains ( fTmp . toString ( ) ) ) { if ( fTmp . length ( ) > ) { fTmp . setLength ( fTmp . length ( ) - ) ; unget_ch ( c ) ; } else { unget_ch ( c ) ; } } if ( fOperators . contains ( fTmp . toString ( ) ) ) { token = new SVIndentToken ( SVIndentTokenType . Operator , fLeadingWS , fTmp . toString ( ) ) ; } else { token = null ; fLog . error ( "" + ( char ) c + "" ) ; } } fLeadingWS = null ; if ( token != null ) { token . setLineno ( lineno ) ; token . setPos ( pos ) ; c = get_ch ( ) ; if ( c == '' ) { token . setIsEndLine ( true ) ; fStartLine = true ; if ( token . getType ( ) == SVIndentTokenType . BlankLine ) { unget_ch ( c ) ; } else { fTmp . setLength ( ) ; while ( ( c = get_ch ( ) ) != - && Character . isWhitespace ( c ) && c != '' ) { fTmp . append ( ( char ) c ) ; } unget_ch ( c ) ; fLeadingWS = fTmp . toString ( ) ; } } else { if ( token . getType ( ) == SVIndentTokenType . BlankLine ) { unget_ch ( c ) ; } else { fTmp . setLength ( ) ; unget_ch ( c ) ; pos = ( int ) fScanner . getPos ( ) ; while ( ( c = get_ch ( ) ) != - && Character . isWhitespace ( c ) && c != '' ) { fTmp . append ( ( char ) c ) ; } if ( c == '' ) { token . setIsEndLine ( true ) ; token . setTrailingWS ( fTmp . toString ( ) ) ; fStartLine = true ; } else { fLeadingWS = fTmp . toString ( ) ; unget_ch ( c ) ; } } } token . setIsStartLine ( start_line ) ; if ( fDebugEn ) { debug ( "" + ( ( token . getType ( ) == SVIndentTokenType . Identifier || token . getType ( ) == SVIndentTokenType . Operator ) ? token . getImage ( ) : token . getType ( ) ) + "" + token . getLineno ( ) ) ; } } else { if ( fDebugEn ) { debug ( "" ) ; } } fCurrent = token ; return token ; } public SVIndentToken current ( ) { return fCurrent ; } private SVIndentToken read_single_line_comment ( String leading_ws ) { int c ; fTmp . setLength ( ) ; fTmp . append ( "" ) ; while ( ( c = get_ch ( ) ) != - && c != '' ) { fTmp . append ( ( char ) c ) ; } unget_ch ( c ) ; return new SVIndentToken ( SVIndentTokenType . SingleLineComment , leading_ws , fTmp . toString ( ) ) ; } private SVMultiLineIndentToken read_multi_line_comment ( String leading_ws ) { SVMultiLineIndentToken ret = new SVMultiLineIndentToken ( leading_ws ) ; int comment [ ] = { - , - } , c ; boolean read_newline = false ; fTmp . setLength ( ) ; fTmp . append ( "" ) ; while ( ( c = get_ch ( ) ) != - ) { if ( read_newline ) { if ( Character . isWhitespace ( c ) && c != '' ) { fTmp . append ( ( char ) c ) ; } else { leading_ws = fTmp . toString ( ) ; fTmp . setLength ( ) ; read_newline = false ; unget_ch ( c ) ; } } else { if ( c == '' ) { SVIndentToken tok = new SVIndentToken ( SVIndentTokenType . MultiLineComment , leading_ws , fTmp . toString ( ) ) ; tok . setIsEndLine ( true ) ; read_newline = true ; ret . addCommentLines ( tok ) ; fTmp . setLength ( ) ; leading_ws = "" ; } else { comment [ ] = comment [ ] ; comment [ ] = c ; fTmp . append ( ( char ) c ) ; if ( comment [ ] == '' && comment [ ] == '' ) { break ; } } } } if ( fTmp . length ( ) > ) { ret . addCommentLines ( new SVIndentToken ( SVIndentTokenType . MultiLineComment , leading_ws , fTmp . toString ( ) ) ) ; } if ( c == - ) { return null ; } else { return ret ; } } private String readIdentifier ( int c ) { fTmp . setLength ( ) ; fTmp . append ( ( char ) c ) ; while ( ( c = get_ch ( ) ) != - && Character . isJavaIdentifierPart ( c ) ) { fTmp . append ( ( char ) c ) ; } unget_ch ( c ) ; return fTmp . toString ( ) ; } private String getIndent ( ) { int c ; fTmp . setLength ( ) ; while ( ( c = get_ch ( ) ) != - && Character . isWhitespace ( c ) && c != '' ) { fTmp . append ( ( char ) c ) ; } if ( c != - ) { unget_ch ( c ) ; } return fTmp . toString ( ) ; } private int get_ch ( ) { int c = - ; if ( fUngetCh != - ) { c = fUngetCh ; fUngetCh = - ; } else { c = fScanner . get_ch ( ) ; if ( fDebugEn ) { debug ( "" + ( char ) c + "" ) ; } fLastCh [ ] = fLastCh [ ] ; fLastCh [ ] = c ; if ( fLastChT == '' ) { fLineno ++ ; } fLastChT = c ; } return c ; } private void unget_ch ( int ch ) { fUngetCh = ch ; } private void debug ( String msg ) { if ( fDebugEn ) { fLog . debug ( msg ) ; } } }
package net . sf . sveditor . core . indent ; public interface ISVIndentScanner { SVIndentToken next ( ) ; SVIndentToken current ( ) ; }
package net . sf . sveditor . core . indent ; public class SVIndentLoopStmt { }
package net . sf . sveditor . core . indent ; import java . util . ArrayList ; import java . util . List ; public class SVMultiLineIndentToken extends SVIndentToken { private List < SVIndentToken > fCommentList ; public SVMultiLineIndentToken ( String leading_ws ) { super ( SVIndentTokenType . MultiLineComment , leading_ws ) ; fCommentList = new ArrayList < SVIndentToken > ( ) ; } public List < SVIndentToken > getCommentLines ( ) { return fCommentList ; } public void addCommentLines ( SVIndentToken tok ) { fCommentList . add ( tok ) ; } @ Override public String getImage ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = ; i < fCommentList . size ( ) ; i ++ ) { SVIndentToken line = fCommentList . get ( i ) ; if ( i != ) { sb . append ( line . getLeadingWS ( ) ) ; } sb . append ( line . getImage ( ) ) ; if ( line . isEndLine ( ) ) { sb . append ( "" ) ; } } return sb . toString ( ) ; } @ Override public void setImage ( String image ) { System . out . println ( "" ) ; } }
package net . sf . sveditor . core . indent ; import java . io . ByteArrayOutputStream ; import java . io . PrintStream ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import java . util . Stack ; import java . util . regex . Pattern ; import net . sf . sveditor . core . Tuple ; import net . sf . sveditor . core . log . LogFactory ; import net . sf . sveditor . core . log . LogHandle ; public class SVDefaultIndenter2 implements ISVIndenter { private ISVIndentScanner fScanner ; private Stack < Tuple < String , Boolean > > fIndentStack ; private List < SVIndentToken > fTokenList ; private SVIndentToken fCurrent ; private String fCurrentIndent ; private LogHandle fLog ; private int fQualifiers ; private static final boolean fDebugEn = false ; private int fNLeftParen , fNRightParen ; private String fIndentIncr = "" ; private Pattern fTabReplacePattern ; private int fAdaptiveIndentEnd ; private boolean fTestMode ; static private Map < String , Integer > fQualifierMap ; static private Set < String > fPreProcDirectives ; private class IndentEOFException extends RuntimeException { private static final long serialVersionUID = ; } static { fQualifierMap = new HashMap < String , Integer > ( ) ; fQualifierMap . put ( "" , << ) ; fQualifierMap . put ( "" , << ) ; fQualifierMap . put ( "" , << ) ; fQualifierMap . put ( "" , << ) ; fQualifierMap . put ( "" , << ) ; fQualifierMap . put ( "" , << ) ; fPreProcDirectives = new HashSet < String > ( ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; fPreProcDirectives . add ( "" ) ; } public SVDefaultIndenter2 ( ) { fIndentStack = new Stack < Tuple < String , Boolean > > ( ) ; fTokenList = new ArrayList < SVIndentToken > ( ) ; fLog = LogFactory . getLogHandle ( "" ) ; } public void setAdaptiveIndent ( boolean adaptive ) { } public void setIndentIncr ( String incr ) { fIndentIncr = incr ; if ( fIndentIncr . charAt ( ) != '' ) { fTabReplacePattern = Pattern . compile ( "" ) ; } else { fTabReplacePattern = null ; } } public void setAdaptiveIndentEnd ( int lineno ) { fAdaptiveIndentEnd = lineno ; } public void setTestMode ( boolean tm ) { fTestMode = tm ; } public void init ( ISVIndentScanner scanner ) { fScanner = scanner ; push_indent_stack ( "" , true ) ; } public String indent ( ) { return indent ( - , - ) ; } public String indent ( int start_line , int end_line ) { StringBuilder sb = new StringBuilder ( ) ; SVIndentToken tok ; fNLeftParen = fNRightParen = ; while ( ( tok = next ( ) ) != null ) { try { do { if ( tok . getType ( ) == SVIndentTokenType . Identifier && fQualifierMap . containsKey ( tok . getImage ( ) ) ) { fQualifiers |= fQualifierMap . get ( tok . getImage ( ) ) ; tok = next ( ) ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_ifc_module_class ( tok . getImage ( ) ) ; fQualifiers = ; } else if ( tok . isId ( "" ) ) { tok = indent_config ( tok . getImage ( ) ) ; fQualifiers = ; } else if ( tok . isId ( "" ) ) { tok = indent_covergroup ( ) ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_task_function ( tok . getImage ( ) ) ; fQualifiers = ; } else if ( tok . isId ( "" ) ) { tok = indent_typedef ( ) ; fQualifiers = ; } else if ( tok . isOp ( "" ) ) { fQualifiers = ; tok = next ( ) ; } else { tok = next ( ) ; } } while ( ( tok = current ( ) ) != null ) ; } catch ( IndentEOFException e ) { break ; } catch ( RuntimeException e ) { if ( fTestMode ) { throw e ; } } } if ( fTestMode ) { if ( fIndentStack . size ( ) != ) { throw new RuntimeException ( "" + fIndentStack . size ( ) + "" ) ; } } if ( fDebugEn ) { debug ( "" ) ; } for ( SVIndentToken t : fTokenList ) { if ( ( t . getLineno ( ) >= start_line || start_line == - ) && ( t . getLineno ( ) <= end_line || end_line == - ) ) { if ( fDebugEn ) { debug ( "" + t . getType ( ) + "" + t . getLineno ( ) + "" + t . getImage ( ) ) ; } String leading_ws = t . getLeadingWS ( ) ; if ( t . isStartLine ( ) && fTabReplacePattern != null ) { leading_ws = fTabReplacePattern . matcher ( leading_ws ) . replaceAll ( fIndentIncr ) ; } sb . append ( leading_ws + t . getImage ( ) + t . getTrailingWS ( ) + ( ( t . isEndLine ( ) ) ? "" : "" ) ) ; } } return sb . toString ( ) ; } public String getLineIndent ( int lineno ) { String ret = null ; for ( SVIndentToken t : fTokenList ) { if ( t . getLineno ( ) == lineno ) { ret = t . getLeadingWS ( ) ; if ( t . isStartLine ( ) && fTabReplacePattern != null ) { ret = fTabReplacePattern . matcher ( ret ) . replaceAll ( fIndentIncr ) ; } break ; } } return ret ; } public boolean isQualifierSet ( String key ) { return ( ( fQualifierMap . get ( key ) & fQualifiers ) != ) ; } private SVIndentToken indent_if ( boolean is_else_if ) { SVIndentToken tok = current ( ) ; if ( fDebugEn ) { debug ( "" + tok . getImage ( ) ) ; } start_of_scope ( tok ) ; tok = next_s ( ) ; if ( tok . isOp ( "" ) ) { tok = consume_expression ( ) ; } else { return tok ; } tok = indent_if_stmts ( null ) ; if ( tok . isId ( "" ) ) { tok = next_s ( ) ; if ( tok . isId ( "" ) ) { tok = indent_if ( true ) ; } else { start_of_scope ( tok ) ; tok = indent_if_stmts ( null ) ; } } if ( fDebugEn ) { debug ( "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private SVIndentToken indent_if_stmts ( String parent ) { SVIndentToken tok = current_s ( ) ; if ( tok . isId ( "" ) ) { parent = "" ; boolean begin_is_start_line = tok . isStartLine ( ) ; if ( begin_is_start_line ) { enter_scope ( tok ) ; start_of_scope ( tok ) ; } tok = next_s ( ) ; if ( ! begin_is_start_line ) { enter_scope ( tok ) ; } else { enter_scope ( tok ) ; } while ( tok != null ) { if ( fDebugEn ) { debug ( "" + tok . getType ( ) + "" + tok . getImage ( ) ) ; } if ( tok . isId ( "" ) ) { leave_scope ( tok ) ; if ( begin_is_start_line ) { leave_scope ( ) ; } if ( fDebugEn ) { debug ( "" + peek_indent ( ) + "" ) ; } tok = next_s ( ) ; if ( begin_is_start_line ) { set_indent ( tok , false ) ; } tok = consume_labeled_block ( tok ) ; break ; } else { tok = indent_block_or_statement ( parent , true ) ; } } } else { enter_scope ( tok ) ; tok = indent_stmt ( parent ) ; leave_scope ( tok ) ; } return tok ; } private SVIndentToken indent_fork ( ) { SVIndentToken tok = current ( ) ; start_of_scope ( tok ) ; tok = next_s ( ) ; enter_scope ( tok ) ; while ( tok != null && ! tok . isId ( "" ) && ! tok . isId ( "" ) && ! tok . isId ( "" ) ) { tok = indent_block_or_statement ( "" , true ) ; } leave_scope ( tok ) ; tok = next_s ( ) ; return tok ; } private SVIndentToken indent_loop_stmt ( ) { SVIndentToken tok , first ; tok = first = current ( ) ; start_of_scope ( tok ) ; if ( fDebugEn ) { debug ( "" + tok . getImage ( ) ) ; } if ( ! tok . isId ( "" ) && ! tok . isId ( "" ) ) { tok = next_s ( ) ; if ( tok . isOp ( "" ) ) { tok = consume_expression ( ) ; } else { return tok ; } } else { tok = next_s ( ) ; } tok = indent_if_stmts ( null ) ; if ( first . isId ( "" ) ) { while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; } if ( fDebugEn ) { debug ( "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private SVIndentToken indent_typedef ( ) { SVIndentToken tok = current ( ) ; boolean enum_struct = false ; start_of_scope ( tok ) ; if ( fDebugEn ) { debug ( "" ) ; } tok = next_s ( ) ; if ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_struct_union_enum ( "" ) ; enum_struct = true ; } while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; if ( fDebugEn ) { debug ( "" ) ; } if ( ! enum_struct ) { leave_scope ( tok ) ; } return tok ; } private SVIndentToken indent_struct_union_enum ( String parent ) { SVIndentToken tok = next_s ( ) ; if ( ! parent . equals ( "" ) ) { start_of_scope ( tok ) ; } while ( ! tok . isOp ( "" , "" ) ) { tok = next_s ( ) ; } if ( tok . isOp ( "" ) ) { tok = next_s ( ) ; if ( ! tok . isOp ( "" ) ) { enter_scope ( tok ) ; } while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } } leave_scope ( tok ) ; return tok ; } private SVIndentToken indent_ifc_module_class ( String item ) { SVIndentToken tok = current_s ( ) ; String end = get_end_kw ( item ) ; if ( fDebugEn ) { debug ( "" + item + "" ) ; } start_of_scope ( tok ) ; tok = next_s ( ) ; start_of_scope ( tok ) ; while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } leave_scope ( tok ) ; tok = next_s ( ) ; enter_scope ( tok ) ; fQualifiers = ; while ( tok != null ) { if ( tok . isId ( end ) ) { break ; } else if ( tok . getType ( ) == SVIndentTokenType . Identifier && fQualifierMap . containsKey ( tok . getImage ( ) ) ) { fQualifiers |= fQualifierMap . get ( tok . getImage ( ) ) ; tok = next_s ( ) ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_task_function ( tok . getImage ( ) ) ; fQualifiers = ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_ifc_module_class ( tok . getImage ( ) ) ; fQualifiers = ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_struct_union_enum ( "" ) ; fQualifiers = ; } else if ( tok . isId ( "" ) || is_always ( tok ) || tok . isId ( "" ) ) { tok = next_s ( ) ; if ( tok . isOp ( "" ) ) { tok = next_s ( ) ; tok = consume_expression ( ) ; } if ( current ( ) . getImage ( ) . equals ( "" ) ) { tok = indent_block_or_statement ( null , false ) ; } else { tok = indent_block_or_statement ( null , false ) ; } fQualifiers = ; } else if ( tok . isId ( "" ) ) { tok = indent_covergroup ( ) ; fQualifiers = ; } else if ( tok . isId ( "" ) ) { tok = indent_constraint ( ) ; fQualifiers = ; } else if ( tok . isPreProc ( ) && tok . isStartLine ( ) ) { while ( ! tok . isEndLine ( ) && ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; fQualifiers = ; } else { tok = indent_block_or_statement ( item , true ) ; } } leave_scope ( tok ) ; end_of_scope ( tok ) ; tok = consume_labeled_block ( next_s ( ) ) ; if ( fDebugEn ) { debug ( "" + item + "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private SVIndentToken indent_config ( String item ) { SVIndentToken tok = current_s ( ) ; String end = "" ; if ( fDebugEn ) { debug ( "" + item + "" ) ; } start_of_scope ( tok ) ; tok = next_s ( ) ; while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; enter_scope ( tok ) ; fQualifiers = ; while ( tok != null ) { if ( tok . isId ( end ) ) { break ; } else { tok = indent_block_or_statement ( item , true ) ; } } leave_scope ( tok ) ; end_of_scope ( tok ) ; tok = consume_labeled_block ( next_s ( ) ) ; if ( fDebugEn ) { debug ( "" + item + "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private static boolean is_always ( SVIndentToken tok ) { return ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) ; } private SVIndentToken indent_covergroup ( ) { SVIndentToken tok = current_s ( ) ; start_of_scope ( tok ) ; if ( fDebugEn ) { debug ( "" ) ; } start_of_scope ( tok ) ; while ( tok != null && ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } leave_scope ( ) ; tok = next_s ( ) ; enter_scope ( tok ) ; while ( tok != null ) { if ( tok . isId ( "" ) ) { leave_scope ( tok ) ; break ; } else { tok = indent_covergroup_item ( ) ; } } tok = next_s ( ) ; if ( fDebugEn ) { debug ( "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private SVIndentToken indent_constraint ( ) { SVIndentToken tok = current_s ( ) ; start_of_scope ( tok ) ; tok = next_s ( ) ; tok = next_s ( ) ; if ( ! tok . isOp ( "" ) ) { return tok ; } tok = next_s ( ) ; enter_scope ( tok ) ; while ( ! tok . isOp ( "" ) ) { tok = indent_constraint_stmt ( ) ; } leave_scope ( tok ) ; tok = next_s ( ) ; return tok ; } private SVIndentToken indent_covergroup_item ( ) { SVIndentToken tok = current ( ) ; tok = next_s ( ) ; start_of_scope ( tok ) ; enter_scope ( tok ) ; while ( ! tok . isOp ( "" ) && ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } leave_scope ( tok ) ; if ( tok . isOp ( "" ) ) { boolean do_indent = true ; int lb_count = , rb_count = ; start_of_scope ( tok ) ; do { tok = next_s ( ) ; if ( do_indent ) { enter_scope ( tok ) ; do_indent = false ; } if ( tok . isOp ( "" ) ) { lb_count ++ ; start_of_scope ( tok ) ; do_indent = true ; } else if ( tok . isOp ( "" ) ) { rb_count ++ ; leave_scope ( tok ) ; } } while ( lb_count != rb_count ) ; } tok = next_s ( ) ; return tok ; } private SVIndentToken indent_task_function ( String item ) { SVIndentToken tok = current_s ( ) ; start_of_scope ( tok ) ; String end = get_end_kw ( item ) ; if ( fDebugEn ) { debug ( "" + item + "" ) ; } while ( tok != null && ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } if ( ! isQualifierSet ( "" ) ) { enter_scope ( tok ) ; tok = next_s ( ) ; while ( tok != null ) { if ( tok . isId ( end ) ) { break ; } else { tok = indent_block_or_statement ( item , true ) ; } } leave_scope ( tok ) ; tok = consume_labeled_block ( next_s ( ) ) ; } else { leave_scope ( ) ; tok = next_s ( ) ; } if ( fDebugEn ) { debug ( "" + item + "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } end_of_scope ( ) ; return tok ; } private SVIndentToken indent_block_or_statement ( String parent , boolean parent_is_block ) { SVIndentToken tok = current ( ) ; if ( fDebugEn ) { debug ( "" + parent_is_block + "" + tok . getImage ( ) ) ; } if ( tok . isId ( "" ) ) { parent = "" ; start_of_scope ( tok ) ; tok = next_s ( ) ; enter_scope ( tok ) ; while ( tok != null ) { if ( fDebugEn ) { debug ( "" + tok . getType ( ) + "" + tok . getImage ( ) ) ; } if ( tok . isId ( "" ) ) { leave_scope ( tok ) ; if ( fDebugEn ) { debug ( "" + peek_indent ( ) + "" ) ; } tok = next_s ( ) ; tok = consume_labeled_block ( tok ) ; break ; } else { tok = indent_block_or_statement ( parent , true ) ; } } } else { if ( ! parent_is_block ) { start_of_scope ( tok ) ; enter_scope ( tok ) ; } tok = indent_stmt ( parent ) ; if ( ! parent_is_block ) { leave_scope ( tok ) ; } } if ( fDebugEn ) { debug ( "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) + "" + parent ) ; } return tok ; } private SVIndentToken indent_stmt ( String parent ) { SVIndentToken tok = current_s ( ) ; if ( fDebugEn ) { debug ( "" + parent + "" + tok . getImage ( ) ) ; } if ( tok . isId ( "" ) ) { tok = indent_if ( false ) ; } else if ( tok . isId ( "" ) ) { tok = indent_fork ( ) ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_case ( ) ; } else if ( is_always ( tok ) || tok . isId ( "" ) || tok . isId ( "" ) ) { enter_scope ( tok ) ; if ( ( tok = next_s ( ) ) . isOp ( "" ) ) { tok = next_s ( ) ; tok = next_s ( ) ; indent_block_or_statement ( null , false ) ; } leave_scope ( ) ; } else if ( tok . isId ( "" ) ) { tok = indent_typedef ( ) ; } else if ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) { tok = indent_loop_stmt ( ) ; } else { boolean do_next = true ; while ( ! tok . isOp ( "" ) ) { if ( parent != null ) { if ( ( parent . equals ( "" ) && tok . isId ( "" ) ) || tok . isId ( "" + parent ) ) { do_next = false ; break ; } else if ( parent . equals ( "" ) && ( tok . isId ( "" ) || tok . isId ( "" ) || tok . isId ( "" ) ) ) { do_next = false ; break ; } } if ( tok . isOp ( "" ) ) { start_of_scope ( tok ) ; } else if ( tok . isOp ( "" ) ) { leave_scope ( ) ; } tok = next_s ( ) ; } if ( do_next ) { tok = next_s ( ) ; } } if ( fDebugEn ) { debug ( "" + parent + "" + tok . getImage ( ) ) ; } return tok ; } private SVIndentToken indent_constraint_block_or_stmt ( ) { SVIndentToken tok = current_s ( ) ; if ( tok . isOp ( "" ) ) { start_of_scope ( tok ) ; tok = next_s ( ) ; enter_scope ( tok ) ; while ( ! tok . isOp ( "" ) ) { tok = indent_constraint_block_or_stmt ( ) ; } leave_scope ( tok ) ; tok = next_s ( ) ; } else { tok = indent_constraint_stmt ( ) ; } return tok ; } private SVIndentToken indent_constraint_if_block_or_stmt ( ) { SVIndentToken tok = current_s ( ) ; if ( tok . isOp ( "" ) ) { boolean begin_is_start_line = tok . isStartLine ( ) ; if ( begin_is_start_line ) { enter_scope ( tok ) ; } tok = next_s ( ) ; if ( ! begin_is_start_line ) { enter_scope ( tok ) ; } while ( ! tok . isOp ( "" ) ) { tok = indent_constraint_block_or_stmt ( ) ; } leave_scope ( tok ) ; tok = next_s ( ) ; } else { enter_scope ( tok ) ; tok = indent_constraint_stmt ( ) ; leave_scope ( tok ) ; } return tok ; } private SVIndentToken indent_constraint_stmt ( ) { SVIndentToken tok = current_s ( ) ; if ( tok . isId ( "" ) ) { tok = indent_constraint_if ( false ) ; } else if ( tok . isOp ( "" ) ) { tok = consume_expression ( ) ; if ( tok . isOp ( "" ) || tok . isOp ( "" ) ) { tok = next_s ( ) ; tok = indent_constraint_block_or_stmt ( ) ; } } else { while ( ! tok . isOp ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; } return tok ; } private SVIndentToken indent_constraint_if ( boolean is_else_if ) { SVIndentToken tok = current ( ) ; if ( fDebugEn ) { debug ( "" + tok . getImage ( ) ) ; } start_of_scope ( tok ) ; tok = next_s ( ) ; if ( tok . isOp ( "" ) ) { tok = consume_expression ( ) ; } else { return tok ; } enter_scope ( tok ) ; tok = indent_constraint_if_block_or_stmt ( ) ; if ( tok . isId ( "" ) ) { tok = next_s ( ) ; if ( tok . isId ( "" ) ) { tok = indent_constraint_if ( true ) ; } else { tok = indent_constraint_block_or_stmt ( ) ; } } if ( fDebugEn ) { debug ( "" + ( ( tok != null ) ? tok . getImage ( ) : "" ) ) ; } return tok ; } private SVIndentToken indent_case ( ) { SVIndentToken tok = current ( ) ; String type = tok . getImage ( ) ; enter_scope ( tok ) ; start_of_scope ( tok ) ; if ( type . equals ( "" ) ) { tok = next_s ( ) ; } tok = next_s ( ) ; enter_scope ( tok ) ; while ( ! tok . isId ( "" ) ) { while ( ! tok . isOp ( "" ) && ! tok . isId ( "" ) ) { tok = next_s ( ) ; } if ( tok . isOp ( "" ) ) { tok = next_s ( ) ; tok = indent_block_or_statement ( "" , false ) ; } } leave_scope ( ) ; if ( tok . isId ( "" ) ) { set_indent ( tok , false ) ; } tok = next_s ( ) ; return tok ; } private void start_of_scope ( SVIndentToken tok ) { incr_indent ( true ) ; if ( fDebugEn ) { debug ( "" + peek_indent ( ) + "" ) ; } } private void end_of_scope ( ) { end_of_scope ( null ) ; } private void end_of_scope ( SVIndentToken tok ) { } private void enter_scope ( SVIndentToken tok ) { set_indent ( tok , false ) ; if ( fDebugEn ) { debug ( "" + peek_indent ( ) + "" ) ; } } private void leave_scope ( ) { leave_scope ( null ) ; } private void leave_scope ( SVIndentToken tok ) { pop_indent ( tok ) ; if ( fDebugEn ) { debug ( "" + peek_indent ( ) + "" ) ; } } private void push_indent_stack ( String indent , boolean provisional ) { if ( fDebugEn ) { debug ( "" + ( fIndentStack . size ( ) + ) + "" + indent + "" + provisional ) ; } fIndentStack . push ( new Tuple < String , Boolean > ( indent , provisional ) ) ; } private String peek_indent ( ) { return fIndentStack . peek ( ) . first ( ) ; } private void incr_indent ( boolean provisional ) { push_indent_stack ( fIndentStack . peek ( ) . first ( ) + fIndentIncr , provisional ) ; if ( fDebugEn ) { debug ( "" + provisional + "" + "" + peek_indent ( ) + "" ) ; } } private void pop_indent ( SVIndentToken tok ) { if ( fDebugEn ) { String img = ( tok != null ) ? tok . getImage ( ) : "" ; debug ( "" + ( fIndentStack . size ( ) - ) + "" + img + "" ) ; } if ( fIndentStack . size ( ) > ) { fIndentStack . pop ( ) ; } else { if ( fTestMode ) { throw new RuntimeException ( "