org.eclipse.xtext.ui.refactoring.impl.StatusWrapper Java Examples
The following examples show how to use
org.eclipse.xtext.ui.refactoring.impl.StatusWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N4JSRefactoringCrossReferenceSerializer.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * If the target has a name field, simply return it as it is already the changed name. The default implementation * {@code getCrossRefText} has a problem: it asks the scope but the scope seems to not have the updated state. */ @Override public String getCrossRefText(EObject owner, CrossReference crossref, EObject target, RefTextEvaluator refTextEvaluator, ITextRegion linkTextRegion, StatusWrapper status) { if (target instanceof IdentifiableElement) { return ((IdentifiableElement) target).getName(); } else { return super.getCrossRefText(owner, crossref, target, refTextEvaluator, linkTextRegion, status); } }
Example #2
Source File: JdtRenameRefactoringParticipantProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Subclasses can decide to override this to allow specific multi-refactorings. * * @since 2.4 */ protected RefactoringStatus preCheckInitialConditions(IProgressMonitor pm) throws CoreException { if (associations.getJvmElements(getTargetElement()).size() > 1) { StatusWrapper statusWrapper = getStatusProvider().get(); statusWrapper.add(ERROR, "Rename from here will not be complete. Try to rename {0} instead.", getTargetElement()); statusWrapper.merge(super.checkInitialConditions(pm)); return statusWrapper.getRefactoringStatus(); } return new RefactoringStatus(); }
Example #3
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { StatusWrapper status = statusProvider.get(); try { status.merge(validateMethodName(methodName)); status.merge(validateParameters()); ITextRegion expressionsRegion = getExpressionsRegion(); ITextRegion predecessorRegion = locationInFileProvider.getFullTextRegion(originalMethod); if (pm.isCanceled()) { throw new OperationCanceledException(); } Section expressionSection = rewriter.newSection(expressionsRegion.getOffset(), expressionsRegion.getLength()); Section declarationSection = rewriter.newSection(predecessorRegion.getOffset() + predecessorRegion.getLength(), 0); createMethodCallEdit(expressionSection, expressionsRegion); if (pm.isCanceled()) { throw new OperationCanceledException(); } createMethodDeclarationEdit(declarationSection, expressionSection.getBaseIndentLevel(), expressionsRegion); if (pm.isCanceled()) { throw new OperationCanceledException(); } textEdit = replaceConverter.convertToTextEdit(rewriter.getChanges()); } catch (OperationCanceledException e) { throw e; } catch (Exception exc) { handleException(exc, status); } return status.getRefactoringStatus(); }
Example #4
Source File: MockRefactoringDocument.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public IRefactoringDocument get(URI resourceURI, StatusWrapper status) { return new MockRefactoringDocument(resourceURI, ""); }
Example #5
Source File: DefaultRenameElementStrategyTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public StatusWrapper getRefactoringStatus() { return null; }
Example #6
Source File: DefaultLinkedPositionGroupCalculator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public StatusWrapper getRefactoringStatus() { return status; }
Example #7
Source File: ExtractVariableRefactoring.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { StatusWrapper status = statusProvider.get(); return status.getRefactoringStatus(); }
Example #8
Source File: ExtractVariableRefactoring.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { StatusWrapper status = statusProvider.get(); try { status.merge(validateNewVariableName(variableName)); ITextRegion expressionRegion = locationInFileProvider.getFullTextRegion(expression); ITextRegion successorRegion = locationInFileProvider.getFullTextRegion(successor); Section callerSection = rewriter.newSection(expressionRegion.getOffset(), expressionRegion.getLength()); if (pm.isCanceled()) { throw new OperationCanceledException(); } if (isNeedsNewBlock) { IRegion lineInformation = document.getLineInformationOfOffset(successorRegion.getOffset()); int previousLineEnd = lineInformation.getOffset() - rewriter.getLineSeparator().length(); Section blockStartSection = getDeclarationSection(Math.max(0, previousLineEnd), expressionRegion.getOffset(), callerSection); if(previousLineEnd > 0 && !Character.isWhitespace(document.getChar(previousLineEnd-1))) blockStartSection.append(" "); blockStartSection.append("{").increaseIndentation().newLine(); appendDeclaration(blockStartSection, expressionRegion); Section blockEndSection = rewriter.newSection(successorRegion.getOffset() + successorRegion.getLength(), 0); blockEndSection.decreaseIndentation().newLine().append("}"); } else { Section declarationSection = getDeclarationSection(successorRegion.getOffset(), expressionRegion.getOffset(), callerSection); appendDeclaration(declarationSection, expressionRegion); declarationSection.newLine(); } if (pm.isCanceled()) { throw new OperationCanceledException(); } String callerText = variableName; // handle closure shortcut syntaxes if(expression.eContainer() instanceof XMemberFeatureCall) { if(((XMemberFeatureCall) expression.eContainer()).getMemberCallArguments().size() == 1) { String expressionExpanded = document.get(expressionRegion.getOffset()-1, expressionRegion.getLength() + 2); if(!expressionExpanded.startsWith("(") || !expressionExpanded.endsWith(")")) callerText = "(" + callerText + ")"; } } callerSection.append(callerText); } catch (OperationCanceledException e) { throw e; } catch (Exception exc) { handleException(exc, status); } return status.getRefactoringStatus(); }
Example #9
Source File: ExtractVariableRefactoring.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void handleException(Exception exc, StatusWrapper status) { status.add(FATAL, "Error during refactoring: {0}", exc, LOG); }
Example #10
Source File: XbaseReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public StatusWrapper getRefactoringStatus() { return delegate.getRefactoringStatus(); }
Example #11
Source File: JvmMemberRenameProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override protected boolean isValidTargetFile(Resource resource, StatusWrapper status) { // don't check, there is no file return true; }
Example #12
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException { StatusWrapper status = statusProvider.get(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(firstExpression, new CancelIndicator() { @Override public boolean isCanceled() { return pm.isCanceled(); } }); try { Set<String> calledExternalFeatureNames = newHashSet(); returnType = calculateReturnType(resolvedTypes); if (returnType != null && !equal("void", returnType.getIdentifier())) returnExpression = lastExpression; boolean isReturnAllowed = isEndOfOriginalMethod(); for (EObject element : EcoreUtil2.eAllContents(originalMethod.getExpression())) { if (pm.isCanceled()) { throw new OperationCanceledException(); } boolean isLocalExpression = EcoreUtil.isAncestor(expressions, element); if (element instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) element; JvmIdentifiableElement feature = featureCall.getFeature(); LightweightTypeReference featureType = resolvedTypes.getActualType(featureCall); boolean isLocalFeature = EcoreUtil.isAncestor(expressions, feature); if (!isLocalFeature && isLocalExpression) { // call-out if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration) { if (!calledExternalFeatureNames.contains(feature.getSimpleName())) { calledExternalFeatureNames.add(feature.getSimpleName()); ParameterInfo parameterInfo = new ParameterInfo(featureType.getIdentifier(), feature.getSimpleName(), parameterInfos.size()); parameterInfos.add(parameterInfo); parameter2type.put(parameterInfo, featureType); } externalFeatureCalls.put(feature.getSimpleName(), featureCall); } } else if (isLocalFeature && !isLocalExpression) { // call-in if (returnExpression != null) { status.add(RefactoringStatus.FATAL, "Ambiguous return value: Multiple local variables are accessed in subsequent code."); break; } returnExpression = featureCall; returnType = featureType; } } else if(isLocalExpression) { if(element instanceof XReturnExpression && !isReturnAllowed) { status.add(RefactoringStatus.FATAL, "Extracting method would break control flow due to return statements."); break; } else if (element instanceof JvmTypeReference) { JvmType type = ((JvmTypeReference) element).getType(); if (type instanceof JvmTypeParameter) { JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod); if (operation != null) { List<JvmTypeParameter> typeParameters = operation.getTypeParameters(); if (typeParameters.contains(type)) neededTypeParameters.add((JvmTypeParameter) type); } } } else if (element instanceof JvmFormalParameter) localFeatureNames.add(((JvmFormalParameter) element).getName()); else if (element instanceof XVariableDeclaration) localFeatureNames.add(((XVariableDeclaration) element).getIdentifier()); } } } catch (OperationCanceledException e) { throw e; } catch (Exception exc) { handleException(exc, status); } return status.getRefactoringStatus(); }
Example #13
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void handleException(Exception exc, StatusWrapper status) { status.add(FATAL, "Error during refactoring: {0}", exc, LOG); }
Example #14
Source File: IRefactoringUpdateAcceptor.java From xtext-eclipse with Eclipse Public License 2.0 | votes |
StatusWrapper getRefactoringStatus();