org.eclipse.core.runtime.Assert Java Examples

The following examples show how to use org.eclipse.core.runtime.Assert. 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: TLCVariableValue.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Factory method to deliver simple values
 * @param input
 * @return
 */
public static TLCVariableValue parseValue(String input)
{
    Assert.isNotNull(input, "The value must be not null");
    input.trim();

    TLCVariableValue result;

    try
    {
        InputPair pair = new InputPair(input, 0);
        result = innerParse(pair);
        if (pair.offset != input.length())
        {
            throw new VariableValueParseException();
        }
    } catch (VariableValueParseException e)
    {
        result = new TLCSimpleVariableValue(input);
    }

    return result;
}
 
Example #2
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Attempts to expand all nodes along the path specified by the node array parameter.
 * The method is copied from SWTBotTree with an additional check if the node is already expanded.
 *
 * @param bot
 *          tree bot, must not be {@code null}
 * @param nodes
 *          node path to expand, must not be {@code null} or empty
 * @return the last tree item that was expanded, or {@code null} if no item was found
 */
public static SWTBotTreeItem expandNode(final SWTBotTree bot, final String... nodes) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(nodes, ARGUMENT_NODES);
  assertArgumentIsNotEmpty(nodes, ARGUMENT_NODES);
  new SWTBot().waitUntil(widgetIsEnabled(bot));
  SWTBotTreeItem item = bot.getTreeItem(nodes[0]);
  if (!item.isExpanded()) {
    item.expand();
  }

  final List<String> asList = new ArrayList<String>(Arrays.asList(nodes));
  asList.remove(0);
  if (!asList.isEmpty()) {
    item = expandNode(item, asList.toArray(new String[asList.size()]));
  }

  return item;
}
 
Example #3
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Enforces the workbench focus policy.
 * <p>
 * <em>Note</em>: Depending on {@link CoreSwtbotTools#getWorkbenchFocusPolicy()}, this method waits until the window under test has focus before returning, or
 * else re-sets the focus on the window.
 * </p>
 *
 * @param bot
 *          the {@link SwtWorkbenchBot} for which to check the focus, must not be {@code null}
 */
public static void enforceWorkbenchFocusPolicy(final SwtWorkbenchBot bot) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  if (bot.getFocusedWidget() == null) {
    if (WorkbenchFocusPolicy.WAIT == getWorkbenchFocusPolicy()) {
      bot.waitUntilFocused();
    } else if (WorkbenchFocusPolicy.REFOCUS == getWorkbenchFocusPolicy()) {
      PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
        /** {@inheritDoc} */
        @Override
        public void run() {
          final Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells();
          if (shells.length > 0) {
            shells[0].forceActive();
          }
        }
      });
    }
  }
}
 
Example #4
Source File: CallHierarchyHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private MethodWrapper getCallRoot(IMember member, boolean isIncomingCall) {
	Assert.isNotNull(member, "member");

	IMember[] members = { member };
	CallHierarchyCore callHierarchy = CallHierarchyCore.getDefault();
	final MethodWrapper[] result;
	if (isIncomingCall) {
		result = callHierarchy.getCallerRoots(members);
	} else {
		result = callHierarchy.getCalleeRoots(members);
	}
	if (result == null || result.length < 1) {
		return null;
	}
	return result[0];
}
 
Example #5
Source File: UseEqualsResolution.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(workingUnit);
    Assert.isNotNull(bug);

    InfixExpression[] stringEqualityChecks = findStringEqualityChecks(getASTNode(workingUnit, bug.getPrimarySourceLineAnnotation()));
    for (InfixExpression stringEqualityCheck : stringEqualityChecks) {
        Operator operator = stringEqualityCheck.getOperator();
        Expression replaceExpression;
        if (EQUALS.equals(operator)) {
            replaceExpression = createEqualsExpression(rewrite, stringEqualityCheck);
        } else if (NOT_EQUALS.equals(operator)) {
            replaceExpression = createNotEqualsExpression(rewrite, stringEqualityCheck);
        } else {
            throw new BugResolutionException("Illegal operator '" + operator + "' found.");
        }
        rewrite.replace(stringEqualityCheck, replaceExpression, null);
    }
}
 
Example #6
Source File: XTool.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
XTool(SdkTool toolDesc) 
{
    Assert.isTrue(!toolDesc.isSeparator(), "XTool() is called for separator"); //$NON-NLS-1$
    this. toolDesc = toolDesc;

    switch (toolDesc.getSourceRoot()) {
	case PRJ_FILE:
	    this.xdsProjectType = XdsProjectType.PROJECT_FILE;
	    break;
	case MAIN_MODULE:
	    this.xdsProjectType = XdsProjectType.MAIN_MODULE;
	    break;
	default:
	    this.xdsProjectType = null;
	}
}
 
