org.netbeans.api.annotations.common.NonNull Java Examples

The following examples show how to use org.netbeans.api.annotations.common.NonNull. 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: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
public static SearchType toSearchType(@NonNull final QuerySupport.Kind searchType) {
    switch (searchType) {
        case CAMEL_CASE:
            return org.netbeans.spi.jumpto.type.SearchType.CAMEL_CASE;
        case CASE_INSENSITIVE_CAMEL_CASE:
            return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_CAMEL_CASE;
        case CASE_INSENSITIVE_PREFIX:
            return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_PREFIX;
        case CASE_INSENSITIVE_REGEXP:
            return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_REGEXP;
        case EXACT:
            return org.netbeans.spi.jumpto.type.SearchType.EXACT_NAME;
        case PREFIX:
            return org.netbeans.spi.jumpto.type.SearchType.PREFIX;
        case REGEXP:
            return org.netbeans.spi.jumpto.type.SearchType.REGEXP;
        default:
            throw new IllegalArgumentException(String.valueOf(searchType));
    }
}
 
Example #2
Source File: DocumentIndexImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private DocumentIndexImpl (
        @NonNull final Index index,
        @NonNull final DocumentIndexCache cache) {
    assert index != null;
    assert cache != null;
    this.luceneIndex = index;
    this.cache = cache;
    Convertor<IndexDocument,Document> _addConvertor = null;
    Convertor<Document,IndexDocument> _queryConvertor = null;
    if (cache instanceof DocumentIndexCache.WithCustomIndexDocument) {
        final DocumentIndexCache.WithCustomIndexDocument cacheWithCustomDoc =
                (DocumentIndexCache.WithCustomIndexDocument) cache;
        _addConvertor = cacheWithCustomDoc.createAddConvertor();
        _queryConvertor = cacheWithCustomDoc.createQueryConvertor();
    }
    addConvertor = _addConvertor != null ? _addConvertor : DEFAULT_ADD_CONVERTOR;
    queryConvertor = _queryConvertor != null ? _queryConvertor : DEFAULT_QUERY_CONVERTOR;
    if (index instanceof Index.Transactional) {
        this.txLuceneIndex = (Index.Transactional)index;
    } else {
        this.txLuceneIndex = null;
    }
}
 
Example #3
Source File: EditHistory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void add(@NonNull EditHistory history) {
    history.previous = this;
    history.version = version+1;

    // Chop off old history. We only need the most recent versions. Typically
    // we only need the most recent history, but in some cases (e.g. when documents
    // are edited during a parse job, the job gets split in two so we need to combine
    // the edit histories)
    if (history.version % MAX_KEEP == 0) {
        EditHistory curr = history;
        for (int i = 0; i < MAX_KEEP; i++) {
            curr = curr.previous;
            if (curr == null) {
                return;
            }
        }
        curr.previous = null;
    }
}
 
Example #4
Source File: BrokenReferencesCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized void notify (
    @NonNull final ProjectProblemsProvider.Status status,
    @NullAllowed final String message) {
    if (message != null) {
        switch (status) {
            case RESOLVED:
                nls.setInformationMessage(message);
                break;
            case RESOLVED_WITH_WARNING:
                nls.setWarningMessage(message);
                break;
            case UNRESOLVED:
                nls.setErrorMessage(message);
                break;
            default:
                throw new IllegalStateException(status.name());
        }
    }
}
 
