org.jetbrains.annotations.NonNls Java Examples

The following examples show how to use org.jetbrains.annotations.NonNls. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddToAppUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static <T> T getStaticFieldValue(@NotNull Class objectClass,
                                        @Nullable("null means any type") Class<T> fieldType,
                                        @NotNull @NonNls String fieldName) {
  try {
    final Field field = findAssignableField(objectClass, fieldType, fieldName);
    if (!Modifier.isStatic(field.getModifiers())) {
      throw new IllegalArgumentException("Field " + objectClass + "." + fieldName + " is not static");
    }
    field.setAccessible(true);
    //noinspection unchecked
    return (T)field.get(null);
  }
  catch (NoSuchFieldException | IllegalAccessException e) {
    return null;
  }
}
 
Example #2
Source File: AddToAppUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static <T> T getStaticFieldValue(@NotNull Class objectClass,
                                        @Nullable("null means any type") Class<T> fieldType,
                                        @NotNull @NonNls String fieldName) {
  try {
    final Field field = findAssignableField(objectClass, fieldType, fieldName);
    if (!Modifier.isStatic(field.getModifiers())) {
      throw new IllegalArgumentException("Field " + objectClass + "." + fieldName + " is not static");
    }
    field.setAccessible(true);
    //noinspection unchecked
    return (T)field.get(null);
  }
  catch (NoSuchFieldException | IllegalAccessException e) {
    return null;
  }
}
 
Example #3
Source File: ConsoleLogToolWindowFactory.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
static void createContent(Project project, ToolWindow toolWindow, ConsoleLogConsole console, String title) {
    // update default Event Log tab title
    ContentManager contentManager = toolWindow.getContentManager();
    Content generalContent = contentManager.getContent(0);
    if (generalContent != null && contentManager.getContentCount() == 1) {
        generalContent.setDisplayName("General");
    }

    final Editor editor = console.getConsoleEditor();

    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
        @Override
        public Object getData(@NonNls String dataId) {
            return PlatformDataKeys.HELP_ID.is(dataId) ? ConsoleLog.HELP_ID : super.getData(dataId);
        }
    };
    panel.setContent(editor.getComponent());
    panel.addAncestorListener(new LogShownTracker(project));

    ActionToolbar toolbar = createToolbar(project, editor, console);
    toolbar.setTargetComponent(editor.getContentComponent());
    panel.setToolbar(toolbar.getComponent());

    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, title, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
}
 
Example #4
Source File: GradleImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@NotNull
protected String injectRepo(@NonNls @Language("Groovy") String config) {
  config = "allprojects {\n" +
           "  repositories {\n" +
           "    maven {\n" +
           "        url 'http://maven.labs.intellij.net/repo1'\n" +
           "    }\n" +
           "  }" +
           "}\n" + config;
  return config;
}
 
Example #5
Source File: IdentifierPSINode.java    From jetbrains-plugin-sample with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Alter this node to have text specified by the argument. Do this by
 *  creating a new node through parsing of an ID and then doing a
 *  replace.
 */
@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
	if ( getParent()==null ) return this; // weird but it happened once
	/*
	IElementType elType = getParent().getNode().getElementType();
	String kind = "??? ";
	if ( elType instanceof RuleIElementType ) {
		int ruleIndex = ((RuleIElementType) elType).getRuleIndex();
		if ( ruleIndex == RULE_call_expr ) {
			kind = "call ";
		}
		else if ( ruleIndex == RULE_statement ) {
			kind = "assign ";
		}
		else if ( ruleIndex == RULE_function ) {
			kind = "func def ";
		}
	}
	System.out.println("IdentifierPSINode.setName("+name+") on "+
		                   kind+this+" at "+Integer.toHexString(this.hashCode()));
	*/
	PsiElement newID = Trees.createLeafFromText(getProject(),
	                                            SampleLanguage.INSTANCE,
	                                            getContext(),
	                                            name,
	                                            SampleParserDefinition.ID);
	if ( newID!=null ) {
		return this.replace(newID); // use replace on leaves but replaceChild on ID nodes that are part of defs/decls.
	}
	return this;
}
 