Example #7
Source File: AssociativeInfixExpressionFragment.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static IExpressionFragment createSubPartFragmentBySourceRange(InfixExpression node, ISourceRange range, ICompilationUnit cu) throws JavaModelException {
	Assert.isNotNull(node);
	Assert.isNotNull(range);
	Assert.isTrue(!Util.covers(range, node));
	Assert.isTrue(Util.covers(SourceRangeFactory.create(node), range));

	if (!isAssociativeInfix(node)) {
		return null;
	}

	InfixExpression groupRoot = findGroupRoot(node);
	Assert.isTrue(isAGroupRoot(groupRoot));

	List<Expression> groupMembers = AssociativeInfixExpressionFragment.findGroupMembersInOrderFor(groupRoot);
	List<Expression> subGroup = findSubGroupForSourceRange(groupMembers, range);
	if (subGroup.isEmpty() || rangeIncludesExtraNonWhitespace(range, subGroup, cu)) {
		return null;
	}

	return new AssociativeInfixExpressionFragment(groupRoot, subGroup);
}
 
Example #8
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public ExtractTempRefactoring(CompilationUnit astRoot, int selectionStart, int selectionLength, Map formatterOptions) {
	Assert.isTrue(selectionStart >= 0);
	Assert.isTrue(selectionLength >= 0);
	Assert.isTrue(astRoot.getTypeRoot() instanceof ICompilationUnit);

	fSelectionStart = selectionStart;
	fSelectionLength = selectionLength;
	fCu = (ICompilationUnit) astRoot.getTypeRoot();
	fCompilationUnitNode = astRoot;

	fReplaceAllOccurrences = true; // default
	fDeclareFinal = false; // default
	fTempName = ""; //$NON-NLS-1$

	fLinkedProposalModel = null;
	fCheckResultForCompileProblems = true;
	fFormatterOptions = formatterOptions;
}
 
Example #9
Source File: AbstractPDFViewerRunnable.java    From tlaplus with MIT License 6 votes vote down vote up
public AbstractPDFViewerRunnable(ProducePDFHandler handler, IWorkbenchPartSite site, IResource aSpecFile) {
	Assert.isNotNull(handler);
	Assert.isNotNull(site);
	Assert.isNotNull(aSpecFile);
	this.handler = handler;
	this.specFile = aSpecFile;
	
	final boolean autoRegenerate = TLA2TeXActivator.getDefault().getPreferenceStore()
			.getBoolean(ITLA2TeXPreferenceConstants.AUTO_REGENERATE);
	if (autoRegenerate) {
		// Subscribe to the event bus with which the TLA Editor save events are
		// distributed. In other words, every time the user saves a spec, we
		// receive an event and provided the spec corresponds to this PDF, we
		// regenerate it.
		// Don't subscribe in EmbeddedPDFViewerRunnable#though, because it is run
		// repeatedly and thus would cause us to subscribe multiple times.
		final IEventBroker eventService = site.getService(IEventBroker.class);
		Assert.isTrue(eventService.subscribe(TLAEditor.SAVE_EVENT, this));
		
		// Register for part close events to deregister the event handler
		// subscribed to the event bus. There is no point in regenerating
		// the PDF if no PDFEditor is open anymore.
		final IPartService partService = site.getService(IPartService.class);
		partService.addPartListener(this);
	}
}
 
Example #10
Source File: TLCModelFactory.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * @see Model#getByName(String)
 */
public static Model getByName(final String fullQualifiedModelName) {
	Assert.isNotNull(fullQualifiedModelName);
	Assert.isLegal(fullQualifiedModelName.contains(Model.SPEC_MODEL_DELIM), "Not a full-qualified model name.");
	
       final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
       final ILaunchConfigurationType launchConfigurationType = launchManager
               .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE);

	try {
		final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType);
		for (int i = 0; i < launchConfigurations.length; i++) {
			// Can do equals here because of full qualified name.
			final ILaunchConfiguration launchConfiguration = launchConfigurations[i];
			if (fullQualifiedModelName.equals(launchConfiguration.getName())) {
				return launchConfiguration.getAdapter(Model.class);
			}
		}
	} catch (CoreException shouldNeverHappen) {
		shouldNeverHappen.printStackTrace();
	}
	
	return null;
}
 
