Search in sources :

Example 86 with Language

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);
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 87 with Language

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));
}
Also used : Language(org.intellij.lang.annotations.Language) XmlBuilder(com.android.tools.idea.XmlBuilder)

Example 88 with Language

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));
}
Also used : NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) JavaLanguage(com.intellij.lang.java.JavaLanguage) Language(org.intellij.lang.annotations.Language) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool)

Example 89 with Language

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;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) Language(org.intellij.lang.annotations.Language) JavaParameters(com.intellij.execution.configurations.JavaParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with Language

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();
}
Also used : URL(java.net.URL) Language(org.intellij.lang.annotations.Language)

Aggregations

Language (org.intellij.lang.annotations.Language)111 TableMetadata (com.facebook.presto.metadata.TableMetadata)25 Test (org.testng.annotations.Test)24 MaterializedResult (com.facebook.presto.testing.MaterializedResult)19 PsiFile (com.intellij.psi.PsiFile)18 MaterializedRow (com.facebook.presto.testing.MaterializedRow)11 List (java.util.List)11 Optional (java.util.Optional)11 Test (org.junit.Test)11 ImmutableList (com.google.common.collect.ImmutableList)10 Session (com.facebook.presto.Session)9 Constraint (com.facebook.presto.spi.Constraint)9 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)9 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)8 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)7 ExpectedValueProvider (com.facebook.presto.sql.planner.assertions.ExpectedValueProvider)7 PlanMatchPattern (com.facebook.presto.sql.planner.assertions.PlanMatchPattern)7 SortOrder (com.facebook.presto.common.block.SortOrder)6