本文整理汇总了Java中org.eclipse.jdt.core.dom.StringLiteral.getStartPosition方法的典型用法代码示例。如果您正苦于以下问题:Java StringLiteral.getStartPosition方法的具体用法?Java StringLiteral.getStartPosition怎么用?Java StringLiteral.getStartPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.StringLiteral
的用法示例。
在下文中一共展示了StringLiteral.getStartPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
@Override
public boolean visit(StringLiteral node) {
// Verifying that cursor in this string node
if (node.getStartPosition() < documentOffset && (node.getLength() + node.getStartPosition()) > documentOffset) {
LOG.info(" found StringLiteral " + node);
if (isStringNodeInFileElement(node)) {
foundeNoded = node;
file = true;
} else if (isStringNodeInPatternElement(node)) {
file = false;
foundeNoded = node;
}else {
//LOG.info("seems not a file");
}
}
return true;
}
示例2: getHoverRegion
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
if (!(getEditor() instanceof JavaEditor))
return null;
ITypeRoot je= getEditorInputJavaElement();
if (je == null)
return null;
// Never wait for an AST in UI thread.
CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
if (ast == null)
return null;
ASTNode node= NodeFinder.perform(ast, offset, 1);
if (node instanceof StringLiteral) {
StringLiteral stringLiteral= (StringLiteral)node;
return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
} else if (node instanceof SimpleName) {
SimpleName simpleName= (SimpleName)node;
return new Region(simpleName.getStartPosition(), simpleName.getLength());
}
return null;
}
示例3: createLiteralMarkerAttrs
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private Map<String, Object> createLiteralMarkerAttrs(StringLiteral literal, String property,
int position, boolean singleProperty) {
String literalValue = literal.getLiteralValue();
int clearRangeStart = 0, clearRangeEnd = 0;
if (singleProperty) {
clearRangeStart = position;
clearRangeEnd = position + property.length();
} else {
int lastComma = literalValue.substring(0, position).lastIndexOf(',');
if (lastComma != -1) {
clearRangeStart = lastComma;
clearRangeEnd = position + property.length();
} else {
int nextComma = literalValue.indexOf(',', position);
if (nextComma != -1) {
clearRangeStart = position;
clearRangeEnd = nextComma + 1;
}
}
}
int startPosition = literal.getStartPosition() + 1;
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IMarker.CHAR_START, startPosition + position);
attributes.put(IMarker.CHAR_END, startPosition + position + property.length());
attributes.put(IMarker.SEVERITY, prefs.getScopeStringErrorSeverity());
if (clearRangeEnd != 0) {
attributes.put(ScopeStringConstants.MARKER_ATTR_CLEAR_RANGE_START, startPosition
+ clearRangeStart);
attributes.put(ScopeStringConstants.MARKER_ATTR_CLEAR_RANGE_END, startPosition
+ clearRangeEnd);
}
return attributes;
}
示例4: calculateProposals
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
static List<ICompletionProposal> calculateProposals(final StringLiteral stringLiteral, final int documentOffset)
throws IOException {
LOG.info("literal value = " + stringLiteral.getLiteralValue());
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
if (stringLiteral.getLiteralValue().trim().length() == 0) {
proposals = calculateProposalsForEmptyString(stringLiteral, documentOffset);
} else {
int fromStart = documentOffset - stringLiteral.getStartPosition();
String pathFromStartLiteralToCursor = stringLiteral.getEscapedValue().substring(1, fromStart);
pathFromStartLiteralToCursor = pathFromStartLiteralToCursor.replace("\"", "").replace("\\\\", "/");
LOG.info(pathFromStartLiteralToCursor);
if (pathFromStartLiteralToCursor.trim().length()==0) {
proposals = calculateProposalsForEmptyString(stringLiteral, documentOffset);
} else {
String pathFromDocumentOfficetToEnd = stringLiteral.getEscapedValue().substring(fromStart);
LOG.info("pathFromDocumentOfficetToEnd " + pathFromDocumentOfficetToEnd);
pathFromDocumentOfficetToEnd = pathFromDocumentOfficetToEnd.replace("\"", "").replace("\\\\", "/");
int nextShalsh = pathFromDocumentOfficetToEnd.indexOf("/");
File file = new File(pathFromStartLiteralToCursor);
if (pathFromStartLiteralToCursor.endsWith("/")) {
if (file.exists() && file.isDirectory()) {
File[] files = file.listFiles();
if (files == null) {
LOG.info("can't list files");
} else {
proposals = calculateProposalsWithSlash(stringLiteral, documentOffset, files, fromStart,
nextShalsh);
}
}
} else {
int lastShalsh = pathFromStartLiteralToCursor.lastIndexOf('/');
// want to get rid just of string
if (lastShalsh != -1) {
String dirrr = pathFromStartLiteralToCursor.substring(0, lastShalsh + 1);
String rest = pathFromStartLiteralToCursor.substring(lastShalsh + 1).toLowerCase();
LOG.info("dirr = " + dirrr);
LOG.info("rest = " + rest);
File file2 = new File(dirrr);
LOG.info("abs path " + file2.getAbsolutePath());
if (file2.exists() && file2.isDirectory()) {
proposals = calculateProposalsWithNotEndSlash(stringLiteral, documentOffset,
file2.listFiles(), fromStart, nextShalsh, rest);
} else {
LOG.info("not exists " + file2);
}
}
}
}
}
LOG.info("proposal count " + proposals.size());
Collections.sort(proposals, new Comparator<ICompletionProposal>() {
public int compare(ICompletionProposal o1, ICompletionProposal o2) {
return o1.getDisplayString().compareToIgnoreCase(o2.getDisplayString());
}
});
return proposals;
}
示例5: calculateProposals
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
public static List<ICompletionProposal> calculateProposals(final StringLiteral stringLiteral,
final int documentOffset) throws IOException {
String escapedValue = stringLiteral.getEscapedValue();
String literalValue = stringLiteral.getLiteralValue();
LOG.info("literal value = " + literalValue);
List<ICompletionProposal> sss = new ArrayList<ICompletionProposal>();
int fromStart = documentOffset - stringLiteral.getStartPosition();
if (fromStart < 2) {
LOG.info("fromStart negative : " + fromStart);
// first char is "
fromStart = 2;
}
if (fromStart >= escapedValue.length()) {
LOG.info("fromStart more then length : " + fromStart + " >= " + escapedValue.length());
fromStart = escapedValue.length() - 1;
}
LOG.info("position = " + fromStart);
List<IContentProposal> vvv = RegExpAllProposals.getProposals(escapedValue, fromStart);
Collections.reverse(vvv);
int i = 0;
for (final IContentProposal iContentProposal : vvv) {
String content = iContentProposal.getContent();
if (content.length() == 0) {
continue;
}
// getting escaped value of content
stringLiteral.setLiteralValue(content);
String content2 = stringLiteral.getEscapedValue();
content2 = content2.substring(1, content2.length() - 1);
int diff = content2.length() - content.length();
LOG.fine(content2);
ICompletionProposal completionProposal = new RegExpCompletionProposal(content2, documentOffset, 0,
iContentProposal.getCursorPosition() + diff, null,
content + " - " + iContentProposal.getDescription(), null, iContentProposal.getDescription(), i++);
sss.add(completionProposal);
i++;
}
return sss;
}