Java Code Examples for org.eclipse.core.runtime.Assert

The following examples show how to use org.eclipse.core.runtime.Assert. These examples are extracted from open source projects. 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 Project: dsl-devkit   Source File: CoreSwtbotTools.java    License: 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 2
Source Project: dsl-devkit   Source File: CoreSwtbotTools.java    License: 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
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 4
@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 5
Source Project: xds-ide   Source File: XTool.java    License: 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 6
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 7
Source Project: eclipse.jdt.ls   Source File: ReorgPolicyFactory.java    License: 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 8
Source Project: eclipse.jdt.ls   Source File: JavaWordIterator.java    License: 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 9
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 10
Source Project: tlaplus   Source File: AbstractPDFViewerRunnable.java    License: 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 11
Source Project: tlaplus   Source File: TLCModelFactory.java    License: 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 12
Source Project: xtext-eclipse   Source File: CommonBreakIterator.java    License: 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 Project: tlaplus   Source File: TLCVariableValue.java    License: 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 14
Source Project: xds-ide   Source File: XdsParser.java    License: 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 15
Source Project: lapse-plus   Source File: LapsePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Outputs a message or an Exception if the current plug-in is debugging.
 * 
 * @param message
 *            if not null, message will be sent to standard out
 * @param e
 *            if not null, e.printStackTrace() will be called.
 */
public static void trace(String trace_mode, String message, Throwable e) {
    if (isDebugging(trace_mode)) {
        Assert.isNotNull(message);
        if (e == null) {
            logInfo(message);
        } else {
            logError(message, e);
        }
    }
}
 
Example 16
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;
}
 
Example 17
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 18
Source Project: nebula   Source File: CTreeComboViewerRow.java    License: 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 19
public MoveCuUpdateCreator(ICompilationUnit[] cus, IPackageFragment pack) {
	Assert.isNotNull(cus);
	Assert.isNotNull(pack);
	fCus = cus;
	fDestination = pack;
	fImportRewrites = new HashMap<>();
	fNewPackage = fDestination.isDefaultPackage() ? "" : fDestination.getElementName() + '.'; //$NON-NLS-1$
}
 
Example 20
@Override
protected void initialize() {

	Assert.isTrue(getDeclaration() instanceof FieldDeclaration);
	Assert.isTrue(((FieldDeclaration) getDeclaration()).fragments().size() == 1);

	fOldFieldFragment= (VariableDeclarationFragment) ((FieldDeclaration) getDeclaration()).fragments().get(0);
	if (getNewElementName() == null) {
		setNewElementName(fOldFieldFragment.getName().getIdentifier());
	}

	setInsertBefore(false); // delegate must be inserted after the original field that is referenced in the initializer
}
 
Example 21
Source Project: eclipse.jdt.ls   Source File: ReorgPolicyFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException {
	final ASTRewrite rewrite= targetRewriter.getASTRewrite();
	switch (element.getElementType()) {
		case IJavaElement.FIELD:
			copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode));
			break;
		case IJavaElement.IMPORT_CONTAINER:
			copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.IMPORT_DECLARATION:
			copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.INITIALIZER:
			copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.METHOD:
			copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.PACKAGE_DECLARATION:
			copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode);
			break;
		case IJavaElement.TYPE:
			copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode);
			break;

		default:
			Assert.isTrue(false);
	}
}
 
Example 22
private static ASTNode[] getArrayPrefix(ASTNode[] array, int prefixLength) {
	Assert.isTrue(prefixLength <= array.length);
	Assert.isTrue(prefixLength >= 0);
	ASTNode[] prefix = new ASTNode[prefixLength];
	for (int i = 0; i < prefix.length; i++) {
		prefix[i] = array[i];
	}
	return prefix;
}
 
Example 23
public ChangeMethodSignatureProposal(String label, ICompilationUnit targetCU, ASTNode invocationNode,
		IMethodBinding binding, ChangeDescription[] paramChanges, ChangeDescription[] exceptionChanges,
		int relevance) {
	super(label, CodeActionKind.QuickFix, targetCU, null, relevance);

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

	fInvocationNode= invocationNode;
	fSenderBinding= binding;
	fParameterChanges= paramChanges;
	fExceptionChanges= exceptionChanges;
}
 
Example 24
Source Project: eclipse.jdt.ls   Source File: ConstantChecks.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private boolean isMemberReferenceValidInClassInitialization(Name name) {
	IBinding binding = name.resolveBinding();
	Assert.isTrue(binding instanceof IVariableBinding || binding instanceof IMethodBinding);

	if (name instanceof SimpleName) {
		return Modifier.isStatic(binding.getModifiers());
	} else {
		Assert.isTrue(name instanceof QualifiedName);
		return checkName(((QualifiedName) name).getQualifier());
	}
}
 
Example 25
Source Project: dsl-devkit   Source File: AbstractScopingTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the scope of the given reference for the given context contains only the expected objects.
 * In addition, checks that the reference of the given context references at least one of the expected
 * objects. If the reference has multiplicity > 1, then every reference must reference at least
 * one of the expected objects.
 *
 * @param context
 *          {@link EObject} from which the given objects shall be referenced, must not be {@code null}
 * @param reference
 *          the structural feature of {@code context} for which the scope should be asserted, must not be {@code null} and part of the context element
 * @param expectedObjects
 *          the objects expected in the scope, must not be {@code null}
 */
