use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet resultSet) {
PsiElement position = parameters.getPosition();
PsiElement originalPosition = parameters.getOriginalPosition();
AndroidFacet facet = AndroidFacet.getInstance(position);
if (facet == null) {
return;
}
PsiElement parent = position.getParent();
PsiElement originalParent = originalPosition != null ? originalPosition.getParent() : null;
if (parent instanceof XmlTag) {
XmlTag tag = (XmlTag) parent;
if (tag.getParentTag() != null) {
return;
}
final ASTNode startTagName = XmlChildRole.START_TAG_NAME_FINDER.findChild(tag.getNode());
if (startTagName == null || startTagName.getPsi() != position) {
return;
}
final PsiFile file = tag.getContainingFile();
if (!(file instanceof XmlFile)) {
return;
}
final PsiReference reference = file.findReferenceAt(parameters.getOffset());
if (reference != null) {
final PsiElement element = reference.getElement();
if (element != null) {
final int refOffset = element.getTextRange().getStartOffset() + reference.getRangeInElement().getStartOffset();
if (refOffset != position.getTextRange().getStartOffset()) {
// do not provide completion if we're inside some reference starting in the middle of tag name
return;
}
}
}
if (!completeTagNames(facet, (XmlFile) file, resultSet)) {
resultSet.stopHere();
}
} else if (parent instanceof XmlAttribute) {
final ASTNode attrName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(parent.getNode());
if (attrName == null || attrName.getPsi() != position) {
return;
}
addAndroidPrefixElement(position, parent, resultSet);
final XmlAttribute attribute = (XmlAttribute) parent;
final String namespace = attribute.getNamespace();
// has already been typed
if (SdkConstants.TOOLS_URI.equals(namespace)) {
addDesignTimeAttributes(attribute.getNamespacePrefix(), position, facet, attribute, resultSet);
}
customizeAddedAttributes(facet, parameters, attribute, resultSet);
} else if (originalParent instanceof XmlAttributeValue) {
completeTailsInFlagAttribute(parameters, resultSet, (XmlAttributeValue) originalParent);
completeDataBindingTypeAttr(parameters, resultSet, (XmlAttributeValue) originalParent);
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidImplicitUsagesProvider method isImplicitWrite.
@Override
public boolean isImplicitWrite(PsiElement element) {
if (!(element instanceof PsiField)) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
return false;
}
final PsiField field = (PsiField) element;
final PsiModifierList modifierList = field.getModifierList();
if (modifierList == null) {
return false;
}
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
for (PsiNameValuePair pair : annotation.getParameterList().getAttributes()) {
final PsiAnnotationMemberValue value = pair.getValue();
if (isResourceReference(value)) {
return true;
}
}
}
return false;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidProjectComponent method projectOpened.
@Override
public void projectOpened() {
final CompilerManager manager = CompilerManager.getInstance(myProject);
manager.addBeforeTask(new AndroidPrecompileTask());
myDisposable = Disposer.newDisposable(getClass().getName());
if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
if (ProjectFacetManager.getInstance(myProject).hasFacets(AndroidFacet.ID)) {
createAndroidSpecificComponents();
} else {
final MessageBusConnection connection = myProject.getMessageBus().connect(myDisposable);
connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {
@Override
public void facetAdded(@NotNull Facet facet) {
if (facet instanceof AndroidFacet) {
createAndroidSpecificComponents();
connection.disconnect();
}
}
});
}
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidPropertyFilesUpdater method updatePropertyFilesIfNecessary.
private void updatePropertyFilesIfNecessary() {
if (myProject.isDisposed())
return;
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final List<VirtualFile> toAskFiles = new ArrayList<VirtualFile>();
final List<AndroidFacet> toAskFacets = new ArrayList<AndroidFacet>();
final List<Runnable> toAskChanges = new ArrayList<Runnable>();
final List<VirtualFile> files = new ArrayList<VirtualFile>();
final List<Runnable> changes = new ArrayList<Runnable>();
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && !facet.requiresAndroidModel()) {
final String updatePropertyFiles = facet.getProperties().UPDATE_PROPERTY_FILES;
final boolean ask = updatePropertyFiles.isEmpty();
if (!ask && !Boolean.parseBoolean(updatePropertyFiles)) {
continue;
}
final Pair<VirtualFile, List<Runnable>> pair = updateProjectPropertiesIfNecessary(facet);
if (pair != null) {
if (ask) {
toAskFacets.add(facet);
toAskFiles.add(pair.getFirst());
toAskChanges.addAll(pair.getSecond());
} else {
files.add(pair.getFirst());
changes.addAll(pair.getSecond());
}
}
}
}
/* We should expire old notification even if there are no properties to update in current event.
For example, user changed "is library" setting to 'true', the notification was shown, but user ignored it.
Then he changed the setting to 'false' again. New notification won't be shown, because the value of
"android.library" in project.properties is correct. However if the old notification was not expired,
user may press on it, and "android.library" property will be changed to 'false'. */
if (myNotification != null && !myNotification.isExpired()) {
myNotification.expire();
}
if (changes.size() > 0 || toAskChanges.size() > 0) {
if (toAskChanges.size() > 0) {
askUserIfUpdatePropertyFile(myProject, toAskFacets, new Processor<MyResult>() {
@Override
public boolean process(MyResult result) {
if (result == MyResult.NEVER) {
for (AndroidFacet facet : toAskFacets) {
facet.getProperties().UPDATE_PROPERTY_FILES = Boolean.FALSE.toString();
}
return true;
} else if (result == MyResult.ALWAYS) {
for (AndroidFacet facet : toAskFacets) {
facet.getProperties().UPDATE_PROPERTY_FILES = Boolean.TRUE.toString();
}
}
if (ReadonlyStatusHandler.ensureFilesWritable(myProject, toAskFiles.toArray(new VirtualFile[toAskFiles.size()]))) {
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (Runnable change : toAskChanges) {
change.run();
}
}
});
}
}, "Update Android property files", null);
}
return true;
}
});
}
if (changes.size() > 0 && ReadonlyStatusHandler.ensureFilesWritable(myProject, files.toArray(new VirtualFile[files.size()]))) {
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (Runnable change : changes) {
change.run();
}
}
});
CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject);
}
}, "Update Android property files", null);
}
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ResourceNameConverter method createReferences.
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue<String> value, PsiElement element, ConvertContext context) {
final Module module = context.getModule();
if (module == null) {
return PsiReference.EMPTY_ARRAY;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return PsiReference.EMPTY_ARRAY;
}
final DomElement parent = value.getParent();
if (parent instanceof Style) {
return getReferencesInStyleName((Style) parent, value, facet);
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations