use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class ResourceTypeClassBase method buildResourceFields.
@NotNull
static PsiField[] buildResourceFields(@NotNull ResourceManager manager, boolean nonFinal, @NotNull String resClassName, @NotNull final PsiClass context) {
ResourceType resourceType = ResourceType.getEnum(resClassName);
if (resourceType == null) {
return PsiField.EMPTY_ARRAY;
}
final Map<String, PsiType> fieldNames = new HashMap<String, PsiType>();
final boolean styleable = ResourceType.STYLEABLE == resourceType;
final PsiType basicType = styleable ? PsiType.INT.createArrayType() : PsiType.INT;
for (String resName : manager.getResourceNames(resourceType)) {
fieldNames.put(resName, basicType);
}
if (styleable) {
for (ResourceEntry entry : manager.getValueResourceEntries(ResourceType.ATTR)) {
final String resName = entry.getName();
final String resContext = entry.getContext();
if (resContext.length() > 0) {
fieldNames.put(resContext + '_' + resName, PsiType.INT);
}
}
}
final PsiField[] result = new PsiField[fieldNames.size()];
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
int idIterator = resourceType.ordinal() * 100000;
int i = 0;
for (Map.Entry<String, PsiType> entry : fieldNames.entrySet()) {
final String fieldName = AndroidResourceUtil.getFieldNameByResourceName(entry.getKey());
final PsiType type = entry.getValue();
final int id = -(idIterator++);
final AndroidLightField field = new AndroidLightField(fieldName, context, type, !nonFinal, nonFinal ? null : id);
field.setInitializer(factory.createExpressionFromText(Integer.toString(id), field));
result[i++] = field;
}
return result;
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidPrecompileTask method checkArtifacts.
private static boolean checkArtifacts(@NotNull CompileContext context) {
final Project project = context.getProject();
final CompileScope scope = context.getCompileScope();
final Set<Artifact> artifacts = ApplicationManager.getApplication().runReadAction(new Computable<Set<Artifact>>() {
@Override
public Set<Artifact> compute() {
return ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
}
});
if (artifacts == null) {
return true;
}
final Set<Artifact> debugArtifacts = new HashSet<>();
final Set<Artifact> releaseArtifacts = new HashSet<>();
final Map<AndroidFacet, List<Artifact>> facet2artifacts = new HashMap<>();
for (final Artifact artifact : artifacts) {
final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
if (properties instanceof AndroidApplicationArtifactProperties) {
final AndroidArtifactSigningMode mode = ((AndroidApplicationArtifactProperties) properties).getSigningMode();
if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
debugArtifacts.add(artifact);
} else {
releaseArtifacts.add(artifact);
}
}
final AndroidFacet facet = ApplicationManager.getApplication().runReadAction(new Computable<AndroidFacet>() {
@Nullable
@Override
public AndroidFacet compute() {
return AndroidArtifactUtil.getPackagedFacet(project, artifact);
}
});
if (facet != null) {
List<Artifact> list = facet2artifacts.get(facet);
if (list == null) {
list = new ArrayList<>();
facet2artifacts.put(facet, list);
}
list.add(artifact);
}
}
boolean success = true;
if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + toString(debugArtifacts) + "\n" + "Release artifacts: " + toString(releaseArtifacts);
context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
success = false;
}
if (releaseArtifacts.size() > 0 && CompileStepBeforeRun.getRunConfiguration(context) != null) {
final String message = "Cannot build release Android artifacts in the 'make before run' session\n" + "Release artifacts: " + toString(releaseArtifacts);
context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
success = false;
}
for (Map.Entry<AndroidFacet, List<Artifact>> entry : facet2artifacts.entrySet()) {
final List<Artifact> list = entry.getValue();
final String moduleName = entry.getKey().getModule().getName();
if (list.size() > 1) {
final Artifact firstArtifact = list.get(0);
final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
for (int i = 1; i < list.size(); i++) {
final Artifact artifact = list.get(i);
if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
context.addMessage(CompilerMessageCategory.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName(), null, -1, -1);
success = false;
break;
}
}
}
}
return success;
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidMavenExecutor method generateResources.
public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
try {
JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {
@Nullable
@Override
public JavaParameters compute() {
try {
return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
} catch (ExecutionException e) {
LOG.info(e);
result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
return null;
}
}
});
if (javaParams == null) {
return result;
}
GeneralCommandLine commandLine = javaParams.toCommandLine();
final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
String message = processor.getMessage();
if (!success) {
LOG.info(message);
String lcmessage = message.toLowerCase();
int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
if (buildErrorIndex >= 0) {
result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
}
}
} catch (ExecutionException e) {
LOG.info(e);
result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
}
return result;
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidFindStyleApplicationsProcessor method isPossibleApplicationOfStyle.
private boolean isPossibleApplicationOfStyle(XmlTag candidate) {
final DomElement domCandidate = DomManager.getDomManager(myProject).getDomElement(candidate);
if (!(domCandidate instanceof LayoutViewElement)) {
return false;
}
final LayoutViewElement candidateView = (LayoutViewElement) domCandidate;
final Map<Pair<String, String>, String> attrsInCandidateMap = new HashMap<Pair<String, String>, String>();
final List<XmlAttribute> attrsInCandidate = AndroidExtractStyleAction.getExtractableAttributes(candidate);
if (attrsInCandidate.size() < myAttrMap.size()) {
return false;
}
for (XmlAttribute attribute : attrsInCandidate) {
final String attrValue = attribute.getValue();
if (attrValue != null) {
attrsInCandidateMap.put(Pair.create(attribute.getNamespace(), attribute.getLocalName()), attrValue);
}
}
for (Map.Entry<AndroidAttributeInfo, String> entry : myAttrMap.entrySet()) {
final String ns = entry.getKey().getNamespace();
final String name = entry.getKey().getName();
final String value = entry.getValue();
final String valueInCandidate = attrsInCandidateMap.get(Pair.create(ns, name));
if (valueInCandidate == null || !valueInCandidate.equals(value)) {
return false;
}
}
if (candidateView.getStyle().getStringValue() != null) {
if (myParentStyleNameAttrValue == null) {
return false;
}
final PsiElement styleNameAttrValueForTag = getStyleNameAttrValueForTag(candidateView);
if (styleNameAttrValueForTag == null || !myParentStyleNameAttrValue.equals(styleNameAttrValueForTag)) {
return false;
}
} else if (myParentStyleNameAttrValue != null) {
return false;
}
return true;
}
use of com.intellij.util.containers.HashMap in project android by JetBrains.
the class AndroidRefactoringUtil method computeAttributeMap.
@Nullable
static Map<AndroidAttributeInfo, String> computeAttributeMap(@NotNull Style style, @NotNull ErrorReporter errorReporter, @NotNull String errorReportTitle) {
final Map<AndroidAttributeInfo, String> attributeValues = new HashMap<AndroidAttributeInfo, String>();
for (StyleItem item : style.getItems()) {
final String attributeName = item.getName().getStringValue();
String attributeValue = item.getStringValue();
if (attributeName == null || attributeName.length() <= 0 || attributeValue == null) {
continue;
}
final int idx = attributeName.indexOf(':');
final String localName = idx >= 0 ? attributeName.substring(idx + 1) : attributeName;
final String nsPrefix = idx >= 0 ? attributeName.substring(0, idx) : null;
if (nsPrefix != null) {
if (!AndroidUtils.SYSTEM_RESOURCE_PACKAGE.equals(nsPrefix)) {
errorReporter.report(RefactoringBundle.getCannotRefactorMessage("Unknown XML attribute prefix '" + nsPrefix + ":'"), errorReportTitle);
return null;
}
} else {
errorReporter.report(RefactoringBundle.getCannotRefactorMessage("The style contains attribute without 'android' prefix."), errorReportTitle);
return null;
}
attributeValues.put(new AndroidAttributeInfo(localName, nsPrefix), attributeValue);
}
return attributeValues;
}
Aggregations