本文整理汇总了Java中org.eclipse.jdt.internal.core.JavaElement类的典型用法代码示例。如果您正苦于以下问题:Java JavaElement类的具体用法?Java JavaElement怎么用?Java JavaElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaElement类属于org.eclipse.jdt.internal.core包,在下文中一共展示了JavaElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnresolvedJavaElement
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的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;
}
}
示例2: newMethodReferenceMatch
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
public MethodReferenceMatch newMethodReferenceMatch(
IJavaElement enclosingElement,
Binding enclosingBinding,
int accuracy,
int offset,
int length,
boolean isConstructor,
boolean isSynthetic,
ASTNode reference) {
SearchParticipant participant = getParticipant();
IResource resource = this.currentPossibleMatch.resource;
boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
if (enclosingBinding != null)
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource);
}
示例3: toString
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Search match"); //$NON-NLS-1$
buffer.append("\n accuracy="); //$NON-NLS-1$
buffer.append(this.accuracy == A_ACCURATE ? "ACCURATE" : "INACCURATE"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append("\n rule="); //$NON-NLS-1$
if ((this.rule & SearchPattern.R_FULL_MATCH) != 0) {
buffer.append("EXACT"); //$NON-NLS-1$
} else if ((this.rule & SearchPattern.R_EQUIVALENT_MATCH) != 0) {
buffer.append("EQUIVALENT"); //$NON-NLS-1$
} else if ((this.rule & SearchPattern.R_ERASURE_MATCH) != 0) {
buffer.append("ERASURE"); //$NON-NLS-1$
}
buffer.append("\n raw="); //$NON-NLS-1$
buffer.append(this.raw);
buffer.append("\n offset="); //$NON-NLS-1$
buffer.append(this.offset);
buffer.append("\n length="); //$NON-NLS-1$
buffer.append(this.length);
if (this.element != null) {
buffer.append("\n element="); //$NON-NLS-1$
buffer.append(((JavaElement)getElement()).toStringWithAncestors());
}
buffer.append("\n"); //$NON-NLS-1$
return buffer.toString();
}
示例4: addChange
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
private void addChange(IMember member, IJavaElementDelta newDelta) throws JavaModelException {
int newKind = newDelta.getKind();
switch (newKind) {
case IJavaElementDelta.ADDED:
ArrayList allTypes = new ArrayList();
getAllTypesFromElement(member, allTypes);
for (int i = 0, length = allTypes.size(); i < length; i++) {
IType innerType = (IType)allTypes.get(i);
addTypeAddition(innerType, (SimpleDelta)this.changes.get(innerType));
}
break;
case IJavaElementDelta.REMOVED:
allTypes = new ArrayList();
getAllTypesFromHierarchy((JavaElement)member, allTypes);
for (int i = 0, length = allTypes.size(); i < length; i++) {
IType type = (IType)allTypes.get(i);
addTypeRemoval(type, (SimpleDelta)this.changes.get(type));
}
break;
case IJavaElementDelta.CHANGED:
addAffectedChildren(newDelta);
break;
}
}
示例5: getAllTypesFromHierarchy
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
private void getAllTypesFromHierarchy(JavaElement element, ArrayList allTypes) {
switch (element.getElementType()) {
case IJavaElement.COMPILATION_UNIT:
ArrayList types = (ArrayList)this.hierarchy.files.get(element);
if (types != null) {
allTypes.addAll(types);
}
break;
case IJavaElement.TYPE:
case IJavaElement.INITIALIZER:
case IJavaElement.FIELD:
case IJavaElement.METHOD:
types = (ArrayList)this.hierarchy.files.get(((IMember)element).getCompilationUnit());
if (types != null) {
for (int i = 0, length = types.size(); i < length; i++) {
IType type = (IType)types.get(i);
if (element.isAncestorOf(type)) {
allTypes.add(type);
}
}
}
break;
}
}
示例6: initializeRegions
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
protected void initializeRegions() {
super.initializeRegions();
IJavaElement[] roots = this.region.getElements();
for (int i = 0; i < roots.length; i++) {
IJavaElement root = roots[i];
if (root instanceof IOpenable) {
this.files.put(root, new ArrayList());
} else {
Openable o = (Openable) ((JavaElement) root).getOpenableParent();
if (o != null) {
this.files.put(o, new ArrayList());
}
}
checkCanceled();
}
}
示例7: getUnresolvedJavaElement
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的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;
}
}
示例8: getJavaElement
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
public IJavaElement getJavaElement() {
JavaElement element = getUnresolvedJavaElement();
if (element != null)
return element.resolved(this.binding);
if (isRecovered()) {
IPackageBinding packageBinding = getPackage();
if (packageBinding != null) {
final IJavaElement javaElement = packageBinding.getJavaElement();
if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
// best effort: we don't know if the recovered binding is a binary or source binding, so go with a simple source type
return ((PackageFragment) javaElement).getCompilationUnit(new String(this.binding.sourceName()) + SuffixConstants.SUFFIX_STRING_java).getType(this.getName());
}
}
return null;
}
return null;
}
示例9: assertElementsEqual
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
protected void assertElementsEqual(String message, String expected, IJavaElement[] elements, boolean showResolvedInfo) {
StringBuffer buffer = new StringBuffer();
if (elements != null) {
for (int i = 0, length = elements.length; i < length; i++){
JavaElement element = (JavaElement)elements[i];
if (element == null) {
buffer.append("<null>");
} else {
buffer.append(element.toStringWithAncestors(showResolvedInfo));
}
if (i != length-1) buffer.append("\n");
}
} else {
buffer.append("<null>");
}
String actual = buffer.toString();
if (!expected.equals(actual)) {
if (this.displayName) System.out.println(getName()+" actual result is:");
System.out.println(displayString(actual, this.tabs) + this.endChar);
}
assertEquals(message, expected, actual);
}
示例10: sortElements
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
protected void sortElements(IJavaElement[] elements) {
Util.Comparer comparer = new Util.Comparer() {
public int compare(Object a, Object b) {
JavaElement elementA = (JavaElement)a;
JavaElement elementB = (JavaElement)b;
char[] tempJCLPath = "<externalJCLPath>".toCharArray();
String idA = new String(CharOperation.replace(
elementA.toStringWithAncestors().toCharArray(),
getExternalJCLPathString().toCharArray(),
tempJCLPath));
String idB = new String(CharOperation.replace(
elementB.toStringWithAncestors().toCharArray(),
getExternalJCLPathString().toCharArray(),
tempJCLPath));
return idA.compareTo(idB);
}
};
Util.sort(elements, comparer);
}
示例11: shortDescription
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的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);
}
示例12: getAnnotation
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
public static IAnnotation getAnnotation(
JavaElement parent, IBinaryAnnotation binaryAnnotation, String memberValuePairName) {
char[] typeName =
org.eclipse.jdt.core.Signature.toCharArray(
CharOperation.replaceOnCopy(binaryAnnotation.getTypeName(), '/', '.'));
return new Annotation(parent, new String(typeName), memberValuePairName);
}
示例13: getJavaElement
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
private JavaElement getJavaElement(LocalVariableBinding binding) {
LocalDeclaration local = binding.declaration;
JavaElement parent = null;
ReferenceContext referenceContext = binding.declaringScope.referenceContext();
if (referenceContext instanceof AbstractMethodDeclaration) {
AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding);
} else if (referenceContext instanceof TypeDeclaration){
// Local variable is declared inside an initializer
TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding);
parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type);
}
if (parent == null) return null;
return new LocalVariable(
parent,
new String(local.name),
local.declarationSourceStart,
local.declarationSourceEnd,
local.sourceStart,
local.sourceEnd,
Util.typeSignature(local.type),
binding.declaration.annotations,
local.modifiers,
local.getKind() == AbstractVariableDeclaration.PARAMETER);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:InternalExtendedCompletionContext.java
示例14: getJavaElementOfCompilationUnit
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
private JavaElement getJavaElementOfCompilationUnit(Binding binding) {
if (!this.hasComputedEnclosingJavaElements) {
computeEnclosingJavaElements();
}
if (this.bindingsToHandles == null) return null;
return (JavaElement)this.bindingsToHandles.get(binding);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:InternalExtendedCompletionContext.java
示例15: createField
import org.eclipse.jdt.internal.core.JavaElement; //导入依赖的package包/类
protected SourceField createField(JavaElement parent, FieldInfo fieldInfo) {
String fieldName = JavaModelManager.getJavaModelManager().intern(new String(fieldInfo.name));
AssistSourceField field = new AssistSourceField(parent, fieldName, this.bindingCache, this.newElements);
if (fieldInfo.node.binding != null) {
this.bindingCache.put(field, fieldInfo.node.binding);
this.elementCache.put(fieldInfo.node.binding, field);
} else {
this.elementWithProblemCache.put(fieldInfo.node, field);
}
return field;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:CompletionUnitStructureRequestor.java