Example #6
Source File: MavenTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected VirtualFile updateSettingsXmlFully(@NonNls @Language("XML") String content) throws IOException {
  File ioFile = new File(myDir, "settings.xml");
  ioFile.createNewFile();
  VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
  setFileContent(f, content, true);
  getMavenGeneralSettings().setUserSettingsFile(f.getPath());
  return f;
}
 
Example #7
Source File: BPMNFileSchemaProvider.java    From intellij-bpmn-editor with GNU General Public License v3.0 5 votes vote down vote up
private static XmlFile getReference(@NotNull @NonNls String url, @NotNull Module module) {
    if (url.equalsIgnoreCase("http://bpmn.sourceforge.net")) {
        return null;
    }
    final URL resource = BPMNFileSchemaProvider.class.getResource(BPMNModelConstants.BPMN_SCHEMA_BASEURI + BPMNModelConstants.BPMN_SYSTEM_ID);
    final VirtualFile fileByURL = VfsUtil.findFileByURL(resource);
    if (fileByURL == null) {
        return null;
    }

    PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(fileByURL);
    return (XmlFile) psiFile.copy();
}
 
Example #8
Source File: AbstractCreateFormAction.java    From react-templates-plugin with MIT License 5 votes vote down vote up
protected String createFormBody(@Nullable String fqn, @NonNls String formName, String layoutManager) throws IncorrectOperationException {
        String s = "";
        try {
            s = FileUtil.loadTextAndClose(getClass().getResourceAsStream(formName));
        } catch (IOException e) {
//      throw new IncorrectOperationException(RTBundle.message("error.cannot.read", formName), (Throwable)e);
        }
        s = fqn == null ? StringUtil.replace(s, "bind-to-class=\"$CLASS$\"", "") : StringUtil.replace(s, "$CLASS$", fqn);
        s = StringUtil.replace(s, "$LAYOUT$", layoutManager);
        return StringUtil.convertLineSeparators(s);
    }
 
Example #9
Source File: BashSdkLexerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
protected void doTest(@NonNls String text, @Nullable String expected, @NotNull Lexer lexer) {
    String result = printTokens(text, 0, lexer);

    if (expected != null) {
        assertSameLines(expected, result);
    }
    else {
        // changed from the original code in LexerTestCase
        // LexerTestCase is expecting that the test is part of the IntelliJ repository
        // BashSupport is not, so we get rid of the call to PathManager.getHomePath()
        assertSameLinesWithFile(getDirPath() + "/" + getTestName(true) + ".txt", result);
    }
}
 
Example #10
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@org.jetbrains.annotations.Nullable
@Override
public Object getData(@NonNls String s) {
  if (PlatformDataKeys.COPY_PROVIDER.is(s) || PlatformDataKeys.CUT_PROVIDER.is(s) || PlatformDataKeys.PASTE_PROVIDER.is(s)) {
    return this;
  }
  return null;
}
 
