本文整理汇总了Java中org.eclipse.jdt.core.SourceRange类的典型用法代码示例。如果您正苦于以下问题:Java SourceRange类的具体用法?Java SourceRange怎么用?Java SourceRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceRange类属于org.eclipse.jdt.core包,在下文中一共展示了SourceRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: toLocation
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
/**
* Creates a location for a given java element.
* Element can be a {@link ICompilationUnit} or {@link IClassFile}
*
* @param element
* @return location or null
* @throws JavaModelException
*/
public static Location toLocation(IJavaElement element) throws JavaModelException{
ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
if (unit == null && cf == null) {
return null;
}
if (element instanceof ISourceReference) {
ISourceRange nameRange = getNameRange(element);
if (SourceRange.isAvailable(nameRange)) {
if (cf == null) {
return toLocation(unit, nameRange.getOffset(), nameRange.getLength());
} else {
return toLocation(cf, nameRange.getOffset(), nameRange.getLength());
}
}
}
return null;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:27,代码来源:JDTUtils.java
示例2: getNameRange
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private static ISourceRange getNameRange(IJavaElement element) throws JavaModelException {
ISourceRange nameRange = null;
if (element instanceof IMember) {
IMember member = (IMember) element;
nameRange = member.getNameRange();
if ( (!SourceRange.isAvailable(nameRange))) {
nameRange = member.getSourceRange();
}
} else if (element instanceof ITypeParameter || element instanceof ILocalVariable) {
nameRange = ((ISourceReference) element).getNameRange();
} else if (element instanceof ISourceReference) {
nameRange = ((ISourceReference) element).getSourceRange();
}
if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) {
nameRange = getNameRange(element.getParent());
}
return nameRange;
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:JDTUtils.java
示例3: compareInTheSameType
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
try {
IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement();
IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement();
if (firstMethod == null || secondMethod == null) {
return 0;
}
ISourceRange firstSourceRange= firstMethod.getSourceRange();
ISourceRange secondSourceRange= secondMethod.getSourceRange();
if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) {
return firstMethod.getElementName().compareTo(secondMethod.getElementName());
} else {
return firstSourceRange.getOffset() - secondSourceRange.getOffset();
}
} catch (JavaModelException e) {
return 0;
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:MethodsSourcePositionComparator.java
示例4: getLineNumber
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
public static Integer getLineNumber(IMember member) throws JavaModelException {
ITypeRoot typeRoot = member.getTypeRoot();
IBuffer buffer = typeRoot.getBuffer();
if (buffer == null) {
return null;
}
Document document = new Document(buffer.getContents());
int offset = 0;
if (SourceRange.isAvailable(member.getNameRange())) {
offset = member.getNameRange().getOffset();
} else if (SourceRange.isAvailable(member.getSourceRange())) {
offset = member.getSourceRange().getOffset();
}
try {
return document.getLineOfOffset(offset);
} catch (BadLocationException e) {
return null;
}
}
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:21,代码来源:JavaEditorUtils.java
示例5: compareInTheSameType
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private int compareInTheSameType(
IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
try {
IMethod firstMethod = (IMethod) firstMethodBinding.getJavaElement();
IMethod secondMethod = (IMethod) secondMethodBinding.getJavaElement();
if (firstMethod == null || secondMethod == null) {
return 0;
}
ISourceRange firstSourceRange = firstMethod.getSourceRange();
ISourceRange secondSourceRange = secondMethod.getSourceRange();
if (!SourceRange.isAvailable(firstSourceRange)
|| !SourceRange.isAvailable(secondSourceRange)) {
return firstMethod.getElementName().compareTo(secondMethod.getElementName());
} else {
return firstSourceRange.getOffset() - secondSourceRange.getOffset();
}
} catch (JavaModelException e) {
return 0;
}
}
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:MethodsSourcePositionComparator.java
示例6: enterField
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
/** @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor */
public void enterField(FieldInfo fieldInfo) {
if (this.typeDepth >= 0) {
this.memberDeclarationStart[this.typeDepth] = fieldInfo.declarationStart;
this.memberNameRange[this.typeDepth] =
new SourceRange(
fieldInfo.nameSourceStart, fieldInfo.nameSourceEnd - fieldInfo.nameSourceStart + 1);
String fieldName = new String(fieldInfo.name);
this.memberName[this.typeDepth] = fieldName;
// categories
IType currentType = this.types[this.typeDepth];
IField field = currentType.getField(fieldName);
addCategories(field, fieldInfo.categories);
}
}
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:SourceMapper.java
示例7: endVisit
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
@Override
public final void endVisit(final QualifiedName node) {
final ASTNode parent= node.getParent();
final Name qualifier= node.getQualifier();
IBinding binding= qualifier.resolveBinding();
if (binding instanceof ITypeBinding) {
final ConstraintVariable2 variable= fModel.createTypeVariable((ITypeBinding) binding, new CompilationUnitRange(RefactoringASTParser.getCompilationUnit(node), new SourceRange(qualifier.getStartPosition(), qualifier.getLength())));
if (variable != null)
qualifier.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable);
}
binding= node.getName().resolveBinding();
if (binding instanceof IVariableBinding && !(parent instanceof ImportDeclaration))
endVisit((IVariableBinding) binding, qualifier, node);
else if (binding instanceof ITypeBinding && parent instanceof MethodDeclaration)
endVisit((ITypeBinding) binding, node);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:SuperTypeConstraintsCreator.java
示例8: initializeSelectedExpression
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private void initializeSelectedExpression(CompilationUnitRewrite cuRewrite) throws JavaModelException {
IASTFragment fragment= ASTFragmentFactory.createFragmentForSourceRange(
new SourceRange(fSelectionStart, fSelectionLength), cuRewrite.getRoot(), cuRewrite.getCu());
if (! (fragment instanceof IExpressionFragment))
return;
//TODO: doesn't handle selection of partial Expressions
Expression expression= ((IExpressionFragment) fragment).getAssociatedExpression();
if (fragment.getStartPosition() != expression.getStartPosition()
|| fragment.getLength() != expression.getLength())
return;
if (Checks.isInsideJavadoc(expression))
return;
//TODO: exclude invalid selections
if (Checks.isEnumCase(expression.getParent()))
return;
fSelectedExpression= expression;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:IntroduceParameterRefactoring.java
示例9: checkKey
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private static RefactoringStatus checkKey(String key) {
RefactoringStatus result= new RefactoringStatus();
if (key == null)
result.addFatalError(NLSMessages.NLSRefactoring_null);
if (key.startsWith("!") || key.startsWith("#")) { //$NON-NLS-1$ //$NON-NLS-2$
RefactoringStatusContext context= new JavaStringStatusContext(key, new SourceRange(0, 0));
result.addWarning(NLSMessages.NLSRefactoring_warning, context);
}
if ("".equals(key.trim())) //$NON-NLS-1$
result.addFatalError(NLSMessages.NLSRefactoring_empty);
final String[] UNWANTED_STRINGS= {" ", ":", "\"", "\\", "'", "?", "="}; //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
//feature in resource bundle - does not work properly if keys have ":"
for (int i= 0; i < UNWANTED_STRINGS.length; i++) {
if (key.indexOf(UNWANTED_STRINGS[i]) != -1) {
String[] args= {key, UNWANTED_STRINGS[i]};
String msg= Messages.format(NLSMessages.NLSRefactoring_should_not_contain, args);
result.addError(msg);
}
}
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:NLSRefactoring.java
示例10: getNameRange
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
public ISourceRange getNameRange() throws JavaModelException {
SourceMapper mapper= getSourceMapper();
if (mapper != null) {
ClassFile classFile = (ClassFile)getClassFile();
if (classFile != null) {
// ensure the class file's buffer is open so that source ranges are computed
classFile.getBuffer();
return mapper.getNameRange(this);
}
}
Object info = getElementInfo();
if (info instanceof AnnotationInfo) {
AnnotationInfo annotationInfo = (AnnotationInfo) info;
return new SourceRange(annotationInfo.nameStart, annotationInfo.nameEnd - annotationInfo.nameStart + 1);
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:Annotation.java
示例11: exitAbstractMethod
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private void exitAbstractMethod(int declarationEnd) {
if (this.typeDepth >= 0) {
IType currentType = this.types[this.typeDepth];
SourceRange sourceRange =
new SourceRange(
this.memberDeclarationStart[this.typeDepth],
declarationEnd - this.memberDeclarationStart[this.typeDepth] + 1);
IMethod method = currentType.getMethod(
this.memberName[this.typeDepth],
convertTypeNamesToSigs(this.methodParameterTypes[this.typeDepth]));
setSourceRange(
method,
sourceRange,
this.memberNameRange[this.typeDepth]);
setMethodParameterNames(
method,
this.methodParameterNames[this.typeDepth]);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:SourceMapper.java
示例12: isSourceAvailable
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
static boolean isSourceAvailable(ISourceReference sourceReference) {
try {
return SourceRange.isAvailable(sourceReference.getSourceRange());
} catch (JavaModelException e) {
return false;
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:StubUtility2.java
示例13: getSourceRange
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
@Override
public ISourceRange getSourceRange() {
try {
return fMember.getSourceRange();
} catch (JavaModelException e) {
return new SourceRange(0, 0);
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:9,代码来源:JavaStatusContext.java
示例14: shortDescription
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private String shortDescription(String javadoc) throws Exception {
IMember member = mock(IMember.class);
IOpenable openable = (IOpenable)mock(JavaElement.class, withSettings().extraInterfaces(IOpenable.class));
when(member.getOpenable()).thenReturn(openable);
IBuffer buffer = BufferManager.createBuffer(openable);
buffer.setContents(javadoc);
when(openable.getBuffer()).thenReturn(buffer);
when(member.getJavadocRange()).thenReturn(new SourceRange(0, javadoc.length()));
return javadocCommentProvider.getJavadocCommentShortDescription(member);
}
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:11,代码来源:JavadocCommentProviderTest.java
示例15: getSelection
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private ISourceRange getSelection(ICompilationUnit cu) throws Exception {
String source = cu.getSource();
// Warning: this *includes* the SQUARE_BRACKET_OPEN!
int offset = source.indexOf(SQUARE_BRACKET_OPEN);
int end = source.indexOf(SQUARE_BRACKET_CLOSE);
return new SourceRange(offset + SQUARE_BRACKET_OPEN.length(), end - offset);
}
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:Rename18Test.java
示例16: getRangeOfOperands
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private static ISourceRange getRangeOfOperands(List<Expression> operands) {
Expression first = operands.get(0);
Expression last = operands.get(operands.size() - 1);
return new SourceRange(
first.getStartPosition(),
last.getStartPosition() + last.getLength() - first.getStartPosition());
}
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:AssociativeInfixExpressionFragment.java
示例17: getSourceRange
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
@Override
public ISourceRange getSourceRange() {
try {
return fMember.getSourceRange();
} catch (JavaModelException e) {
return new SourceRange(0, 0);
}
}
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:JavaStatusContext.java
示例18: addShadowsError
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private static void addShadowsError(
ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
// Old match not found in new matches -> reference has been shadowed
// TODO: should not have to filter declarations:
if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
return;
ISourceRange range = new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
RefactoringStatusContext context = JavaStatusContext.create(cu, range);
String message =
Messages.format(
RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
result.addError(message, context);
}
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:RenameAnalyzeUtil.java
示例19: isInlineMethodAvailable
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException {
if (method == null) return false;
if (!method.exists()) return false;
if (!method.isStructureKnown()) return false;
if (!method.isBinary()) return true;
if (method.isConstructor()) return false;
return SourceRange.isAvailable(method.getNameRange());
}
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:RefactoringAvailabilityTester.java
示例20: checkAssignments
import org.eclipse.jdt.core.SourceRange; //导入依赖的package包/类
private RefactoringStatus checkAssignments(VariableDeclaration decl) {
TempAssignmentFinder assignmentFinder = new TempAssignmentFinder(decl);
getASTRoot().accept(assignmentFinder);
if (!assignmentFinder.hasAssignments()) return new RefactoringStatus();
ASTNode firstAssignment = assignmentFinder.getFirstAssignment();
int start = firstAssignment.getStartPosition();
int length = firstAssignment.getLength();
ISourceRange range = new SourceRange(start, length);
RefactoringStatusContext context = JavaStatusContext.create(fCu, range);
String message =
Messages.format(
RefactoringCoreMessages.InlineTempRefactoring_assigned_more_once,
BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
return RefactoringStatus.createFatalErrorStatus(message, context);
}
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:InlineTempRefactoring.java
注:本文中的org.eclipse.jdt.core.SourceRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论