use of com.intellij.util.text.StringTokenizer in project intellij-plugins by JetBrains.
the class AnnotationBackedDescriptorImpl method getEnumeratedValues.
@Override
public String[] getEnumeratedValues() {
@NonNls String[] enumerationValues = myEnumeratedValues;
if (enumerationValues == null) {
enumerationValues = ArrayUtil.EMPTY_STRING_ARRAY;
if (myEnumerated) {
if (JSCommonTypeNames.BOOLEAN_CLASS_NAME.equals(type)) {
enumerationValues = TRUE_FALSE;
} else {
final PsiElement element = getDeclaration();
JSAttributeNameValuePair pair = null;
if (element instanceof JSAttributeNameValuePair) {
pair = ((JSAttribute) element.getParent()).getValueByName(ENUMERATION_ATTR_NAME);
} else if (element instanceof JSAttributeListOwner) {
JSAttribute inspectableAttr = findInspectableAttr(element);
if (inspectableAttr != null) {
pair = inspectableAttr.getValueByName(ENUMERATION_ATTR_NAME);
}
}
if (pair != null) {
final String simpleValue = pair.getSimpleValue();
if (simpleValue != null) {
StringTokenizer tokenizer = new StringTokenizer(simpleValue, ", ");
enumerationValues = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreElements()) {
enumerationValues[i++] = tokenizer.nextElement();
}
}
}
}
}
myEnumeratedValues = enumerationValues;
}
return enumerationValues;
}
use of com.intellij.util.text.StringTokenizer in project intellij-plugins by JetBrains.
the class MxmlReferenceContributor method buildStateRefs.
private static PsiReference[] buildStateRefs(PsiElement element, boolean stateGroupsOnly) {
SmartList<PsiReference> refs = new SmartList<>();
StringTokenizer t = new StringTokenizer(StringUtil.unquoteString(element.getText()), FlexReferenceContributor.DELIMS);
while (t.hasMoreElements()) {
String val = t.nextElement();
int end = t.getCurrentPosition();
refs.add(new FlexReferenceContributor.StateReference(element, new TextRange(1 + end - val.length(), 1 + end), stateGroupsOnly));
}
return refs.toArray(new PsiReference[refs.size()]);
}
use of com.intellij.util.text.StringTokenizer in project intellij-plugins by JetBrains.
the class FlexCompilerHandler method consumeOutput.
private Result consumeOutput(final String command, @Nullable final CompilerMessagesBuffer messagesBuffer) throws IOException {
Result result = Result.OK;
String lastRead = "";
out: while (true) {
int read = out.read(buf);
if (read == -1) {
read = err.read(buf);
if (read > 0) {
messagesBuffer.addMessage(CompilerMessageCategory.ERROR, new String(buf, 0, read), null, -1, -1);
}
break;
}
@NonNls String output = lastRead + new String(buf, 0, read);
trace(TraceType.OUT, output);
StringTokenizer tokenizer = new StringTokenizer(output, "\r\n");
while (tokenizer.hasMoreElements()) {
@NonNls String s = tokenizer.nextElement().trim();
if (s.length() == 0)
continue;
if (s.startsWith("(fcsh)")) {
if (s.indexOf("need to repeat command") != -1) {
// special marker from idea-fcsh-fix;
// if fcsh-idea-fix fails for any reason it launches standard fcsh, so we need to repeat command
result = Result.NEED_TO_REPEAT_COMMAND;
} else if (s.indexOf("out of memory") != -1) {
result = Result.OUT_OF_MEMORY;
}
myCancelledReadErrStream = true;
myReadErrStreamAlarm.cancelAllRequests();
scanErrorStream(messagesBuffer);
break out;
}
if (s.startsWith(FCSH_ASSIGNED_MARKER) && command != null) {
int id = Integer.parseInt(s.substring(FCSH_ASSIGNED_MARKER.length(), s.indexOf(' ', FCSH_ASSIGNED_MARKER.length())));
commandToIdMap.put(command, id);
continue;
} else if (s.startsWith("fcsh: Target") && s.indexOf("not found") != -1) {
result = Result.TARGET_NOT_FOUND;
continue;
}
if (!tokenizer.hasMoreElements() && tokenizer.getCurrentPosition() == output.length()) {
lastRead = s + "\n";
break;
}
messagesBuffer.addMessage(CompilerMessageCategory.INFORMATION, s, null, -1, -1);
}
}
return result;
}
use of com.intellij.util.text.StringTokenizer in project intellij-community by JetBrains.
the class CreateClassUtil method createParentDirectories.
@NotNull
private static PsiDirectory createParentDirectories(@NotNull PsiDirectory directoryRoot, @NotNull String className) throws IncorrectOperationException {
final PsiPackage currentPackage = JavaDirectoryService.getInstance().getPackage(directoryRoot);
final String packagePrefix = currentPackage == null ? null : currentPackage.getQualifiedName() + ".";
final String packageName = extractPackage(packagePrefix != null && className.startsWith(packagePrefix) ? className.substring(packagePrefix.length()) : className);
final StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
while (tokenizer.hasMoreTokens()) {
String packagePart = tokenizer.nextToken();
PsiDirectory subdirectory = directoryRoot.findSubdirectory(packagePart);
if (subdirectory == null) {
directoryRoot.checkCreateSubdirectory(packagePart);
subdirectory = directoryRoot.createSubdirectory(packagePart);
}
directoryRoot = subdirectory;
}
return directoryRoot;
}
use of com.intellij.util.text.StringTokenizer in project intellij-community by JetBrains.
the class DocumentFoldingInfo method readExternal.
@Override
public void readExternal(final Element element) {
ApplicationManager.getApplication().runReadAction(() -> {
clear();
if (!myFile.isValid())
return;
final Document document = FileDocumentManager.getInstance().getDocument(myFile);
if (document == null)
return;
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getCachedPsiFile(document);
String date = null;
boolean canRestoreElement = psiFile != null && (!DumbService.getInstance(myProject).isDumb() || FoldingUpdate.supportsDumbModeFolding(psiFile));
for (final Object o : element.getChildren()) {
Element e = (Element) o;
Boolean expanded = Boolean.valueOf(e.getAttributeValue(EXPANDED_ATT));
if (ELEMENT_TAG.equals(e.getName())) {
String signature = e.getAttributeValue(SIGNATURE_ATT);
if (signature == null) {
continue;
}
FoldingInfo fi = new FoldingInfo(DEFAULT_PLACEHOLDER, expanded);
if (canRestoreElement) {
PsiElement restoredElement = FoldingPolicy.restoreBySignature(psiFile, signature);
if (restoredElement != null && restoredElement.isValid()) {
myPsiElements.add(SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(restoredElement));
restoredElement.putUserData(FOLDING_INFO_KEY, fi);
}
} else {
// Postponed initialization
mySerializedElements.add(new SerializedPsiElement(signature, fi));
}
} else if (MARKER_TAG.equals(e.getName())) {
if (date == null) {
date = getTimeStamp();
}
if (date.isEmpty())
continue;
if (!date.equals(e.getAttributeValue(DATE_ATT)) || FileDocumentManager.getInstance().isDocumentUnsaved(document))
continue;
StringTokenizer tokenizer = new StringTokenizer(e.getAttributeValue(SIGNATURE_ATT), ":");
try {
int start = Integer.valueOf(tokenizer.nextToken()).intValue();
int end = Integer.valueOf(tokenizer.nextToken()).intValue();
if (start < 0 || end >= document.getTextLength() || start > end)
continue;
RangeMarker marker = document.createRangeMarker(start, end);
myRangeMarkers.add(marker);
String placeholderAttributeValue = e.getAttributeValue(PLACEHOLDER_ATT);
String placeHolderText = placeholderAttributeValue == null ? DEFAULT_PLACEHOLDER : XmlStringUtil.unescapeIllegalXmlChars(placeholderAttributeValue);
FoldingInfo fi = new FoldingInfo(placeHolderText, expanded);
marker.putUserData(FOLDING_INFO_KEY, fi);
} catch (NoSuchElementException exc) {
LOG.error(exc);
}
} else {
throw new IllegalStateException("unknown tag: " + e.getName());
}
}
});
}
Aggregations