Example #11
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getLocations(@NotNull @NonNls final String namespace, @NotNull final XmlFile context) throws ProcessCanceledException {
    Set<String> locations = new HashSet<>();
    final Module module = ModuleUtil.findModuleForPsiElement(context);
    if (module == null) {
        return null;
    }
    try {
        final Map<String, XmlFile> schemas = getSchemas(module);
        for (Map.Entry<String, XmlFile> entry : schemas.entrySet()) {
            final String s = getNamespace(entry.getValue(), context.getProject());
            if (s != null && s.equals(namespace)) {
                if (!entry.getKey().contains("mule-httpn.xsd")) {
                    locations.add(entry.getKey()); //Observe the formatting rules
                    XmlFile schemaFile = entry.getValue();
                    try {
                        String url = schemaFile.getVirtualFile().getUrl();
                        if (url != null) {
                            if (url.startsWith("jar://"))
                                url = url.substring(6);
                            ExternalResourceManager.getInstance().addResource(namespace, url);
                        }
                    } catch (Throwable ex) {
                        Notifications.Bus.notify(new Notification("Schema Provider", "Schema Provider", ex.toString(),
                                NotificationType.ERROR));
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
Example #12
Source File: JreSettings.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NonNls
@Nullable
public static String getProperty(@NotNull @NonNls String key, @Nullable String defaultValue) {
    if (OVERRIDES.containsKey(key)) {
        String ret = OVERRIDES.get(key);
        if (ret == null) {
            ret = defaultValue;
        }
        return ret;
    }
    return System.getProperty(key, defaultValue);
}
 
Example #13
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Balloon showPopup(
  InspectorGroupManagerService inspectorGroupManagerService,
  Project project,
  Component component,
  @Nullable DiagnosticsNode node,
  @NonNls InspectorService.Location location,
  FlutterDartAnalysisServer service,
  Point point
) {
  final Balloon balloon = showPopupHelper(inspectorGroupManagerService, project, node, location, service);
  balloon.show(new RelativePoint(component, point), Balloon.Position.above);
  return balloon;
}
 
Example #14
Source File: BashVarImpl.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public PsiElement setName(@NonNls @NotNull String newName) throws IncorrectOperationException {
    if (!BashIdentifierUtil.isValidNewVariableName(newName)) {
        throw new IncorrectOperationException("Invalid variable name");
    }

    PsiElement replacement = BashPsiElementFactory.createVariable(getProject(), newName, isParameterExpansion());
    return BashPsiUtils.replaceElement(this, replacement);
}
 
Example #15
Source File: AbstractCreateElementActionBase.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected static PsiClass createClassFromTemplate( @NotNull PsiDirectory directory,
                                                   @NotNull String className,
                                                   @NotNull String templateName,
                                                   @NonNls String... parameters )
    throws IncorrectOperationException
{
    String classFileName = className + "." + StdFileTypes.JAVA.getDefaultExtension();
    PsiFile file = createFromTemplateInternal( directory, className, classFileName, templateName, parameters );
    return ( (PsiJavaFile) file ).getClasses()[ 0 ];
}
 
Example #16
Source File: AbstractInspectionTestCase.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Pattern("[a-zA-Z_0-9.-]+")
@Override
@NotNull
@NonNls
public String getID() {
    return delegate.getID();
}
 
Example #17
Source File: SqliteMagicLightModifierList.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
public void setModifierProperty(@PsiModifier.ModifierConstant @NotNull @NonNls String name, boolean value) throws IncorrectOperationException {
  if (value) {
    addModifier(name);
  } else {
    if (hasModifierProperty(name)) {
      removeModifier(name);
    }
  }
}
 
Example #18
Source File: SqliteMagicLightModifierList.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
private void removeModifier(@PsiModifier.ModifierConstant @NotNull @NonNls String name) {
  final Collection<String> myModifiers = collectAllModifiers();
  myModifiers.remove(name);

  clearModifiers();

  for (String modifier : myModifiers) {
    addModifier(modifier);
  }
}
 
Example #19
Source File: JreSettings.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NonNls
@Nullable
public static String getEnv(@NotNull @NonNls String key) {
    if (OVERRIDES.containsKey(key)) {
        // even if null!
        return OVERRIDES.get(key);
    }
    return System.getenv(key);
}
 
Example #20
Source File: SqliteMagicLightModifierList.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@Override
@NotNull
public PsiAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) {
  final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
  final PsiAnnotation psiAnnotation = elementFactory.createAnnotationFromText('@' + qualifiedName, null);
  myAnnotations.put(qualifiedName, psiAnnotation);
  return psiAnnotation;
}
 
Example #21
Source File: VcsDockedComponent.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public boolean addVcsTab(@NotNull @NonNls String title,
        @NotNull JComponent component,
        boolean showTab,
        boolean replaceExistingComponent) {
    if (component instanceof Disposable) {
        Disposer.register(this, (Disposable) component);
    }
    final ToolWindow toolW = getToolWindow();
    if (toolW == null) {
        // cannot do anything
        return false;
    }
    final ContentManager contentManager = getToolWindow().getContentManager();
    final Content existingContent = contentManager.findContent(title);
    if (existingContent != null) {
        if (!replaceExistingComponent) {
            contentManager.setSelectedContent(existingContent);
            return true;
        }
        else if (!existingContent.isPinned()) {
            contentManager.removeContent(existingContent, true);
            existingContent.release();
        }
    }

    final Content content = contentManager.getFactory().createContent(component, title, false);
    contentManager.addContent(content);
    if (showTab) {
        getToolWindow().activate(null, false);
    }

    return true;
}
 
Example #22
Source File: PolygeneApplicationComponent.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public final FileTemplateGroupDescriptor getFileTemplatesDescriptor()
{
    FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(
        message( "polygene.file.template.group.title" ), null
    );

    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    for( @NonNls String template : FILE_TEMPLATES )
    {
        Icon icon = fileTypeManager.getFileTypeByFileName( template ).getIcon();
        group.addTemplate( new FileTemplateDescriptor( template, icon ) );
    }

    return group;
}
 
Example #23
Source File: NewVueActionBase.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static PsiFile createFileFromTemplate(final PsiDirectory directory,
                                                String className,
                                                @NonNls String templateName,
                                                @NonNls String... parameters) throws IncorrectOperationException {
    final String ext = "." + VueFileType.INSTANCE.getDefaultExtension();
    String filename = (className.endsWith(ext)) ? className : className + ext;
    return VueTemplatesFactory.createFromTemplate(directory, className, filename, templateName, parameters);
}
 
Example #24
Source File: NewWeFileActionBase.java    From weex-language-support with MIT License 5 votes vote down vote up
protected PsiFile createFileFromTemplate(final PsiDirectory directory,
                                         String className,
                                         @NonNls String templateName,
                                         @NonNls String... parameters) throws IncorrectOperationException {
    final String ext = "." + WeexFileType.INSTANCE.getDefaultExtension();
    String filename = (className.endsWith(ext)) ? className : className + ext;
    return WeexTemplateFactory.createFromTemplate(directory, className, filename, templateName, parameters);
}
 
Example #25
Source File: SerializableValueConstructionException.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
public SerializableValueConstructionException(@NonNls String message) {
	super(message);
}
 
Example #26
Source File: BashCodeInsightFixtureTestCase.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
/**
 * Return absolute path to the test data. Not intended to be overridden.
 *
 * @return absolute path to the test data.
 */
@NonNls
protected String getTestDataPath() {
    String basePath = getBasePath();
    return BashTestUtils.getBasePath() + (basePath.endsWith(File.separator) ? "" : File.separator) + basePath;
}
 
Example #27
Source File: CreateReferenceIntentionActionTest.java    From intellij-swagger with MIT License 4 votes vote down vote up
@Override
@NonNls
protected String getBasePath() {
  return "/intention/createreference/json";
}
 
Example #28
Source File: ADCData.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** A universally unique id used for identifying which part of the config belongs to which {@link ADCData} instance */
@NonNls
@NotNull String getDataID();
 
Example #29
Source File: SimpleToolWindowPanel.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
public Object getData(@NonNls String dataId) {
  return QuickActionProvider.KEY.is(dataId) && myProvideQuickActions ? this : null;
}
 
Example #30
Source File: JsonnetTokenType.java    From intellij-jsonnet with Apache License 2.0 4 votes vote down vote up
public JsonnetTokenType(@NotNull @NonNls String debugName) {
    super(debugName, JsonnetLanguage.INSTANCE);
}