本文整理汇总了Java中org.eclipse.jdt.core.ISourceRange.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java ISourceRange.getOffset方法的具体用法?Java ISourceRange.getOffset怎么用?Java ISourceRange.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ISourceRange
的用法示例。
在下文中一共展示了ISourceRange.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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;
}
}
示例4: 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;
}
示例5: 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;
}
示例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: getUnresolvedJavaElement
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
/** Returns the IInitializer that contains the given local variable in the given type */
public static JavaElement getUnresolvedJavaElement(
int localSourceStart, int localSourceEnd, JavaElement type) {
try {
if (!(type instanceof IType)) return null;
IInitializer[] initializers = ((IType) type).getInitializers();
for (int i = 0; i < initializers.length; i++) {
IInitializer initializer = initializers[i];
ISourceRange sourceRange = initializer.getSourceRange();
if (sourceRange != null) {
int initializerStart = sourceRange.getOffset();
int initializerEnd = initializerStart + sourceRange.getLength();
if (initializerStart <= localSourceStart && localSourceEnd <= initializerEnd) {
return (JavaElement) initializer;
}
}
}
return null;
} catch (JavaModelException e) {
return null;
}
}
示例9: 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 org.eclipse.jdt.core.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;
}
示例10: collectIntersectingJavadocRanges
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
private void collectIntersectingJavadocRanges(IJavaElement element, IRegion region, List<ISourceRange> elements) throws JavaModelException {
if (element instanceof IParent) {
for (IJavaElement child : ((IParent) element).getChildren()) {
collectIntersectingJavadocRanges(child, region, elements);
}
}
if (element instanceof IMember) {
ISourceRange range = ((IMember) element).getJavadocRange();
if (range != null) {
if (range.getOffset() <= region.getOffset() + region.getLength() && range.getOffset() + range.getLength() >= region.getOffset()) {
elements.add(range);
}
}
}
}
示例11: createDtoFile
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
/**
* Parse un fichier candidat de DTO.
*
* @param file Fichier.
* @param javaProject Projet Java du fichier.
* @return Le DTO, <code>null</code> sinon.
*/
private DtoFile createDtoFile(IFile file, IJavaProject javaProject) {
/* Charge l'AST du fichier Java. */
ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
if (compilationUnit == null) {
return null;
}
List<String> dtoParentClassesList = LegacyManager.getInstance().getDtoParentsClasseList(javaProject.getProject());
try {
LegacyStrategy strategy = LegacyManager.getInstance().getStrategy(file);
/* Parcourt les types du fichier Java. */
for (IType type : compilationUnit.getAllTypes()) {
/* Vérifie que c'est un Dto */
boolean isDtoType = strategy.isDtoType(type) || JdtUtils.isSubclass(type, dtoParentClassesList);
if (!isDtoType) {
continue;
}
/* Parse les champs. */
List<DtoField> fields = strategy.parseDtoFields(type);
/* Créé le DtoFile. */
String javaName = type.getElementName();
String packageName = type.getPackageFragment().getElementName();
ISourceRange nameRange = type.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
return new DtoFile(fileRegion, javaName, packageName, fields);
}
} catch (JavaModelException e) {
ErrorUtils.handle(e);
}
return null;
}
示例12: handleMethod
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
private void handleMethod(IMethod method, String pathPrefix, IFile file, List<WsRoute> wsRoutes) throws JavaModelException {
/* Filtre pour ne garder que les méthodes publiques d'instance */
if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
return;
}
/* Parcourt les verbes HTTP */
for (String verb : HTTP_VERBS) {
/* Extrait l'annotation du verbe. */
IAnnotation verbAnnotation = JdtUtils.getAnnotation(method, verb);
if (verbAnnotation == null) {
continue;
}
/* Extrait la route partielle. */
String routePatternSuffix = JdtUtils.getMemberValue(verbAnnotation);
/* Calcule la route complète. */
String routePattern = pathPrefix + routePatternSuffix;
/* Créé la WsRoute. */
String javaName = method.getElementName();
ISourceRange nameRange = method.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
WsRoute wsRoute = new WsRoute(fileRegion, javaName, routePattern, verb);
wsRoutes.add(wsRoute);
}
}
示例13: createJavaClassFile
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
/**
* Parse un fichier de classe Java.
*
* @param file Fichier.
* @param javaProject Projet Java du fichier.
* @return Le fichier de classe Java, <code>null</code> sinon.
*/
private JavaClassFile createJavaClassFile(IFile file, IJavaProject javaProject) {
/* Charge l'AST du fichier Java. */
ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(file, javaProject);
if (compilationUnit == null) {
return null;
}
try {
/* Parcourt les types du fichier Java. */
for (IType type : compilationUnit.getAllTypes()) {
if (!type.isClass()) {
continue;
}
/* Créé le JavaClassFile. */
String javaName = type.getElementName();
String packageName = type.getPackageFragment().getElementName();
ISourceRange nameRange = type.getNameRange();
FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
return new JavaClassFile(fileRegion, javaName, packageName);
}
} catch (JavaModelException e) {
ErrorUtils.handle(e);
}
return null;
}
示例14: findSubGroupForSourceRange
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
private static List<Expression> findSubGroupForSourceRange(
List<Expression> group, ISourceRange range) {
Assert.isTrue(!group.isEmpty());
List<Expression> subGroup = new ArrayList<Expression>();
boolean entered = false, exited = false;
if (range.getOffset() == group.get(0).getStartPosition()) entered = true;
for (int i = 0; i < group.size() - 1; i++) {
Expression member = group.get(i);
Expression nextMember = group.get(i + 1);
if (entered) {
subGroup.add(member);
if (rangeEndsBetween(range, member, nextMember)) {
exited = true;
break;
}
} else {
if (rangeStartsBetween(range, member, nextMember)) entered = true;
}
}
Expression lastGroupMember = group.get(group.size() - 1);
if (Util.getEndExclusive(range)
== Util.getEndExclusive(SourceRangeFactory.create(lastGroupMember))) {
subGroup.add(lastGroupMember);
exited = true;
}
if (!exited) return new ArrayList<Expression>(0);
return subGroup;
}
示例15: addDeclarationUpdate
import org.eclipse.jdt.core.ISourceRange; //导入方法依赖的package包/类
private void addDeclarationUpdate(TextChangeManager manager) throws CoreException {
if (getDelegateUpdating()) {
// create the delegate
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(getDeclaringCU());
rewrite.setResolveBindings(true);
MethodDeclaration methodDeclaration =
ASTNodeSearchUtil.getMethodDeclarationNode(getMethod(), rewrite.getRoot());
DelegateMethodCreator creator = new DelegateMethodCreator();
creator.setDeclaration(methodDeclaration);
creator.setDeclareDeprecated(getDeprecateDelegates());
creator.setSourceRewrite(rewrite);
creator.setCopy(true);
creator.setNewElementName(getNewElementName());
creator.prepareDelegate();
creator.createEdit();
CompilationUnitChange cuChange = rewrite.createChange(true);
if (cuChange != null) {
cuChange.setKeepPreviewEdits(true);
manager.manage(getDeclaringCU(), cuChange);
}
}
String editName = RefactoringCoreMessages.RenameMethodRefactoring_update_declaration;
ISourceRange nameRange = getMethod().getNameRange();
ReplaceEdit replaceEdit =
new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
addTextEdit(manager.get(getDeclaringCU()), editName, replaceEdit);
}