use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class SourceMapper method enterAbstractMethod.
private void enterAbstractMethod(MethodInfo methodInfo) {
if (this.typeDepth >= 0) {
this.memberName[this.typeDepth] = new String(methodInfo.name);
this.memberNameRange[this.typeDepth] = new SourceRange(methodInfo.nameSourceStart, methodInfo.nameSourceEnd - methodInfo.nameSourceStart + 1);
this.memberDeclarationStart[this.typeDepth] = methodInfo.declarationStart;
IType currentType = this.types[this.typeDepth];
int currenTypeModifiers = this.typeModifiers[this.typeDepth];
char[][] parameterTypes = methodInfo.parameterTypes;
if (methodInfo.isConstructor && currentType.getDeclaringType() != null && !Flags.isStatic(currenTypeModifiers)) {
IType declaringType = currentType.getDeclaringType();
String declaringTypeName = declaringType.getElementName();
if (declaringTypeName.length() == 0) {
IClassFile classFile = declaringType.getClassFile();
int length = parameterTypes != null ? parameterTypes.length : 0;
char[][] newParameterTypes = new char[length + 1][];
declaringTypeName = classFile.getElementName();
declaringTypeName = declaringTypeName.substring(0, declaringTypeName.indexOf('.'));
newParameterTypes[0] = declaringTypeName.toCharArray();
if (length != 0) {
System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
}
this.methodParameterTypes[this.typeDepth] = newParameterTypes;
} else {
int length = parameterTypes != null ? parameterTypes.length : 0;
char[][] newParameterTypes = new char[length + 1][];
newParameterTypes[0] = declaringTypeName.toCharArray();
if (length != 0) {
System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
}
this.methodParameterTypes[this.typeDepth] = newParameterTypes;
}
} else {
this.methodParameterTypes[this.typeDepth] = parameterTypes;
}
this.methodParameterNames[this.typeDepth] = methodInfo.parameterNames;
IMethod method = currentType.getMethod(this.memberName[this.typeDepth], convertTypeNamesToSigs(this.methodParameterTypes[this.typeDepth]));
// type parameters
if (methodInfo.typeParameters != null) {
for (int i = 0, length = methodInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = methodInfo.typeParameters[i];
ITypeParameter typeParameter = method.getTypeParameter(new String(typeParameterInfo.name));
setSourceRange(typeParameter, new SourceRange(typeParameterInfo.declarationStart, typeParameterInfo.declarationEnd - typeParameterInfo.declarationStart + 1), new SourceRange(typeParameterInfo.nameSourceStart, typeParameterInfo.nameSourceEnd - typeParameterInfo.nameSourceStart + 1));
}
}
// parameters infos
if (methodInfo.parameterInfos != null) {
for (int i = 0, length = methodInfo.parameterInfos.length; i < length; i++) {
ParameterInfo parameterInfo = methodInfo.parameterInfos[i];
LocalVariableElementKey key = new LocalVariableElementKey(method, new String(parameterInfo.name));
SourceRange[] allRanges = new SourceRange[] { new SourceRange(parameterInfo.declarationStart, parameterInfo.declarationEnd - parameterInfo.declarationStart + 1), new SourceRange(parameterInfo.nameSourceStart, parameterInfo.nameSourceEnd - parameterInfo.nameSourceStart + 1) };
this.parametersRanges.put(key, allRanges);
if (parameterInfo.modifiers != 0) {
if (this.finalParameters == null) {
this.finalParameters = new HashSet();
}
this.finalParameters.add(key);
}
}
}
// categories
addCategories(method, methodInfo.categories);
}
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class SourceMapper method getSourceRange.
/**
* Returns the <code>SourceRange</code> for the given element, or
* {-1, -1} if no source range is known for the element.
*/
public SourceRange getSourceRange(IJavaElement element) {
switch(element.getElementType()) {
case IJavaElement.METHOD:
if (((IMember) element).isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
element = getUnqualifiedMethodHandle((IMethod) element, true)[0];
} else {
element = el[0];
}
}
break;
case IJavaElement.TYPE_PARAMETER:
IJavaElement parent = element.getParent();
if (parent.getElementType() == IJavaElement.METHOD) {
IMethod method = (IMethod) parent;
if (method.isBinary()) {
IJavaElement[] el = getUnqualifiedMethodHandle(method, false);
if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
method = (IMethod) getUnqualifiedMethodHandle(method, true)[0];
} else {
method = (IMethod) el[0];
}
element = method.getTypeParameter(element.getElementName());
}
}
break;
case IJavaElement.LOCAL_VARIABLE:
LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName());
SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[0];
}
}
SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[0];
}
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class InlineTempRefactoring method checkAssignments.
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);
}
use of org.eclipse.jdt.core.SourceRange in project bndtools by bndtools.
the class MemberValuePairLocationRetriever method visit.
/**
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation)
*/
@Override
public boolean visit(SingleMemberAnnotation node) {
final IAnnotationBinding annotationBinding = node.resolveAnnotationBinding();
if (annotationBinding != null) {
final String nodeName = annotationBinding.getAnnotationType().getQualifiedName();
boolean match;
try {
match = this.annotationNameMatch.test(nodeName);
} catch (Exception e) {
match = false;
}
if (match) {
this.locatedSourceRange = new SourceRange(node.getValue().getStartPosition(), node.getValue().getLength());
}
}
return false;
}
Aggregations