use of org.eclipse.jface.text.Document in project generator by mybatis.
the class ExistingJavaFileVisitorTest method testRegularInterface.
@Test
public void testRegularInterface() throws Exception {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTableMapper.java.src");
String source = getResourceAsString(resource);
IDocument document = new Document(source);
CompilationUnit cu = getCompilationUnitFromSource(source);
cu.recordModifications();
ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
// delete all the old generated stuff
cu.accept(visitor);
assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
assertThat(visitor.getTypeDeclaration().isInterface(), is(true));
assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTableMapper"));
// generate a new compilation unit that is stripped of old stuff
TextEdit textEdit = cu.rewrite(document, null);
textEdit.apply(document);
CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
assertThat(summary, hasImportCount(11));
assertThat(summary, hasInterface("AwfulTableMapper"));
assertThat(summary, hasInterface("AwfulTableMapper", withSuperInterfaceCount(0)));
assertThat(summary, hasInterface("AwfulTableMapper", withMethodCount(0)));
assertThat(summary, hasInterface("AwfulTableMapper", withFieldCount(0)));
}
use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class SQLEditorPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof SQLEditorBase)) {
return false;
}
SQLEditor editor = (SQLEditor) receiver;
final Control editorControl = editor.getEditorControl();
if (editorControl == null) {
return false;
}
boolean hasConnection = editor.getDataSourceContainer() != null;
switch(property) {
case PROP_CAN_EXECUTE:
// Do not check hasActiveQuery - sometimes jface don't update action enablement after cursor change/typing
return hasConnection;
/* && (!"statement".equals(expectedValue) || editor.hasActiveQuery())*/
case PROP_CAN_EXPLAIN:
return hasConnection && DBUtils.getAdapter(DBCQueryPlanner.class, editor.getDataSource()) != null;
case PROP_CAN_NAVIGATE:
{
// Check whether some word is under cursor
ISelectionProvider selectionProvider = editor.getSelectionProvider();
if (selectionProvider == null) {
return false;
}
ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
Document document = editor.getDocument();
return selection != null && document != null && !new SQLIdentifierDetector(editor.getSyntaxManager().getStructSeparator(), editor.getSyntaxManager().getQuoteSymbol()).detectIdentifier(document, new Region(selection.getOffset(), selection.getLength())).isEmpty();
}
case PROP_CAN_EXPORT:
return hasConnection && editor.hasActiveQuery();
case PROP_HAS_SELECTION:
{
ISelection selection = editor.getSelectionProvider().getSelection();
return selection instanceof ITextSelection && ((ITextSelection) selection).getLength() > 0;
}
}
return false;
}
use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class ParseUtils method main.
public static void main(String[] args) {
System.out.println("Test SCM parser");
String sql = "SELECT * FROM SCHEMA.TABLE WHERE COL1 <> 100 AND COL2 = 'TEST'";
SCMRoot nodeTree = ParseUtils.parseDocument(new Document(sql), new SQLNodeParser());
System.out.println(nodeTree);
}
use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class ResultSetFilterPanel method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
if (viewer.getDataContainer() != null) {
syntaxManager.init(viewer.getDataContainer().getDataSource());
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
final String word = wordDetector.getFullWord().toLowerCase(Locale.ENGLISH);
List<IContentProposal> proposals = new ArrayList<>();
for (DBDAttributeBinding attribute : viewer.getModel().getAttributes()) {
final String name = attribute.getName();
if (CommonUtils.isEmpty(word) || name.toLowerCase(Locale.ENGLISH).startsWith(word)) {
final String content = name.substring(word.length()) + " ";
proposals.add(new ContentProposal(content, attribute.getName(), SQLContextInformer.makeObjectDescription(null, attribute.getAttribute(), false), content.length()));
}
}
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class BaseTextEditor method loadFromExternalFile.
public void loadFromExternalFile() {
final File loadFile = DialogUtils.openFile(getSite().getShell(), new String[] { "*.sql", "*.txt", "*", "*.*" });
if (loadFile == null) {
return;
}
String newContent = null;
try {
try (Reader reader = new InputStreamReader(new FileInputStream(loadFile), GeneralUtils.DEFAULT_FILE_CHARSET)) {
StringWriter buffer = new StringWriter();
IOUtils.copyText(reader, buffer);
newContent = buffer.toString();
}
} catch (IOException e) {
UIUtils.showErrorDialog(getSite().getShell(), "Can't load file", "Can't load file '" + loadFile.getAbsolutePath() + "' - " + e.getMessage());
}
if (newContent != null) {
Document document = getDocument();
if (document != null) {
document.set(newContent);
}
}
}
Aggregations