넷빈즈에서 루비 에디팅 하기 :: NetBeans Ruby Editing

넷빈즈 6.0 출시를 앞두고 마이스톤 10까지 발표된 현재, netbeans.org에 넷빈즈6.0 와 JDK6.0에 포함 되는 루비에 대해 넷빈즈에서는 어떻게 지원이 되고 있는지에 대한 기사가 올라 왔습니다.
기사 내용을 보면 일반적인 IDE의 에디터가 제공하는 거의 모든 기능을 제공하고 있는 듯 합니다.


Syntax Highlighting

Lexical scanning is done with JRuby's scanner, which identifies elements like global variables and instance variables. As in the Java editor, fields are shown in green. The editor also recognizes Ruby's identifiers, so double clicking in the editor to select the symbol under the mouse pointer includes non-Java identifier characters like @, $, and so on.

Note: You can change the font used in the editor by choosing Tools > Options > Fonts and Colors. In this Options dialog box, by default the Syntax tab and the Default category are selected. Change the font for the Default category to change the font in the editor.

Navigation Display

The Navigator window displays the structure of the file from modules down to individual methods, fields and attributes. Double-clicking an element in the Navigator window, shown in the figure below, displays its source in the editor.

Figure 1: Navigator Window
Figure 1: Navigator Window

The structure analyzer is aware of Ruby constructs. For example, attr, attr_accessor, attr_reader, and module_function will properly construct fields, singleton methods, and so on that are included in navigation and code completion.

The Filters buttons at the bottom of the window enable you to filter out private methods, fields, and so on.

Code Folding

Modules, classes and methods can be folded, as shown in the next figure.

Figure 2: Code Folding
Figure 2: Code Folding

Background Error Parsing

The JRuby parser is run in the background when the user stops typing. It provides error messages as error annotations. On a successful parse, the parse tree is used to drive additional features. (And in the future, JRuby will hopefully provide partial parse trees even on erroneous Ruby files.)

Figure 3: Error Annotation
Figure 3: Error Annotation

Semantic Syntax Highlighting

This feature identifies method calls and definitions, parameters, and unused variables.

Figure 4: Semantic Syntax Highlighting
Figure 4: Semantic Syntax Highlighting

Mark Occurrences

Positioning the edit cursor on an element (such as a local variable, dynamic variable, instance variable, global variable, method call, or class reference) highlights all other references as well as redefinitions of the current symbol.

The first example shows how parameters are highlighted when you position the cursor on one of them:

Figure 5: Highlighted Parameters
Figure 5: Highlighted Parameters

The next figure shows method calls and method definitions that are highlighted when the cursor is positioned on the second method from the bottom. The editor uses method arity to select which of the overloaded methods apply.

Figure 6:  Highlighted Methods
Figure 6: Highlighted Methods

There is additional highlighting behavior. If you place the cursor on a method definition, the editor highlights all the potential exit points - the last statement of the method as well as any return, yield, raise, or fail statements.

Go To Declaration

If you right-click an element and choose Go To > Declaration, the editor will go to the declaration for the element if possible. If you hold down the Ctrl key (or the Command key on the Macintosh) and drag the mouse pointer over the source code, identifiers are highlighted as hyperlinks. Clicking a hyperlink goes to its declaration if possible.

Figure 7: Ctrl-Drag Shows Go To Declaration Hyperlinks

Figure 7: Ctrl-Drag Shows Go To Declaration Hyperlinks

Note: This feature always works for local variables and dynamic variables, but it is not as reliable for methods, classes, and such because it requires the type inference engine as well as some other facilities for finding references in the built-in libraries.

Instant Rename

Renaming a local or dynamic variable is done in place, and all references are updated on the fly. To invoke this feature, right click the element and chose Instant Rename, or press Ctrl-R on Microsoft Windows systems or Command-R on Macintosh systems. All instances to be renamed are selected, as shown in the figure below, and when you type the new name, all are updated.

Figure 8: Instant Rename

Figure 8: Instant Rename

Code Completion

Some basic code completion is provided. As you are typing, if you press Ctrl-Space, completion is provided for local variables and dynamic variables in the current block, as well as method names, class names, and constants in the same file. In addition, various Ruby built-ins, such as keywords and predefined constants, are provided.

If you try code completion on any complicated arbitrary expression, it will show you a number of possible method completions along with the corresponding class, as shown in the following figure. This feature gives you much the same information as ri, the Ruby Interactive Reference.

Figure 9: Code Completion:

Figure 9: Code Completion: All Matches

In many contexts, you know the exact type. For example, if you type File.c and invoke code completion, the editor shows you only the singleton methods of class File that start with c, as well as inherited methods and module mixins.

