use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class NlPropertiesTest method testViewInRelativeLayout.
public void testViewInRelativeLayout() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout>" + " <TextView />" + "</RelativeLayout>";
XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
String tag = "TextView";
XmlTag rootTag = xmlFile.getRootTag();
assert rootTag != null;
XmlTag[] subTags = rootTag.getSubTags();
assertEquals(1, subTags.length);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(MockNlComponent.create(subTags[0])));
// at least 190 attributes are available as of API 22
assertTrue(properties.size() > 180);
// A text view should have all of its attributes and the parent class's (View) attributes
assertPresent(tag, properties, ANDROID_URI, TEXT_VIEW_ATTRS);
assertPresent(tag, properties, ANDROID_URI, ANDROID_VIEW_ATTRS);
assertPresent(tag, properties, "", NO_NAMESPACE_VIEW_ATTRS);
// Since it is embedded inside a relative layout, it should only have relative layout's layout attributes
assertPresent(tag, properties, ANDROID_URI, RELATIVE_LAYOUT_ATTRS);
assertAbsent(tag, properties, ANDROID_URI, GRID_LAYOUT_ATTRS);
assertAbsent(tag, properties, ANDROID_URI, FRAME_LAYOUT_ATTRS);
}
use of org.intellij.lang.annotations.Language in project android by JetBrains.
the class PaletteTestCase method assertLimitedHeightLayout.
private void assertLimitedHeightLayout(@NotNull Palette.BaseItem item, @NotNull String tag, @NotNull String expectedGradleCoordinate) {
@Language("XML") String xml = new XmlBuilder().startTag(tag).androidAttribute(ATTR_LAYOUT_WIDTH, VALUE_MATCH_PARENT).androidAttribute(ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT).endTag(tag).toString();
checkItem(item, tag, STANDARD_VIEW.getTitle(tag), STANDARD_LAYOUT.getIcon(tag), xml, NO_PREVIEW, NO_PREVIEW, expectedGradleCoordinate, NO_SCALE);
checkComponent(createMockComponent(tag), STANDARD_VIEW.getTitle(tag), STANDARD_LAYOUT.getIcon(tag));
}
use of org.intellij.lang.annotations.Language in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testLIPGetAllParentsAfterCodeBlockModification.
public void testLIPGetAllParentsAfterCodeBlockModification() throws Throwable {
@Language("JAVA") String text = "class LQF {\n" + " int f;\n" + " public void me() {\n" + " //<caret>\n" + " }\n" + "}";
configureByText(StdFileTypes.JAVA, text);
final List<PsiElement> visitedElements = Collections.synchronizedList(new ArrayList<>());
class MyVisitor extends PsiElementVisitor {
@Override
public void visitElement(PsiElement element) {
visitedElements.add(element);
}
}
final LocalInspectionTool tool = new LocalInspectionTool() {
@Nls
@NotNull
@Override
public String getGroupDisplayName() {
return "fegna";
}
@Nls
@NotNull
@Override
public String getDisplayName() {
return getGroupDisplayName();
}
@NotNull
@Override
public String getShortName() {
return getGroupDisplayName();
}
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new MyVisitor();
}
};
disposeOnTearDown(() -> disableInspectionTool(tool.getShortName()));
enableInspectionTool(tool);
List<HighlightInfo> infos = highlightErrors();
assertEmpty(infos);
List<PsiElement> allPsi = CollectHighlightsUtil.getElementsInRange(myFile, 0, myFile.getTextLength());
assertEquals(new HashSet<>(allPsi), new HashSet<>(visitedElements));
// inside code block modification
visitedElements.clear();
backspace();
backspace();
infos = highlightErrors();
assertEmpty(infos);
PsiMethod method = ((PsiJavaFile) myFile).getClasses()[0].getMethods()[0];
List<PsiElement> methodAndParents = CollectHighlightsUtil.getElementsInRange(myFile, method.getTextRange().getStartOffset(), method.getTextRange().getEndOffset(), true);
assertEquals(new HashSet<>(methodAndParents), new HashSet<>(visitedElements));
}
use of org.intellij.lang.annotations.Language in project intellij-community by JetBrains.
the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.
@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
if (!isApplicable(executeRunConfigurationTask))
return null;
ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
PsiClass mainClass = applicationConfiguration.getMainClass();
if (mainClass == null)
return null;
VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
if (module == null)
return null;
final JavaParameters params = new JavaParameters();
JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
String javaExePath = null;
try {
final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
if (jdk == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
final SdkTypeId type = jdk.getSdkType();
if (!(type instanceof JavaSdkType))
throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
if (javaExePath == null)
throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
javaExePath = FileUtil.toSystemIndependentName(javaExePath);
} catch (CantRunException e) {
ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
}
StringBuilder parametersString = new StringBuilder();
for (String parameter : params.getProgramParametersList().getParameters()) {
parametersString.append("args '").append(parameter).append("'\n");
}
StringBuilder vmParametersString = new StringBuilder();
for (String parameter : params.getVMParametersList().getParameters()) {
vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
}
ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
final String runAppTaskName = "run " + mainClass.getName();
taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
if (environment != null) {
RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
assert runnerAndConfigurationSettings != null;
ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
if (gradlePath == null)
return null;
final String sourceSetName;
if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
} else {
sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
}
if (sourceSetName == null)
return null;
@Language("Groovy") String initScript = "projectsEvaluated {\n" + " rootProject.allprojects {\n" + " if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + " project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? " executable = '" + javaExePath + "'\n" : "") + " classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + " main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + " }\n" + " }\n" + " }\n" + "}\n";
runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
return environment;
} else {
return null;
}
}
use of org.intellij.lang.annotations.Language in project intellij-community by JetBrains.
the class UIUtil method getCssFontDeclaration.
@Language("HTML")
public static String getCssFontDeclaration(@NotNull Font font, @Nullable Color fgColor, @Nullable Color linkColor, @Nullable String liImg) {
StringBuilder builder = new StringBuilder().append("<style>\n");
String familyAndSize = "font-family:'" + font.getFamily() + "'; font-size:" + font.getSize() + "pt;";
builder.append("body, div, td, p {").append(familyAndSize);
if (fgColor != null)
builder.append(" color:#").append(ColorUtil.toHex(fgColor)).append(';');
builder.append("}\n");
builder.append("a {").append(familyAndSize);
if (linkColor != null)
builder.append(" color:#").append(ColorUtil.toHex(linkColor)).append(';');
builder.append("}\n");
builder.append("code {font-size:").append(font.getSize()).append("pt;}\n");
URL resource = liImg != null ? SystemInfo.class.getResource(liImg) : null;
if (resource != null) {
builder.append("ul {list-style-image:url('").append(StringUtil.escapeCharCharacters(resource.toExternalForm())).append("');}\n");
}
return builder.append("</style>").toString();
}
Aggregations