Example #11
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example #12
Source File: CommonBreakIterator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean consume(char ch) {
	int kind = getKind(ch);
	fState = MATRIX[fState][kind];
	switch (fState) {
		case S_LOWER:
		case S_ONE_CAP:
		case S_ALL_CAPS:
			length++;
			return true;
		case S_EXIT:
			return false;
		case S_EXIT_MINUS_ONE:
			length--;
			return false;
		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example #13
Source File: JavaWordIterator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns <code>true</code> if the given sequence into the underlying text
 * represents a delimiter, <code>false</code> otherwise.
 *
 * @param offset
 *            the offset
 * @param exclusiveEnd
 *            the end offset
 * @return <code>true</code> if the given range is a delimiter
 */
private boolean isDelimiter(int offset, int exclusiveEnd) {
	if (exclusiveEnd == DONE || offset == DONE) {
		return false;
	}

	Assert.isTrue(offset >= 0);
	Assert.isTrue(exclusiveEnd <= getText().getEndIndex());
	Assert.isTrue(exclusiveEnd > offset);

	CharSequence seq = fIterator.fText;

	while (offset < exclusiveEnd) {
		char ch = seq.charAt(offset);
		if (ch != '\n' && ch != '\r') {
			return false;
		}
		offset++;
	}

	return true;
}
 
Example #14
Source File: AnnotationWithQuickFixesHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setInput(Object input) {
	Assert.isLegal(input instanceof AnnotationInfo);
	fInput= (AnnotationInfo)input;
	disposeDeferredCreatedContent();
	deferredCreateContent();
}
 
Example #15
Source File: TLCOutputSourceRegistry.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Disconnect the source from the listener
 */
public synchronized void disconnect(ITLCOutputListener listener)
{
    Assert.isNotNull(listener);

    ITLCOutputSource source = this.sources.get(listener.getModel());
    if (source != null)
    {
        source.removeTLCOutputListener(listener);
    }

    printStats();
}
 
Example #16
Source File: RenameTypeProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RefactoringStatus checkNewElementName(String newName) {
	Assert.isNotNull(newName, "new name"); //$NON-NLS-1$
	RefactoringStatus result = Checks.checkTypeName(newName, fType);
	if (Checks.isAlreadyNamed(fType, newName)) {
		result.addFatalError(RefactoringCoreMessages.RenameTypeRefactoring_choose_another_name);
	}
	return result;
}
 
Example #17
Source File: UiThreadDispatcher.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Runs the specified runnable on the UI thread. This method waits until the
 * runnable has been executed and returns with a result of the specified
 * type.
 *
 * @param runnable
 *          the runnable to invoke on the UI thread
 * @return the result of the runnable
 * @param <T>
 *          the type of the result
 */
@SuppressWarnings("PMD.AvoidFinalLocalVariable")
public static <T> T dispatchAndWait(final Function<T> runnable) {
  final List<T> result = new ArrayList<T>();
  Display.getDefault().syncExec(new Runnable() {
    @Override
    public void run() {
      result.add(runnable.run());
    }
  });
  Assert.isTrue(!result.isEmpty(), "Result is empty."); //$NON-NLS-1$
  return result.get(0);
}
 
Example #18
Source File: ReplaceRewrite.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected ReplaceRewrite(ASTRewrite rewrite, ASTNode[] nodes) {
	Assert.isNotNull(rewrite);
	Assert.isNotNull(nodes);
	Assert.isTrue(nodes.length > 0);
	fRewrite= rewrite;
	fToReplace= nodes;
	fDescriptor= fToReplace[0].getLocationInParent();
	if (nodes.length > 1) {
		Assert.isTrue(fDescriptor instanceof ChildListPropertyDescriptor);
	}
}
 
Example #19
Source File: DeleteChangeCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static Change createDeleteChange(IJavaElement javaElement) throws JavaModelException {
	Assert.isTrue(! ReorgUtils.isInsideCompilationUnit(javaElement));

	switch(javaElement.getElementType()){
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return createPackageFragmentRootDeleteChange((IPackageFragmentRoot)javaElement);

		case IJavaElement.PACKAGE_FRAGMENT:
			return createSourceManipulationDeleteChange((IPackageFragment)javaElement);

		case IJavaElement.COMPILATION_UNIT:
			return createSourceManipulationDeleteChange((ICompilationUnit)javaElement);

		case IJavaElement.CLASS_FILE:
			//if this assert fails, it means that a precondition is missing
			Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile);
			return createDeleteChange(((IClassFile)javaElement).getResource());

		case IJavaElement.JAVA_MODEL: //cannot be done
			Assert.isTrue(false);
			return null;

		case IJavaElement.JAVA_PROJECT: //handled differently
			Assert.isTrue(false);
			return null;

		case IJavaElement.TYPE:
		case IJavaElement.FIELD:
		case IJavaElement.METHOD:
		case IJavaElement.INITIALIZER:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_CONTAINER:
		case IJavaElement.IMPORT_DECLARATION:
			Assert.isTrue(false);//not done here
			return new NullChange();
		default:
			Assert.isTrue(false);//there's no more kinds
			return new NullChange();
	}
}
 
Example #20
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RefactoringStatus checkExpressionFragmentIsRValue() throws JavaModelException {
	switch (Checks.checkExpressionIsRValue(getSelectedExpression().getAssociatedExpression())) {
		case Checks.NOT_RVALUE_MISC:
			return RefactoringStatus.createStatus(RefactoringStatus.FATAL, RefactoringCoreMessages.ExtractTempRefactoring_select_expression, null, IConstants.PLUGIN_ID, RefactoringStatusCodes.EXPRESSION_NOT_RVALUE,
					null);
		case Checks.NOT_RVALUE_VOID:
			return RefactoringStatus.createStatus(RefactoringStatus.FATAL, RefactoringCoreMessages.ExtractTempRefactoring_no_void, null, IConstants.PLUGIN_ID, RefactoringStatusCodes.EXPRESSION_NOT_RVALUE_VOID, null);
		case Checks.IS_RVALUE_GUESSED:
		case Checks.IS_RVALUE:
			return new RefactoringStatus();
		default:
			Assert.isTrue(false);
			return null;
	}
}
 
Example #21
Source File: CTreeComboViewerRow.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.ViewerRow#getTreePath()
 */
public TreePath getTreePath() {
	CTreeComboItem tItem = item;
	LinkedList<Object> segments = new LinkedList<Object>();
	while (tItem != null) {
		Object segment = tItem.getData();
		Assert.isNotNull(segment);
		segments.addFirst(segment);
		tItem = tItem.getParentItem();
	}

	return new TreePath(segments.toArray());
}
 
Example #22
Source File: FieldModifierResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(workingUnit);
    Assert.isNotNull(bug);

    TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
    FieldDeclaration field = getFieldDeclaration(type, bug.getPrimaryField());

    Modifier finalModifier = workingUnit.getAST().newModifier(getModifierToAdd());

    ListRewrite modRewrite = rewrite.getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
    modRewrite.insertLast(finalModifier, null);
}
 
