use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class ExtractTempRefactoring method getSelectedExpression.
private IExpressionFragment getSelectedExpression() throws JavaModelException {
if (fSelectedExpression != null)
return fSelectedExpression;
IASTFragment selectedFragment = ASTFragmentFactory.createFragmentForSourceRange(new SourceRange(fSelectionStart, fSelectionLength), fCompilationUnitNode, fCu);
if (selectedFragment instanceof IExpressionFragment && !Checks.isInsideJavadoc(selectedFragment.getAssociatedNode())) {
fSelectedExpression = (IExpressionFragment) selectedFragment;
} else if (selectedFragment != null) {
if (selectedFragment.getAssociatedNode() instanceof ExpressionStatement) {
ExpressionStatement exprStatement = (ExpressionStatement) selectedFragment.getAssociatedNode();
Expression expression = exprStatement.getExpression();
fSelectedExpression = (IExpressionFragment) ASTFragmentFactory.createFragmentForFullSubtree(expression);
} else if (selectedFragment.getAssociatedNode() instanceof Assignment) {
Assignment assignment = (Assignment) selectedFragment.getAssociatedNode();
fSelectedExpression = (IExpressionFragment) ASTFragmentFactory.createFragmentForFullSubtree(assignment);
}
}
if (fSelectedExpression != null && Checks.isEnumCase(fSelectedExpression.getAssociatedExpression().getParent())) {
fSelectedExpression = null;
}
return fSelectedExpression;
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class AssociativeInfixExpressionFragment method getRangeOfOperands.
private static ISourceRange getRangeOfOperands(List<Expression> operands) {
Expression first = operands.get(0);
Expression last = operands.get(operands.size() - 1);
return new SourceRange(first.getStartPosition(), last.getStartPosition() + last.getLength() - first.getStartPosition());
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class StatementAnalyzer method checkSelectedNodes.
protected void checkSelectedNodes() {
ASTNode[] nodes = getSelectedNodes();
if (nodes.length == 0)
return;
ASTNode node = nodes[0];
int selectionOffset = getSelection().getOffset();
try {
int start = fScanner.getNextStartOffset(selectionOffset, true);
if (start == node.getStartPosition()) {
int lastNodeEnd = ASTNodes.getExclusiveEnd(nodes[nodes.length - 1]);
int pos = fScanner.getNextStartOffset(lastNodeEnd, true);
int selectionEnd = getSelection().getInclusiveEnd();
if (pos <= selectionEnd) {
IScanner scanner = fScanner.getScanner();
//see https://bugs.eclipse.org/324237
char[] token = scanner.getCurrentTokenSource();
if (start < lastNodeEnd && token.length == 1 && (token[0] == ';' || token[0] == ',')) {
setSelection(Selection.createFromStartEnd(start, lastNodeEnd - 1));
} else {
ISourceRange range = new SourceRange(lastNodeEnd, pos - lastNodeEnd);
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_end_of_selection, JavaStatusContext.create(fCUnit, range));
}
}
// success
return;
}
} catch (CoreException e) {
// fall through
}
ISourceRange range = new SourceRange(selectionOffset, node.getStartPosition() - selectionOffset + 1);
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_beginning_of_selection, JavaStatusContext.create(fCUnit, range));
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class SourceMapper method enterField.
/**
* @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
*/
public void enterField(FieldInfo fieldInfo) {
if (this.typeDepth >= 0) {
this.memberDeclarationStart[this.typeDepth] = fieldInfo.declarationStart;
this.memberNameRange[this.typeDepth] = new SourceRange(fieldInfo.nameSourceStart, fieldInfo.nameSourceEnd - fieldInfo.nameSourceStart + 1);
String fieldName = new String(fieldInfo.name);
this.memberName[this.typeDepth] = fieldName;
// categories
IType currentType = this.types[this.typeDepth];
IField field = currentType.getField(fieldName);
addCategories(field, fieldInfo.categories);
}
}
use of org.eclipse.jdt.core.SourceRange in project che by eclipse.
the class SourceMapper method enterType.
/**
* @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
*/
public void enterType(TypeInfo typeInfo) {
this.typeDepth++;
if (this.typeDepth == this.types.length) {
// need to grow
System.arraycopy(this.types, 0, this.types = new IType[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.typeNameRanges, 0, this.typeNameRanges = new SourceRange[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.typeDeclarationStarts, 0, this.typeDeclarationStarts = new int[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberName, 0, this.memberName = new String[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberDeclarationStart, 0, this.memberDeclarationStart = new int[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.memberNameRange, 0, this.memberNameRange = new SourceRange[this.typeDepth * 2], 0, this.typeDepth);
System.arraycopy(this.methodParameterTypes, 0, this.methodParameterTypes = new char[this.typeDepth * 2][][], 0, this.typeDepth);
System.arraycopy(this.methodParameterNames, 0, this.methodParameterNames = new char[this.typeDepth * 2][][], 0, this.typeDepth);
System.arraycopy(this.typeModifiers, 0, this.typeModifiers = new int[this.typeDepth * 2], 0, this.typeDepth);
}
if (typeInfo.name.length == 0) {
this.anonymousCounter++;
if (this.anonymousCounter == this.anonymousClassName) {
this.types[this.typeDepth] = getType(this.binaryType.getElementName());
} else {
this.types[this.typeDepth] = getType(new String(typeInfo.name));
}
} else {
this.types[this.typeDepth] = getType(new String(typeInfo.name));
}
this.typeNameRanges[this.typeDepth] = new SourceRange(typeInfo.nameSourceStart, typeInfo.nameSourceEnd - typeInfo.nameSourceStart + 1);
this.typeDeclarationStarts[this.typeDepth] = typeInfo.declarationStart;
IType currentType = this.types[this.typeDepth];
// type parameters
if (typeInfo.typeParameters != null) {
for (int i = 0, length = typeInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = typeInfo.typeParameters[i];
ITypeParameter typeParameter = currentType.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));
}
}
// type modifiers
this.typeModifiers[this.typeDepth] = typeInfo.modifiers;
// categories
addCategories(currentType, typeInfo.categories);
}
Aggregations