Figure 10: Code Completion: Singleton

Figure 10: Code Completion: Singleton

In some cases, the editor can detect that it is dealing with an instance of an object, so it has more information than just the class. In that case, it can show all the instance methods too, not just the class methods.

In the following figure, code completion is being applied to a regular expression literal. Code completion works for all kinds of literals in your code: strings, regular expressions, arrays, hashes, symbols, numbers, and so on, and you can even use it with the nil keyword. For example, with arrays, try code completion with [1,2,3].e to see the each method and its documentation.

Figure 11: Code Completion: Instance
Figure 11: Code Completion: Instance

When there is associated Ruby documentation (rdoc) for a program element, it is displayed in a documentation popup below the code completion window, as you can see in the previous figure. There is also documentation for some built-in keywords that is based on the Ruby spec at http://www.headius.com/rubyspec/index.php/Ruby_Language, as shown for the yield keyword in the next figure.

Figure 12: Code Completion: Keyword Documentation
Figure 12: Code Completion: Keyword Documentation

Code completion also provides help in specific contexts. For example, if you invoke code completion within the string of a require or load statement, you see a list of available imports:

Figure 13: Code Completion: Require Statement

Figure 13: Code Completion: Require Statement


If you invoke code completion while typing a regular expression, you get help with regular expression syntax, as shown in the following figure.

Figure 14: Code Completion: Regular Expression
Figure 14: Code Completion: Regular Expression

If you're typing Ruby code and can't remember the names or meanings of dollar variables or what the escape codes are following a percent sign, use code completion as shown in the following two figures.

Figure 15: Code Completion: Dollar Variable
Figure 15: Code Completion: Dollar Variable

Figure 16: Code Completion: Dollar Variable
Figure 16: Code Completion: Percent Symbol

There are more scenarios. For example, invoking code completion after a def keyword lists only the inherited methods from the superclasses. For more applications of code completion, see Tor Norbye's blog Ruby Screenshot of the Week #10: Taking Up The Gauntlet.

Pair Matching

The editor automatically highlights matching parentheses (), braces {}, brackets [], string delimiters " ', regular expression delimiters %r{}, and so on. In addition, as you're editing, the editor tries to automatically insert and remove matching delimiters automatically without getting in the way. For example, if you type %x{, the editor modifies the document to contain %x{|}, and if you then type the closing }, it removes the previously added } so the document contains only one closing brace. The important part here is that while you're editing, the file stays valid so that code completion and similar features will work.

Pair Matching works on blocks as well. If you type for something or def (something) and press Enter, the editor automatically adds an end statement for you if one is needed, inserts a line above it, and positions the cursor on that line. The feature works similarly for closing braces in blocks. It also works on =begin/=end pairs. If you type =begin and press Enter, the editor automatically adds =end for you if it is needed. Additionally, if you put the cursor on an end statement, the editor highlights the statement that began the block.

Figure 18: Matching End to Beginnning of a Block
Figure 18: Matching End to Beginning of a Block

Smart Indent

Pressing Enter to create a new line causes the new line to be indented appropriately, either with the same indent as the previous line or further indented if establishing a new block, such as with an if statement or case statement

Smart indent also works in other cases. For example, if you type end at the beginning of a line, the editor indents the line to align the end with the corresponding opening statement, such as class, def, for, and so on. If you continue typing more characters after end (for example, end is the first three characters of endiandCheck()), the line is indented to its original position immediately.

Figure 17: Smart Indent
Figure 17: Smart Indent

Smart Selection

If you press Alt-Shift-Up Arrow or Alt-Shift-Down Arrow on a Microsoft Windows machine or Ctrl-Shift-Up Arrow/Down Arrow on a Macintosh, the editor selects progressively larger (Up Arrow) or smaller (Down Arrow) code blocks around the cursor. For example, if you're in a for block that is inside an if block, on the first press of Alt-Shift-Up Arrow, the for block is selected, then on subsequent key presses the surrounding if block is selected, then the method definition, then the class, then the module. In a comment, first the line is selected, then the whole comment block, then whatever logical code block surrounds the comment.

Formatting

The Reformat Code command reformats the source code by using the same line indenting logic that Smart Indent uses. To automatically reformat your code, right-click and choose Reformat Code, or press Ctrl-Shift-F. There is also a Pretty Printer, which will go a bit further in reorganizing code, adding or removing parentheses, and so on. The Pretty Printer is incomplete and is not yet enabled.

RDoc Support and String Support

RDoc is the Ruby Documentation System. In the Ruby Editor, comments containing RDoc tags or directives will show the RDoc directives as highlighted. Similarly, quoted strings will show the escape sequences in bold.