protected void assertScopedObjects(final EObject context, final EReference reference, final Collection<? extends EObject> expectedObjects) {
  Assert.isNotNull(context, PARAMETER_CONTEXT);
  Assert.isNotNull(reference, PARAMETER_REFERENCE);
  Assert.isNotNull(expectedObjects, PARAMETER_EXPECTED_OBJECTS);
  Assert.isTrue(context.eClass().getEAllReferences().contains(reference), String.format("Contract for argument '%s' failed: Parameter is not within specified range (Expected: %s, Actual: %s).", PARAMETER_CONTEXT, "The context object must contain the given reference.", "Reference not contained by the context object!"));
  Set<URI> expectedUriSet = Sets.newHashSet();
  for (EObject object : expectedObjects) {
    expectedUriSet.add(EcoreUtil.getURI(object));
  }
  IScope scope = getScopeProvider().getScope(context, reference);
  Iterable<IEObjectDescription> allScopedElements = scope.getAllElements();
  Set<URI> scopedUriSet = Sets.newHashSet();
  for (IEObjectDescription description : allScopedElements) {
    URI uri = description.getEObjectURI();
    scopedUriSet.add(uri);
  }
  if (!expectedUriSet.equals(scopedUriSet)) {
    fail("The scope must exactly consist of the expected URIs. Missing " + Sets.difference(expectedUriSet, scopedUriSet) + " extra "
        + Sets.difference(scopedUriSet, expectedUriSet));
  }
  // test that link resolving worked
  boolean elementResolved;
  if (reference.isMany()) {
    @SuppressWarnings("unchecked")
    EList<EObject> objects = (EList<EObject>) context.eGet(reference, true);
    elementResolved = !objects.isEmpty(); // NOPMD
    for (Iterator<EObject> objectIter = objects.iterator(); objectIter.hasNext() && elementResolved;) {
      EObject eObject = EcoreUtil.resolve(objectIter.next(), context);
      elementResolved = expectedUriSet.contains(EcoreUtil.getURI(eObject));
    }
  } else {
    EObject resolvedObject = (EObject) context.eGet(reference, true);
    elementResolved = expectedUriSet.contains(EcoreUtil.getURI(resolvedObject));
  }
  assertTrue("Linking must have resolved one of the expected objects.", elementResolved);
}
 
Example 26
Source Project: xds-ide   Source File: XdsModel.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void handleRemoveResource(IResourceDelta rootDelta, IResource affectedResource) {
    if (DEBUG_PRINT_OF_THE_CHANGE_NOTIFICATIONS) System.out.println("Remove resource : " + affectedResource); //$NON-NLS-1$
    
    Lock writeLock = instanceLock.writeLock();
    try{
    	writeLock.lock();
    	
        IXdsResource xdsElement = getWorkspaceXdsElement(affectedResource);
        if (xdsElement instanceof IXdsProject) { // just remove project
            removeProjectFromModel((IXdsProject)xdsElement);
            CompilationSetManager.getInstance().removeFromCompilationSet(affectedResource.getProject());
        }
        else if (xdsElement != null) { // it can be null for say .project resource
        	IXdsResource tmpElement = getWorkspaceXdsElement(affectedResource.getParent());
        	if (tmpElement instanceof IEditableXdsFolderContainer) {
        	    IEditableXdsFolderContainer xdsElementParent = (IEditableXdsFolderContainer) tmpElement;
                Assert.isNotNull(xdsElementParent, "Non-project element should always has parent"); //$NON-NLS-1$
                if (xdsElementParent.getChildResources().contains(affectedResource)) {
                    xdsElementParent.removeChild(xdsElement);
                }
        	}
            
            if (xdsElement instanceof IXdsCompilationUnit) {
                String path = ResourceUtils.getAbsolutePath(affectedResource);
                CompilationSetManager.getInstance().removeFromCompilationSet(affectedResource.getProject(), path);
            }
        }
    }
    finally {
    	writeLock.unlock();
    }
}
 
Example 27
public NewVariableCorrectionProposal(String label, ICompilationUnit cu, int variableKind, SimpleName node,
		ITypeBinding senderBinding, int relevance) {
	super(label, CodeActionKind.QuickFix, cu, null, relevance);
	if (senderBinding == null) {
		Assert.isTrue(variableKind == PARAM || variableKind == LOCAL);
	} else {
		Assert.isTrue(Bindings.isDeclarationBinding(senderBinding));
	}

	fVariableKind= variableKind;
	fOriginalNode= node;
	fSenderBinding= senderBinding;
}
 
Example 28
Source Project: tm4e   Source File: TMPresentationReconciler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void install(ITextViewer viewer) {
	Assert.isNotNull(viewer);

	this.viewer = viewer;
	viewer.addTextInputListener(internalListener);

	IDocument document = viewer.getDocument();
	if (document != null) {
		internalListener.inputDocumentChanged(null, document);
	}
	themeChangeListener = new ThemeChangeListener();
	ThemeManager.getInstance().addPreferenceChangeListener(themeChangeListener);
}
 
Example 29
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 30
Source Project: tlaplus   Source File: ProverHelper.java    License: 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;

}