Example #23
Source File: EmbeddedEditorActions.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void setAction(String actionID, final IAction action) {
	Assert.isNotNull(actionID);
	if (action == null) {
		allActions.remove(actionID);
	} else {
		if (action.getId() == null)
			action.setId(actionID); // make sure the action ID has been set
		allActions.put(actionID, action);
	}
}
 
Example #24
Source File: TempOccurrenceAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public TempOccurrenceAnalyzer(VariableDeclaration tempDeclaration, boolean analyzeJavadoc){
	Assert.isNotNull(tempDeclaration);
	fReferenceNodes= new HashSet<>();
	fJavadocNodes= new HashSet<>();
	fAnalyzeJavadoc= analyzeJavadoc;
	fTempDeclaration= tempDeclaration;
	fTempBinding= tempDeclaration.resolveBinding();
	fIsInJavadoc= false;
}
 
Example #25
Source File: ResourceModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds the given resource to the list of renamed
 * resources.
 *
 * @param rename the resource to be renamed
 * @param arguments the arguments of the rename
 */
public void addRename(IResource rename, RenameArguments arguments) {
	Assert.isNotNull(rename);
	Assert.isNotNull(arguments);
	if (fRename == null) {
		fRename= new ArrayList<>(2);
		fRenameArguments= new ArrayList<>(2);
	}
	fRename.add(rename);
	fRenameArguments.add(arguments);
	if (fIgnoreCount == 0) {
		IPath newPath= rename.getFullPath().removeLastSegments(1).append(arguments.getNewName());
		internalAdd(new MoveDescription(rename, newPath));
	}
}
 
Example #26
Source File: TagCloudViewer.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a new TagCloudViewer for the given {@link TagCloud}, which must
 * not be <code>null</code>.
 * 
 * @param cloud
 */
public TagCloudViewer(TagCloud cloud) {
	Assert.isLegal(cloud != null, "TagCloud must not be null!");
	Assert.isLegal(!cloud.isDisposed(), "TagCloud must not be disposed!");
	this.cloud = cloud;
	initListeners();
}
 