Note: As mentioned previously under Code Completion, if there is rdoc support for an element, you see the rdoc when you display the code completion pop-up. This section discusses code editor support for your rdoc comments in your code, not the rdoc displayed by the editor for code completion.

Figure 23: RDoc Comments and Quoted Strings
Figure 23: RDoc Comments and Quoted Strings

Embedded code fragments within String literals and regular expressions are also supported, as shown in the next figure.

Figure 24: Embedded Code Fragment Support in Strings and Regular Expressions

Figure 24
: Embedded Code Fragment Support in Strings and Regular Expressions


원문 출처 : http://www.netbeans.org/kb/60/ruby-editing.html
2007/07/10 18:21 2007/07/10 18:21
Trackback Address:이 글에는 트랙백을 보낼 수 없습니다

UTF-8로 설정한 MySQL 4.1 이상 Tomcat 5.0 이상에서 JDBC접속 URL설정

회사의 인턴에 대한 교육을 목적으로 정말 오랜만에  Tomcat , MySQL 조합으로 예제 코드를
작성 하고 있었다.

톰캣이랑 MySQL의 조합을 마지막으로 사용 해 본게 톰캣 3.X 시절의 일이다.

현재의 조합은 톰캣 5.0 + MySQL 4.1.22 에 utf-8 로 캐릭터 셋을 설정 한데다
서블릿 필터와 JDBC 드라이버 버전업으로  예전의 그 악몽같던 JDBC 한글문제는 사라졌을거라 믿었다..

그러나 왠걸.. 코드를 작성하고 돌려보니 java 클래스 단까지는 한글이 잘 전달 되는데
db에 인서트 하는데 아래와 같은 익셉션이  발생...

MysqlDataTruncation 발생..


이때의  connection url은
jdbc:mysql://localhost:3306/subby_test?useUnicode=true&characterEncoding=UTF8

이 문제는 꽤 간단하게 해결 할 수 있었다.
url에 Truncation 옵션을 false 로 주어서 해결 할 수 있었지만 여전히 DB에는 한글이 안들어가고 있다.

생 ㅈㄹ을 다 해 본다. JDBC버전 별로 봐꿔가며 컴파일과 실행.. 그옜날 썼던 new String() 하며
캐릭터셋 바꿔보기..  그래도 안된다..  그만큼 짜증도 밀려오고..

잠시 머리를 식히고 다시 차근차근 생각 해 봤다. 우선 톰캣의 JSP와 MYSQL의 캐릭터 셋은
분명히 utf-8인 상황이다.  그럼 순순히 안 될리가 없지않나?  역시나 JDBC 드라이버 문제인가?
JDBC드라이버를 최신의 안정버전인 5.0.6 으로 선택하고 JDBC 메뉴얼을 살피기 시작했다..

그러다 찾게 된 희망의 한 단락
Using the UTF-8 Character Encoding - Prior to MySQL server version 4.1, the UTF-8 character encoding was not supported by the
server, however the JDBC driver could use it, allowing storage of multiple character sets in latin1 tables on the server.
Starting with MySQL-4.1, this functionality is deprecated. If you have applications that rely on this functionality, and can not upgrade
them to use the official Unicode character support in MySQL server version 4.1 or newer, you should add the following property
to your connection URL:
useOldUTF8Behavior=true

쌍.. 장난하냐? 장난해? 이놈은 뻑하면 옵션을 바꿔...
답은 useOldUTF8Behavior 에 있는 듯했다.. 적용하고 돌려보니 깔끔..
이런 옵션이야 메뉴얼에서 찾는게 정석이긴 하지만, MySQL은 버전이나 서버 설정에 따른 옵션 변화가
너무 많아 난감한 경우가 한두번이 아니다..

아~ 내 3시간은 어딜가서 하소연 하나...

최종적으로 문제를 해결한 utf8 과 MySQL JDBC Driver 5.0 에서의 DB URL은
jdbc:mysql://localhost:3306/subby_test?useUnicode=true&characterEncoding=UTF8&jdbcCompliantTruncation=false&useOldUTF8Behavior=true
2007/07/10 11:49 2007/07/10 11:49
Trackback Address:이 글에는 트랙백을 보낼 수 없습니다
  1. 2008/05/12 16:56
    애드널의 생각 Tracked from addnull's me2DAY
  2. 2011/06/30 14:53
    Mysql 저장시 한글문제 Tracked from IT 잡동산
  1. Blog Icon
    카우보이

    헐 감사합니다. 저두 이것저것 삽질해보다 저위에 올리신 옵션쓰고나서야 제대로 출력이 되네요

    2시간 삽질

  2. Blog Icon
    Sean

    Wow 덕분에 잘 해결했습니다.