forked from dsldevkit/dsl-devkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move find references filter (part 1).
Adds InferredModelReferenceFilter to ide plugin as first part of moving it from ui plugin.
- Loading branch information
1 parent
ef856ac
commit 502fb3b
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...k.xtext.ide/src/com/avaloq/tools/ddk/xtext/ide/findrefs/InferredModelReferenceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Avaloq Group AG and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Avaloq Group AG - initial API and implementation | ||
*******************************************************************************/ | ||
package com.avaloq.tools.ddk.xtext.ide.findrefs; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.xtext.resource.IReferenceDescription; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
|
||
/** | ||
* A filter for filtering out inferred model elements. | ||
*/ | ||
public class InferredModelReferenceFilter implements Predicate<IReferenceDescription> { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return true if {@code input} is not an inferred model element. | ||
*/ | ||
@Override | ||
public boolean apply(final IReferenceDescription input) { | ||
return !isInferredModelElement(input.getSourceEObjectUri()); | ||
} | ||
|
||
/** | ||
* Checks a model element's URI to determine if it is an inferred model element. | ||
* | ||
* @param elementURI | ||
* the URI to check | ||
* @return true if {@code elementURI} is the URI of an inferred model element; false otherwise. | ||
*/ | ||
protected boolean isInferredModelElement(final URI elementURI) { | ||
String fragment = elementURI.fragment(); | ||
if (fragment.length() > 1) { | ||
char firstCharacter = fragment.charAt(1); | ||
// Normally, URI fragments of non-inferred elements look like: /0/x/y/z/ | ||
// However, there is an exception to this rule, which is WFD that uses a custom FragmentProvider | ||
// There, EMF feature names are used and fragments look in the following way: /WfdSource/Wfd/x/y/z | ||
// Hence, the first check is needed to handle this case | ||
return Character.isDigit(firstCharacter) && firstCharacter != '0'; | ||
} | ||
return false; | ||
} | ||
|
||
} |