use of org.eclipse.jface.text.BadLocationException in project KaiZen-OpenAPI-Editor by RepreZen.
the class AbstractJsonHyperlinkDetector method getHyperlinkInfo.
protected HyperlinkInfo getHyperlinkInfo(ITextViewer viewer, IRegion region) {
final JsonDocument document = (JsonDocument) viewer.getDocument();
IRegion line;
try {
line = document.getLineInformationOfOffset(region.getOffset());
} catch (BadLocationException e) {
return null;
}
String lineContent;
try {
lineContent = document.get(line.getOffset(), line.getLength());
} catch (BadLocationException e) {
return null;
}
if (lineContent == null || emptyToNull(lineContent) == null) {
return null;
}
final int column = region.getOffset() - line.getOffset();
final IRegion selected = getSelectedRegion(line, lineContent, column);
String text;
try {
text = document.get(selected.getOffset(), selected.getLength());
} catch (BadLocationException e) {
return null;
}
if (emptyToNull(text) == null || text.trim().equals(":") || text.trim().equals("$ref:")) {
return null;
}
return new HyperlinkInfo(selected, text, column);
}
use of org.eclipse.jface.text.BadLocationException in project KaiZen-OpenAPI-Editor by RepreZen.
the class StyledCompletionProposal method apply.
@Override
public void apply(IDocument document) {
int length = 0;
int offset = replacementOffset;
String text = replacementString;
if (Strings.emptyToNull(prefix) != null) {
if (replacementString.toLowerCase().startsWith(prefix)) {
text = replacementString.substring(prefix.length());
} else if (replacementString.toLowerCase().contains(prefix)) {
offset = replacementOffset - prefix.length();
length = prefix.length();
}
}
try {
document.replace(offset, length, text);
} catch (BadLocationException x) {
// ignore
}
}
use of org.eclipse.jface.text.BadLocationException in project KaiZen-OpenAPI-Editor by RepreZen.
the class SwaggerTemplateContext method createTemplateTranslator.
protected TemplateTranslator createTemplateTranslator() {
try {
int offset = getStart();
IRegion lineRegion = getDocument().getLineInformationOfOffset(offset);
String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
int i = 0;
// support for array items
StringBuilder indentation = new StringBuilder();
while (i < line.length()) {
char indentSymbol = line.charAt(i);
if (Character.isWhitespace(indentSymbol)) {
indentation.append(indentSymbol);
i++;
} else if ('-' == indentSymbol) {
// array item
indentation.append(' ');
i++;
} else {
break;
}
}
if (i != 0)
return new IndentationAwareTemplateTranslator(indentation.toString());
return new TemplateTranslator();
} catch (BadLocationException ex) {
return new TemplateTranslator();
}
}
use of org.eclipse.jface.text.BadLocationException in project cubrid-manager by CUBRID.
the class SQLContentAssistProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
IDocument document = viewer.getDocument();
int currOffset = offset - 1;
try {
String currWord = "";
char currChar;
while (currOffset >= 0 && !isKeywordSeparator(currChar = document.getChar(currOffset))) {
currWord = currChar + currWord;
currOffset--;
}
currWord = trimQualifier(currWord);
if (currWord.trim().length() == 0 && isSQLEndPos(document, currOffset)) {
return null;
}
// if currWord is "" or AssistProcessor is displaying return null;
if (currWord.trim().equals("") && isRunning()) {
return null;
}
setRunning(true);
List<ICompletionProposal> finalProposals = new ArrayList<ICompletionProposal>();
if (GeneralPreference.isAutoCompleteTablesOrColumns()) {
// columns
List<ColumnProposalDetailInfo> tableColumns = getColumnNames(currWord.toUpperCase(Locale.getDefault()), document, offset - 1);
List<ICompletionProposal> columnProposals = buildColumnProposals(tableColumns, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/table_column_item.png"), false);
finalProposals.addAll(columnProposals);
// tables
List<String> tableNames = getTableNames(currWord.toUpperCase(Locale.getDefault()), document, offset - 1);
List<ICompletionProposal> tableProposals = buildProposals(tableNames, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/schema_table_item.png"), false);
finalProposals.addAll(tableProposals);
}
// keywords
if (GeneralPreference.isAutoCompleteKeyword()) {
List<String> suggestions = wordTracker.suggest(currWord.toUpperCase(Locale.getDefault()), databaseProvider.getDatabaseInfo());
List<ICompletionProposal> keywordProposals = buildProposals(suggestions, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/sql.png"), true);
finalProposals.addAll(keywordProposals);
}
return finalProposals.toArray(new ICompletionProposal[finalProposals.size()]);
} catch (BadLocationException e) {
LOGGER.error("", e);
lastError = e.getMessage();
return null;
} finally {
setRunning(false);
}
}
use of org.eclipse.jface.text.BadLocationException in project AutoRefactor by JnRouvignac.
the class TestHelper method normalizeJavaSourceCode.
public static String normalizeJavaSourceCode(String source) {
final CodeFormatter codeFormatter = createCodeFormatter(getJava7Options());
final TextEdit edit = codeFormatter.format(K_COMPILATION_UNIT, // source to format
source, // source to format
0, // source to format
source.length(), // initial indentation and line separator
0, // initial indentation and line separator
System.getProperty("line.separator"));
try {
final IDocument document = new Document(source);
edit.apply(document);
return document.get();
} catch (MalformedTreeException e) {
throw new RuntimeException(e);
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
Aggregations