Example #27
Source File: ProverHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Takes the String representation of the status of a step
 * or obligation and translates to the integer representation
 * of the status of a proof step.
 * 
 * This can be used to map from the current state of an obligation
 * and the new status of the obligation for a prover into the new state
 * of the obligation. See {@link ColorPredicate} for explanation of
 * obligation states.
 * 
 * Returns currentStatus if status is not a known status. Also throws
 * an {@link AssertionFailedException} in that case.
 * 
 * @param status the new status string from tlapm
 * @param currentState the current state of the obligation
 * @param backEndName the name of the backend, e.g. isabelle, tlapm, zenon
 * @return
 */
public static int getIntFromStringStatus(String status, int currentState, String backEndName)
{
    int backendNum = getNumOfBackend(backEndName);

    if (status.equals(PROVED) || status.equals(TRIVIAL))
    {
        return ColorPredicate.newStateNumber(currentState, backendNum, ColorPredicate.numberOfProverStatus(
                backendNum, ColorPredicate.PROVED_STATUS));
    } else if (status.equals(BEING_PROVED))
    {
        return ColorPredicate.newStateNumber(currentState, backendNum, ColorPredicate.numberOfProverStatus(
                backendNum, ColorPredicate.PROVING_STATUS));
    } else if (status.equals(FAILED))
    {
        return ColorPredicate.newStateNumber(currentState, backendNum, ColorPredicate.numberOfProverStatus(
                backendNum, ColorPredicate.FAILED_STATUS));
    } else if (status.equals(INTERUPTED))
    {
        return ColorPredicate.newStateNumber(currentState, backendNum, ColorPredicate.numberOfProverStatus(
                backendNum, ColorPredicate.STOPPED_STATUS));
    }

    Assert.isTrue(false, "Unknown status : " + status);
    return currentState;

}
 
Example #28
Source File: ExtractConstantRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public ExtractConstantRefactoring(CompilationUnit astRoot, int selectionStart, int selectionLength, Map formatterOptions) {
	Assert.isTrue(selectionStart >= 0);
	Assert.isTrue(selectionLength >= 0);
	Assert.isTrue(astRoot.getTypeRoot() instanceof ICompilationUnit);

	fSelectionStart = selectionStart;
	fSelectionLength = selectionLength;
	fCu = (ICompilationUnit) astRoot.getTypeRoot();
	fCuRewrite = new CompilationUnitRewrite(null, fCu, astRoot, formatterOptions);
	fLinkedProposalModel = null;
	fConstantName = ""; //$NON-NLS-1$
	fCheckResultForCompileProblems = true;
	fFormatterOptions = formatterOptions;
}
 
Example #29
Source File: XdsParser.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * PointerType = "POINTER" [DirectLanguageSpec] "TO" BoundType <br>
 * BoundType   = TypeIdentifier | NewType <br>
 */
private IPointerTypeSymbol parsePointerTypeDefinition( String typeName
                                                     , String hostName  
                                                     , ISymbolWithScope scope, ISymbolWithScope typeResolver ) 
{
    Assert.isTrue(token == POINTER_KEYWORD);
    AstPointerType typeAst = builder.beginProduction(POINTER_TYPE_DEFINITION);

    boolean isTypeDeclaration = (typeName != null);
    
    PointerTypeSymbol typeSymbol = createPointerTypeSymbol(
        typeName, hostName, scope, typeAst
    );
    typeName = typeSymbol.getName();
    setAstSymbol(typeAst, typeSymbol);
    addSymbolForResolving(typeSymbol);
    
    nextToken();
    
    modifierParser.parseDirectLanguageSpec(scope, typeResolver);
    typeSymbol.setLanguage(modifierParser.language);
    
    parseToken(TO_KEYWORD);

    if (isTypeDeclaration) {
        declaredType = typeSymbol;
    }
    
    ITypeSymbol boundTypeSymbol = parseTypeDefinition(null, typeName, scope, typeResolver, true, true);
    
    setBoundTypeSymbol(typeSymbol, boundTypeSymbol);
    
    builder.endProduction(typeAst);
    return typeSymbol;
}
 
Example #30
Source File: AbstractMethodCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public AbstractMethodCorrectionProposal(String label, ICompilationUnit targetCU, ASTNode invocationNode,
		ITypeBinding binding, int relevance) {
	super(label, CodeActionKind.QuickFix, targetCU, null, relevance);

	Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));

	fNode= invocationNode;
	fSenderBinding= binding;
}