use of org.eclipse.jface.text.IRegion in project tdi-studio-se by Talend.
the class ExpressionComposite method setExpression.
/*
* (non-Javadoc)
*
* @see
* org.talend.expressionbuilder.ui.ExpressionController#setExpression(org.talend.designer.rowgenerator.data.Function
* )
*/
public void setExpression(Function f) {
String newValue = PERL_FUN_PREFIX;
if (f != null) {
final List<Parameter> parameters = f.getParameters();
if (FunctionManager.isJavaProject()) {
String fullName = f.getName();
//$NON-NLS-1$
newValue = fullName + "(";
for (Parameter pa : parameters) {
newValue += pa.getValue() + FUN_PARAM_SEPARATED;
}
if (!parameters.isEmpty()) {
newValue = newValue.substring(0, newValue.length() - 1);
}
//$NON-NLS-1$
newValue += ")";
} else {
//$NON-NLS-1$
newValue += f.getName() + "(";
for (Parameter pa : parameters) {
newValue += pa.getValue() + FUN_PARAM_SEPARATED;
}
newValue = newValue.substring(0, newValue.length() - 1);
newValue += PERL_FUN_SUFFIX;
}
}
IRegion region = viewer.getViewerRegion();
try {
document.replace(region.getOffset(), region.getLength(), newValue);
} catch (BadLocationException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.eclipse.jface.text.IRegion in project tdi-studio-se by Talend.
the class ReconcilerViewer method getAllSnippetsAnnotations.
private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
IDocument document = getDocument();
int curOffset = 0;
FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
try {
//$NON-NLS-1$
IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
while (startRegion != null && startRegion.getOffset() >= curOffset) {
int startLine = document.getLineOfOffset(startRegion.getOffset());
int startOffset = document.getLineOffset(startLine);
curOffset = startOffset + document.getLineLength(startLine);
//$NON-NLS-1$
IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
if (endRegion != null) {
int endLine = document.getLineOfOffset(endRegion.getOffset());
int endOffset = document.getLineOffset(endLine);
endOffset += document.getLineLength(endLine);
curOffset = endOffset;
String text = document.get(startOffset, endOffset - startOffset);
ProjectionAnnotation annotation = new ProjectionAnnotation(true);
annotation.setText(text);
annotation.setRangeIndication(true);
annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
}
if (curOffset < document.getLength()) {
//$NON-NLS-1$
startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
}
}
} catch (BadLocationException e) {
ExceptionHandler.process(e);
}
return annotations;
}
use of org.eclipse.jface.text.IRegion 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.IRegion in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReferenceHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
URI baseURI = getBaseURI();
AbstractNode node = doc.getModel().find(pointer);
JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
if (reference == null) {
reference = getFactory().create(node);
}
if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
return null;
}
if (reference.isLocal()) {
IRegion target = doc.getRegion(reference.getPointer());
if (target == null) {
return null;
}
return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
} else {
URI resolved;
try {
resolved = baseURI.resolve(reference.getUri());
} catch (IllegalArgumentException e) {
// the given string violates RFC 2396
return null;
}
IFile file = DocumentUtils.getWorkspaceFile(resolved);
if (file != null && file.exists()) {
return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
}
}
return null;
}
use of org.eclipse.jface.text.IRegion in project KaiZen-OpenAPI-Editor by RepreZen.
the class DefinitionHyperlinkDetector method doDetect.
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
JsonPointer targetPath;
if (pointer.toString().matches(REQUIRED_PATTERN)) {
targetPath = getRequiredPropertyPath(doc, info, pointer);
} else {
targetPath = getTagDefinitionPath(doc, info, pointer);
}
if (targetPath == null) {
return null;
}
IRegion target = doc.getRegion(targetPath);
if (target == null) {
return null;
}
return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
Aggregations