本文整理汇总了Java中org.eclipse.jdt.core.IMember类的典型用法代码示例。如果您正苦于以下问题:Java IMember类的具体用法?Java IMember怎么用?Java IMember使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMember类属于org.eclipse.jdt.core包,在下文中一共展示了IMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCallersOf
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
/**
* Find methods calling method 'm'
*/
public static HashSet<IMethod> getCallersOf(IMethod m) {
CallHierarchy callHierarchy = CallHierarchy.getDefault();
IMember[] members = { m };
MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
HashSet<IMethod> callers = new HashSet<IMethod>();
for (MethodWrapper mw : methodWrappers) {
MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
HashSet<IMethod> temp = getIMethods(mw2);
callers.addAll(temp);
}
return callers;
}
示例2: getCallLocationsOf
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
/**
* Find calling sites for method 'm'
*/
public static HashSet<CallLocation> getCallLocationsOf(IMethod m) {
CallHierarchy callHierarchy = CallHierarchy.getDefault();
IMember[] members = { m };
MethodWrapper[] methodWrappers = callHierarchy.getCallerRoots(members);
HashSet<CallLocation> callers = new HashSet<CallLocation>();
for (MethodWrapper mw : methodWrappers) {
MethodWrapper[] mw2 = mw.getCalls(new NullProgressMonitor());
HashSet<CallLocation> temp = getCallLocations(mw2);
callers.addAll(temp);
}
return callers;
}
示例3: processType
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private void processType(ITypeVisitor visitor, BinaryTypeName btn,
IType type, IProgressMonitor monitor) throws JavaModelException {
final String binaryname = btn.toString();
monitor.subTask(binaryname);
visitor.visit(type, binaryname);
for (final IJavaElement child : type.getChildren()) {
if (monitor.isCanceled()) {
break;
}
switch (child.getElementType()) {
case IJavaElement.TYPE:
IType nestedtype = (IType) child;
processType(visitor, btn.nest(nestedtype), nestedtype, monitor);
break;
case IJavaElement.METHOD:
case IJavaElement.INITIALIZER:
case IJavaElement.FIELD:
processAnonymousInnerTypes(visitor, btn, (IMember) child, monitor);
break;
}
}
}
示例4: getNameRange
import org.eclipse.jdt.core.IMember; //导入依赖的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;
}
示例5: getNodeToInsertBefore
import org.eclipse.jdt.core.IMember; //导入依赖的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;
}
示例6: uniteWithSupertypes
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private void uniteWithSupertypes(IType anchor, IType type) throws JavaModelException {
IType[] supertypes = fHierarchy.getSupertypes(type);
for (int i = 0; i < supertypes.length; i++) {
IType supertype = supertypes[i];
IType superRep = fUnionFind.find(supertype);
if (superRep == null) {
//Type doesn't declare method, but maybe supertypes?
uniteWithSupertypes(anchor, supertype);
} else {
//check whether method in supertype is really overridden:
IMember superMethod = fTypeToMethod.get(supertype);
if (JavaModelUtil.isVisibleInHierarchy(superMethod, anchor.getPackageFragment())) {
IType rep = fUnionFind.find(anchor);
fUnionFind.union(rep, superRep);
// current type is no root anymore
fRootTypes.remove(anchor);
uniteWithSupertypes(supertype, supertype);
} else {
//Not overridden -> overriding chain ends here.
}
}
}
}
示例7: appendTypeParameterLabel
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
/**
* Appends the styled label for a type parameter.
*
* @param typeParameter the element to render
* @param flags the rendering flags. Flags with names starting with 'T_' are considered.
*/
public void appendTypeParameterLabel(ITypeParameter typeParameter, long flags) {
try {
appendTypeParameterWithBounds(typeParameter, flags);
// post qualification
if (getFlag(flags, JavaElementLabels.TP_POST_QUALIFIED)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
IMember declaringMember= typeParameter.getDeclaringMember();
appendElementLabel(declaringMember, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("", e); // NotExistsException will not reach this point
}
}
示例8: internalGetContentReader
import org.eclipse.jdt.core.IMember; //导入依赖的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: isAvailable
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
if (javaElement == null) {
return false;
}
if (!javaElement.exists()) {
return false;
}
if (javaElement.isReadOnly()) {
return false;
}
// work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
// the Java project is now cheating regarding its children so we shouldn't
// call isStructureKnown if the project isn't open.
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown()) {
return false;
}
if (javaElement instanceof IMember && ((IMember) javaElement).isBinary()) {
return false;
}
return true;
}
示例10: computeDefinitionNavigation
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
try {
IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor);
if (element == null) {
return null;
}
ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
if (compilationUnit != null || (cf != null && cf.getSourceRange() != null) ) {
return JDTUtils.toLocation(element);
}
if (element instanceof IMember && ((IMember) element).getClassFile() != null) {
return JDTUtils.toLocation(((IMember) element).getClassFile());
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Problem computing definition for" + unit.getElementName(), e);
}
return null;
}
示例11: getBookmarkLocation
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
@Override
public JavaTypeMemberBookmarkLocation getBookmarkLocation(Bookmark bookmark, IProgressMonitor monitor) {
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
List<IMember> memberCandidates = getMemberCandidates(bookmark, subMonitor.newChild(30));
for (IMember member : memberCandidates) {
LinePosition linePosition = getLineNumber(member, bookmark, subMonitor.newChild(70));
if (linePosition != null) {
return new JavaTypeMemberBookmarkLocation(member, linePosition.lineNumber, linePosition.lineOffset);
}
}
if (memberCandidates.isEmpty()) {
return null;
} else {
return new JavaTypeMemberBookmarkLocation(memberCandidates.get(0), null, null);
}
}
示例12: getMemberCandidates
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private List<IMember> getMemberCandidates(IType type, Bookmark javaBookmark) {
String elementKind = javaBookmark.getPropertyValue(PROP_JAVA_ELEMENT_KIND);
String elementName = javaBookmark.getPropertyValue(PROP_JAVA_ELEMENT_NAME);
if (KIND_FIELD.equals(elementKind)) {
IField field = type.getField(elementName);
return field.exists() ? Lists.newArrayList(field) : Collections.emptyList();
}
if (KIND_METHOD.equals(elementKind)) {
String signature = javaBookmark.getPropertyValue(PROP_JAVA_METHOD_SIGNATURE);
IMethod method = null;
if (signature != null) {
method = getMethod(type, elementName, signature);
}
if (method == null) {
List<IMethod> candidates = getMethodsWithName(type, elementName);
return Lists.newArrayList(candidates);
}
return Lists.newArrayList(method);
}
if (JavaEditorUtils.isType(elementKind) && elementName != null) {
IType memberType = type.getType(elementName);
return memberType.exists() ? Lists.newArrayList(memberType) : Collections.emptyList();
}
return Collections.emptyList();
}
示例13: addMemberBookmarkProperties
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
protected void addMemberBookmarkProperties(Map<String, String> bookmarkProperties, IMember member) {
putIfAbsent(bookmarkProperties, PROP_JAVA_ELEMENT_NAME, member.getElementName());
if (member.getDeclaringType() != null) {
putIfAbsent(bookmarkProperties, PROP_JAVA_DECLARING_TYPE,
member.getDeclaringType().getFullyQualifiedName());
}
putIfAbsent(bookmarkProperties, PROP_JAVA_ELEMENT_KIND, getKind(member));
if (member instanceof IMethod) {
putIfAbsent(bookmarkProperties, PROP_JAVA_METHOD_SIGNATURE,
JavaEditorUtils.getMethodSimpleSignature((IMethod) member));
putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME,
bookmarkProperties.get(PROP_JAVA_DECLARING_TYPE) + '.' + member.getElementName() + "()");
}
if (member instanceof IType) {
IType type = (IType) member;
putIfAbsent(bookmarkProperties, PROP_JAVA_TYPE, type.getFullyQualifiedName());
putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME, type.getFullyQualifiedName());
}
if (member instanceof IField) {
putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME,
bookmarkProperties.get(PROP_JAVA_DECLARING_TYPE) + '.' + member.getElementName());
}
putIfAbsent(bookmarkProperties, Bookmark.PROPERTY_NAME, member.getElementName());
}
示例14: getJavadocCommentAsText
import org.eclipse.jdt.core.IMember; //导入依赖的package包/类
private String getJavadocCommentAsText(IMember member) {
try (Reader reader = JavadocContentAccess.getHTMLContentReader(member, true, true)) {
if (reader == null) {
return null;
}
String javadocAsHtml = CharStreams.toString(reader);
String javadocAsString = Jsoup.clean(javadocAsHtml, "", Whitelist.none(), new OutputSettings().prettyPrint(false));
// trim lines
try (BufferedReader bufferedReader = new BufferedReader(new StringReader(javadocAsString))) {
return bufferedReader.lines().map(line->line.trim()).collect(Collectors.joining("\n"));
}
} catch (JavaModelException | IOException e) {
return null;
}
}
示例15: getLineNumber
import org.eclipse.jdt.core.IMember; //导入依赖的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;
}
}