本文整理汇总了Java中org.eclipse.jdt.core.ISourceRange类的典型用法代码示例。如果您正苦于以下问题:Java ISourceRange类的具体用法?Java ISourceRange怎么用?Java ISourceRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ISourceRange类属于org.eclipse.jdt.core包,在下文中一共展示了ISourceRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classFileNavigation
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
private OpenDeclarationDescriptor classFileNavigation(IClassFile classFile, IJavaElement element)
throws JavaModelException {
OpenDeclarationDescriptor dto =
DtoFactory.getInstance().createDto(OpenDeclarationDescriptor.class);
dto.setPath(classFile.getType().getFullyQualifiedName());
dto.setLibId(classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode());
dto.setBinary(true);
if (classFile.getSourceRange() != null) {
if (element instanceof ISourceReference) {
ISourceRange nameRange = ((ISourceReference) element).getNameRange();
dto.setOffset(nameRange.getOffset());
dto.setLength(nameRange.getLength());
}
}
return dto;
}
示例2: handleType
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
private void handleType(IType type, IFile file, List<ServiceImplementation> serviceImplementations) throws JavaModelException {
/* Parcourt les méthodes. */
for (IMethod method : type.getMethods()) {
/* Filtre pour ne garder que les méthodes publiques d'instance */
if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
continue;
}
/* Créé le ServiceImplementation. */
String javaName = method.getElementName();
ISourceRange nameRange = method.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
ServiceImplementation serviceImplementation = new ServiceImplementation(fileRegion, javaName);
serviceImplementations.add(serviceImplementation);
}
}
示例3: handleType
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
private void handleType(IType type, IFile file, List<DaoImplementation> daoImplementations) throws JavaModelException {
/* Parcourt les méthodes. */
for (IMethod method : type.getMethods()) {
/* Filtre pour ne garder que les méthodes publiques d'instance */
if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
continue;
}
/* Créé le DaoImplementation. */
String javaName = method.getElementName();
ISourceRange nameRange = method.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
DaoImplementation daoImplementation = new DaoImplementation(fileRegion, javaName);
daoImplementations.add(daoImplementation);
}
}
示例4: toLocation
import org.eclipse.jdt.core.ISourceRange; //导入依赖的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;
}
示例5: getNameRange
import org.eclipse.jdt.core.ISourceRange; //导入依赖的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;
}
示例6: compareInTheSameType
import org.eclipse.jdt.core.ISourceRange; //导入依赖的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;
}
}
示例7: getNodeToInsertBefore
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
/**
* Evaluates the insertion position of a new node.
*
* @param listRewrite The list rewriter to which the new node will be added
* @param sibling The Java element before which the new element should be added.
* @return the AST node of the list to insert before or null to insert as last.
* @throws JavaModelException thrown if accessing the Java element failed
*/
public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElement sibling) throws JavaModelException {
if (sibling instanceof IMember) {
ISourceRange sourceRange= ((IMember) sibling).getSourceRange();
if (sourceRange == null) {
return null;
}
int insertPos= sourceRange.getOffset();
List<? extends ASTNode> members= listRewrite.getOriginalList();
for (int i= 0; i < members.size(); i++) {
ASTNode curr= members.get(i);
if (curr.getStartPosition() >= insertPos) {
return curr;
}
}
}
return null;
}
示例8: internalGetContentReader
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
/**
* Gets a reader for an IMember's Javadoc comment content from the source attachment.
* The content does contain only the text from the comment without the Javadoc leading star characters.
* Returns <code>null</code> if the member does not contain a Javadoc comment or if no source is available.
* @param member The member to get the Javadoc of.
* @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
* does not contain a Javadoc comment or if no source is available
* @throws JavaModelException is thrown when the elements javadoc can not be accessed
* @since 3.4
*/
private static Reader internalGetContentReader(IMember member) throws JavaModelException {
IBuffer buf= member.getOpenable().getBuffer();
if (buf == null) {
return null; // no source attachment found
}
ISourceRange javadocRange= member.getJavadocRange();
if (javadocRange != null) {
JavaDocCommentReader reader= new JavaDocCommentReader(buf, javadocRange.getOffset(), javadocRange.getOffset() + javadocRange.getLength() - 1);
if (!containsOnlyInheritDoc(reader, javadocRange.getLength())) {
reader.reset();
return reader;
}
}
return null;
}
示例9: addEdits
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu= getCompilationUnit();
IPackageFragment parentPack= (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls= cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i= 0; i < decls.length; i++) {
ISourceRange range= decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = "\n";
String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
示例10: createSubPartFragmentBySourceRange
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
public static IExpressionFragment createSubPartFragmentBySourceRange(
InfixExpression node, ISourceRange range, ICompilationUnit cu) throws JavaModelException {
Assert.isNotNull(node);
Assert.isNotNull(range);
Assert.isTrue(!Util.covers(range, node));
Assert.isTrue(Util.covers(SourceRangeFactory.create(node), range));
if (!isAssociativeInfix(node)) return null;
InfixExpression groupRoot = findGroupRoot(node);
Assert.isTrue(isAGroupRoot(groupRoot));
List<Expression> groupMembers =
AssociativeInfixExpressionFragment.findGroupMembersInOrderFor(groupRoot);
List<Expression> subGroup = findSubGroupForSourceRange(groupMembers, range);
if (subGroup.isEmpty() || rangeIncludesExtraNonWhitespace(range, subGroup, cu)) return null;
return new AssociativeInfixExpressionFragment(groupRoot, subGroup);
}
示例11: compareInTheSameType
import org.eclipse.jdt.core.ISourceRange; //导入依赖的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;
}
}
示例12: getNodeToInsertBefore
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
/**
* Evaluates the insertion position of a new node.
*
* @param listRewrite The list rewriter to which the new node will be added
* @param sibling The Java element before which the new element should be added.
* @return the AST node of the list to insert before or null to insert as last.
* @throws JavaModelException thrown if accessing the Java element failed
*/
public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElement sibling)
throws JavaModelException {
if (sibling instanceof IMember) {
ISourceRange sourceRange = ((IMember) sibling).getSourceRange();
if (sourceRange == null) {
return null;
}
int insertPos = sourceRange.getOffset();
List<? extends ASTNode> members = listRewrite.getOriginalList();
for (int i = 0; i < members.size(); i++) {
ASTNode curr = members.get(i);
if (curr.getStartPosition() >= insertPos) {
return curr;
}
}
}
return null;
}
示例13: addReferenceShadowedError
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
private static void addReferenceShadowedError(
ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
// Found a new match with no corresponding old match.
// -> The new match is a reference which was pointing to another element,
// but that other element has been shadowed
// TODO: should not have to filter declarations:
if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
return;
ISourceRange range = getOldSourceRange(newMatch);
RefactoringStatusContext context = JavaStatusContext.create(cu, range);
String message =
Messages.format(
RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed,
new String[] {
BasicElementLabels.getFileName(cu),
BasicElementLabels.getJavaElementName(newElementName)
});
result.addError(message, context);
}
示例14: getSortedChildren
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
private ArrayList<IJavaElement> getSortedChildren(IType parent) throws JavaModelException {
IJavaElement[] children = parent.getChildren();
ArrayList<IJavaElement> sortedChildren = new ArrayList<IJavaElement>(Arrays.asList(children));
Collections.sort(
sortedChildren,
new Comparator<IJavaElement>() {
public int compare(IJavaElement e1, IJavaElement e2) {
if (!(e1 instanceof ISourceReference)) return 0;
if (!(e2 instanceof ISourceReference)) return 0;
try {
ISourceRange sr1 = ((ISourceReference) e1).getSourceRange();
ISourceRange sr2 = ((ISourceReference) e2).getSourceRange();
if (sr1 == null || sr2 == null) return 0;
return sr1.getOffset() - sr2.getOffset();
} catch (JavaModelException e) {
return 0;
}
}
});
return sortedChildren;
}
示例15: checkInitialConditions
import org.eclipse.jdt.core.ISourceRange; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
if (fVisibility < 0)
fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
RefactoringStatus result = new RefactoringStatus();
result.merge(Checks.checkAvailability(fField));
if (result.hasFatalError()) return result;
fRoot =
new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
.parse(fField.getCompilationUnit(), true, pm);
ISourceRange sourceRange = fField.getNameRange();
ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
if (node == null) {
return mappingErrorFound(result, node);
}
fFieldDeclaration =
(VariableDeclarationFragment) ASTNodes.getParent(node, VariableDeclarationFragment.class);
if (fFieldDeclaration == null) {
return mappingErrorFound(result, node);
}
if (fFieldDeclaration.resolveBinding() == null) {
if (!processCompilerError(result, node))
result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
return result;
}
computeUsedNames();
return result;
}