Example #5
Source File: RemotePlatformProjectSaver.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void save(@NonNull final Project project) {
    Parameters.notNull("project", project);         //NOI18N
    final Runnable action = new Runnable() {
        @Override
        public void run() {
            try {
                final boolean hasExtension = Utilities.hasRemoteExtension(project);
                final Utilities.UpdateConfigResult res = Utilities.updateRemotePlatformConfigurations(project);
                if (!hasExtension && res.hasRemotePlatform()) {
                    try {
                        Utilities.addRemoteExtension(project);
                        ProjectManager.getDefault().saveProject(project);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            } catch (IOException ioe) {
                Exceptions.printStackTrace(ioe);
            }
        }
    };
    runDeferred(action);
}
 
Example #6
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static long calculateCRC(@NonNull final InputStream in) throws IOException {
    final CRC32 crc = new CRC32();
    int last = -1;
    int curr;
    while ((curr = in.read()) != -1) {
        if (curr != '\n' && last == '\r') { //NOI18N
            crc.update('\n');               //NOI18N
        }
        if (curr != '\r') {                 //NOI18N
            crc.update(curr);
        }
        last = curr;
    }
    if (last == '\r') {                     //NOI18N
        crc.update('\n');                   //NOI18N
    }
    return crc.getValue();
}
 
Example #7
Source File: JavaParsingContext.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
public FQN2Files getFQNs() throws IOException {
    if (fqn2Files == null) {
        fqn2Files = FQN2Files.forRoot(ctx.getRootURI());
    }
    return fqn2Files;
}
 
Example #8
Source File: J2SEProject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private LogicalViewProviders.CompileOnSaveBadge newCoSBadge() {
    return new LogicalViewProviders.CompileOnSaveBadge() {
        @Override
        public boolean isBadgeVisible() {
            return !J2SEProjectUtil.isCompileOnSaveEnabled(J2SEProject.this) &&
                J2SEProjectUtil.isCompileOnSaveSupported(J2SEProject.this);
        }
        @Override
        public boolean isImportant(@NonNull final String propertyName) {
            return ProjectProperties.COMPILE_ON_SAVE.equals(propertyName) ||
            propertyName.startsWith(ProjectProperties.COMPILE_ON_SAVE_UNSUPPORTED_PREFIX);
        }
    };
}
 
Example #9
Source File: TaskProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void callUserTask(
        final @NonNull UserTask task,
        final @NonNull ResultIterator resultIterator) throws Exception {
    assert task != null;
    assert resultIterator != null;
    assert !Thread.holdsLock(INTERNAL_LOCK);
    assert parserLock.isHeldByCurrentThread();
    task.run(resultIterator);
}
 
Example #10
Source File: J2SEProjectUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of property names which need to be tested for broken references.
 * @param project to return property names for
 * @return the list of breakable properties
 */
public static String[] getBreakableProperties(@NonNull final J2SEProject project) {
    SourceRoots roots = project.getSourceRoots();
    String[] srcRootProps = roots.getRootProperties();
    roots = project.getTestSourceRoots();
    String[] testRootProps = roots.getRootProperties();
    String[] result = new String [BREAKABLE_PROPERTIES.length + srcRootProps.length + testRootProps.length];
    System.arraycopy(BREAKABLE_PROPERTIES, 0, result, 0, BREAKABLE_PROPERTIES.length);
    System.arraycopy(srcRootProps, 0, result, BREAKABLE_PROPERTIES.length, srcRootProps.length);
    System.arraycopy(testRootProps, 0, result, BREAKABLE_PROPERTIES.length + srcRootProps.length, testRootProps.length);
    return result;
}
 
Example #11
Source File: LineDocumentUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Tests whether the line contains only whitespace characters.
 * @param doc document to operate on
 * @param offset position anywhere on the tested line
 * @return whether the line is empty or not
 */
public static boolean isLineWhitespace(@NonNull LineDocument doc, int offset)
throws BadLocationException
{
    checkOffsetValid(doc, offset);
    return getLineFirstNonWhitespace(doc, offset) == -1;
}
 
Example #12
Source File: PatchModuleFileManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
PatchModuleFileManager(
        @NonNull final JavaFileManager binDelegate,
        @NonNull final JavaFileManager srcDelegate,
        @NonNull ClassPath src) {
    this.binDelegate = binDelegate;
    this.srcDelegate = srcDelegate;
    this.src = src;
    this.patches = new HashMap<>();
    this.roots = new HashMap<>();
}
 
Example #13
Source File: Context.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @NonNull Set<Modifier> modifiers(@NonNull Variable variable) {
    final Element e = ctx.getInfo().getTrees().getElement(getSingleVariable(variable));

    if (e == null) {
        return Collections.unmodifiableSet(EnumSet.noneOf(Modifier.class));
    }

    return Collections.unmodifiableSet(e.getModifiers());
}
 
Example #14
Source File: FileUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static URI getDirURI(@NonNull File root, @NonNull String path) {
    String pth = path.trim();
    pth = pth.replaceFirst("^\\./", ""); //NOI18N
    pth = pth.replaceFirst("^\\.\\\\", ""); //NOI18N
    File src = FileUtilities.resolveFilePath(root, pth);
    return Utilities.toURI(FileUtil.normalizeFile(src));
}
 
Example #15
Source File: SourceRoots.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean validFiles(@NonNull Iterable<? extends FileObject> files) {
    for (FileObject file : files) {
        if (!file.isValid()) {
            return false;
        }
    }
    return true;
}
 
Example #16
Source File: WhiteListImplementationBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Integer getName(@NonNull final String name) {
    assert name != null;
    final int hc = name.hashCode() & hashMask;
    final byte[] sbytes = decode(name);
    Entry entry = slots[hc];
    while (entry != null && !contentEquals(entry,sbytes)) {
        entry = entry.next;
    }
    return entry == null ? null : entry.pos;
}
 
Example #17
Source File: BaseActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
BrokenAPIActionDecorator(@NonNull final JavaActionProvider.ScriptAction delegate) {
    super(
            delegate.getCommand(),
            null,
            delegate.getActionFlags().contains(ActionProviderSupport.ActionFlag.PLATFORM_SENSITIVE),
            delegate.getActionFlags().contains(ActionProviderSupport.ActionFlag.JAVA_MODEL_SENSITIVE),
            delegate.getActionFlags().contains(ActionProviderSupport.ActionFlag.SCAN_SENSITIVE),
            delegate.getActionFlags().contains(ActionProviderSupport.ActionFlag.COS_ENABLED));
    this.delegate = delegate;
    this.frame = new ThreadLocal<>();
}
 
Example #18
Source File: ServerUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Build domains folder for GlassFish server using GlassFish version.
 * <p/>
 * Domains folder name is build using all versions number parts
 * (<code>major</code>, <code>minor</code>, <code>update</code>
 * and <code>build</code>). But <code>update</code> and <code>build</code>
 * <p/>
 * values are used only when they are not part of zero only sequence.<br/>
 * Folder names for individual GlassFish server versions will be:<ul>
 * <li><code>GF_3.0</code> for GlassFish 3</li>
 * <li><code>GF_3.1</code> for GlassFish 3.1</li>
 * <li><code>GF_3.0.1</code> for GlassFish 3.0.1</li>
 * <li><code>GF_3.1.2.2</code> for GlassFish 3.1.2.2</li><ul/>
 * <p/>
 * @param instance GlassFish server to build domains folder for.
 * @return Domains folder.
 */
public static String getDomainsFolder(@NonNull GlassfishInstance instance) {
    GlassFishVersion version = instance.getVersion();
    if (version == null) {
        throw new IllegalStateException(NbBundle.getMessage(
                GlassfishInstance.class,
                "GlassfishInstance.getDomainsFolder.versionIsNull",
                instance.getDisplayName()));
    }
    boolean useBuild = version.getBuild() > 0;
    boolean useUpdate = useBuild || version.getUpdate() > 0;
    // Allocate 2 characters per version number part and 1 character
    // per separator.
    StringBuilder sb = new StringBuilder(DOMAINS_FOLDER_PREFIX.length() + 5
            + (useUpdate ? (useBuild ? 6 : 3) : 0));
    sb.append(DOMAINS_FOLDER_PREFIX);
    sb.append(Short.toString(version.getMajor()));
    sb.append(GlassFishVersion.SEPARATOR);
    sb.append(Short.toString(version.getMinor()));
    if (useUpdate) {
        sb.append(GlassFishVersion.SEPARATOR);
        sb.append(Short.toString(version.getUpdate()));
        if (useBuild) {
            sb.append(GlassFishVersion.SEPARATOR);
            sb.append(Short.toString(version.getBuild()));
        }
    }
    return sb.toString();
}
 
Example #19
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private @NonNull String getVariable(@NonNull Element el) {
    String var = element2Variable.get(el);

    if (var == null) {
        element2Variable.put(el, var = "$" + currentVariableIndex++);
    }

    return var;
}
 
Example #20
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Sets test runtime module path properties.
 * @param modulePathProperties  the names of properties containing the test runtime module path, by default {@link ProjectProperties#RUN_TEST_MODULEPATH}
 * @return {@link Builder}
 * @since 1.86
 */
@NonNull
public Builder setRunTestModulepathProperties(@NonNull final String[] modulePathProperties) {
    Parameters.notNull("modulePathProperties", modulePathProperties);
    this.testModuleExecutePath = Arrays.copyOf(modulePathProperties, modulePathProperties.length);
    return this;
}
 
Example #21
Source File: TimeStamps.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Collection<? extends String> getEnclosedFiles(@NonNull final String relativePath) {
    final Set<String> res = new HashSet<String>();
    for (String filePath : timestamps.keySet()) {
        if (filePath.startsWith(relativePath)) {
            res.add(filePath);
        }
    }
    return res;
}
 
Example #22
Source File: EntityMappingsMetadataModelHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
public Builder setSourcePath(@NullAllowed ClassPath sourcePath) {
    if (sourcePath == null) {
        sourcePath = ClassPath.EMPTY;
    }
    this.sourcePath = sourcePath;
    return this;
}
 
Example #23
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static RemotePlatform findRemotePlatform(@NonNull final String platformId) {
    Parameters.notNull("platformId", platformId);   //NOI18N
    final JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(
            null,
            new Specification(RemotePlatform.SPEC_NAME, null));
    for (JavaPlatform platform : platforms) {
        final String antPlatformName = platform.getProperties().get(RemotePlatform.PLAT_PROP_ANT_NAME);
        if (platformId.equals(antPlatformName) && (platform instanceof RemotePlatform)) {
            return (RemotePlatform) platform;
        }
    }
    return null;
}
 
Example #24
Source File: RootsListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@org.netbeans.api.annotations.common.SuppressWarnings(
value="DMI_COLLECTION_OF_URLS",
justification="URLs have never host part")
synchronized boolean addBinary(@NonNull final URL root) {
    if (binariesListener != null && !binaryRoots.containsKey(root)) {
        File f = null;
        final URL archiveUrl = FileUtil.getArchiveFile(root);
        try {
            final URI uri = archiveUrl != null ? archiveUrl.toURI() : root.toURI();
            if (uri.getScheme().equals("file")) { //NOI18N
                f = BaseUtilities.toFile(uri);
            }
        } catch (URISyntaxException use) {
            LOG.log (
                Level.INFO,
                "Can't convert: {0} to java.io.File, due to: {1}, (archive url: {2}).", //NOI18N
                new Object[]{
                    root,
                    use.getMessage(),
                    archiveUrl
                });
        }
        if (f != null) {
            if (archiveUrl != null) {
                // listening on an archive file
                safeAddFileChangeListener(binariesListener, f);
            } else {
                // listening on a folder
                safeAddRecursiveListener(binariesListener, f, null);
            }
            binaryRoots.put(root, Pair.of(f, archiveUrl != null));
        }
    }
    return listens;
}
 
Example #25
Source File: LayeredDocumentIndex.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean filtered(
    @NullAllowed final IndexDocument doc,
    @NonNull final Set<? extends String> filter) {
    return doc == null ?
        true :
        filter.contains(doc.getPrimaryKey());
}
 
Example #26
Source File: FlaggedClassPathImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void setFlags(@NonNull final Set<ClassPath.Flag> flags) {
    Parameters.notNull("flags", flags); //NOI18N
    synchronized (this) {
        this.flags = flags;
    }
    support.firePropertyChange(PROP_FLAGS, null, null);
}
 
Example #27
Source File: ServerInstance.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Set<ServerLibraryDependency> getDeployableDependencies(
        @NonNull Set<ServerLibraryDependency> dependencies) {
    ServerLibraryManager libraryManager = getDisconnectedServerLibraryManager();

    Set<ServerLibraryDependency> result = Collections.emptySet();
    if (libraryManager != null) {
        result = libraryManager.getDeployableDependencies(dependencies);
    }

    return result;
}
 
Example #28
Source File: BinaryAnalyser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
void visit(@NonNull final Method m) {
    final String name = m.getName();
    if (getIdentLevel().accepts(m) &&
        !m.isSynthetic() &&
        !isInit(name) &&
        !isAccessorMethod(name)) {
        addIdent(name);
    }
    super.visit(m);
}
 
Example #29
Source File: Worker.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
Strategy createStrategy() {
    return new FSStrategy();
}
 
Example #30
Source File: CompilerOptionsQueryImplementation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Utility method the tokenize the command line into individual arguments.
 * @param commandLine the command line to be tokenized
 * @return a list of command line arguments
 */
protected final List<String> parseLine(@NonNull final String commandLine) {
    final List<String> result = new ArrayList<>();
    StringBuilder current = new StringBuilder();
    boolean escape = false, doubleQuote = false, quote = false;
    for (int i = 0; i < commandLine.length(); i++) {
        final char c = commandLine.charAt(i);
        switch (c) {
            case '\\':  //NOI18N
                if (!quote) {
                    escape = !escape;
                }
                break;
            case '\'':  //NOI18N
                if (!escape && !doubleQuote) {
                    quote = !quote;
                }
                escape = false;
                break;
            case '"':   //NOI18N
                if (!escape && !quote) {
                    doubleQuote = !doubleQuote;
                }
                escape = false;
                break;
            case ' ':   //NOI18N
            case '\t':  //NOI18N
                if (!escape && !quote && !doubleQuote) {
                    if (current.length() > 0) {
                        result.add(current.toString());
                        current = new StringBuilder();
                    }
                } else {
                    current.append(c);
                }
                escape = false;
                break;
            default:
                current.append(c);
                escape = false;
                break;
        }
    }
    if (current.length() > 0) {
        result.add(current.toString());
    }
    return Collections.unmodifiableList(result);
}